akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct data{
	long long x,y;
}t[300001];
long long n,s1,s2,k1,k2,f[300001],k[300001],m=1000000007,s[300001],cnt,id[300001],sum,ans=1,col[300001],colmax[300001];
bool d[300001],r[300001];
bool cmp(data a,data b){
	return a.y<b.y;
}
long long get_pow(long long a,long long b){
	long long p=1;
	while(b){
		if(b%2)p=(p*a)%m;
		a=(a*a)%m;
		b=b/2;
	}
	return p;
}
long long c(long long a,long long b){
    return (((k[a]*f[b])%m)*f[a-b])%m;
}
void add(long long a){
	long long p=a;
	while(t[col[p]].y+t[a].y<=s1){
		if(!col[p])break;
		s[t[a].x]++;
		sum++;
		p=col[p];
		r[p]=1;
	}
}
int main(){
	scanf("%lld%lld%lld",&n,&s1,&s2);
	k[0]=1;
    for(long long i=1;i<=n;i++)k[i]=(k[i-1]*i)%m;
    f[n]=get_pow(k[n],m-2);
    for(long long i=n-1;i>1;i--)f[i]=(f[i+1]*(i+1))%m;
    f[0]=1;
    f[1]=1;
	for(long long i=1;i<=n;i++)scanf("%lld%lld",&t[i].x,&t[i].y);
	sort(t+1,t+n+1,cmp);
	for(long long i=1;i<=n;i++){
		col[colmax[t[i].x]]=i;
		colmax[t[i].x]=i;
	}
	k1=1;
	k2=2;
	while(k2<=n&&t[k2].x==t[k1].x)k2++;
	if(k2!=n+1){
		if(t[k1].y+t[k2].y<=s2){
			for(long long i=1;i<=n;i++){
				if((t[i].x!=t[k1].x&&t[k1].y+t[i].y<=s2)||(t[i].x!=t[k2].x&&t[k2].y+t[i].y<=s2)){
					if(!d[t[i].x]){
						d[t[i].x]=1;
						r[i]=1;
						cnt++;
						id[cnt]=t[i].x;
						s[t[i].x]++;
						sum++;
						add(i);
					}else if(!r[i]){
						s[t[i].x]++;
						r[i]=1;
						sum++;
					}
				}
			}
			for(long long i=1;i<=cnt;i++){
				ans=(ans*c(sum,s[id[i]]))%m;
				sum=sum-s[id[i]];
			}
		}
	}
	printf("%lld\n",ans);
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int h, n;
  cin >> h >> n;
  rep(i, n) {
    int a;
    cin >> a;
    if (h > 0) h -= a;
  }
  cout << (h > 0 ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <set>

#define ll long long

using namespace std;

ll color[100005];

ll
getColor(ll n) {
  ll end = n;
  while (color[end] != end) 
    end = color[end];

  ll mid = n;
  while (color[mid] != end) {
    ll temp = color[mid];
    color[mid] = end;
    mid = temp;
  }

  return end;
}

int
main() {
  ll n, m;
  cin>>n>>m;

  for (ll i=1; i<=n; i++) color[i] = i;

  ll x, y;
  for (ll i=0; i<m; i++) {
    cin>>x>>y;

    ll a = getColor(x);
    ll b = getColor(y);
    color[a] = b;
  }

  set<ll> c;
  for (ll i=1; i<=n; i++)
    c.insert(getColor(i));
  cout<<c.size()-1<<endl;

  return 0;
}


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

typedef long long ll;
ll N, K;
vector<ll> A, B, C;
void n(){
    cout << -1 << '\n';
    exit(0);
}

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

    cin >> N >> K;

    if(N & 1){
        if(2 * K > N + 1) n();

        int l;
        int r = N;
        ll c = K + 2 * N + (N / 2);
        for(l = N - 1 ; r <= 2 * N - 1 ; l--, r += 2, c++){
            A.push_back(K + l); B.push_back(K + r); C.push_back(c);
        }

        c = K + 2 * N + (N / 2) - 1;
        for(l = 0, r = 2 * N - 2 ; r >= N ; l++, r -= 2, c--){
            A.push_back(K + l); B.push_back(K + r); C.push_back(c);
        }

        for(int i = 0 ; i < A.size() ; i++) {
            cout << A[i] << ' ' << B[i] << ' ' << C[i] << '\n';
        }
    }
    else{
        int l;
        int r = N;
        ll c = K + 2 * N + (N / 2);
        for(l = N - 1 ; r <= 2 * N - 1; l--, r += 2, c++){
            A.push_back(K + l); B.push_back(K + r); C.push_back(c);
        }

        c = K + 2 * N + (N / 2) - 1;
        for(l = 0, r = 2 * N - 1; r >= N ; l++, r -= 2, c--){
            A.push_back(K + l); B.push_back(K + r); C.push_back(c);
        }

        for(int i = 0 ; i < A.size() ; i++){
            if(A[i] + B[i] > C[i]) n();
        }
        
        for(int i = 0 ; i < A.size() ; i++) {
            cout << A[i] << ' ' << B[i] << ' ' << C[i] << '\n';
        }
    }

    return 0; 
}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll unsigned long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int mod = 1e9 + 7;
int main()
{
	int n, m;
	cin >> n >> m;
	int arr[n];
	for (int i = 0; i < n; ++i)
	{
		arr[i] = -1;
	}

	int s, c;
	std::vector<int> mark(n, -1);

	for (int i = 0; i < m; ++i)
	{
		cin >> s >> c;
		s--;
		if (mark[s]!=-1 && mark[s]!=c)
		{
			cout << -1;
			return 0;
		}
		else
		{
			mark[s] = c;
			arr[s] = c;

		}
	}

	if (arr[0]==0 && n!=1)
	{
		cout << -1;
			return 0;
	}

	bool get_first_no = false;

	if (n==1 && m==0)
	{
		cout << 0;
		return 0;

	}

	for (int i = 0; i < n; ++i)
	{
		if (arr[i] != -1)
		{
			get_first_no = true;
			cout << arr[i];
		}
		else if (get_first_no)
		{
			cout << 0;
		}
		else
		{
			cout << 1;
			get_first_no = true;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>


int main()
{
	int i,j,temp,k=0,cnt=0,N=0;
	int num[3];

	scanf("%d",&N);
	int *p = (int *)malloc(N*sizeof(int));
	if (p)
	{
		while (cnt < N)
		{
			for (i = 0; i < 3; i++)
			{
				scanf("%d", &num[i]);
			}
			
			for (i = 0; i < 2; i++)
			{
				for (j = i + 1; j < 3; j++)
				{
					if (num[i] > num[j])
					{
						temp = num[i];
						num[i] = num[j];
						num[j] = temp;
					}
				}
			}

			if ((num[0] * num[0] + num[1] * num[1]) == num[2] * num[2])
			{
				*(p + k) = 1;
			}
			else
			{
				*(p + k) = 0;
			}
			++k;

			++cnt;
		}
	}
	
	
	for (k = 0; k<N; k++)
	{
		if (*(p + k))
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 584
# coding: utf-8
A, B, C = map(int, input().split())
mod = [A % B]
i = 1
while True:
    i += 1
    if mod[0] * i % B not in mod:
        mod.append(mod[0] * i % B)
    else:
        break
print(['NO', 'YES'][C in mod])


Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
using namespace std;
const int maxd = 2e5+10;
typedef pair<int,int> P;
char a[maxd],b[maxd];
long long gcd(long long x,long long y)
{
    if(!y) return x;
    return gcd(y,x%y);
}
void solve()
{
    long long x,y;scanf("%lld %lld",&x,&y);
    printf("%lld",x/gcd(x,y)*y);
}
int main()
{
//    freopen("a.in","r",stdin);
//    freopen("k.out","w",stdout);
    //int t;scanf("%d",t);
    int t = 1;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl "\n" 
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define umap unordered_map
#define uset unordered_set 
#define mod 1000000007
#define imax INT_MAX
#define imin INT_MIN
#define exp 1e9
#define sz(x) (int((x).size()))
#define int long long

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x, t;
    cin >> n >> x >> t;
    // cout << (t*n) / x ;
    for(int i = x; i < 100000; i += x) {
        if(i >= n) {
            cout << (i * t) / x;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<string.h>
int main ()

{
    char a[3];
    gets(a);
    if(a[0]=='S'&&a[1]=='A'&&a[2]=='T'){
    printf("1");
    }
    else if(a[0]=='S'&&a[1]=='U'&&a[2]=='N'){
    printf("7");
    }
    else if(a[0]=='M'&&a[1]=='O'&&a[2]=='N'){
    printf("6");
    }
    else if(a[0]=='T'&&a[1]=='U'&&a[2]=='E'){
    printf("5");
    }
    else if(a[0]=='W'&&a[1]=='E'&&a[2]=='D'){
    printf("4");
    }
    else if(a[0]=='T'&&a[1]=='H'&&a[2]=='U'){
    printf("3");
    }
    else if(a[0]=='F'&&a[1]=='R'&&a[2]=='I'){
    printf("2");
    }
















return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long

using namespace std;



int main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);

        int k;

        cin >> k;
        int even, odd;
        if(k % 2 == 0) {
                even = k/2;
                odd = k/2;
        } else {
                even = k/2;
                odd = k/2 + 1;
        }
        int res = even*odd;
        cout << res << endl;
        return 0;
}


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

namespace ABC125_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<long> numList = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToList();

            numList = numList.OrderByDescending(i => Math.Abs(i)).ToList();

            for (int i = 0; i < n - 1; i++)
            {
                if (numList[i] < 0)
                {
                    numList[i] *= -1;
                    numList[i+1] *= -1;
                }
            }

            long ans = 0;
            for (int i = 0; i < n; i++)
            {
                ans += numList[i];
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 31836
S = input()
n = len(S)
start0 = ''
start1 = ''
ans0 = 0
ans1 = 0
for i in range(n):
    if i % 2 == 0:
        start0 += '0'
        start1 += '1'
    else:
        start0 += '1'
        start1 += '0'
for i in range(n):
    if start0[i] != S[i]:
        ans0 += 1
    if start1[i] != S[i]:
        ans1 += 1
print(min(ans0, ans1))

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
string s;
ll n,m,r,c,t;
int main(){
	int n,r;
	cin>>n>>r;
	if(n>=10)cout<<r;
	else cout<<r+100*(10-n);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
typedef long long LL;
const int MAX=100010;
int n,m;
char s[MAX];
int main()
{
    int i,j,k,t,l;
    while(~scanf("%s",s))
    {
        n=strlen(s);
        int num1=0,num2=0;
        for(i=0;i<n;i++)
        {
            if(s[i]=='g')
                num1++;
            else
                num2++;
        }
        int sum1=(n+1)/2,sum2=n/2;
        int ans=sum2-num2;
        printf("%d\n",ans);

    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD(a * a), N / 2);
	}
	else{
		return MOD(a * power(a, N - 1));
	}
}

signed main(){
	int N, C, i, j, k;
	scanf("%lld%lld", &N, &C);
	vector<int> A(N + 1), B(N + 1);
	for(i = 1; i <= N; i++){
		scanf("%lld", &A[i]);
	}
	int Bmax = 0;
	for(i = 1; i <= N; i++){
		scanf("%lld", &B[i]);
		Bmax = max(Bmax, B[i]);
	}
	vector<vector<int>> v(C + 1, vector<int>(Bmax + 1, 0));
	for(i = 0; i <= C; i++){
		for(j = 1; j <= Bmax; j++){
			v[i][j] = MOD(v[i][j - 1] + power(j, i));
		}
	}
	vector<vector<int>> dp(N + 1, vector<int>(C + 1, 0));
	dp[0][0] = 1;
	for(i = 1; i <= N; i++){
		for(j = 0; j <= C; j++){
			for(k = 0; k <= j; k++){
				dp[i][j] = MOD(dp[i][j] + dp[i - 1][j - k] * (v[k][B[i]] - v[k][A[i] - 1]));
			}
		}
	}
/*	for(i = 0; i <= N; i++){
		for(j = 0; j <= C; j++){
			printf("dp[%lld][%lld] = %lld\n", i, j, dp[i][j]);
		}
		printf("\n");
	}
*/	printf("%lld\n", dp[N][C]);
	return 0;
}

Measured memory_bytes: 2816
N,*A = `dd`.split.map(&:to_i)
p 2*(N-1)
J = (0...N).max_by{ |i| A[i].abs } + 1
(1..N).each{ |i|
  next if i == J
  puts "#{J} #{i}"
}
if A[J-1] >= 0
  (1...N).each{ |i| puts "#{i} #{i+1}" }
else
  (2..N).reverse_each{ |i| puts "#{i} #{i-1}" }
end


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define mod 1000000007

using namespace std;
class CompareFirst
{
public:
  bool operator()(pair<int,int> n1,pair<int,int> n2) {
    return n1.first>n2.first; //>:desc <:asc
  }
};


int main(){

  string s;
  int i,j,k,l,n,m,Lsum=0,Lmax=0;
  long long ans = 1;
  vector<string> vs;
  vector<int> vi;
  pair<int,int> pr;
  //unordered_map<string,int> mp;
  //priority_queue<int> pq; // default ‘å‚«‚¢‡
  //priority_queue<pair<int,int>,vector<pair<int,int>>,CompareFirst> pq;

  cin >> n;
  cin >> s;
  int a[2*n]={0};//0:L, 1:R
  
  rep(i,0,2*n-1){
    if(i%2==0){
      if(s[i]=='W')s[i]='B';
      else s[i]='W';
    }
    if(s[i]=='B'){
      if(Lsum<1){
        cout << 0 << endl;
        return 0;
      }
      ans *= Lsum;
      ans%=mod;
      --Lsum;
    }else{
      Lmax++;
      Lsum++;
    }
  }
  if(Lsum>0){
    cout << 0 << endl;
    return 0;
  }
  rep(i,1,Lmax){
    ans*=i;
    ans%=mod;
  }
  cout << ans << endl;

  return 0;

}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int n; cin>>n;
    int arr[n][3];
    int i;
    f1(i,0,n)
    	cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

    int dp[n][3];
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    f1(i,1,n)
    {
    	dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
    	dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
    	dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    return 0;
}

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

using namespace std;

int field[16][16];
// y,xÌ}X©çènßÄÅ«é·×èûÌ
int dp[16][16];

const int dy[]={1,1,1};
const int dx[]={-1,0,1};
int w,h;

int search(int sx,int sy){
	if(field[sy][sx]==2){
		if(sy>=h-2){
			return 1;
		}
		else if(field[sy+2][sx]==1)
			return 0;
		else{
			return search(sx,sy+2);
		}
	}
	if(dp[sy][sx]!=-1){
		return dp[sy][sx];
	}
	int cnt=0;

	if(sy!=h-1){
		for(int i = 0; i < 3; i++){
			int nx=sx+dx[i];
			int ny=sy+dy[i];
			if(nx>=0&&nx<w){
				if(ny>h-1){
					cnt++;
				}
				else if(ny==h-1&&field[ny][nx]==0){
					cnt++;
				}
				else if(field[ny][nx]==2&&dx[i]==0){
					cnt+=search(nx,ny);
				}
				else if(field[ny][nx]==0){
					cnt+=search(nx,ny);
				}
			}
		}
	}
	else{
		if(field[sy][sx]==0)
			cnt++;
	}

	dp[sy][sx]=cnt;
	return dp[sy][sx];
}


int main(){

	while(cin>>w>>h&&!(w==0&&h==0)){
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>field[i][j];
				dp[i][j]=-1;
			}
		}
		int sum=0;
		for(int i = 0; i < w; i++){
			if(field[0][i]==0)
				sum+=search(i,0);
		}
		cout<<sum<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
def solve(n, k, q, a)
  return if k == 0
  t = [q, a].min
  if n == t * t
    @ans += 1
    t -= 1
  end
  t.downto(t/k) do |x|
    solve(n - x * x, k - 1, Math.sqrt(n - x * x).to_i, x)
  end
end

while n = gets.to_i
  break if n == 0
  @ans = 0
  solve(n, 4, Math.sqrt(n).to_i, n)
  puts @ans
end

Measured memory_bytes: 8748
module graph_mod
    use,intrinsic :: iso_fortran_env
    implicit none
    type node
        integer(int32),allocatable:: to(:)
        integer(int32):: l
    contains
        procedure::  init => node_init
        procedure:: regist => node_regist
    end type


    type graph
        type(node),allocatable:: n(:)
    contains
        procedure:: regist => graph_regist
        procedure:: l => graph_elem_num
        procedure:: v => graph_elem_val
    end type
    interface graph
        module procedure graph_init
    end interface
    private
    public:: graph
contains
    function graph_init(n) result(g)
        type(graph):: g
        integer(int32),intent(in):: n
        integer(int32):: i

        allocate(g%n(n))
        do i=1,n
            call g%n(i)%init()
        end do
    end function


    subroutine graph_regist(g,x,y)
        class(graph):: g
        integer(int32):: x,y

        call g%n(x)%regist(y)
        call g%n(y)%regist(x)
    end subroutine


    function graph_elem_num(g,i) result(ret)
        class(graph):: g
        integer(int32):: i,ret

        ret = g%n(i)%l
    end function


    function graph_elem_val(g,i,j) result(ret)
        class(graph):: g
        integer(int32):: i,j,ret

        ret = g%n(i)%to(j)
    end function


    subroutine node_init(n)
        class(node):: n
        allocate(n%to(1))

        n%l = 0
    end subroutine


    subroutine node_regist(n,m)
        class(node):: n
        integer(int32):: m

        if (n%l+1 > size(n%to)) call add_(n)
        n%l=n%l+1
        n%to(n%l) = m
    end subroutine


    subroutine add_(n)
        type(node):: n
        integer(int32),allocatable:: tmp(:)
        integer(int32):: l

        l = size(n%to)
        allocate(tmp(l))
        tmp(:) = n%to(:)
        deallocate(n%to)
        allocate(n%to(l*2))
        n%to(1:l) = tmp(:)
        deallocate(tmp)
    end subroutine
end module

program abc075_c
    use,intrinsic :: iso_fortran_env
    use graph_mod
    implicit none
    integer(int32):: n,m,i,j,ans
    integer(int32), allocatable:: a(:),b(:)
    type(graph):: g
    logical,allocatable:: pass(:)
    logical:: sep

    read*, n,m
    allocate(a(m),b(m))
    allocate(pass(n))
    do i=1,m
        read*, a(i),b(i)
    end do
    ans=0
    do i=1,m
    g = graph(n)

        do j=1,m
            if (i==j) cycle
            call g%regist(a(j),b(j))
        end do
        pass(:) = .false.
        call dfs(1)
        sep = .false.
        do j=1,n
            if (.not. pass(j)) sep = .true.
        end do
        if (sep) ans=ans+1
    end do
    print'(i0)', ans
contains
    recursive subroutine dfs(n)
        integer(int32):: n,next,i

        pass(n) = .true.
        do i=1,g%l(n)
            next = g%v(n,i)
            if (pass(next)) cycle
            call dfs(next)
        end do
    end subroutine
end program abc075_c

Measured memory_bytes: 256
grades = []
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        grades.append('F')
        continue
    if m + f >= 80:
        grades.append('A')
        continue
    if m + f >= 65:
        grades.append('B')
        continue
    if m + f >= 50:
        grades.append('C')
        continue
    if m + f >= 30:
        if r >= 50:
            grades.append('C')
            continue
        else:
            grades.append('D')
            continue
    if m + f < 30:
        grades.append('F')

for grade in grades:
    print(grade)


Measured memory_bytes: 5600
N = int(input())
a = [0]+list(map(int,input().split()))

b = [0 for i in range(N+1)]
M = 0

for i in range(N):
    ind = N-i
    val = 0
    j=2
    while ind*j<=N:
        val += b[ind*j]
        j+=1
    if val%2 != a[ind]:
        M+=1
        b[ind]=1
print(M)
if M!=0:
    for i in range(1,N+1):
        if b[i]==1:
            M-=1
            if M!=0:
                print(i,end=' ')
            else:
                print(i)


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

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

    int x, y;
    int cnt = 0, max_cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        if (x == y) {
            cnt++;
        } else {
            cnt = 0;
        }
        max_cnt = max(cnt, max_cnt);
    }

    if (max_cnt >= 3) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int n;cin>>n;
	vector<int>X,Y;
	rep(i,n){
		int x,y;scanf("%d%d",&x,&y);
		X.push_back(x-y);
		Y.push_back(x+y);
	}
	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());
	cout<<max(X[n-1]-X[0],Y[n-1]-Y[0])<<endl;
}

Measured memory_bytes: 5032
flag = [True]*52
suit = ["S", "H", "C", "D"]

n = int(input())
for i in range(n):
    s, k = input().split()
    k = int(k)
    for j in range(4):
        if s == suit[j]:
            flag[j*13 + k - 1] = False

for i in range(52):
    if flag[i]:
        print(suit[i//13], str(i%13 + 1))


Measured memory_bytes: 5600
n=gets.to_i
a=gets.chomp.split.map(&:to_i)
b=a.sort
counter=0
a.each_with_index do|x,i|
  if x != b[i]
    counter=counter+1
  end  
end 
if counter==0 || counter==2
  puts "YES"
else
  puts "NO"
end  

Measured memory_bytes: 1788
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Long> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextLong());
        }
        Collections.sort(a);
        long max = a.get(n - 1);
        long middle = max / 2;
        long r = 0;
        long tmp = max;
        for (long i : a) {
            if (i == max) {
                continue;
            }
            if (Math.abs(middle - i) <= tmp) {
                tmp = Math.abs(middle - i);
                r = i;
            }
        }
        System.out.printf("%d %d%n", max, r);
    }
}


Measured memory_bytes: 59272
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
	  	Scanner scanner = new Scanner(System.in);
		int i = 0;
		int num = 0;
 		
		while(true){
			num = scanner.nextInt();
			
			if(num == 0)
				break;
			
		    System.out.println("Case "+ (i+1) + ": "+ num );
		    
		    i ++;
        }
		scanner.close();
    }
}


Measured memory_bytes: 42744
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<stack>
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef vector<P> VP;
typedef vector<int> VI;
typedef vector<VP> VVP;
typedef vector<VI> VVI;
class Pox
{
public:
  int cost,now;
  Pox():cost(0),now(0){}
  Pox(int now,int cost):now(now),cost(cost){}
};

class ope{
public:
  bool operator() (Pox a,Pox b)
  {
    return a.cost > b.cost;
  }
};

const int INF = (1<<28);
int N,M,K;
VVP G;
VI mincost;
//map<P,int> D;

int main()
{
  scanf("%d %d %d",&N,&M,&K);
  G.resize(N),mincost.resize(N);
  for(int i=0;i<N;i++)
      mincost[i] = INF;

  for(int i=0;i<M;i++)
    {
      int a,b,c;
      scanf("%d %d %d",&a,&b,&c);
      a--,b--;
      G[a].push_back(P(b,c));
      G[b].push_back(P(a,c));
      //D[P(a,b)] = D[P(b,a)] = c;
    }

  priority_queue<Pox,vector<Pox>,ope> Q;
  for(int i=0;i<K;i++)
    {
      int a;
      scanf("%d",&a);
      a--;
      Q.push(Pox(a,0));
      mincost[a] = 0;
    }

  while(!Q.empty())
    {
      Pox pox = Q.top(); Q.pop();
      int now = pox.now;
      int total = pox.cost;

      for(int i=0;i<G[now].size();i++)
	{     
	  P p = G[now][i];
	  int to = p.F;
	  int cost = p.S;
	  if(mincost[to] <= total + cost)
	    continue;

	  mincost[to] = total + cost;
	  Q.push(Pox(to,total+cost));
	}
    }


  double mex = 0;
  for(int i=0;i<N;i++)
    for(int j=i+1;j<N;j++)
      for(int k=0;k<G[i].size();k++)
	if(j != i && mincost[j] != INF && mincost[i] != INF && G[i][k].F == j/*D[P(i,j)]*/)
	  mex = max(mex,(double)(mincost[i]+mincost[j]+G[i][k].S/*D[P(i,j)]*/)/2.0 );
	    

  cout << round(mex) << endl;

  return 0;
}

Measured memory_bytes: 4276
#include <iostream>
#include <vector>
#include <queue>
#define INF (1<<26)
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

struct NODE{
	int to , cost , my;
	NODE(int a,int b,int c) { to = a , cost = b , my = c ; }
};

bool operator < (const NODE &a , const NODE &b){
	return a.cost > b.cost;
}
int main(){
	int N,M,L,K,A,H;
	while(cin >> N >> M >> L >> K >> A >> H && N){
		int ice[1001] = {0};
		int wf[101][101];
		rep(i,101)rep(j,101)wf[i][j] = (i!=j ? INF : 0);
		ice[A] = ice[H] = true;
		rep(i,L){
			int a; cin >> a; ice[a] = true;
		}
		rep(i,K){
			int a,b,c;
			cin >> a >> b >> c;
			wf[a][b] = wf[b][a] = c;
		}
		rep(i,N) rep(j,N) rep(k,N) wf[j][k] = min(wf[j][k],wf[j][i] + wf[i][k]);
		
		rep(i,N) rep(j,N) 
			if( !(ice[i] && ice[j] && wf[i][j] <= M) ) wf[i][j] = INF;
		
		bool done[101] = {0};
		priority_queue<NODE> Q;
		Q.push(NODE(A,0,M));
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if(done[q.to]) continue; else done[q.to] = true;
			if(q.to == H){ cout << q.cost << endl; goto exit	; } 
			for(int i = 0 ; i < N ; i++){
				if(ice[i]){
					if(wf[q.to][i] != INF) Q.push(NODE(i , q.cost + wf[q.to][i] + max( 0 , wf[q.to][i] - q.my) , max(0,q.my - wf[q.to][i] ) ) );
				}
			}
		}
		cout << "Help!" << endl;
		exit:;
		
	}  
}

Measured memory_bytes: 0
#include <stdio.h>

int main() {
    int n, ans;
    int odd = 0;
    int even = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        if (i % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }
    ans = odd * even;
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K, S;
    cin >> K >> S;
    int y = 0;
    rep(i, K + 1){
        rep(j, K + 1) {
            int g = S - (i + j);
            if(g <= K && g >= 0){
                y ++;
            }

        }
    }
    cout << y << endl;
}



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

int main(){
  int x;
  for(int i=0;; i++){
    cin >> x;
    if(x == 0)
      break;
    else
      cout << "Case " << i+1 << ": " << x << endl;
  }
  return 0;
}



Measured memory_bytes: 3100
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int len = Integer.parseInt(bf.readLine());
 		String s = bf.readLine().trim();
 		int count =0 ;
 		for(int i = 0;i<s.length()-2;i++){
 			if (s.charAt(i) == 'A' && s.charAt(i+1) == 'B' && s.charAt(i+2) == 'C')
 				count++;
 		}
 		out.println(count);
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25400
n = gets.chomp.to_i
inputs = []
count = 0
ans = true

n.times do
    inputs << gets.chomp.split(" ").map(&:to_i)
end

inputs.sort!{|a, b| a[1] <=> b[1]}

inputs.each do |a, b|
    count += a
    if count > b then
        ans = false
        break
    end
end

puts ans ? "Yes" : "No"

Measured memory_bytes: 18424
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
for i in range(1, N):
    if A[i] != A[0]:
        idx = i
        break
# int((N - idx) / K)
if (N - idx) % (K - 1) == 0:
    print(int((N - idx) / (K - 1)))
else:
    print(int((N - idx) / (K - 1)) + 1)

Measured memory_bytes: 52476
#pragma GCC optimize("O3")
/* #pragma GCC target ("avx2") */
/* #pragma GCC optimize("Ofast") */
/* #pragma GCC optimize("unroll-loops") */
/* #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T, typename cmp=less<T>>
using ordered_set=tree<T,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>;
template<typename K, typename V, typename cmp=less<K>>
using ordered_map=tree<K, V, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
using ll = long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax = 1000*1007;
#define ar array
#define len(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define tT template<typename T
#define tV typename V
#define ins inline string
#ifdef LOCAL
tT>ins to_string(T& t);
ins to_string(string s) {return '"' + s + '"';}
ins to_string(char c){string res="'";res.push_back(c);return res+"'";}
ins to_string(const char* s) {return to_string((string)s);}
ins to_string(char* s) {return to_string((string)s);}
template <size_t N>ins to_string(bitset<N> v) {string res="";for(size_t i = 0; i < N; i++){
res += static_cast<char>('0' + v[i]);}return res;}
ins to_string(bool b) {return (b ? "true" : "false");}
tT,tV>ins to_string(pair<T, V>& p){return "("+ to_string(p.first)+", "+to_string(p.second)+")";}
tT>ins to_string(T& v){string res="{";for(auto& i:v){res+=to_string(i)+',';} return res+'}';}
#define log(...) cerr<< "[" << #__VA_ARGS__ << " : "<< to_string(__VA_ARGS__) << "]"<<endl
#else
#define log(...) 0x30
#endif

vector<int> h;
int dp[100000+7];

int solve(int N){
    /* if(N==0) return; */
    if(N == 1) return 0;
    if(N == 2) return abs(h[0] - h[1]);
    if(dp[N] != -1) return dp[N];
    return dp[N] = min(abs(h[N-1]-h[N-2]) + solve(N-1), abs(h[N-1]-h[N-3])+solve(N-2));
}

int iter_solve(int N){
    dp[1] = 0;
    dp[2] = abs(h[0]-h[1]);
    for(int i=3; i<=N; i++){
        dp[i] = min(abs(h[i-1]-h[i-2]) + dp[i-1], abs(h[i-1]-h[i-3])+dp[i-2]);
    }
    return dp[N];
}

inline void test_case(){
    memset(dp, -1, sizeof dp);
    int N;
    cin>>N;
    h.resize(N);
    for(int& i : h) cin>>i;
    cout<<iter_solve(N)<<"\n";
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    tt=  1;
    for(int qq=1; qq<=tt; qq++){
        /* cout<<"Case #"<<qq<<": "; */
        test_case();
    }
}   



Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF (1LL<<59)
#define int ll

//verified AOJ GRL_1
#define MAX_V 100000
struct edge{int to,cost;};
vector<edge> G[MAX_V];

void dijkstra(int s, vector<ll> &d){
	priority_queue< pii,vector<pii>,greater<pii> > que;
	//    rep( i,d.size() )d[i]=INF;
	d[s] = 0;
	que.push( pii(0,s) );
	
	while( que.size() ){
		pii p=que.top();
		que.pop();
		
		int v=p.second;
		if(d[v]<p.first)continue;
		
		rep(i,G[v].size()){
			edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(pii(d[e.to],e.to));
			}
		}
	}
}


template<class T>
class segtree{
private:
	vector<T> dat;
	int _size;  //the number of leaves
	T _init;
	
public:
	segtree(int __size=0 , T init=T() ):_size(__size) , _init(init) , dat(4*__size,init){
		if(__size==0)return ;
		int x=1;
		while(x<_size)x*=2;
		_size = x;
	}
	
	
	void init(int m,int x){
		int i = m+_size;
		dat[i].pb(x);
	}
	
	void refresh(){
		for(int i=_size-1;i>0;i--){
			T tmp = dat[2*i];
			tmp.insert( tmp.end(),all(dat[2*i+1]) );
			dat[i] = tmp;
		}
	}
 
	
	int find(int s,int t,int p,int num=1,int a=0,int b=-1){
		if(b==-1)b=_size-1; //I couldn't "int b=_size".
		if(b<s||t<a)return 0;
		if(s<=a&&b<=t)return dat[num].size()-(lower_bound(all(dat[num]),p)-dat[num].begin());
		int  ret,res;
		ret = find(s,t,p,num*2,a,(a+b)/2);
		res = find(s,t,p,num*2+1,(a+b)/2+1,b);
		
		return ret+res;
	}
	
	void sortAll(){
		rep(i,_size*2-1){
			sort(all(dat[i]));
		}
	}
};


signed main(){
	set<ll> valid_number;
	int n,m;
	cin>>n>>m;
	rep(i,m) {
		int a,b,c;
		scanf("%lld%lld%lld",&a,&b,&c);
		
		G[a].pb(edge{b,c});
		G[b].pb(edge{a,c});
	}
	
	vector<ll> ds(n,INF), dg(n,INF);
	dijkstra(0,ds);
	dijkstra(n-1,dg);
	
	rep(i,ds.size()) valid_number.insert(ds[i]);
	
	
	int q;
	cin>>q;
	vector<pair<ll,ll>> query;
	rep(i,q){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		valid_number.insert(a);
		query.pb(pair<ll,ll>(a,b));
	}
	
	
	map<ll,int> conv;
	int c=0;
	for(auto & num:valid_number){
		conv[num] = c++;
	}
	
	
	segtree<vi> st( valid_number.size() );
	rep(i,n){
		st.init(conv[ds[i]],dg[i]);
	}
	st.refresh();
	st.sortAll();
	
	rep(i,q){
		printf( "%lld\n",st.find(0,conv[query[i].first],query[i].second));
	}
}

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

int main() {
  int n, k; cin >> n >> k;
  vector<int> x(n);
  rep(i, n) cin >> x[i];

  int ans = 0;
  rep(i, n) ans += min(x[i], abs(k-x[i]));
  cout<<2*ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <list>
#include <algorithm>

using namespace std;

int main()
{
    int q, x, i;
    char com[20];
    // 標準ライブラリより list を使用
    list<int> v;

    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%s", com);
        if (com[0] == 'i') {        // insert
            scanf("%d", &x);
            v.push_front(x);
        } else if (com[6] == 'L') { // deleteLast
            v.pop_back();
        } else if (com[6] == 'F') { // deleteFirst
            v.pop_front();
        } else if (com[0] == 'd') { // delete
            scanf("%d", &x);
            for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
                if (*it == x) {
                    v.erase(it);
                    break;
                }
            }
        }
    }

    i = 0;
    for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if (i++) printf(" ");
        printf("%d", *it);
    }
    printf("\n");

    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int diff = b - a;
    int ret = (diff-1+1) * (diff-1) / 2;
    cout << ret - a << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define ln "\n"
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define ppll pair<ll,pll>
#define vll vector<ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define sll stack<ll>
#define qll queue<ll>
#define pqll priority_queue<ll>
#define mp make_pair
#define f first
#define s second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define Test ll tt;cin>>tt; while(tt--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define init(x,n,v) for(ll i=0;i<=n;i++) x[i]=v
#define scan(x,n)  for(ll i=0;i<n;i++) cin>>x[i]
#define scan1(x,n) for(ll i=1;i<=n;i++) cin>>x[i]
#define all(x) x.begin(),x.end()
ll mod = 1e9+7;
#define N 300005

int main() 
{
	fast_io;
	// Test
    ll n,i;
    cin>>n;
    ll arr[n],dp[n];
    scan(arr,n); init(dp,n-1,1e9);
    dp[0]=0;dp[1]=abs(arr[0]-arr[1]);
    for(i=2;i<n;i++)
     dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i-1]-arr[i]));
    cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
int main() {
	std::string s;
	int n, q;
	std::cin >> n >> q;
	std::cin >> s;
	int r, l;
	std::vector<int> sum;
	sum.resize(n);
	bool flag = false;
	int cache = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'A')
			flag = true;
		if (flag) {
			if (s[i] == 'C') {
				cache++;
			}
			if (s[i] != 'A')
				flag = false;
		}
		sum[i] = cache;
	}
	std::vector<int> ans;
	ans.resize(q);
	for (int i = 0; i < q; i++) {
		std::cin >> l >> r;
		ans[i] = sum[r-1] - sum[std::max(l - 1,0)];
	}
    
	for (auto& e : ans) {
		std::cout << e << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
using namespace std;

typedef long long int lli;

string S;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> S;
    if(S == "ABC")
        cout << "ARC";
    else
        cout << "ABC";
    return 0;
}

Measured memory_bytes: 3648
def main():
    N, P = (int(i) for i in input().split())
    S = input()
    ans = 0
    if P == 2 or P == 5:
        for i, s in enumerate(S, start=1):
            if int(s) % P == 0:
                ans += i
        return print(ans)
    cnt = [0]*P
    cnt[0] += 1
    d = 1
    cur = 0
    for s in S[::-1]:
        s = int(s)
        cur += (s * d) % P
        cur %= P
        d *= 10
        d %= P
        cnt[cur] += 1
    for c in cnt:
        if c:
            ans += c*(c-1)//2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41968
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};


int main(void){
    lint N,K;
    cin >> N >> K;
    lint A[N];
    vector<lint> m,p;
    rep(i,N) cin >> A[i];
    sort(A,A+N);
    lint minus=0,zero=0,plus=0;
    rep(i,N){
        if(A[i]<0) minus++,m.push_back(-A[i]);
        if(A[i]==0) zero++;
        if(A[i]>0) plus++,p.push_back(A[i]);
    }
    sort(p.begin(),p.end());
    sort(m.begin(),m.end());
    lint minusp,zerop,plusp;
    minusp=minus*plus;
    zerop=zero*plus+zero*minus+(zero*(zero-1))/2;
    plusp=(minus*(minus-1))/2+(plus*(plus-1))/2;
    int hugou=0;
    if(K<=minusp) hugou=-1;
    else if(K<=minusp+zerop) hugou=0;
    else hugou=+1;
    if(hugou==0) cout << 0 << endl;
    else if(hugou==-1){
        lint hi=1e18,lo=0;
        lint ans=0,count=0;
        while(hi-lo>1){
            ans=0,count=0;
            lint mid=(hi+lo)/2;
            rep(i,m.size()){
                auto itr=lower_bound(p.begin(),p.end(),(mid+m[i]-1)/m[i]);
                count+=p.size()-(itr-p.begin());
            }
            (count>=K?lo:hi)=mid;
            ans=mid;
        }
        cout << -lo << endl;
    }
    else{
        K=(N*(N-1))/2+1-K;
        lint hi=1e18,lo=0;
        lint ans=0,count=0;
        while(hi-lo>1){
            ans=0,count=0;
            lint mid=(hi+lo)/2;
            rep(i,m.size()){
                auto itr=lower_bound(m.begin(),m.end(),(mid+m[i]-1)/m[i]);
                count+=m.size()-(itr-m.begin());
                if(itr-m.begin()<=i) count--; 
            }
            rep(i,p.size()){
                auto itr=lower_bound(p.begin(),p.end(),(mid+p[i]-1)/p[i]);
                count+=p.size()-(itr-p.begin());
                if(itr-p.begin()<=i) count--;
            }
            count/=2;
            (count>=K?lo:hi)=mid;
            ans=mid;
        }
        cout << lo << endl;
    }
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-4;
const int MAX=1e5+10;
const ll mod=1e9+7;
/***************************************  head  **********************************************/
int main()
{
	string s;
	int ans;
	while(cin>>s)
	{
		ans=0;
		for(int i=0;i<3;i++) ans+=(s[i]=='1');
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin >> N >> S;
  int f = 0, b = 0;
  for (int i = 0; i < (int) S.size(); i++) {
    if (S.at(i) == '(') {
      f++;
    }
    else {
      b++;
    }
    if (f < b) {
      S = '(' + S;
      f++;
      i++;
    }
  }
  for (int i = 0; i < f - b; i++) {
    S += ')';
  }
  cout << S << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> T keta(T num){ T k=0; while(num>0){ num/=10; k++; } return k; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebug(multimap<T1, T2> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mdebugr(map<T1, T2, greater<T1>> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebugr(multimap<T1, T2, greater<T1>> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

	int n, k;
	ll ain;
	ll asum[1010];
	asum[0] = 0;
	cin >> n >> k;
	reps(i, 1, n){
		cin >> ain;
		asum[i] = asum[i-1] + ain;
	}
	
	vector<ll> sums;
	reps(l, 0, n){
		reps(r, l, n){
			ll num = asum[r]-asum[l];
			sums.push_back(num);
		}
	}
	
	ll res = 0;
    vector<ll> dist = sums;
    repr(i, 40, 0){
        ll cnt = 0;
        vector<ll> tmp;
        for(auto const& d : dist){
            if(d & 1LL<<i){
                tmp.push_back(d);
                cnt++;
            }
        }
        if(cnt >= k){
            res += (1LL<<i);
            dist.clear();
            dist = tmp;
        }
    }
	
	cout << res << endl;
	
	// debug
	/*
	reps(i, 0, 40){
		cout << bit[i].size() << endl;
	}
	adebug(asum, n);
	*/

    return 0;
}


Measured memory_bytes: 9964
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
	Node *cur = nil->next;
	while (cur != nil&&cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList() {
	Node *cur = nil->next;
	int isf = 0;
	while (1) {
		if (cur == nil)break;
		if (isf++ > 0)printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t) {
	if (t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	deleteNode(listSearch(key));
}

void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') {
			insert(key);
			np++;
			size++;
		}
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F')deleteFirst();
				else if (com[6] == 'L')deleteLast();
			}
			else {
				deleteKey(key); nd++;
			}
			size--;
		}
	}

	printList();

	return 0;
}

Measured memory_bytes: 33840