akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9+7;
int32_t main()
{
    int n;
    cin>>n;
    vector<int>A(n);
    int s = 0;
    int x = 0;
    for (int i = 0;i<n;i++){cin>>A[i];s+=A[i];s%=mod;if (A[i]>=1e5)A[i]-=mod;x+=A[i]*A[i];x%=mod;}
    if (s>=1e5)s-=mod;
    s = s * s;
    s%=mod;
    x%=mod;
    int ans = (s - x)%mod;
    if (ans%2!=0)ans+=mod;
    ans/=2;
    cout<<(ans+mod)%mod;
    return 0;
}

Measured memory_bytes: 4724
firstInput=list(map(int,input().split()))
even=firstInput[0]
odd=firstInput[1]
evenSum=0
oddSum=0
if even>=2:
  nFactorial=1
  nMinusKFactorial=1
  for i in range(1,even+1): nFactorial*=i
  for i in range(1,even-1): nMinusKFactorial*=i
  evenSum=nFactorial/(2*nMinusKFactorial)
if odd>=2:
  nFactorial=1
  nMinusKFactorial=1
  for i in range(1,odd+1): nFactorial*=i
  for i in range(1,odd-1): nMinusKFactorial*=i
  oddSum=nFactorial/(2*nMinusKFactorial)
print(int(evenSum+oddSum))

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

int main() {
    int n, ans=0;
    cin>>n;

    vector<int> b(n-1);
    for(int i=0; i<n-1; i++){
        cin>>b.at(i);
    }

    ans+=b.at(n-2);
    ans+=b.at(0);

    for(int i=0; i<n-2; i++) ans+=min(b.at(i),b.at(i+1));

    cout<<ans<<endl;

}


Measured memory_bytes: 256
// READ & UNDERSTAND
// ll, int overflow, array bounds
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

ll dp[101][4][4][4];

void jia(ll &a, ll b){
	a%=MOD; b%=MOD; a+=b; a%=MOD;
}

// A=0, G=1, C=2, T=3
// violates rule 3 if any of these, AGC, GAC, ACG, A?GC, AG?C , appears as substring
//                                  012, 102, 021, 0?12, 01?2
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	dp[0][3][3][3]=1LL;
	for(int len=0; len<n; len++){
		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				for(int k=0; k<4; k++){
					for(int add=0; add<4; add++){
						if(!dp[len][i][j][k])continue;
						if(add==2 and k==1 and j==0)continue;
						if(add==2 and k==0 and j==1)continue;
						if(add==1 and k==2 and j==0)continue;
						if(add==2 and k==1 and i==0)continue;
						if(add==2 and j==1 and i==0)continue;
						jia(dp[len+1][j][k][add],dp[len][i][j][k]);
					}
				}
			}
		}
	}
	ll ans = 0LL;
	for(int i=0; i<4; i++)
		for(int j=0; j<4; j++)
			for(int k=0; k<4; k++)
				jia(ans,dp[n][i][j][k]);
	cout << ans << endl;
}	


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 
public class Main {
 
	public static final MyScanner in = new MyScanner();
 
	public static final Map<Integer, Integer> map = new HashMap<>();
	public static final Integer ZERO = Integer.valueOf(0);
	public static int N;
	public static int X;
	public static int Y;
 
	public static void main(String[] args) {
 
		N = in.nextInt();
		X = in.nextInt();
		Y = in.nextInt();
 
		for(int i=1;i<N;i++) {
			for(int j=i+1;j<N+1;j++) {
				int warp_route = Math.abs(i-X)+1 + Math.abs(Y-j);
				int simple = j - i;
				countUp(Math.min(warp_route, simple));
			}
		}
		for(int i=1;i<N;i++) print(i);
	}

	public static void countUp(int len) {
		int cnt = map.getOrDefault(len, ZERO);
		map.put(len, cnt+1);
	}
 
	public static void print(int k) {
		System.out.println(map.getOrDefault(k, ZERO));
	}
 
	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

Measured memory_bytes: 59676
n=int(input())
l=list(map(int,input().split()))
max=max(l)
cnt=0
c=0
for i in range(n):
    if l[i]==max and cnt==0:
        cnt+=1
    else:
        c+=l[i]
if max<c:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
N = int(input())
a = list(map(int, input().split()))
Sum = 1
mod = 1000000007

a.sort()
data = []
if N % 2 == 0:
    for i in range(int(N / 2)):
        data.append(1 + i * 2)
        data.append(1 + i * 2)
else:
    data.append(0)
    for i in range(1, N // 2 + 1):
        data.append(i * 2)
        data.append(i * 2)

if a == data:
    for i in range(N // 2):
        Sum *= 2
        Sum %= mod
    print(Sum)
else:
    print(0)


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

#define all(x) begin(x), end(x)
typedef long long ll;
using namespace std;

const ll MAXN = 1e5 + 5;
ll N;
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    vector<array<ll, 4>> probs(N);
    for (ll i = 0; i < N; i++) {
        cin >> probs[i][0] >> probs[i][1];
    }
    ll ans = 0;

    {
        sort(all(probs), [](auto a, auto b) { return make_tuple(a[1], a[0]) < make_tuple(b[1], b[0]); });
        set<ll> lftVals, rghtVals;
        for (ll i = 0; i < N; i++) {
            lftVals.insert(probs[i][0]);
            rghtVals.insert(probs[i][1]);
            probs[i][2] = max(0ll, *rghtVals.begin() - *lftVals.rbegin() + 1);
        }
        reverse(all(probs));
        lftVals.clear(), rghtVals.clear();
        for (ll i = 0; i < N; i++) {
            lftVals.insert(probs[i][0]);
            rghtVals.insert(probs[i][1]);
            probs[i][3] = max(0ll, *rghtVals.begin() - *lftVals.rbegin() + 1);
        }
        reverse(all(probs));
        for (ll i = 0; i < N - 1; i++) {
            ans = max(probs[i][2] + probs[i + 1][3], ans);
        }
    }

    {
        sort(all(probs), [](auto a, auto b) { return make_tuple(a[1], -a[0]) < make_tuple(b[1], -b[0]); });
        set<ll> lftVals, rghtVals;
        for (ll i = 0; i < N; i++) {
            lftVals.insert(probs[i][0]);
            rghtVals.insert(probs[i][1]);
            probs[i][2] = max(0ll, *rghtVals.begin() - *lftVals.rbegin() + 1);
        }
        reverse(all(probs));
        lftVals.clear(), rghtVals.clear();
        for (ll i = 0; i < N; i++) {
            lftVals.insert(probs[i][0]);
            rghtVals.insert(probs[i][1]);
            probs[i][3] = max(0ll, *rghtVals.begin() - *lftVals.rbegin() + 1);
        }
        reverse(all(probs));
        for (ll i = 0; i < N - 1; i++) {
            ans = max(probs[i][2] + probs[i + 1][3], ans);
        }
    }
    {
        multiset<ll> lftVals, rghtVals;
        for (ll i = 0; i < N; i++) {
            lftVals.insert(probs[i][0]);
            rghtVals.insert(probs[i][1]);
        }
        for (int i = 0; i < N; i++) {
            lftVals.erase(lftVals.find(probs[i][0]));
            rghtVals.erase(rghtVals.find(probs[i][1]));
            ans =
                max(ans, max(0ll, *rghtVals.begin() - *lftVals.rbegin() + 1) + max(0ll, probs[i][1] - probs[i][0] + 1));
            lftVals.insert(probs[i][0]);
            rghtVals.insert(probs[i][1]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int md = 1e9+7;
const int sz = 1e5;
// int A[sz+1];
// int F[sz+1];

int A[sz+1];


void solve(){
	int n;cin>>n;
	cout<<(1-n);
	

return;
}



int32_t main()
{
    // IOS;
    // A[0] = 0;
    // F[0] = 1;

    // for (int i = 1; i <= sz; ++i)
    // {
    // 	A[i] = A[i-1]+i;
    // 	F[i] = F[i-1]*i;
    // }

    // for(int i=0;i<10;i++){
    // 	cout<<A[i]<<" ";
    // }
    // cout<<endl;
    // for(int i=0;i<10;i++){
    // 	cout<<F[i]<<" ";
    // }
    // cout<<endl;    
    // coust<<"A and F is filled"<<endl;
    // int t;
    // cin >> t;
    // while (t--) 
        solve();
    return 0;
        

    
}



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

using namespace std;

struct card {
	char c;
	int v;
};

void BubbleSort(card A[], int n) {

	for (int i = 0; i < n; ++i) {
		for (int j = n - 1; j > i; --j) {
			if (A[j - 1].v > A[j].v)
				swap(A[j - 1], A[j]);
		}
	}

}

void SelectionSort(card A[], int n) {
	for (int i = 0; i < n; ++i) {
		int minIdx = i;
		int minv = A[i].v;
		for (int j = i + 1; j < n; ++j) {
			if (A[j].v < minv) {
				minv = A[j].v;
				minIdx = j;
			}
		}
		swap(A[i], A[minIdx]);
	}
}

int main() {

	int n;
	scanf("%d", &n);

	card A[n];
	for (int i = 0; i < n; ++i) {
		char c;
		int v;
		cin >> c >> v;
		card cd;
		cd.c = c;
		cd.v = v;
		A[i] = cd;
	}
	card B[n];

	for (int i = 0; i < n; ++i) {
		B[i] = A[i];
	}

	BubbleSort(A, n);

	for (int i = 0; i < n; ++i) {
		if (i != 0)
			cout << " " << A[i].c << A[i].v;
		else
			cout << A[i].c << A[i].v;

	}
	cout << endl << "Stable" << endl;

	SelectionSort(B, n);
	for (int i = 0; i < n; ++i) {
		if (i != 0)
			cout << " " << B[i].c << B[i].v;
		else
			cout << B[i].c << B[i].v;
	}
	cout << endl;

	//check A
	bool stable = true;
	for (int i = 0; i < n; ++i) {
		if (A[i].c != B[i].c || A[i].v != B[i].v) {
			cout << "Not stable" << endl;
			stable = false;
			break;
		}
	}
	if (stable)
		cout << "Stable" << endl;

	return 0;
}

Measured memory_bytes: 3224
N, M = map(int, input().split())
P = [0] * (N + 1)
S = [0] * (N + 1)
for i in range(M):
  x, p = input().split()
  s = int(x)
  if P[s] == 0:
    if p == 'AC':
      P[s] = 1
    else:
      S[s] += 1
A = sum([S[i] for i in range(N + 1) if P[i] == 1])
print(P.count(1), A)

Measured memory_bytes: 5528
import itertools
import math
import fractions
import functools
import copy

n, x = map(int, input().split())
l  = list(map(int, input().split()))
count = 1
d = 0
for i in range(n):
    d +=l[i]
    if d <= x:
        count += 1
    else:
        break

print(count)

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

int main() {
    double a, b, h, m;  cin >> a >> b >> h >> m;
    double th1 = (60* h + m) * 360.0 / 720.0;
    double th2 = m * 360.0 / 60.0;
    double PI = acos(-1);
    double th = abs(th1 - th2);
    // DUMP(th1, th2);
    if  (abs(th1 - th2) > 180) th = 360 - abs(th1 - th2);
    th *= 2 * PI / 360.0;
    // DUMP(th, cos(th));
    cout << fixed << setprecision(10) << sqrt(a*a + b*b - 2*a*b*cos(th)) << endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
int d;

int D[25];
ll dp[25][25][2][2];
int L;
ll dfs(int l, int r, int b0, int b1){
    if(dp[l][r][b0][b1] != -1) return dp[l][r][b0][b1];
    ll ans = 0;
    if(l+1 == r){
        for(int a=0;a<=9;a++){
            for(int b=0;b<=9;b++){
                if(r == L && a == 0) continue;
                for(int x=0;x<2;x++){
                    for(int y=0;y<2;y++){
                        int A = a, B = b;
                        if(x == 1) A = A + 10;
                        if(y == 1) B = B - 1;
                        if(b0 == 1) A = A - 1;
                        if(b1 == 1) B = B + 10;
                        if(A-b == D[l] && B-a == D[r]){
                            if(x == y){
                                ans++;
                            }
                        }
                    }
                }
            }
        }
    }
    else if(l == r){
        for(int a=0;a<=9;a++){
            if(r == L && a == 0) continue;
            int A = a;
            if(b0 == 1) A = A - 1;
            if(b1 == 1) A = A + 10;
            if(A-a == D[l]) ans++;
        }
    }
    else{
        for(int a=0;a<=9;a++){
            for(int b=0;b<=9;b++){
                if(r == L && a == 0) continue;
                for(int x=0;x<2;x++){
                    for(int y=0;y<2;y++){
                        int A = a, B = b;
                        if(x == 1) A = A + 10;
                        if(y == 1) B = B - 1;
                        if(b0 == 1) A = A - 1;
                        if(b1 == 1) B = B + 10;
                        if(A-b == D[l] && B-a == D[r]) ans += dfs(l+1, r-1, x, y);
                    }
                }
            }
        }
    }
    return dp[l][r][b0][b1] = ans;
}

ll solve(int l){
    memset(dp, -1, sizeof(dp));
    L = l;
    return dfs(1, l, 0, 0);
}

int main(){
    scanf("%d", &d);
    int x = d, l = 0;
    while(x){
        l++;
        D[l] = x%10;
        x/=10;
    }
    for(int i=l+1;i<=20;i++) D[i] = 0;
    ll ans = 0;
    for(int i=l;i<=20;i++) ans += solve(i);
    printf("%lld\n", ans);
}

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

int main() {
  int A,B;
  char c;
  cin >> A >> c >> B;
  if ( c =='+' ) cout << A+B << endl;
  else cout << A-B << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
int gcd(int a, int b) // assuming a,b >= 1
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    if (a % b == 0)
        return b;
    return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
    return  a * b / gcd(a, b);
}
using namespace std;
#pragma endregion
signed main() {
    int N;
    cin >> N;
    vector <int> A(N);
    rep(i, N)
        cin >> A[i];
    rep(i, N) {
        if (A[i] % 2 == 0) {
            if (A[i] % 3 != 0 && A[i] % 5 != 0) {
                cout << "DENIED";
                return 0;
            }

        }

    }
    cout << "APPROVED";
}

Measured memory_bytes: 888
N = input()

num = len(N) - 1

if N[num] == "2" or N[num] == "4" or N[num] == "5" or N[num] == "7" or N[num] == "9":
    print("hon")
elif N[num] == "3":
    print("bon")
else:
    print("pon")

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

#define MAX 200000
using namespace std;

int main(){
  long int R[MAX], n;
  cin >> n;
  for(int i=0;i<n;i++) cin >> R[i];
  long int maxv = -1145141919810;
  long int minv=R[0];

  for(int i=1;i<n;i++){
    maxv=max(maxv, R[i]-minv);
    minv=min(minv,R[i]);
  }
  cout << maxv << endl;
  return 0;
}



Measured memory_bytes: 4660
#include"bits/stdc++.h"
using namespace std;
#define LL long long

LL N,M,K,ans,r,a;

pair<LL, LL>bc;
vector<pair<LL, LL>>BC;
int main() {

	cin >> N >> M>>K;
	ans = min(N + K, M + K);
	ans = min(ans, N + M);
	cout << ans << endl;
	return 0;

}


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

int main() {
    int n,m;
    cin>>n>>m;
    map<int, int> mp;
    int ans = 0, pen = 0;
    for(int i = 0; i < m; ++i) {
        int a; string b;
        cin>>a>>b;
        if(b == "AC") {
            if(mp[a] == -1) continue;
            pen += mp[a];
            ans++;
            mp[a] = -1;
        } else {
            if(mp[a] == -1) continue;
            mp[a]++;
        }
    }
    cout<<ans<<" "<<pen<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	
	string S;
	cin >> S;
	
	vector<int> nums;
	
	int now = 1;
	int cnt = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == (char)('0' + now)) {
			cnt++;
		} else {
			now = 1 - now;
			nums.push_back(cnt);
			cnt = 1;
		}
	}
	nums.push_back(cnt);	// 最後の要素
	
	// if (nums.size() % 2 == 0)
		// nums.push_back(0);
	
	// for (int aaa : nums)	cout << aaa << endl;
	
	int res = 0;
	int k_now = 0;
	int tmp = 0;
	/* start位置 */
	// for (int i = 0; i < nums.size(); i+=2) {	// 1始まりでループ
		// /* 計測 */
		// for (int j = i; j < nums.size(); j++) {
			// if (j % 2 == 1) {		// 0の連続数
				// if (k_now >= K)
					// break;
				// k_now++;
			// }
			// tmp += nums[j];
		// }
		// res = max(res, tmp);
		// tmp = 0;
		// k_now = 0;
	// }
	
	int left = 0;
	int right = 0;
	int add = 2 * K + 1;

	for (int i = 0; i < nums.size(); i+=2) {
		int next_left = i;
		int next_right = min(i + add, (int)nums.size());	// [left, right)
		
		while(next_left > left) {
			tmp -= nums[left];
			left++;
		}
		while(next_right > right) {
			tmp += nums[right];
			right++;
		}
		res = max(res, tmp);
	}
	
	cout << res << endl;
	return 0;
}

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

int main(){
	string a, b;
	cin >> a >> b;
	a += b;
	int sr = (int)sqrt(stoi(a));
	if(sr * sr == stoi(a)) {
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}


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

int main() {
	int A, B, cnt = 0;
	cin >> A >> B;

	for (int i = A; i < B+1; i++)
	{
		if (i / 1000 == i % 10 * 10 + i / 10 % 10)
			cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 3604
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val s = next()

    var len = 0
    var max = 0
    s.forEach {
        if (it in "ACGT") {
            len++
        } else {
            if (len > max) max = len
            len = 0
        }
    }

    if (len > max) max = len

    println(max)
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

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

int main() {
	int s,s1,s2,s3;
	cin >> s;
	s1 = s / 100;
	s = s - s1 * 100;
	s2 = s / 10;
	s = s - s2 * 10;
	s3 = s;
	cout << s1+s2+s3 << endl;

}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];

    bool ans = true;
    for (int i = n - 2; i >= 0; i--) {
        if (h[i] > h[i + 1] + 1) {
            ans = false;
            break;
        }

        h[i] = min(h[i], h[i + 1]);
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  vector<int>a(100004,0);
  for(int i=2;i<100004;i++){
    for(int j=2;j<sqrt(i);j++){
      if(i % j == 0) a[i] = 1;
    }
  }
  
  while(a[n] == 1) n++;
  
  cout << n << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int64_t m,n;
  cin >> m >> n;
  if (m == 1 && n > 3)cout << m*n-2 << endl;
  else if(m > 3 && n == 1)cout << m*n-2 << endl;
  else cout << (m-2)*(n-2) << endl;
}

Measured memory_bytes: 3612
use std::collections::VecDeque;

fn main() {
    let hw = read_vec::<usize>();
    let h = hw[0];
    let w = hw[1];
    let mut maze: Vec<Vec<char>> = Vec::new();
    for _ in 0..h {
        let s = read::<String>();
        let v: Vec<char> = s.chars().into_iter().collect();
        maze.push(v);
    }
    let maze = maze;

    let mut ma = 0;
    for i in 0..h {
        for j in 0..w {
            if maze[i][j] == '#' {
                continue;
            }

            let mut _maze = maze.clone();
            let mut queue: VecDeque<((usize, usize), usize)> = VecDeque::new();
            queue.push_back(((i, j), 0));
            let cnt = bfs(&mut _maze, &mut queue, h, w);

            if cnt > ma {
                ma = cnt;
            }
        }
    }

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

fn bfs(maze: &mut Vec<Vec<char>>, queue: &mut VecDeque<((usize, usize), usize)>, h: usize, w:usize) -> usize {
    if let Some(((y, x), cnt)) = queue.pop_front() {
        maze[y][x] = '#';

        if x > 0 && maze[y][x-1] != '#' {
            queue.push_back(((y, x-1), cnt+1));
            maze[y][x-1] = '#'
        }
        if x < w-1 && maze[y][x+1] != '#' {
            queue.push_back(((y, x+1), cnt+1));
            maze[y][x+1] = '#'
        }
        if y > 0 && maze[y-1][x] != '#' {
            queue.push_back(((y-1, x), cnt+1));
            maze[y-1][x] = '#'
        }
        if y < h-1 && maze[y+1][x] != '#' {
            queue.push_back(((y+1, x), cnt+1));
            maze[y+1][x] = '#'
        }

        let tmp = bfs(maze, queue, h, w);

        if tmp > cnt {
            tmp
        } else {
            cnt
        }
    } else {
        0
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


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

using namespace std;

int main(void){
  int n;
  long long k;
  cin >> n >> k;
  vector<vector<int>> a(n, vector<int>(2, -1));

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

  int now = 0;
  long long  period = -1;

  long long i = k;

  while(i){
    if(a[now][1] != -1){
      period = (k - i) - a[now][1];
      break;
    }
    a[now][1] = k - i;
    now = a[now][0] - 1;
    i--;
  }

  i = i % (long long)period;
  
  for(int j = 0; j < i; j++)
    now = a[now][0] - 1;
  
  cout << now + 1 << endl;
  
  return 0;
}


Measured memory_bytes: 14348
// probati liste i stabla
#include<stdio.h>
#include<stdlib.h>

int poredi(const void *a, const void *b){
    int x = *(int*)a;
    int y = *(int*)b;
    
    return x-y;    
}

int main(){
    int n;
    scanf("%d", &n);
    //greska
    
    int *niz;
    niz = (int*)malloc(sizeof(int)*n);
    //greska
    
    for(int i=0; i<n; i++){
        scanf("%d", &niz[i]);
        //greska
    }
    
    qsort(niz, n, sizeof(int), &poredi);
//     for(int i=0; i<n; i++){
//         printf("%d ", niz[i]);}
    
    double min=niz[0];
    for(int i=1; i<n; i++){
        min = (min+(double)niz[i])/2;
//         printf("%lf\n", min);
;//         niz[i+1] = (niz[i]+niz[i+1])/2;
    }
    
    printf("%lf", min);
    
    free(niz);
    exit(EXIT_SUCCESS);
}


Measured memory_bytes: 128
program main;
var x:integer;
begin
    readln(x);
    if trunc(x/100) = 7
    then writeln('Yes')
        else if trunc((x-(trunc(x/100)*100))/10) = 7
        then writeln('Yes')
            else if x-(trunc(x/100)*100)-((trunc((x-(trunc(x/100)*100))/10))*10) = 7
            then writeln('Yes')
            else writeln('No');
end.

Measured memory_bytes: 1380
#include <bits/stdc++.h>
	
using namespace std;
	
#define endl "\n"
#define ll long long
#define vi vector <int >
#define vii vectir < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define a first
#define b second

ll gcd(ll a, ll b){
	while(b){
		a = a%b;
		swap(a, b);
	}
	return a;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	vi arr;
	int n;
	cin >> n;
	forn(i, n){
		int k;
		cin >> k;
		arr.pb(k);
	}

	int pos = 1;
	int ans = 0;
	forn(i, n){
		if(arr[i] == pos){
			pos++;
		}else{
			ans++;
		}
	}
	if(ans == n){
		cout << "-1" << endl;
	}else{
		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 1400
from sys import stdin
import heapq as hq
input = stdin.readline

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

A.sort(reverse=True)
ans = 0

ls = []
hq.heapify(ls)

hq.heappush(ls, [-A[0], -A[0]])

for i in range(1, N):
    c = A[i]
    a, b = hq.heappop(ls)
    ans += abs(max(a, b))
    hq.heappush(ls, [-min(abs(A[i]), abs(a)), -max(abs(A[i]), abs(a))])
    hq.heappush(ls, [-min(abs(A[i]), abs(b)), -max(abs(A[i]), abs(b))])

print(ans)


Measured memory_bytes: 48364
#include<iostream>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define SIZE 100000
const int INF = 2000000000;
int single[101][SIZE+1];
int res_all[SIZE+1];
int res_single[SIZE+1];

void calc_single(int maxhp,vector<int>&mp,vector<int>&damage){
  int n=mp.size(),m=maxhp;
  rep(i,n+1)rep(j,m+1)single[i][j]=INF;
  single[0][0]=0;
  rep(i,n){
    rep(j,m+1){
      if ( single[i][j] >=INF)continue;
      single[i+1][j]=min(single[i][j],single[i+1][j]);
      if ( j+damage[i] <=maxhp){
	single[i][j+damage[i]]=min(single[i][j+damage[i]],single[i][j]+mp[i]);
	//single[i+1][j+damage[i]]=min(single[i+1][j+damage[i]],single[i][j]+mp[i]);
      }else single[i+1][maxhp]=min(single[i+1][maxhp],single[i][j]+mp[i]);
    }
  }

  /*
  int tmp=single[n][maxhp];
  for(int i=maxhp;i>=0;i--){
    if ( tmp > single[n][i])tmp=single[n][i];
    res_single[i]=tmp;
  }
  */

}


int solve(int maxhp,vector<int>& hp,vector<int>&mpsingle,vector<int>& damagesingle,
	  vector<int>&mpall,vector<int> &damageall){
  int ret = INF,n,tmp;
  calc_single(maxhp,mpsingle,damagesingle);
  n=mpsingle.size();
  tmp=single[n][maxhp];
  for(int i=maxhp;i>=0;i--){
    if (tmp>single[n][i])tmp=single[n][i];
    res_single[i]=tmp;
  }
  calc_single(maxhp,mpall,damageall);
  n=mpall.size();
  tmp = INF;
  for(int i=maxhp;i>=0;i--){
    if ( single[n][i] >=INF){res_all[i]=INF;continue;}
    //if (tmp>single[n][i])tmp=single[n][i];
    else res_all[i]=single[n][i];
  } 
 

  rep(i,maxhp+1){
    if ( res_all[i]>=INF)continue;
    tmp=res_all[i];
    rep(j,hp.size()){
      if ( hp[j]-i<=0)continue;
      if(  res_single[hp[j]-i]==INF){tmp=INF;break;}
      tmp+=res_single[hp[j]-i];
    }
    ret=min(tmp,ret);
  }
  return ret;
}

main(){
  int n;
  while(cin>>n && n){
    int m;
    int maxhp=0;
    vector<int>hp;
    rep(i,n){
      int tmp;
      cin>>tmp;
      maxhp=max(maxhp,tmp);
      hp.push_back(tmp);
    }
    cin>>m;
    vector<int> mpsingle,mpall,damagesingle,damageall;
    rep(i,m){
      string t,check;
      int tmp,tdamage;
      cin>>t>>tmp>>check>>tdamage;
      if ( check[0] == 'A' && tdamage != 0)mpall.push_back(tmp),damageall.push_back(tdamage);
      else if ( check[0] == 'S'&&tdamage!=0)mpsingle.push_back(tmp),damagesingle.push_back(tdamage);
    }
    cout << solve(maxhp,hp,mpsingle,damagesingle,mpall,damageall)<<endl;
  }
}

Measured memory_bytes: 30000
"use strict";
// https://atcoder.jp/contests/abc158/tasks/abc158_a
function main(s) {
    let i = 1;
    for (let ch = s[0]; i < 3; i++) {
         if (ch !== s[i]) {
               break;
         }
    }
    console.log(i === 3? "No": "Yes");
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<stdio.h>
int main()
{
  int a,b,c,x,y;
  y=0;
  scanf( "%d%d%d",&a,&b,&c );
  for( x=a;x<=b;x++ ){
    if( c%x==0 ){ y=y+1; }
    else{ y=y; }
  }
  printf( "%d\n",y );
  return 0;
}


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

#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*****************************************************START******************************************************************/


int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1 ;
	 //cin >> T;
	// cin.ignore(); must be there when using getline(cin, s)
	while (T--)
	{
		int a,b,x,y; cin >> a >> b >> x >> y; 
		string s = "";
			int lx = x - a , ly = y - b; 
			s.append(lx , 'R'); s.append(ly , 'U');
			s.append(lx , 'L'); s.append(ly , 'D');
			lx ++; ly++;
			s.append(1,'D'); s.append(lx , 'R'); s.append(ly , 'U');
			s.append(1,'L'); s.append(1,'U'); s.append(lx,'L'); s.append(ly,'D');
			s.append(1,'R');
			cout << s << endl;
	}
	return 0;
}


Measured memory_bytes: 3652
import java.util.*;
class Main{
  static int counter;
  static int n;
  static int s;

  public static void makeC(int m, int n, int sum){
    if (n == 0) {
      if (sum == s) {
        counter++;
      }
    }
    else {
      for (int i = m; i < 10; i++) {
        makeC(i + 1, n - 1, sum + i);
      }
    }
  }
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true) {
      n = sc.nextInt();
      s = sc.nextInt();
      if (n == 0 && s == 0) {
        break;
      }
      counter = 0;
      makeC(0, n, 0);
      System.out.println(counter);
    }
  }
}

Measured memory_bytes: 12000
n = int(input())
li = list(map(int,input().split()))

licol = [0]*9
for i in range(n):
  if li[i]//400 <= 7:
    licol[li[i]//400] += 1
  else:
    licol[8] += 1
ans = 0
for i in range(8):
  if licol[i] != 0:
    ans += 1
if ans == 0:
  print(1,end=" ")
else:
  print(ans,end=" ")
print(ans+licol[8])

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <algorithm>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9;
const int E = numeric_limits<int>::min();

int main(void)
{
    int X, N;
    cin >> X >> N;
    vector<int> p(N);
    rep(i, N){
        cin >> p[i];
    }
    map<int, bool> m;
    P minp = P(INF, X);
    rep(i, N){
        m[p[i]] = true;
        int dif = abs(p[i] - X);
        if (minp.first > dif){
            minp = P(dif, p[i]);
        }
    }

    queue<int> q;
    q.push(minp.second);
    int f = q.front();
    bool flag = true;
    if (m[f] == false){
        cout << f << endl;
        return 0;
    }
    q.pop();
    q.push(f - 1);
    q.push(f + 1);
    while(true){
        f = q.front();
        if (m[f] == false){
            cout << f << endl;
            return 0;
        }
        q.pop();
        if (flag){
            q.push(f - 1);
            flag = false;
        }
        else{
            q.push(f + 1);
            flag = true;
        }
    }

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << endl)

using namespace std;
using ll = unsigned long long;

int main() {
	int N;
	cin >> N;
	vector<ll> L;
	L.push_back(2);
	L.push_back(1);
	int i;
	for(i = 2; i <= N; i++) {
		L.push_back(L[i-1] + L[i-2]);
	}
	cout << L[N] << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
count = 0
_a = 100
for a in A:
    count += B[a-1]
    if a - _a == 1:
        count += C[_a-1]
    _a = a
print(str(count))

Measured memory_bytes: 3064
/*
* @Author: dnhirapara
* @Date: 2020-04-04 18:08
* @Name: abc161_b
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m, n;
  cin>>n>>m;
  int a[n], sum=0;
  double tar;
  for(int i=0; i<n; i++){
    cin>>a[i];
    sum+=a[i];
  }
  tar = ((double)sum/(4*m));
  int cnt=0;
  sort(a, a+n, greater<int>());
  for(int i=0; i<n; i++){
    if(a[i]>=tar && cnt<m){
      cnt++;
    }else
      break;
  }
  if(cnt==m){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) = println(run {
    var s = readLine()!!.toInt()

    val exist = mutableSetOf<Int>()
    exist.add(s)
    repeat(1000000) {
        if(s%2==0) s/=2 else s=3*s+1
        if(s in exist) return@run it+2
        exist.add(s)
    }
})


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

 int main () {
   int A, B, C;
   cin >> A >> B >> C;
   
   if (A==C && A!=B) {
     cout << "Yes" << endl;
   }
   
   else if (A==B && A!=C) {
     cout << "Yes" << endl;
   }
   
   else if (B==C && A!=B) {
     cout << "Yes" << endl;
   }
   
   else {
     cout << "No" << endl;
   }
 }


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

#define all(v) (v).begin(), (v).end()
using namespace std;

void simulate_fight(vector <int> &H)
{
    int smallest, smallest_position = H.size();
    for(int i = 0; i < H.size(); i++)
    {
        if(H[i] != 0)
        {
            smallest = H[i];
            smallest_position = i;
            break;
        }
    }

    for(int i = smallest_position + 1; i < H.size(); i++)
    {
        H[i] %= smallest;
    }

    sort(all(H));
}

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

    vector <int> health(no_of_monsters, 0);
    for(int i = 0; i < no_of_monsters; i++)
        cin >> health[i];

    sort(all(health));

    while(health[no_of_monsters - 2] > 0)
    {
        simulate_fight(health);
    }

    cout << health[no_of_monsters - 1];
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}
 
int main(){
    ll n,x;
    cin >> n;
    x=n/2;
    if (n%2==1)x+=1;
    cout << x << endl;
    return 0;
}


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

int N;
vector<string> g;
int used[128],x1[128],x2[128],y1[128],y2[128];
vector<int> p;

vector<char> v;
bool bt(){

	for(int k=p.size()-1;k<p.size();k++){
		for(int i=y1[p[k]];i<=y2[p[k]];i++){
			for(int j=x1[p[k]];j<=x2[p[k]];j++){
				char c = g[i][j];
				if(c == '.')return false;
				if(find(p.begin(),p.end(),p[k]) > find(p.begin(),p.end(),c)){
					return false;
				}
			}			
		}
	}
	for(int k=0;k<v.size();k++){
		if(!used[v[k]]){
			used[v[k]] = true;
			p.push_back(v[k]);
			if( bt() ) return true;
			p.pop_back();
			used[v[k]] = false;
		}
	}
	return p.size() == v.size();
}
int main(){
	int T;
	
	cin >> T;
	while(T--){
		int W,H;
		cin >> H >> W;
		vector<string> data(H);
		for(int i=0;i<H;i++)
			cin >> data[i];
			
		g = data;
		
		int check[128];
		
		for(int i=0;i<128;i++)
			x1[i] = x2[i] = y1[i] = y2[i] = used[i] = check[i] = 0;

		for(int i=0;i<128;i++)
			x1[i] = y1[i] = 9999;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				char c = data[i][j];
				if(c != '.'){
					check[c] = true;
					x1[c] = min(j,x1[c]);
					x2[c] = max(j,x2[c]);
					y1[c] = min(i,y1[c]);
					y2[c] = max(i,y2[c]);
				}
			}
		}
		
		v.clear();
		p.clear();
		
		for(int i=0;i<128;i++)
			if(check[i])v.push_back(i);

			
		cout << ( bt() ? "SAFE" : "SUSPICIOUS") << endl;
	}
}

Measured memory_bytes: 936
import math
N = int(input())
prime = True
if N == 2:
  print(2)
  exit()
else:
  for k in range(N, 110000):
    prime = True
    max = math.ceil(math.sqrt(k))
    for i in range(2, max+1):
      if k % i == 0:
        prime = False
        break
    if prime == True:
      ans = k
      break
print(ans)

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

int main(){
	string p,s;
	bool judge=false;
	cin>>p;
	cin>>s;
	p=p+p;
	for(int i=0;i<p.size();i++){
		if(s[0]==p[i]){
			for(int j=0;j<s.size();j++){
				if(s[j]!=p[i+j]) break;
				if(j==s.size()-1){
					judge=true;
					break;
				}
			}
		}
	}
	if(judge) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3228
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main(){
	int x, y;
	cin >> x >> y;
	if (x == 2 ) {
		cout << "No" << endl;
	}
	else if(x==4|| x == 6 || x == 9 ||x==11 ){
		if (y == 4 || y == 6 || y == 9 || y == 11) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		if (y == 1 || y == 3 || y == 5 || y == 7||y==8||y==10||y==12) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; ll K; ll A[201010];
//---------------------------------------------------------------------------------------------------
ll getMinus(ll lim) {
	vector<ll> mi, pl;
	rep(i, 0, N) {
		if (A[i] < 0) mi.push_back(A[i]);
		if (0 < A[i]) pl.push_back(A[i]);
	}

	int j = 0;
	ll res = 0;
	fore(m, mi) {
		// m * p <= lim
		while (j < pl.size() && lim < m * pl[j]) j++;
		res += pl.size() - j;
	}
	return res;
}
//---------------------------------------------------------------------------------------------------
ll getZeros() {
	int zero = 0;
	rep(i, 0, N) if (A[i] == 0) zero++;
	return 1LL * zero * (N - zero) + 1LL * zero * (zero - 1) / 2;
}
//---------------------------------------------------------------------------------------------------
ll getPlus(ll lim) {
	vector<ll> mi, pl;
	rep(i, 0, N) if (0 < A[i]) pl.push_back(A[i]);
	rrep(i, N - 1, 0) if (A[i] < 0) mi.push_back(-A[i]);

	ll res = 0;

	int n = mi.size();
	int j = n - 1;
	rep(i, 0, n) {
		while (i < j && lim < mi[i] * mi[j]) j--;
		res += max(0, j - i);
	}

	n = pl.size();
	j = n - 1;
	rep(i, 0, n) {
		while (i < j && lim < pl[i] * pl[j]) j--;
		res += max(0, j - i);
	}

	return res;
}
//---------------------------------------------------------------------------------------------------
ll getCount(ll lim) {
	ll res = getMinus(min(lim, -1LL));
	if (0 <= lim) res += getZeros();
	if (0 < lim) res += getPlus(lim);
	return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	rep(i, 0, N) cin >> A[i];
	sort(A, A + N);

	ll ng = -infl, ok = infl;
	while (ng + 1 != ok) {
		ll md = (ok + ng) / 2;
		if (K <= getCount(md)) ok = md;
		else ng = md;
	}
	cout << ok << endl;
}







Measured memory_bytes: 5260
// Copyright 2017 wu_qing
#include <cstdio>
#include <cstring>
#include <algorithm>

const int N = 310;
int n, m, cnt[N], ans, max, mid, a[N][N];
bool l[N];

int main() {
    memset(l, true, sizeof l);
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            scanf("%d", &a[i][j]);
    for (int i = 1; i <= n; i++)
        cnt[a[i][1]]++;
    for (int i = 1; i <= m; i++)
        if (ans < cnt[i]) {
            ans = cnt[i];
            mid = i;
        }
    for (int i = 1; i < m; i++) {
        l[mid] = false;
        max = 0;
        memset(cnt, 0, sizeof cnt);
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= m; k++)
                if (l[a[j][k]]) {
                    cnt[a[j][k]]++;
                    break;
                }
        for (int j = 1; j <= m; j++)
            if (l[j] && max < cnt[j]) {
                max = cnt[j];
                mid = j;
            }
        ans = std::min(ans, max);
    }
    printf("%d\n", ans);
    return 0;
}


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

#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
 
using namespace std;

int32_t main(){
    int n, ans=0;
    cin >> n;
    vector<int> v(n);
    REP(i, n){
        cin >> v[i];
    }

    vector<int> s;
    s.pb(0);
    REP(i, n){
        s.pb(s[i]+v[i]);
    }
    s.pb(INF);
    SORT(s);

    int cnt=1;
    REP(i, n+2){
        if(s[i]==s[i+1]){
            cnt++;
        }
        else{
            ans+=cnt*(cnt-1)/2;
            cnt=1;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3956
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	b := make([]int, n)
	ans := make([]int, 0, n)
	for i := len(a); i >= 1; i-- {
		x := 0
		for j := 2; j <= n; j++ {
			if i*j > n {
				break
			}
			x ^= b[i*j-1]
		}
		b[i-1] = x ^ a[i-1]
		if b[i-1] == 1 {
			ans = append(ans, i)
		}
	}

	fmt.Println(len(ans))
	for i, v := range ans {
		if i == len(ans)-1 {
			fmt.Println(v)
			continue
		}
		fmt.Printf("%d ", v)
	}
}


Measured memory_bytes: 8320
#include "bits/stdc++.h"
#include <set>

using namespace std;
#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 rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n, m;
	cin >> n >> m;
	print((n - 1)*(m - 1));
}

Measured memory_bytes: 3644
while gets do
  n = $_.to_i
  next if n.zero?
  sums = {}
  n.times do
    i, p , q = gets.split
    sums[i] += p.to_i * q.to_i if sums[i] ||= 0
  end
  sums.delete_if{|k, v| v < 1_000_000}
  puts sums.empty? ? "NA" : sums.keys
end

Measured memory_bytes: 6108
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
string s;
int bits,ind;
bool cs(void)
{
  if(s[ind]=='T'){
    ++ind;
    return true;
  }else if(s[ind]=='F'){
    ++ind;
    return false;
  }else if(s[ind]=='-'){
    ++ind;
    return !cs();
  }else if(s[ind]=='('){
    ++ind;
    bool x=cs(),y;
    if(s[ind]=='*'){
      ++ind;
      y=cs();
      x=x&&y;
    }else if(s[ind]=='+'){
      ++ind;
      y=cs();
      x=x||y;
    }else if(s[ind]=='-'){
      ++ind;
      ++ind;
      y=cs();
      x=!x||y;
    }
    ++ind;
    return x;
  }else{
    bool tmp=(bool)(bits&(1<<(s[ind]-'a')));
    ++ind;
    return tmp;
  }
}
int main(void)
{
  for(;;){
    cin >> s;
    if(s=="#") return 0;
    bool flag=false;
    REP(i,(1<<11)){
      bits=i,ind=0;
      bool tmp=cs();
      ++ind;
      flag=flag||(tmp^cs());
    }
    cout << (flag?"NO":"YES") << endl;
  }
}

Measured memory_bytes: 3164