akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Scanner;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.nextLine());
		int[][] sq = new int[6][n];
		for(int i = 0;i < n;i++){
			String tmp = scan.nextLine();
			for(int j = 0;j < 6;j++){
				sq[j][i] = Integer.parseInt(tmp.split(" ")[j]);
			}
		}
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(i != j){
				if(check(sq[0][i],sq[1][i] , sq[2][i], sq[3][i], sq[4][i], sq[5][i], sq[0][j], sq[1][j], sq[2][j], sq[3][j], sq[4][j], sq[5][j])){
					System.out.println("No");
					return;
				}
			}
			}
		}
		System.out.println("Yes");
	}

	public static boolean check(int one, int two, int three, int four, int five, int six, int one2, int two2, int three2,
			int four2, int five2, int six2) {
		String s = "EEEENEEEENEEEESSSEEEENESEEEENWWSEEEE";

		for (int i = 0; i < s.length(); i++) {
			int tmp;
			if (s.charAt(i) == 'E') {
				tmp = one;
				one = four;
				four = six;
				six = three;
				three = tmp;
			} else if (s.charAt(i) == 'N') {
				tmp = one;
				one = two;
				two = six;
				six = five;
				five = tmp;
			} else if (s.charAt(i) == 'S') {
				tmp = one;
				one = five;
				five = six;
				six = two;
				two = tmp;
			} else if (s.charAt(i) == 'W') {
				tmp = one;
				one = three;
				three = six;
				six = four;
				four = tmp;
			}
			if (one == one2 && two == two2 && three == three2 && four == four2 && five == five2 && six == six2) {
				return true;
			}
		}
		return false;
	}
}
// }



Measured memory_bytes: 27660
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for(i=0; i<n; i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    
    int i,j;
    set<string>X;
    string s;
    map<string,int>mp;
    int n;
    cin >> n;
    while(n--)
    {
        cin >> s;
    //    X.pb(s);
        mp[s]++;
    }
    
    cout << "AC x " << mp["AC"] << '\n';
    cout << "WA x " << mp["WA"] << '\n';
    cout << "TLE x " << mp["TLE"] << '\n';
    cout << "RE x " << mp["RE"] << '\n';
        

}


Measured memory_bytes: 3656
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(right(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll a, m=0, ans=0;
	for(ll i=0; i<n; i++){
		cin >> a;
		if(a >= m){
			ans ++;
			m = a;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3588
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        var x = new int[s.Length + 1];

        for (int i = 0; i < s.Length; i++) {
            var c = s[i];
            if (c == '<') {
                x[i + 1] = x[i] + 1;
            }
        }

        var x2 = new int[s.Length + 1];

        for (int i = s.Length - 1; i >= 0; i--) {
            var c = s[i];
            if (c == '>') {
                x2[i] = x2[i + 1] + 1;
            }
        }

        long sum = 0;
        for (int i = 0; i < x.Length; i++) {
            sum += Math.Max(x[i], x2[i]);
            //Debug.Write(Math.Max(x[i], x2[i]));
            //Debug.Write(" ");
        }
        //Debug.WriteLine("");
        return sum;
    }
}


Measured memory_bytes: 16736
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	vector<pair<int, int>> data;
	FOR(i, 1, N + 1)
	{
		int b;
		cin >> b;
		data.push_back(make_pair(b, i));
	}

	sort(range(data));

	FOR(i, 0, N)
		cout << data.at(i).second << " ";
	cout << endl;

	return 0;
}



Measured memory_bytes: 4284
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
using namespace std;
 
ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int main()
{
    int n,k;
    int r=1;
    cin>>n>>k;
    for(int i=0;i<n;i++){
           if(r*2>r+k)r=r+k;
           else r=r*2;
    }
   
    cout<<r; 
    return 0;
}


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

int main (){
	string s1,s2;
	cin >>s1>>s2;
	int count =0;
	for (int i=0; i<s1.length(); i++){
		if (s1[i] != s2[i]) count ++;
	}
	cout <<count;
	return 0;
}

Measured memory_bytes: 3836
'use strict';
function main(input) {
  input = input.split(/\s+/).map(x => x);
  // console.log(input);
  let n = input.shift();
  let m = input.shift();
  let c = input.shift();
  let b = [];
  let ans = 0;

  for (let i = 0; i < m; ++i) b.push(input.shift());
  for (let i = 0; i < n; ++i) {
    let total = 0;
    for (let j = 0; j < m; ++j) {
      let a = input.shift();
      total += a * b[j];
    }
    total += Number(c);
//    console.log(total)
    if (total > 0) ans += 1;
  }

  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

#define fi first
#define se second

#define pb push_back
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef long double ld;

const int base = 1000 * 1000 * 1000;

const int N = (int)2e5 + 2;
const int INF = (int)1e9 + 7;

const ld pi = acos(-1);
const ll linf = (ll)1e18;

typedef pair < ll, ll > pll;
typedef pair < int, int > pii;

int n, h, w;
int main(){
    scanf ("%d %d %d", &n, &h, &w);
    int ans = 0;
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= n; ++j){
            if (j + w - 1 <= n && i + h - 1 <= n){
                ans++;
            }
        }
    }
    printf ("%d\n", ans);
    return 0;
}


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

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_MAX;

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long int COM(long int n,long int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    int vn[200000] = {},v1[200000] = {};
    int n,m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        if(a == 1){
            v1[b-1]++;
        }
        if(b == n){
            vn[a-1]++;
        }
    }
    for(int i = 0; i < 200000; ++i){
        if(vn[i] >= 1 && v1[i] >= 1){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;

}

Measured memory_bytes: 1792
# 高橋くんのモンスターは体力Aで攻撃力B
# 青木くんのモンスターは体力Cで攻撃力D
# 高橋くんが勝つならYes、負けるならNoを出力する

A, B, C, D = map(int, input().split())

while A > 0 and C > 0:
    C -= B
    A -= D

if C <= 0:
    print('Yes')
elif A <= 0:
    print('No')


Measured memory_bytes: 8880
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
std::deque<char> s1, s2;
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	std::string tmp;
	in >> tmp;
	for (auto& c : tmp) {
		s1.push_back(c);
	}
	in >> tmp;
	for (auto& c : tmp) {
		s2.push_back(c);
	}
	for (size_t i = 0; i < tmp.size(); i++)
	{
		if (s1 == s2) {
			out << "Yes" << endl;
			return 0;
		}
		s1.push_front(s1.back());
		s1.pop_back();
	}
	out << "No" << endl;

	return 0;
}
#endif


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>ostream&operator<<(ostream &o,const vector<T>&t){o<<'[';FOR(i,t){if(i!=t.begin())o<<',';o<<*i;}return o<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void out(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void out(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);out<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';out<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T *a,int n){REP(i,n){if(i)cout<<',';cout<<a[i];}cout<<endl;}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>void output(T t){if(t<0)t=-t,putchar(45);static int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;putchar(c[--k]^48));}
template<class S,class ...T>void output(S a,T...t){output(a);putchar(' ');output(t...);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());t=10*t+c-48);t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }

ll modmul(ll a, ll b, ll m) {
  ll r = 0;
  for (;b;b>>=1,a=(a<<1)%m) if (b&1) r = (r+a)%m;
  return r;
}

ll modpow(ll a, ll n, ll m) {
  ll r = 1;
  for (ll x=a%m; n; n>>=1, x=modmul(x,x,m)) if (n&1) r = modmul(r,x,m);
  return r;
}

bool Miller_Rabin(ll n, int k=20) {
  if (n<=1) return 0;
  if (!(n&1)) return n==2;
  if (n%3==0) return n==3;

  ll s = 0, d = n-1;                    // n-1 = s^2 * d (d: odd)
  while(!(d&1)) s++, d>>=1;
  while(k--) {
    ll a = (ll)rand()*rand()%(n-3)+2;
    ll x=modpow(a,d,n);
    if (x==1 || x==n-1) continue;
    bool b = 0;
    for (int r=1; r<s; ++r) {
      x = modmul(x,x,n);
      if (x==1) return 0;
      if (x==n-1) {
        b = 1;
        break;
      }
    }
    if (!b) return 0;
  }
  return 1;  
}

int main() {
  int n;
  while(cin >> n) {
    int res = 0;
    REP(i,n) {
      ll A; cin >> A;
      A = 2*A+1;
      while(A%2==0) A/=2;
      if (A==1||Miller_Rabin(A)) res++;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1172
import java.util.*;
 
public class Main {
    static final long MOD=1000000007;
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        long[] nums=new long[n];
        nums[0]=sc.nextInt();
        for(int i=1;i<n;i++){
            nums[i]=nums[i-1]+sc.nextInt();
        }
        long output=Long.MAX_VALUE;
        for(int i=0;i<n-1;i++){
            output=Math.min(output, Math.abs(nums[n-1]-nums[i]*2));
        }
        System.out.println(output);
    }
}

Measured memory_bytes: 65288
n, w = map(int, input().split())
vw = [input().split() for _ in range(n)]
vw = [(int(x[0]), int(x[1]))for x in vw]

pdp = [0 for _ in range(w+1)]
cdp = [0 for _ in range(w+1)]

for i in range(n):
    for j in range(w):
        if j + vw[i][1] < w + 1:
            cdp[j + vw[i][1]] = max(pdp[j + vw[i][1]], pdp[j] + vw[i][0])
    pdp = cdp[:]
print(max(cdp))



Measured memory_bytes: 6596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    ll n;
    cin >> n;
    string ans = "";
    char letters[26];
    letters[0] = 'z';
    char a = 97;
    for(int i = 1; i<26; i++){
        letters[i] = a++;
    }
    if(n < 26){
        cout << letters[n] << "\n";
        return 0;
    }
    while(n > 0){
        n -= 1;
        ans.push_back(('a' + n%26));
        n /= 26;
    }

    // if(n == 1 || n == 0){
    //     ans.push_back(letters[n]);
    // }

    reverse(ans.begin(), ans.end());

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3584
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
INF = float('inf')

def dfs(cursor=0, a=0, b=0, c=0):
    if cursor == N:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if a*b*c > 0 else INF

    no_compound = dfs(cursor+1, a, b, c)
    A_compound = dfs(cursor+1, a+L[cursor], b, c) + 10
    B_compound = dfs(cursor+1, a, b+L[cursor], c) + 10
    C_compound = dfs(cursor+1, a, b, c+L[cursor]) + 10
    return min(no_compound, A_compound, B_compound, C_compound)

print(dfs())


Measured memory_bytes: 3064
n = input()
p = map(float, raw_input().strip().split())

dp = [[0 for i in xrange(n + 1)] for j in xrange(n + 1)]
dp[0][0] = 1

for i in xrange(1, n + 1):
    for j in xrange(i + 1):
        dp[i][j] = dp[i - 1][j] + p[i - 1] * (dp[i - 1][j - 1] - dp[i - 1][j])

ans = 0
for k in xrange(n + 1):
    if 2 * k > n: ans += dp[i][k]

print "{0:.10f}".format(ans)

Measured memory_bytes: 169628
#include<stdio.h>

int main(void)

{

int  i, j = 0, seisu[10000], max = -10000000, min = 10000000, num;

long int sum = 0;

scanf("%d", &i);



while(j != i)

{

      scanf("%d", &seisu[j]);



      j++;

}



j = 0;



for(j=0; j<i; j++)

{

num = seisu[j];

if(max < num)

{

   max = num;

}

if(min > num)

{

   min = num;

}

sum = sum + num;

}

printf("%d %d %ld\n", min, max, sum);

return 0;

}

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

const int N = 2010;

int n, m, d, c1, c2, p1, p2;
int ans[N][N];
char c;
char ch[4] = {'R', 'Y', 'G', 'B'};

int main(void) {
	scanf("%d%d%d", &n, &m, &d);
	for (int i = -1010; i <= 1010; i += d) {
		c1 ^= 1;
		for (int j = -1010; j <= 1010; j += d) {
			c2 ^= 1;
			for (int x = 0; x < d; x++)
				for (int y = 0; y < d; y++) {
					c = ch[c1 << 1 | c2];
					if (i + x + j + y < 0 || i + x - j - y < 0) continue;
					ans[(i + x + j + y) >> 1][(i + x - j - y) >> 1] = c;
				}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++)
			putchar(ans[i][j]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 15488
{-# LANGUAGE BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Applicative
import Text.Printf


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

main = do
    [h, w] <- replicateM 2 readInt
    if h == 0 && w == 0
        then return ()
        else draw h w >> putStrLn "" >> main

draw h w = putStrLn (replicate w '#') >> inside >> putStrLn (replicate w '#')
  where inside = replicateM (h-2) (putStr "#" >> replicateM (w-2) (putStr ".") >> putStrLn "#")


Measured memory_bytes: 4128
#include<stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  int count=0;
  if(N!=0){
  int chr[N];
  for(int i=0;i<N;i++){
    scanf("%d",&chr[i]);
  }
  int j=1;
  while(j){
    for(int i=0;i<N;i++){
      if(chr[i]%2==1){
        j=0;
        break;
      }
      else
        chr[i]=chr[i]/2;
    }
    if(j!=0)
    count++;
  }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            a = int.Parse(Console.ReadLine());
            int h = a / 3600;
            int m = a % 3600 / 60;
            int s = a % 3600 % 60;
            Console.WriteLine("{0}:{1}:{2}",h,m,s);
        }
    }
}

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

int main(){
    int H,W;

    while(1){
        cin >> H >> W;
        if(H==0 && W==0)break;

        for(int i=0;i<H ; i++){
            for(int j=0 ; j<W ; j++){
                cout << "#";
             }
                 cout << "\n";
            }
            cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

struct edge{
    int to, c, h, r;
};


void solve(int n,int m,int h,int k){
    vector<vector<edge>> v(n);
    rep(i,m){
        int a,b,c,d,e;
        cin>>a>>b>>c>>d>>e;
        --a;--b;--e;
        v[a].push_back({b,c,d,e});
        v[b].push_back({a,c,d,e});
    }
    int s,t;
    cin>>s>>t;--s;--t;
    int p;
    cin>>p;
    vector<int> d(p),mask(p);
    rep(i,p){
        int l;cin>>l>>d[i];
        rep(j,l){
            int x;
            cin>>x;
            --x;
            mask[i]+=1<<x;
        }
    }
    vector<int> dp(1<<k, inf);
    dp[0]=0;
    rep(i,p)rep(j,1<<k){
        dp[j|mask[i]]=min(dp[j|mask[i]],dp[j]+d[i]);
    }
    int ans=inf;
    rep(j,1<<k){
        vector<vector<int>> dist(n,vector<int>(h+1,inf));
        dist[s][0]=dp[j];
        using T = pair<int,pair<int,int>>;
        priority_queue<T,vector<T>,greater<T>> pq;
        pq.push({dp[j],{s,0}});
        while(!pq.empty()){
            auto q = pq.top();pq.pop();
            int cd=q.first, cx=q.second.first, ch=q.second.second;
            if(cd!=dist[cx][ch])continue;
            for(auto e:v[cx]){
                int nd;
                if((1<<e.r)&j)nd=cd;
                else nd=cd+e.c;
                if(ch+e.h<=h && nd<dist[e.to][ch+e.h]){
                    dist[e.to][ch+e.h]=nd;
                    pq.push({nd,{e.to,ch+e.h}});
                }
            }
        }
        rep(i,h+1){
            ans=min(ans,dist[t][i]);
        }
    }
    if(ans==inf)cout<<-1<<endl;
    else cout<<ans<<endl;
}




int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,h,k;
    while(cin>>n>>m>>h>>k,n!=0)solve(n,m,h,k);
    return 0;
}


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

int main() {
    // input
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        int an;
        cin >> an;
        a[i] = an;
    }

    // solve
    int ans = 1000000000;
    sort(a.begin(), a.end());
    for (int i = a[0]; i <= a[N - 1]; ++i) {
        int tmp = 0;
        for (int j = 0; j < N; ++j) {
            tmp += (i - a[j]) * (i - a[j]);
        }
        ans = min(ans, tmp);
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a;
    cin>>a;
    if(a==7 || a==5 || a==3)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;

ll n, q, cnt[101010], sum;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    for(int i=1; i<=n; i++){
        ll t; cin >> t; cnt[t]++; sum += t;
    }
    cin >> q;
    while(q--){
        ll a, b; cin >> a >> b;
        sum -= cnt[a] * a;
        sum -= cnt[b] * b;
        cnt[b] += cnt[a]; cnt[a] = 0;
        sum += cnt[b] * b;
        cout << sum << "\n";
    }
}

Measured memory_bytes: 4432
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int num[5] = {};
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if(s[0] == 'M') num[0]++;
        if(s[0] == 'A') num[1]++;
        if(s[0] == 'R') num[2]++;
        if(s[0] == 'C') num[3]++;
        if(s[0] == 'H') num[4]++;
    }
    ll ans = 0;
    for(int i = 0; i < 5; i++) {
        for(int j = i + 1; j < 5; j++) {
            for(int k = j + 1; k < 5; k++) {
                ans += (ll)num[i] * num[j] * num[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>

#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)

#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

int dp[200010],sum[200010];        
signed main() {
	
	//fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//https://codeforces.com/contest/1084/problem/D
	// https://codeforces.com/contest/1155/problem/E
	//https://www.spoj.com/problems/MON2012/
	//https://codeforces.com/blog/entry/52726	
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	dp[0]=1;
	sum[arr[0]]=1;
	for(int i=1;i<n;i++)
	{
		if(arr[i]!=arr[i-1])
		{
			sum[arr[i]]+=dp[i-1];
			sum[arr[i]]%=MOD;
		}
		dp[i]=sum[arr[i]];
	}
	cout<<dp[n-1];
	return  0;


}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll m;
ll v;
ll p;
ll a[100100];
ll d[100100];
int main(){
	cin>>n>>m>>v>>p;
	REP(i,n)cin>>a[i];
	sort(a,a+n,greater<ll>());
	for(int i=p;i<n;i++){
		d[i]=a[p-1]-a[i];
	}
	ll ans=p;
	ll co=0;
	for(ll i=p;i<n;i++){
		if(a[i]+m<a[p-1]){
			cout<<ans<<endl;
			return 0;
		}
		ll tt=m*(p-1+n-i)+co+(a[i]+m-a[p-1])*(i-p+1);
		if(tt>=m*v){
			ans++;
		}
		co+=d[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

signed main(){
  int N; cin >> N;
  int sum = 0, sum1 = 0;
  vector<int> a(N), b(N);
  for(int i = 0; i < N; i++){
    cin >> a[i]; sum += a[i];
  }
  for(int i = 0; i < N; i++){
    cin >> b[i]; sum1 += b[i];
  }
  if(sum < sum1){
    cout << -1 << endl;
    return 0;
  }
  sum = 0;
  int c = 0;
  vector<int> sa(N);
  for(int i = 0; i < N; i++){
    sa[i] = a[i] - b[i];
    if(sa[i] < 0) {
      sum += sa[i]; c++;
    } 
  }
  sort(sa.begin(), sa.end()); reverse(sa.begin(), sa.end());
  int i = 0;
  while(sum < 0){
    sum += sa[i];
    i++;
  }
  cout << c + i << endl;
}

Measured memory_bytes: 2560
a, b = map(int, input().split())

# a - b - 0 -> n or p
# a - 0 - b -> zero
# 0 - a - b -> p
def main():
    if a <= 0 <= b:
        return 'Zero'
    if 1 <= a:
        return 'Positive'
    
    c = b - a + 1
    if c % 2 == 0:
        return 'Positive'
    else:
        return 'Negative'

print(main())

Measured memory_bytes: 2940
object Main extends App {
    var get = readLine.split(" ")
  var n = get(0).toInt
  var x = get(1).toInt
  var sum = 1
  var jump = 0
    var get2 = readLine.split(" ")
  for( i <- 0 until n){ 
    jump = jump + get2(i).toInt
    if(jump <= x)
    sum = sum + 1
  }
  println(sum)
}

Measured memory_bytes: 25420
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

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;

int n;

int tab[nax];

vi wyn;

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		scanf("%d", &tab[i]);
		wyn.push_back(tab[i]);
	}
	sort(wyn.begin(), wyn.end());
	reverse(wyn.begin(), wyn.end());
	for (int i=1; i<=n; i++)
		printf("%d\n", wyn[wyn[0]==tab[i]]);
	return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<ll> h(n);
	rep(i,n) cin >> h[i];
	if(n == 1){
		cout << "Yes" << endl;
		return 0;
	}
	for(int i(n-2);i>=0;--i){
		if(h[i] - h[i+1] >= 2){
			cout << "No" << endl;
			return 0;
		}else if(h[i] - h[i+1] == 1){
			h[i]--;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
//#define INF 1145141919
#define INF (1LL<<60)
#define MOD 1000000007

int N;
long long dp[5001];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<P2> xs;
  rep(i, N) {
    int h, p;
    cin >> h >> p;
    xs.pb(P2(h+p, P(h, p)));
  }
  sort(all(xs));
  rep(i, N+1) dp[i] = INF;
  dp[0] = 0;
  rep(i, N) {
    int h = xs[i]._2._1, p = xs[i]._2._2;
    for (int j=N; j>=0; j--) {
      if (dp[j] <= h) dp[j+1] = min(dp[j+1], dp[j]+p);
    }
  }
  int m = 0;
  rep(i, N+1) if (dp[i] != INF) m = max(m, i);
  cout << m << "\n";
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  string S;
  cin>>S;
  int s[30];
  for(int i=0; i<30; ++i) s[i]=0;
  
  for(int i=0; i<S.size(); ++i){
    if(S.at(i)=='q') s[1]+=1;
    if(S.at(i)=='w') s[2]+=1;
    if(S.at(i)=='e') s[3]+=1;
    if(S.at(i)=='r') s[4]+=1;
    if(S.at(i)=='t') s[5]+=1;
    
    if(S.at(i)=='y') s[6]+=1;
    if(S.at(i)=='u') s[7]+=1;
    if(S.at(i)=='i') s[8]+=1;
    if(S.at(i)=='o') s[9]+=1;
    if(S.at(i)=='p') s[10]+=1;
    
    if(S.at(i)=='a') s[11]+=1;
    if(S.at(i)=='s') s[12]+=1;
    if(S.at(i)=='d') s[13]+=1;
    if(S.at(i)=='f') s[14]+=1;
    if(S.at(i)=='g') s[15]+=1;
    
    if(S.at(i)=='h') s[16]+=1;
    if(S.at(i)=='j') s[17]+=1;
    if(S.at(i)=='k') s[18]+=1;
    if(S.at(i)=='l') s[19]+=1;
    if(S.at(i)=='z') s[20]+=1;
    
    if(S.at(i)=='x') s[21]+=1;
    if(S.at(i)=='c') s[22]+=1;
    if(S.at(i)=='v') s[23]+=1;
    if(S.at(i)=='b') s[24]+=1;
    if(S.at(i)=='n') s[25]+=1;
    if(S.at(i)=='m') s[26]+=1;
  }
  
  bool CAN=true;
  for(int i=0; i<30; ++i){
    if(s[i]%2!=0) CAN=false;
  }
  if(CAN) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
input_raw = input() # yyyy/mm/dd
str_list = input_raw.split("/")

yyyymmdd = int(str_list[0]) * 10000 + int(str_list[1]) * 100 + int(str_list[2])

if yyyymmdd <= 20190430:
  print('Heisei')
else:
  print('TBD')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
//#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch VariousSushi | diff VariousSushi.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address VariousSushi.cpp && ./a.out

/*
 
 2/19/2019
 
 21:25-21:59 WA
 
 */

const int MAX_N=1e6+1;
LL D[MAX_N];
int T[MAX_N];
int N,K;

void solve() {
  vector<pair<LL,int>> X(N);
  REP(i,N) X[i]={D[i],T[i]};
  sort(X.rbegin(),X.rend());
  
  dumpc(X);
  
  LL cur=0;
  MAPII ts;
  
  REP(i,K) {
    cur+=X[i].first;
    ts[X[i].second]++;
  }
  LL res=cur+1LL*SZ(ts)*SZ(ts);
  int l=K-1,r=K,n=K;
  dump(l,r,cur,SZ(ts),n);
  while(l>=0&&r<N) {
    while(l>=0) {
      int t; LL d; tie(d,t)=X[l--];
      if(ts[t]>1) {
        cur-=d,ts[t]--,--n;
        break;
      }
    }
    while(r<N) {
      int t; LL d; tie(d,t)=X[r++];
      if(ts.count(t)==0) {
        cur+=d,ts[t]++,++n;
        break;
      }
    }
    dump(l,r,n);
    if(n!=K) break;
    SMAX(res,cur+1LL*SZ(ts)*SZ(ts));
    dump(l,r,cur,SZ(ts));
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>K;
  REP(i,N) cin>>T[i]>>D[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 9740
n, m = map(int, input().split())
island_set = set()

for i in range(m):
    island_set.add(tuple(map(int, input().split())))

for i in range(2, n):
    if (1, i) in island_set:
        if (i, n) in island_set:
            print("POSSIBLE")
            break

else:
    print("IMPOSSIBLE")


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

const int MAX = 100005;

int main() {
  int A[MAX];
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];

  int num_divisions = 1;
  int current_index = 1;
  bool is_increasing = false;
  while (current_index < N) {
    while ((current_index < N) && (A[current_index] == A[current_index - 1])) {
      current_index++;
    }
    while ((current_index < N) &&  (A[current_index] - A[current_index - 1] >= 0)) {
      is_increasing = true;
      current_index++;
    }
    if (!is_increasing) {
      while ((current_index < N) && (A[current_index] - A[current_index - 1] <= 0)) {
        current_index++;
      }
    }
    if (current_index == N) {
      break;
    }
    num_divisions++;
    current_index++;
    is_increasing = false;
  }
  cout << num_divisions << endl;
  return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 110;
vector<int> pw;
int n;

int findPow (vector<int>& u, int x) {
  int res = 0;
  for (int i = 0; i < sz(u); i++) {
    while (u[i] % x == 0) { res++; u[i] /= x; }
  }
  cerr << x << ", " << res << "\n";
  return res;
}

int solve() {
  vector<int> u(n);
  for (int i = 0; i < n; i++) u[i] = i + 1;

  for (int i = 2; i <= n; i++) {
    int k = findPow(u, i);
    if (k) pw.push_back(k);
  }

  int ans = 0;
  int a = 0, b = 0; 
  
  for (int i = 0; i < sz(pw); i++) {
    if (pw[i] >= 4) a++;
    else if (pw[i] >= 2) b++;
  }
  cerr << a << ", " << b << "\n";
  ans += b * a * (a - 1) / 2;
  ans += a * (a - 1) * (a - 2) / 2;

  a = 0; b = 0;
  for (int i = 0; i < sz(pw); i++) {
    if (pw[i] >= 24) a++;
    else if (pw[i] >= 2) b++;
  }
  cerr << a << ", " << b << "\n";
  ans += a * b + a * (a - 1);

  a = 0; b = 0;
  for (int i = 0; i < sz(pw); i++) {
    if (pw[i] >= 14) a++;
    else if (pw[i] >= 4) b++;
  }
  cerr << a << ", " << b << "\n";
  ans += a * b + a * (a - 1);

  a = 0;
  for (int i = 0; i < sz(pw); i++) a += (pw[i] >= 74);
  cerr << a << ", " << b << "\n";
  ans += a;

  return ans;
}

int main() {
  scanf("%d", &n);
  printf("%d\n", solve());
}



Measured memory_bytes: 256
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    mod = 10 ** 9 + 7

    count = [0 for i in range(N)]

    for i in range(N):
        count[A[i]] += 1

    M = N % 2

    res = 1

    if M == 1:
        if count[0] != 1:
            print(0)
            sys.exit()
        test = 0
        for i in range(1,N):
            if count[i] == test:
                res *= max(test,1)
                res %= mod
            else:
                res = 0
                break
            if test == 0:
                test = 2
            else:
                test = 0
    else:
        if count[0] != 0:
            print(0)
            sys.exit()
        test = 2
        for i in range(1,N):
            if count[i] == test:
                res *= max(test,1)
                res %= mod
            else:
                res = 0
                break
            if test == 0:
                test = 2
            else:
                test = 0

    print(res)



main()


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

#define ll long long int
#define mod 1000000007

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;


ll add(ll a,ll b){
    return (a + b) % mod;
}

ll mul(ll a,ll b){
	return a * b % mod;
}

ll sub(ll a,ll b){
	ll ans = (a - b) % mod;
	if(ans<0) ans+=mod;
	return ans;
}

const int inf = 1e6;
int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,k;
    cin>>n>>k;
    
    auto p=[&](ll a,ll b){
		ll an=1;
		while(b>0){
			if(b&1)an=mul(an,a);
			b>>=1;
			a=mul(a,a);
		}
		return an;
	};
    
    vector<ll> v(k+1);
    
    for(int i=k;i>0;i--){
		ll ans=0;
		ans=add(ans,p((k/i),n));
		for(int j=2*i;j<=k;j+=i){
			ans=sub(ans,v[j]);
		}
		v[i]=ans;
		//debug2(i,v[i]);
	}
	
	ll sum=0;
	for(int i=1;i<=k;i++){
		sum=add(sum,mul(i,v[i]));
	}
	cout<<sum<<"\n";	
   
}



Measured memory_bytes: 3976
#include<iostream>
#include<queue>
#include<vector>
#define rep(i,n) for(i = 0;i < n;i++)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef pair<PP,int> PPI;
const int INF = 10000000;

int X,Y;
int X1,Y1;
int X2,Y2;
int data[52][52];			//行,列でのデータ
int dp[52][52][52][52];		//T君が(Y,X) , K君が(Y,X)に来る時の最短手数。( 座標は(行,列) )
queue<PPI> que;

P add( P p1,P p2 ){
	p1.first += p2.first;
	p1.second += p2.second;
	return p1;
}

int BFS()
{
	PPI now;
	P pos1,pos2,next1,next2;
	int cnt;
	int dx[4] = {0,1,0,-1};
	int dy[4] = {1,0,-1,0};

	que.push( PPI( PP( P( Y1,X1 ),P( Y2,X2 ) ),0 ) );
	while( !que.empty() )
	{
		now = que.front();
		pos1 = now.first.first;
		pos2 = now.first.second;
		cnt  = now.second;
		que.pop();
		//確定
		dp[pos1.first][pos1.second][pos2.first][pos2.second] = cnt;
		//どちらも行けない場所または遷移したことがある⇒continue
		//pos1を固定すると行けるか…
		//枝を出す.  
		for( int i = 0;i < 4;i++ ){
			next1 = add( pos1 , P(dy[i],dx[i]) );
			next2 = add( pos2 , P(dy[(i+2)%4],dx[(i+2)%4]) );
			if( data[ next1.first ][ next1.second ] == 1 )
				next1 = pos1;
			if( data[ next2.first ][ next2.second ] == 1 )
				next2 = pos2;
			if( dp[ next1.first ][ next1.second ][ next2.first ][ next2.second ] > cnt+1 )
			{
				dp[ next1.first ][ next1.second ][ next2.first ][ next2.second ] = cnt+1;
				que.push( PPI( PP( next1,next2 ),cnt+1 ) );
			}
		}
	}
	int ans = INF;
	int i,j;
	rep(i,Y+2){
		rep(j,X+2){
			ans = min( ans,dp[i][j][i][j] );
		}
	}
	return ans;
}

int main(){
	int i,j,k,l;
	while( cin >> X >> Y ){
		if( X == 0 && Y == 0 )
			break;
		//dataの番兵
		rep(i,Y+2){
			rep(j,X+2){
				if(i == 0 || i == Y+1 || j == 0 || j == X+1)
					data[i][j] = 1;
				else
					data[i][j] = 0;
			}
		}
		//入力
		cin >> X1 >> Y1 >> X2 >> Y2;
		rep(i,Y){
			rep(j,X){
				cin >> data[i+1][j+1];
			}
		}
		//DPテーブルの初期化っぽいこと
		rep(i,Y+2){
			rep(j,X+2){
				rep(k,Y+2){
					rep(l,X+2){
						dp[i][j][k][l] = INF;
					}
				}
			}
		}
		//最短手数は?
		int ret = BFS();
		if( ret >= 100 )
			cout << "NA" << endl;
		else
			cout << ret << endl;
		//queを空っぽにする
		while(!que.empty())
			que.pop();
	}
	return 0;
}

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

int n, a[2001], b[2001], ans;

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		b[a[i]]++;
	}
	for (int i = 1; i <= 2000; ++i) {
		b[i] += b[i-1];
		for (int j = b[i-1]; j < b[i]; ++j)
			a[j] = i;
	}
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < i; ++j)
			ans += b[a[i]+a[j]-1]-i-1;
	cout << ans;
}


Measured memory_bytes: 256