akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
def prod(A,k,mod):
  ans = 1
  for i in range(k):
      ans *= A[i]
      ans %= mod
  return ans
def solve():
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  mod = 10**9+7
  ans = 1
  if K==N:
    return prod(A,N,mod)
  minus = len([a for a in A if a<0])
  if minus==N:
    if K%2==0:
      A.sort()
    else:
      A.sort(reverse=True)
    return prod(A,K,mod)
  if K==1:
    return max(A)
  A.sort(key=lambda x:-abs(x))
  if A[K]==0:
    return 0
  minus = len([a for a in A[:K] if a<0])
  flag = [1]*K+[0]*(N-K)
  d = defaultdict(lambda: -1)
  if minus%2==1:
    for i in range(K,N):
      if A[i]>=0:
        d['p2'] = i
        break
    for i in range(K,N):
      if A[i]<0:
        d['m2'] = i
        break
    for i in range(K-1,-1,-1):
      if A[i]>0:
        d['p1'] = i
        break
    for i in range(K-1,-1,-1):
      if A[i]<0:
        d['m1'] = i
        break
    if d['p2']==-1 or d['m1']==-1:
      flag[d['m2']],flag[d['p1']] = 1,0
    elif d['m2']==-1 or d['p1']==-1:
      flag[d['p2']],flag[d['m1']] = 1,0
    elif A[d['p2']]*A[d['p1']]>A[d['m1']]*A[d['m2']]:
        flag[d['p2']],flag[d['m1']] = 1,0
    else:
      flag[d['m2']],flag[d['p1']] = 1,0
    ans = 1
    for i in range(N):
      if flag[i]==1:
        ans *= A[i]
        ans %= mod
    return ans
  return prod(A,K,mod)
print(solve())

Measured memory_bytes: 121184
var x = require('fs').readFileSync('/dev/stdin', 'utf8');

var array = x.split("\n").map(Number);

for ( var i = 0; i < array.length; i++) {
    if (array[i] == 0) break;
    console.log("Case " + (i+1) + ": " + array[i]);
}


Measured memory_bytes: 22680
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(auto &x:v)
    {
        cin>>x;
    }
    sort(v.begin(),v.end());
    ll ans = 0;
    for( ll i = n-1; i >= 1; i--)
    {
        ll l = 0;
        ll r = i-1;
        while( l < r)
        {
            if( v[l] + v[r] > v[i])
            {

                ans += r - l ;
                r--;
            }
            else
            {
                l++;
            }

        }
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll NMAX = 1e7;
vector<ll> divv(NMAX, 2);
int main()
{
    ll n;
    cin >> n;
    if (n == 1e7)
        cout << 838627288460105;
    else
    {
        divv[1] = 1;
        for (ll i = 2; i <= n; ++i)
            for (ll j = i + i; j <= n; j += i)
                divv[j]++;
        ll rez = 0;
        for (ll i = 1; i <= n; ++i)
            rez += 1ll * i * divv[i];
        cout << rez;
    }
    return 0;
}


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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=13){ cout << b << endl; }
    else if (6<=a && a<13){ cout << b/2 << endl; }
    else {
        cout << 0 << endl;
    }
    return 0;
}


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

int main()
{
  int N ;
  cin>>N ;
  int64_t L[N+1] ;
  L[0]=2,L[1]=1 ;
  for(int i=2;i<=N;i++) L[i]=L[i-1]+L[i-2] ;
  cout<<L[N]<<endl ;
  
  return 0 ;
}


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

#define rep(i, n) for(int i=0; i<n; i++)

int N;
int C[111][111];

int main(int argc, char *argv[])
{
  cin >> N;
  rep(i, N) rep(j, N) cin >> C[i][j];

  long long res = 0LL;
  rep(i, N) rep(j, i) res += min(C[i][j], C[j][i]);
  cout << res << endl;
  
  return 0;
}

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

#define ll long long
const int inf = 1e9+7;
const ll INF = 1e18+7;

using namespace std;

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

  int n;
  cin>>n;
  int a[n];
  for(int i = 0; i < n; ++i){
    cin>>a[i];
  }
  int dp[n];
  dp[0] = 0;
  dp[1] = abs(a[0]-a[1]);
  for(int i = 2;i < n; ++i){
    dp[i] = min(dp[i-2]+abs(a[i-2]-a[i]),dp[i-1]+abs(a[i-1]-a[i]));
  }
  cout<<dp[n-1]<<"\n";
  
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  string s,t;
  cin >> s >> t;
  int cnt=0;
  rep(i,s.size()){
    if(s[i]!=t[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
#include <boost/range/adaptor/indexed.hpp>
using namespace std;

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

template <typename T>
std::ostream &operator<<(std::ostream &ostr, const std::vector<T> &v) {
  for (const auto &i : v | boost::adaptors::indexed())
    ostr << (i.index() > 0 ? " " : "") << i.value();
  return ostr;
}

using P = pair<int, int>;
const int INF = 1e9;
const int NX[4] = {-1, 1, 0, 0};
const int NY[4] = {0, 0, -1, 1};

inline void Main() {
  // code
  long long int a, b;
  cin >> a >> b;

  int res = 0;
  while(a <= b) {
    a *= 2;
    res++;
  }

  cout << res << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, h, w;
    cin >> n >> h >> w;
    int c = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i + h <= n && j + w <= n) c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x;cin >> n >> x;
    vector<int> l(n);
    int ans=1;
    int now=0;
    for(int i=0;i<n;i++){
        cin >> l[i];
        now+=l[i];
        if(now<=x){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        int n;
        cin >> n;
        vector<int> v(n);
        for (int i = 0; i < n; i++) {
            cin >> v[i];
        }
        multiset<int> vt;
        for (int i = 0; i < n; i++) {
            multiset<int>::iterator it = vt.lower_bound(v[i]);

            if (it == vt.begin()) vt.insert(v[i]);
            else {
                it--;
                vt.erase(it);
                vt.insert(v[i]);
            }
        }
        cout << (int)vt.size() << endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){
        a=b;
        return true;
    }
    return false;
}

const ll LOG_N=30;

int main(){
    ll N;
    cin >> N;
    vector<ll> x(N);
    rep(i,N) cin >> x[i];
    ll L,Q;
    cin >> L >> Q;
    vector<vector<ll>> next(LOG_N,vector<ll>(N,-1));
    rep(i,N){
        ll y=upper_bound(x.begin(),x.end(),x[i]+L)-x.begin()-1;
        next[0][i]=y;
    }
    rep(i,LOG_N-1){
        rep(j,N){
            next[i+1][j]=next[i][next[i][j]];
        }
    }
    rep(i,Q){
        ll a,b,ans=0;
        cin >> a >> b;
        if (a>b) swap(a,b);
        --a,--b;
        for (int i=LOG_N-1;i>=0;--i){
            if (next[i][a]<b){
                ans+=1<<i;
                a=next[i][a];
            }
        }
        ++ans;
        cout << ans << endl;
    }
}

Measured memory_bytes: 25344
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	string s;
	getline(cin, s);
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == ',')
			s[i] = ' ';
		cout << s[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())


def Find(x):	#xの根を返す
	global table

	if table[x] == x:
		return x
	else:
		table[x] = Find(table[x])	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def Unite(x,y):	#xとyを繋げる
	x = Find(x)
	y = Find(y)

	if x == y:
		return

	if rank[x] > rank[y]:
		table[y] = x
	else:
		table[x] = y
		if rank[x] == rank[y]:
			rank[y] += 1

def Check(x,y):
	if Find(x) == Find(y):
		return True
	else:
		return False

N,M = inpl()

lines = [inpl() for i in range(M)]
ans = 0
for j in range(M):
	table = [_ for _ in range(N+1)]
	rank  = [1 for _ in range(N+1)]
	for i in range(M):
		if i == j:
			continue
		x,y = lines[i]
		Unite(x,y)
	x,y = lines[j]

	if not Check(x,y):
		ans += 1

print(ans)


Measured memory_bytes: 4212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(){
    int N;
    int max = 0;
    int min = 100000;
    int res;
    int max_res = 0;
    map<int, int>mp;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++){
        cin >> a[i];
        if(max < a[i]){
            max = a[i];
        }
        if(min > a[i]){
            min = a[i];
        }

        mp[a[i]]++;
    }

    int ans = 0;

    for(int X=min; X<=max; X++){
        
        int res = 0;
        res += mp[X];
        res += mp[X + 1];
        res += mp[X - 1];

        if(ans < res) ans = res;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5376
#include "bits/stdc++.h"
#define lpa(i,a,b) for(int i=a; i<b; ++i)
#define lp(i,n) lpa(i,0,n)
using namespace std;
int main()
{
	string s;
	int i;
	cin>>s;
	for(i=0;i<26;i++)
	{
		int f=1;
		lp(j,s.size()) if(s[j]==char(i+int('a'))) f=0;
		if(f){ cout<<char(i+int('a')); break; }
	}
	if(i==26) cout<<"None";
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define mx 100005
#define ll long long
long long a[mx],dp[mx+100];
const long long inf = 10000000000000000;
int n,k;
void memo(int i,int n,int k)
{
    for(int i=0; i<n; i++)
    {
        for(int m=1; m<=k; m++)
        {
            if(i+m<n)
            dp[i+m] =min(dp[i+m],dp[i]+abs(a[i+m]-a[i]));
        }
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<mx+k; i++)
        dp[i] = inf;
    dp[0] = 0;
    memo(0,n,k);
    cout<<dp[n-1]<<endl;
    return 0;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, 0, N) cin >> L[i];
    sort(L.begin(), L.end());
    int sum = 0;
    rep(i, 0, N - 1) sum += L[i];
    cout << (L[N - 1] < sum ? "Yes" : "No") << endl;
}


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

int main(){
  char str[5];
  int in1,in2;
  gets(str, sizeof(str), stdin);
  in1 = atoi(strtok(str," "));
  in2 = atoi(strtok(NULL," "));
  
  if(in1 < in2){
    printf("0");
  }else{
    printf("10");
  }

  return 0;
}

Measured memory_bytes: 128
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		ArrayDeque<String> que = new ArrayDeque<>();
		String[] first = sc.next().split("");
		for(String s :first) {
			que.offerLast(s);
		}
		
		int Q = sc.nextInt();
		boolean reversed = false;
		for(int i =0;i<Q;i++ ) {
			int query_type = sc.nextInt();
			if(query_type==1) {
				reversed = !reversed;
			}else {
				int query_type2 = sc.nextInt();
				String add_str = sc.next();
				if((reversed&&query_type2==1)||(!reversed&&query_type2==2)) {
					que.offerLast(add_str);
				}else {
					que.offerFirst(add_str);
				}
			}
		}
		List<String> ans_list= new ArrayList<>( que );
		if(reversed) {
			Collections.reverse(ans_list);	
		}
		String ans = ans_list.stream().collect(Collectors.joining(""));
		System.out.println(ans);

	}

}


Measured memory_bytes: 175256
#coding:utf-8

def main():
    mtrx = []
    for _ in range(3):
        li = list(map(int, input().split()))
        mtrx.append(li)
        
    n = int(input())
    for _ in range(n):
        num = int(input())
        for i in range(3):
            for j in range(3):
                if mtrx[i][j] == num:
                    mtrx[i][j] = -1
                    
    for i in range(3):
        if mtrx[0][i] == -1 and mtrx[1][i] == -1 and mtrx[2][i] == -1:
            print('Yes')
            return
        if mtrx[i][0] == -1 and mtrx[i][1] == -1 and mtrx[i][2] == -1:
            print('Yes')
            return
    
    if mtrx[0][0] == -1 and mtrx[1][1] == -1 and mtrx[2][2] == -1:
        print('Yes')
        return
    if mtrx[2][0] == -1 and mtrx[1][1] == -1 and mtrx[0][2] == -1:
        print('Yes')
        return
    print('No')

if __name__ == '__main__':
    main()


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

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

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

    // solve
    for (int i = 0; i <= N - 1; ++i) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        // output
        for (int i = 0; i < N - 1; ++i) {
            cout << A[i] << " ";
        }
        cout << A[N - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3072
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll k,s;
  cin>>k>>s;
  ll ans = 0;
  rep(i,0,k+1){
    rep(j,0,k+1){
      ll a = s-i-j;
      if(a>=0&&a<=k)ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> v(5);
    for(int i = 0; i < 5; i++) cin >> v[i];
    int ans = 0;
    int tmp = 0;
    bool flag = false;
    for(int i = 0; i < 5; i++)
    {
        if(v[i] % 10 == 0) ans += v[i];
        else
        {
            int t = v[i];
            while(v[i] % 10 != 0) v[i]++;
            ans += v[i];
            tmp = max(tmp, v[i] - t);
            flag = true;
        }
    }
    if(flag) ans -= tmp;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int ans = 1;
  REP(i, N){
    if(A[i]%2 == 0) if(A[i]%3 != 0 && A[i]%5 != 0) ans = 0;
  }

  if(!ans) cout << "DENIED" << endl;
  else cout << "APPROVED" << endl;

  return 0;
}

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

int main(){
  int N, sum = 0 ;
  cin >> N;
  vector<int> a(N);
  
  for(int i = 0;i < N;i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  for(int i = 0;i < a.size();i++){
    if(i % 2 == 0){
      sum += a.at(i);
    }
    else{
      sum -= a.at(i);
    }  
  }
  cout << sum << endl;
  
  return 0;
}

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

int seiyaku_check(double i,int Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	
	int a;
	string s;
	
	cin >> a;
	cin >> s;
	
	seiyaku_check(a,2800,5200);
	if(s.length() < 1 || 10 < s.length())exit(1);
	
	if(a>=3200){
		cout << s << endl;
	}else{
		cout << "red" << endl;
	}
	
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] s = sc.next().toCharArray();
    char[] t = sc.next().toCharArray();
    int ans = 0;
    for (int cnt = 0; cnt < s.length; cnt++) {
      if (s[cnt] != t[cnt]) {
        ans++;
      }
    }
    System.out.println(ans + "");
    sc.close();
  }
}


Measured memory_bytes: 43348
#include <iostream>

using namespace std;

int main(void){
    int N, M, C;
    int i, j;
    int sum = 0;
    int clear = 0;

   cin >> N >> M >> C;

    int a[N][M];
    int b[M];

   for(i = 0; i < M; i++)
    cin >> b[i];

    for(i = 0; i < N; i++)
        for(j = 0; j < M; j++)
            cin >> a[i][j];

    for(i = 0; i < N; i++){
        for(j = 0; j < M; j++)
            sum += a[i][j] * b[j];
        sum += C;
        if(sum > 0)
            clear++;
        sum = 0;
    }
    cout << clear << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

vector<vector<Int>> G;
vector<vector<Int>> isok;//isok[i][j]: 頂点iに3で割った余りがjになるような行き方の最短距離

void dfs(Int e) {

	for (Int i = 0; i < 3; i++) {
		if (isok[e][i]!=INF) {
			for (const auto& next_e : G[e]) {
				if (isok[next_e][(i+1)%3]<= isok[e][i] + 1) {
					continue;
				}
				else {
					isok[next_e][(i + 1) % 3] = isok[e][i] + 1;
					dfs(next_e);
				}
			}
		}
		else {
			continue;
		}
	}
}

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

	Int N, M;
	cin >> N >> M;

	G.resize(N);
	Int u, v;
	for (Int i = 0; i < M; i++) {
		cin >> u >> v;
		u--;
		v--;
		G[u].push_back(v);
	}



	isok.resize(N);
	for (Int i = 0; i < N; i++) {
		isok[i].resize(3, INF);
	}

	Int S, T;

	cin >> S >> T;
	S--;
	T--;

	isok[S][0] = 0;

	dfs(S);

	if (isok[T][0]==INF) {
		cout << -1 << "\n";
	}
	else {
		cout << isok[T][0]/3 << "\n";
	}
}


Measured memory_bytes: 101120
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
}
signed main(){
	sc(s)
	int n=s.size();
	rep(0,i,n){
		if(s[n-i-1]!=s[i]){
			c("No")
			return 0;
		}
	}
	rep(0,i,(n-1)/2){
		if(s[(n-3)/2-i]!=s[i]){
			c("No")
			return 0;
		}
	}
	rep((n+1)/2,i,n){
		if(s[(n-1-i)]!=s[i]){
			c("No")
			return 0;
		}
	}
	c("Yes")			
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
typedef pair<P,int> PP;
ll d[111111][2],n,m;
vector<int> v[111111];

void dfs(int x,int p,int t) {
  t=(t+1)%2;
  rep(i,v[x].size()) {
    int y=v[x][i];
    if(y==p) continue;
    if(d[y][t]) continue;
    d[y][t]=1;
    dfs(y,x,t);
  }
}

void Main() {
  cin >> n >> m;
  rep(i,m) {
    int x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
  }
  d[0][0]=1;
  dfs(0,-1,0);
  ll c[2];mem(c);
  rep(i,n)rep(j,2) c[j]+=d[i][j];
  ll ans;
  if(c[1]==n) ans=n*(n-1)/2-m;
  else ans=c[0]*c[1]-m;
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 11264
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			Map<Character, Integer> map = new HashMap<>();
			for (char c : sc.next().toCharArray()) {
				map.put(c, map.containsKey(c) ? map.get(c) + 1 : 1);
			}
			if (map.size() == 2) {
				for (int cnt : map.values()) {
					if (cnt != 2) {
						System.out.println("No");
						return;
					}
				}
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 23764
# -*- coding: utf-8 -*-
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
write = sys.stdout.write
# template


def solve():
    ofs = 1000
    h, w = map(int, readline().split())
    A = [list(map(int, readline().split())) for i in range(h)]
    B = [list(map(int, readline().split())) for i in range(h)]
    dp = [0 for _ in range(w+1)]
    x = abs(A[0][0]-B[0][0])
    dp[0] = 1 << ofs

    for i in range(h):
        for j in range(w):
            x = abs(A[i][j]-B[i][j])
            t = (dp[j] | dp[j-1])
            dp[j] = ((t << x) | (t >> x))

    b = list(map(lambda s: s == '1', list(bin(dp[w-1])[-ofs-1:-ofs+100])))
    for i, s in enumerate(b):
        if(s):
            print(i)
            return


if __name__ == "__main__":
    solve()


Measured memory_bytes: 41324
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)


void solve(long long a, std::string s){
  if (a>=3200)cout<<s<<endl;
  else cout<<"red"<<endl;
}

int main(){
  long long a;
  scanf("%lld",&a);
  std::string s;
  std::cin >> s;
  solve(a, s);
  return 0;
}


Measured memory_bytes: 256
t[55],y[55],n,x,z;main(i){for(;n-2||!z++;){for(i=1;i<2||getchar()==44;scanf("%d",y+i++));if(i>n)for(n=i;--i;t[i]=y[i]+fmax(t[i],t[i-1]));else for(n=i,i=0;i++<n;t[i]=y[i]+fmax(t[i],t[i+1]));}n=!printf("%d\n",t[1]);}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using u32 = uint32_t;
using ll = long long;

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;

ll continuous(std::string& str, const char c, ll cnt, ll idx, ll dir)
{
    if (idx < 0 || idx >= static_cast<ll>(str.size())) { return cnt; }

    if (str[idx] != c) { return cnt; }

    return continuous(str, c, cnt + 1, idx + dir, dir);
}

ll cnt_change(std::string& str)
{
    ll cnt = 0;
    for (ll i = 0; i < static_cast<ll>(str.size()); )
    {
        ll c = continuous(str, str[i], 0, i, 1);
        cnt += c / 2;
        i += c;
    }

    return cnt;
}

bool same(std::string& str)
{
    for (u32 i = 0; i < str.size(); i++)
    {
        if (str[i] != str[0]) { return false; }
    }

    return true;
}

int main()
{
    std::string str;
    ll k;
    cin >> str >> k;

    if (str[0] != str[str.size() - 1])
    {
        cout << cnt_change(str) * k << endl;
    }
    else
    {
        ll end = continuous(str, str[str.size() - 1], 0, str.size() - 1, -1);
        auto head = str.substr(0, str.size() - end);
        auto tail = str.substr(str.size() - end);
        auto new_str = tail + head;
        ll ans = 0;
        
        if (same(new_str))
        {
            ans = new_str.size() * k / 2;
        }
        else
        {
            ans = cnt_change(head)
                + cnt_change(new_str) * (k - 1)
                + cnt_change(tail);
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(1, n - 1):
    dp[i + 1] = min(dp[i - 1] + abs(h[i + 1] - h[i - 1]), dp[i] + abs(h[i + 1] - h[i]))
print(dp[n - 1])

Measured memory_bytes: 13928
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

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

   vector<ll> a(n);
   vector<ll> b(n+1);

   for(int i=0;i<n;i++){
       ll x;
       cin>>x;
       a[i] = x;
       b[i] = 0;
   }

   for(int i=0;i<n;i++){
       if(i==0 && a[0]!=0){
            cout<<"0"<<endl;
            return 0;
       }else if(i!=0 && a[i] == 0){
           cout<<"0"<<endl;
            return 0;
       } else{
           b[a[i]]++;
       }
   }


   ll sum = 1;
   for(int i=2;i<n+1;i++){
      // if(b[i]!=0){
          ll ans=1;
          for(int j=0;j<b[i];j++){
              ans *= (b[i-1]);
              ans = ans%998244353;
          }
          sum*= ans;
            //sum *= pow(b[i-1], b[i])%998244353;
      // }
       sum = sum%998244353;
   }

//     int piv = 0;
//    for(int i=1;i<n+1;i++){
//        if(b[i]==0)piv=1;
//        if(piv==1 && b[i]!=0){
//            cout<<"0"<<endl;
//             return 0;
//        }
//    }
// for(int i=0;i<n+1;i++){
//     cout<<b[i];
// }
// cout<<endl;
    // sort(b.begin(), b.end());
//     for(int i=0;i<n+1;i++){
//     cout<<b[i];
// }
    // for(int i=0;i<n;i++){
    //     //cout<<b[i]<< " ";
    //     if(b[i]!=b[i+1] && b[i+1] != b[i]+1){
    //         cout<<"0"<<endl;
    //         return 0;
    //     }
    // }
    cout<<sum<<endl;



    return 0;
}

Measured memory_bytes: 1792
<?php
# 整数の入力
fscanf(STDIN, "%d", $n);
# スペース区切りの整数の入力を配列で受け取る
$input = explode(' ',trim(fgets(STDIN)));

function result($n, $input) {
    $count = 0;
    foreach ($input as $key => $num) {
        if (($key + 1) % 2 != 0) {
            if ($num % 2 != 0) {
                $count ++;
            }
        }
    }

    return $count;
}

# 出力
echo result($n, $input);
?>

Measured memory_bytes: 16132
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

_ans = 0
_buff = 0

for i in range(N+1):
    if A[i]-_buff > 0:
        A[i] -= _buff
        _ans += _buff
    else:
        _ans += A[i]
        A[i] = 0

    # print('ans2')
    # print(_ans)
    _buff = 0
    if i < N:
        if A[i]-B[i] > 0:
            _ans += B[i]
        else:
            _ans += A[i]
            _buff = B[i]-A[i]
    # print('ans')
    # print(_ans)
    # print('buff')
    # print(_buff)


print(_ans)

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

#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
    long long x;
    cin >> x;
    for (int a = 1; a < 200; a++)
    {
        ll a5 = 1;
        rep(i, 5) a5 *= a;
        for (int b = -1000; b < 1000; b++)
        {
            ll b5 = 1;
            rep(i, 5) b5 *= b;
            if (a5 - b5 == x)
            {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3624
def main():
    from itertools import zip_longest
    n, *a = map(lambda x: bin(int(x))[2:][::-1], open(0).read().split())
    n = int('0b' + n[::-1], 2)

    mod = 10 ** 9 + 7
    ans = 0
    
    for i, j in enumerate(zip_longest(*a)):
        o = j.count('1')
        z = n - o
        ans += z * o * pow(2, i, mod)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 65240
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int f = 0;
        int s = 0;

        for (int i = 0; i < 3; i++) {
            int num = sc.nextInt();
            if (num == 5) {
                f++;
            } else if (num == 7) {
                s++;
            }
        }

        sc.close();

        boolean ans = false;
        if (f == 2 && s == 1) {
            ans = true;
        }

        System.out.println(ans ? "YES" : "NO");

    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long double arr[N] = {};
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    sort(arr + 1, arr + 1 + n);
    if (arr[1] == 0) {
        cout << "0\n";
    }
    else {
        long double ans = arr[1];
        for (int i = 2; i <= n; i++) {
            if (ans > (1e18 / arr[i])) {
                ans = -1;
                break;
            }
            else ans *= arr[i];
        }
        cout << (long long)ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 5352
#include <bits/stdc++.h>
using namespace std;
 bool is_prime(long long n) {
if (n <= 1) return false;
for(long long p = 2; p * p <= n; ++p){
    if (n % p == 0)return false;
}
return true;


}

int main() {

long long X;
cin >> X;
long long res = X;
while(!is_prime(res))res++;

cout << res << endl;
}






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

int main(){
	int a,b;
	cin>>a>>b;
	int s=1;
	int bb=b;
	while(bb>0){
		bb/=10;
		s*=10;
	}
	int ans=a*s+b;
	
	for(int i=1;i<1000;i++){
		if(i*i==ans){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))
counts = [0] * (N + 1)
for a in As:
    counts[a] += 1
tot = 0
for count in counts:
    tot += (count * count - count) // 2
for a in As:
    print(tot - counts[a] + 1)


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

int main()
{
ll n ;
cin >> n ;
vector<ll> hist(n+1);
vector<ll> ans(n+1);
vector<ll> num;
rep(i, n){
  ll aa;
  cin >> aa;
  hist[aa]++;
}
for(auto b:hist){
  if(b!=0)num.push_back(b);
}
sort(num.begin(),num.end());
vector<ll> sum;
sum.push_back(0);
rep(i,num.size()){
  sum.push_back(num[i]+sum[i]);
}
ans[num.size()]=num[0];
ll full=1;
rep(i,num.size()-1){
  while(full!=num.size()-1){
    if(num[full+1]*(full-i+1)-sum[full+2]+sum[i+1]<sum[i+1])full++;
    else break;
  }
  ans[num.size()-1-i]=num[full]+(sum[full+1]-num[full]*(full-i))/(full-i);
}
rep(i,n){
  cout << ans[i+1] << endl;
  
}
return 0;
}

Measured memory_bytes: 13676
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int updivide(int a,int b){
    if(b==1) return a;
    else if(a%b==0) return a/b;
    else return (a/b)+1;
}

int main(){
    int n;
    in(n);
    vector<int> vec(n);
    in(vec);
    sort(all(vec));
    out(updivide(vec[n-1]-vec[0],2));
}


Measured memory_bytes: 3288
S = input()

ct_1 = S.count('dream')
ct_2 = S.count('erase')
ct_3 = S.count('dreamerase')
ct_4 = S.count('dreamer')
ct_5 = S.count('eraser')
ct_dream = ct_1 - ct_4 + ct_3
ct_erase = ct_2 - ct_5
ct_dreamer = ct_4 - ct_3
ct_eraser = ct_5

length = 5*(ct_dream+ct_erase) + 6*(ct_eraser) + 7*(ct_dreamer)

if length == len(S):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  int N;
  int M;
  set<int> s,ss;
  cin>>N>>M;
  FOR(i,0,M){
    int a,b;
    cin>>a>>b;
    if(a==1){
      s.insert(b);
    }else if(b==N){
      ss.insert(a);
    }
  }
  for(set<int>::iterator it=s.begin();it!=s.end();it++){
    if(ss.find(*it)!=ss.end()){
      cout<<"POSSIBLE"<<endl;
      return 0;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
  return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define lp(i,n) for(int i=0;i<(n);i++)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:n)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define CTOI(x) (x - 'A') 
#define ctoi(x) (x - 'a')
#define BIT(x) (1 << (x))
#define int long long
using namespace std;

PII operator+(const PII&a, const PII&b){
    return PII(a.first+b.first, a.second+b.second);
}

signed main(){
    int N;
    while(cin>>N&&N){
        vector<PII> line(N);
        set<PII> s;
        foreach(i, line){
            cin>>i.first>>i.second;
            s.insert(i);
        }
        int ans = 0;
        foreach(i, line){
            foreach(j, line){
                if(i==j)continue;
                PII d;
                d.second = j.first - i.first;
                d.first = i.second - j.second;
                if(s.count(i+d)*s.count(j+d)){
                    ans = max(ans, d.first*d.first+d.second*d.second);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3316
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
from bisect import bisect_left
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n = int(input())
    cumsum = list()
    for i in range(n):

        if i == 0:
            cumsum.append(1)
            continue
        
        else:
            cumsum.append(cumsum[i-1]+i+1)

        if cumsum[i] > n:
            break
    
    ban = cumsum[-1]-n
    for i in range(1, len(cumsum)+1):
        if i != ban:
            print(i)

    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 5620
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

struct BIT{
private:
    vector<ll> a;
    int n;
public:
    BIT(int sz){
        n=sz;
        a.resize(sz+1);
    }
    ll sum(int i){
        ll res=0;
        while(i>0){
            res+=a[i];
            i-=i&-i;
        }
        return res;
    }
    ll sum(int i,int j){
        return sum(j)-sum(i-1);
    }
    void add(int i,ll x){
        while(i<=n){
            a[i]+=x;
            i+=i&-i;
        }
    }
};

int main(){
    ll n;
    cin>>n;
    ll a[n];
    rep(i,n)cin>>a[i];
    ll s[n+1];
    s[0]=0;
    ll lb=0,ub=inf;
    while(ub-lb>1){
        ll x=(ub+lb)/2;
        rep(i,n){
            if(a[i]<=x)s[i+1]=1;
            else s[i+1]=0;
            s[i+1]+=s[i];
        }
        rep(i,n+1){
            s[i]=2*s[i]-i;
        }
        pair<int,int> p[n+1];
        rep(i,n+1){
            p[i]=make_pair(s[i],-i);
        }
        sort(p,p+n+1);
        BIT bit(n+1);
        ll cnt=0;
        rep(i,n+1){
            int it=-p[i].second;
            cnt+=bit.sum(it);
            bit.add(it+1,1);
        }
        if(cnt<n*(n+1)/4+1)lb=x;
        else ub=x;
    }
    cout<<ub<<endl;
}


Measured memory_bytes: 3328