akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int,input().split()))
cnt = [0] * (n+1)

for i in a:
  cnt[i] += 1

sum = 0
for i in cnt:
  sum += i * (i-1)//2

for i in a:
  sum -= cnt[i] * (cnt[i] - 1) // 2
  cnt[i] -= 1
  sum += cnt[i] * (cnt[i] - 1) // 2
  print(sum)
  sum -= cnt[i] * (cnt[i] - 1) // 2
  cnt[i] += 1
  sum += cnt[i] * (cnt[i] - 1) // 2


Measured memory_bytes: 26140
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<sstream>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;


int main()
{
	LL n,k,s;
	cin >> n >> k >> s;
	if(k <= n){
		for(int i = 1;i <= k;i++){
			if(i != 1){
				printf(" ");
			}
			printf("%lld",s);
		}
		for(int i = k + 1;i <= n;i++){
			if(i != 1){
				printf(" ");
			}
			printf("%lld",s == 1e9?s-1:s + 1);
		}
	}
	return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n;
	cin >> n;
	vll a(n),b(n);
	rep(i,n){
		cin >> a[i];
		b[i]=a[i];
	}
	sort(all(b));
	Eunique(b);
	cout << (SIZE(a)==SIZE(b)?"YES\n":"NO\n");
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,ans=0,pos=0;cin>>n;
  lvector v(n,0);rep(i,n) cin>>v[i];
  while(accumulate(v.begin(),v.end(),0)>0) {
    for(ll i=0;i<n;++i) {
      while(v[i]>0) {
        pos=i;
        while(v[pos]>0) {v[pos]-=1;pos+=1;}
        ans+=1;
      }
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;



void solve() {
	string S; cin >> S;
	REP(i, 2) {
		if (S[i + 1] != S[i]) {
			print("Yes"); return;
		}
	}
	print("No");
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  map<int,int>k;
  for(int i=0;i<N;i++){
    k[a[i]]++;
  }
  if(k[0]==N){cout<<"Yes"<<endl;}
  else if(N%3!=0){
    if(k[0]==N){cout<<"Yes"<<endl;}
    else {cout<<"No"<<endl;}
  }
  else{
    int q=0;
    bool ok=true;
    int test=N/3;
    for(auto c:k){
      if(c.second%test!=0){ok=false;}
      q^=c.first;
      for(int i=0;i<=c.second/test;i++){q^=c.first;}
    }
    if(q!=0){ok=false;}
    if(ok){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
  }
  return 0;  
}

Measured memory_bytes: 7168
#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>

using namespace std;

typedef string::const_iterator State;
class ParseError {};

int expression(State&);
int number(State&);
int factor(State&);
int term(State&);

int expression(State &begin){
  //cout <<"expression"<<endl;
  int ret = term(begin);
  while(1){
    if(*begin == '+'){
      begin++;
      ret += term(begin);
    }
    else if(*begin == '-'){
      begin++;
      ret -= term(begin);
    }
    else break;
  }
  return ret;
}

int term(State &begin){
  //cout <<"term"<<endl;
  int ret = factor(begin);
  
  while(1){
    if(*begin == '*'){
      begin++;
      ret *= factor(begin);
    }
    else if(*begin == '/'){
      begin++;
      ret /= factor(begin);
    }
    else break;
  }
  return ret;
}

int number(State &begin){
  //cout <<"number"<<endl;
  int ret = 0;
  while(isdigit(*begin)){
    ret *= 10;
    ret += *begin - '0';
    begin++;
  }
  return ret;
}

int factor(State &begin){
  //cout <<"factor"<<endl;
  if(*begin == '('){
    begin++;
    int ret = expression(begin);
    begin++; // ')' をスキップ
    return ret;
  }

  if(*begin == '-'){
    begin++;
    return -factor(begin);
  }
  return number(begin);
}

// beginがexpectedを指していたらbeginを一つ進める。
/*void consume(State &begin, char expected) {
  if (*begin == expected) {
    begin++;
  } else {
    cerr << "Expected '" << expected << "' but got '" << *begin << "'"
	 << endl;
    cerr << "Rest string is '";
    while (*begin) {
      cerr << *begin++;
    }
    cerr << "'" << endl;
    throw ParseError();
    }
    }*/

int main(){
  int n;
  cin >> n;
  cin.ignore();
  for(int i = 0 ; i < n ; i++){
    string s;
    getline(cin, s);
    //cout << s << endl;
    State begin = s.begin();
    int ans = expression(begin);
    //consume(begin, '=');
    cout << ans << endl;
  }
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
template<class T> inline void chmin(T& a, T b) { if(a > b) a = b; }
template<class T> inline void chmax(T& a, T b) { if(a < b) a = b; }

int main(){
	std::string s;
	std::cin >> s;
	if(s.back() == 's'){
		std::cout << s + "es" << std::endl;
	}else{
		std::cout << s + 's' << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3604
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

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

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	a := make([]int, 3*n)
	for i := range a {
		sc.Scan()
		v, err := strconv.Atoi(sc.Text())
		if err != nil {
			panic("invalid value")
		}
		a[i] = v
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	var ans int64
	for i := 1; i <= 2*n; i += 2 {
		ans += int64(a[i])
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 41;

int a[MAX_N];
int b[MAX_N];
int c[MAX_N];
int dp[MAX_N][400][400];

int main()
{
	int n,ma,mb;
	cin >> n >> ma >> mb;
	rep(i,n){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	}
	int suma=0;
	int sumb=0;
	rep(i,n){
		suma += a[i];
		sumb += b[i];
	}
	fill(dp[0][0],dp[n+1][0],INF);
	dp[0][0][0] = 0;
	rep(i,n){
		rep(j,suma){
			rep(k,sumb){
				dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
				if(j>=a[i]&&k>=b[i]){
					dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j-a[i]][k-b[i]]+c[i]);
				}
			}
		}
	}
	int ca = ma;
	int cb = mb;
	int ans = INF;
	while(ca<=suma&&cb<=sumb){
		ans = min(ans,dp[n][ca][cb]);
		ca += ma;
		cb += mb;
	}
	if(ans==INF){
		cout << "-1\n";
	}else{
		cout << ans <<"\n";
	}
}

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

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

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.Collections;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        int l = sc.nextInt();
        
        ArrayList<String> list = new ArrayList<>();
        
        for (int i = 0; i < n; i++) {
            list.add(sc.next());
        }
        
        Collections.sort(list);
        
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(list.get(i));
        }
        
        System.out.println(sb);
    }
}


Measured memory_bytes: 9936
import sys
sys.setrecursionlimit(500*500)


n = int(input())
nodes = [list(map(int,input().split())) for _ in range(n-1)]
a = [[] for _ in range(n+1)]

for node in nodes:
    a[node[0]].append([node[1],node[2]])
    a[node[1]].append([node[0],node[2]])

depth = [-1] * (n+1)
depth[1] = 0

def dfs(a,s):
    for v in a[s]:
        if depth[v[0]] == -1:
            depth[v[0]] = depth[s] + v[1]
            dfs(a,v[0])    
dfs(a,1)
for d in depth[1:]:
    if d % 2 == 0:
        print(0)
    else:
        print(1)


Measured memory_bytes: 98636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    string s, t;
    cin >> s >> t;

    int a, b;
    cin >> a >> b;

    string u;
    cin >> u;

    if (s == u) a--; else b--;

    cout << a << ' ' << b << endl;

    return 0;
}

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

typedef struct{
  int k;
  int pk;
  int lk;
  int rk;
}Heap;

int main(){
  Heap A[251];
  int H;
  int i;

  scanf("%d", &H);
  if(250 < H)
    exit(0);

  for(i = 1; i <= H; i++){
    scanf("%d", &A[i].k);
    if(A[i].k < -2000000000 || 2000000000 < A[i].k)
      exit(1);
    A[i].pk = NULL;
    A[i].lk = NULL;
    A[i].rk = NULL;
  }
    
  for(i = 1; i <= H; i++){
    if(i == 1){
      A[i].lk = A[i*2].k;
      A[i].rk = A[i*2+1].k;
    }
    else{
      A[i].pk = A[i/2].k;
      if(i * 2 <= H && A[i*2].k != NULL)
	A[i].lk = A[i*2].k;
      if(i * 2 + 1 <= H && A[i*2+1].k != NULL)
	A[i].rk = A[i*2+1].k;
    }
  }

  for(i = 1; i <= H; i++){
    printf("node %d: key = %d, ", i, A[i].k);
    if(A[i].pk != NULL)
      printf("parent key = %d, ", A[i].pk);
    if(A[i].lk != NULL)
      printf("left key = %d, ", A[i].lk);
    if(A[i].rk != NULL)
      printf("right key = %d, ", A[i].rk);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 604
#include <algorithm>
#include <cstdio>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=200010,INF=0x3f3f3f3f;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
struct data{
	int x,y;
	bool operator < (const data &b)const{return x<b.x;}
}a[maxn];
int n,mx,mxp,mn,bmn=INF;
ll ans;
multiset<int> A,B;
int main()
{
	read(n);
	if(n==1){puts("0");return 0;}
	for(int i=1;i<=n;i++)
	{
		read(a[i].x);read(a[i].y);
		if(a[i].x>a[i].y) swap(a[i].x,a[i].y);
		getmax(mx,a[i].y);getmin(bmn,a[i].y);
		A.insert(a[i].x);B.insert(a[i].y);
	}
	sort(a+1,a+n+1);
	mn=a[1].x;ans=(ll)(mx-bmn)*(a[n].x-mn);
	for(int i=2;i<=n;i++) if(a[i].y==mx){mxp=i;break;}
	for(int i=1;i<=n;i++)
	{
		A.erase(A.find(a[i].x));
		B.insert(a[i].x);
		B.erase(B.find(a[i].y));
		A.insert(a[i].y);
	  	getmin(ans,(ll)(*A.rbegin()-*A.begin())*(*B.rbegin()-*B.begin()));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 20608
N,T=map(x->parse(Int,x),split(readline()))
A=map(x->parse(Int,x),split(readline()))
cummin=1145141919810
rieki=0
for a=A
  cummin=min(a,cummin)
  rieki=max(rieki,a-cummin)
end
ans=0
cummin=1145141919810
for a=A
  cummin=min(a,cummin)
  if rieki==a-cummin
    ans+=1
  end
end
println(ans)

Measured memory_bytes: 138952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair



int main() {
    int X, Y; cin >> X >> Y;
    bool exist = false;
    REP(t, X+1) {
        int k = X - t;
        if (2 * t + 4 * k == Y) exist = true;
    }
    if (exist) PRINT("Yes");
    else PRINT("No");
    return 0;
}

Measured memory_bytes: 3620
bunsetu_num = gets.split.map!(&:to_i)

#print bunsetu_num

bunsetu_num.sort!.reverse!
if bunsetu_num[0] == 7 && bunsetu_num[1] == 5 && bunsetu_num[2] == 5 then print 'YES'
else print 'NO'
end

Measured memory_bytes: 1788
#include <stdio.h>
#define SIZE 20

/* ---------------------------------------------------------------------------- */

typedef unsigned short point;
#define point(y, x) (((y)<<8) | (x))
#define x(pt) ((pt) & 255)
#define y(pt) (((pt)>>8) & 255)

/* ---------------------------------------------------------------------------- */

point queue[SIZE*SIZE], pp, gp;
#define put(pt) (queue[pp++] = pt)
#define get() (queue[gp++])
#define empty() (gp == pp)
#define init() (pp = gp = 0)

/* ---------------------------------------------------------------------------- */

#define search(y, x) (count++, map[y][x] = 'w', put(point(y, x)))

char map[SIZE][SIZE+1];

int main(void)
{
    int w, h, x, y, count; point p;

    while(scanf("%d %d%*c", &w, &h), w+h)
    {
        /* init, input */

        init(); count = 0;
        for(y=0; y<h; y++) gets(map[y]);

        /* search for start */

        for(y=0; y<h; y++)
            for(x=0; x<w; x++)
                if(map[y][x] == '@') goto OUTER;
      OUTER:

        /* search */

        search(y, x);

        while(!empty())
        {
            p = get(); x = x(p), y = y(p);
            if(x-1 >= 0 && map[y][x-1] == '.') search(y, x-1);
            if(x+1 <  w && map[y][x+1] == '.') search(y, x+1);
            if(y-1 >= 0 && map[y-1][x] == '.') search(y-1, x);
            if(y+1 <  h && map[y+1][x] == '.') search(y+1, x);
        }

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

    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;


const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18;


int main(){
	IOS;
	str s;
	cin >> s;
	ll n = s.size();

	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			str ss = "";
			for (int k = 0; k < n; k++){
				if (k >=i && k <= j) continue;
				ss += s[k];
			}
			if (ss == "keyence") kill("YES");
		}
	}	
	kill("NO");
	
	
	
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




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

using namespace std;

int main()
{
    int n, m;
    int ans = 0;
    int card[1001];
    int cnt = 0;
    int dummy;

    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        cin >> card[i] >> dummy;
    }

    sort(card, card + m);
    reverse(card, card + m);

    for (int i = 0; i < m-1; i++) {
        if (n - card[i] > 0) {
            ans += n - card[i];
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3100
n,a,b = map(int, input().split())
ans = list()
for i in range(1, n+1):
    i = str(i)
    plus = 0
    for j in range(len(i)):
        plus += int(i[j])
    if a <= plus <= b:
        ans.append(int(i))
print(sum(ans))

Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


int n;
ll a[1000000];


int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];

  }

  ll ans=0;
  ll i=0,j=0,pi=0,pj=0;
  ll s=0,xs=0;
  a[n] = LLONG_MAX;
  while(i<n){
    s+=a[i];
    xs = xs^a[i];
    while(s!=xs){
      s-=a[j];
      xs = xs^a[j];
      j++;
    }
    if((s+a[i+1])!=(xs^a[i+1])){
      ans+=(i-j+1)*(i-j)/2;
      if(pj<j&&j<pi&&pi<i) ans -=(pi-j+1)*(pi-j)/2;
      pi = i; pj = j;
      }
    i++;

  }
  if(s==0) ans += (i-j+1)*(i-j)/2;
  else ans += n;

  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/****************************/
ll n,m,k; 
string s;
int main()
{
	cin>>k;
	cin>>s;
	if(s.size()<=k)
	{
		cout<<s;
	}
	else
	{
		cout<<s.substr(0,k)<<"...";
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

template<typename T>
vector<vector<T>> warshall_floyd(const vector<vector<pair<int, T>>> &graph) {
  int n = graph.size();
  vector<vector<T>> dists(n, vector<T>(n, numeric_limits<T>::max()));
  for (int i = 0; i < n; ++i) {
    dists[i][i] = 0;
    for (auto e : graph[i]) {
      int nx; T cost;
      tie(nx, cost) = e;
      dists[i][nx] = cost;
    }
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) if (dists[i][k] != numeric_limits<T>::max()) {
      for (int j = 0; j < n; ++j) if (dists[k][j] != numeric_limits<T>::max()) {
        dists[i][j] = min(dists[i][j], dists[i][k]+dists[k][j]);
      }
    }
  }
  return dists;
}

int main() {
  int n, m;
  long long l;
  cin>>n>>m>>l;

  vector<vector<pair<int, long long>>> g(n);
  rep(i, m) {
    int a, b; long long c;
    cin>>a>>b>>c;
    --a; --b;
    if (c <= l) {
      g[a].emplace_back(b, c);
      g[b].emplace_back(a, c);
    }
  }
  auto dists = warshall_floyd(g);

  vector<vector<pair<int, long long>>> g2(n);
  rep(i, n) REP(j, i, n) {
    if (dists[i][j] <= l) {
      g2[i].emplace_back(j, 1);
      g2[j].emplace_back(i, 1);
    }
  }
  auto dists2 = warshall_floyd(g2);

  int q; cin>>q;
  rep(i, q) {
    int s, t; cin>>s>>t;
    --s; --t;
    if (dists2[s][t] == numeric_limits<long long>::max()) print(-1);
    else print(dists2[s][t]-1);
  }

  return 0;
}

Measured memory_bytes: 6784
import Control.Applicative ((<$>))
import Control.Monad (unless)
import Data.List (foldl', unfoldr)

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    print $ solve n
    main

solve :: Int -> Int
solve n = foldl' f 0 $ takeWhile ((<=n).(*2)) [2..]
  where f ct x | isP x && isP (n-x) = ct+1
               | otherwise = ct

ps = 2 : unfoldr f 3
  where f x | isP x = Just (x, x+2)
            | otherwise = f (x+2)

isP x = all ((/=0).(mod x)) . takeWhile ((<=x).(^2)) $ ps



Measured memory_bytes: 4160
#include<stdio.h>

int main(void)
{
        int n,a;
        int i,j;

        scanf("%d",&n);

        for(i=0;i<26;i++){
                for(j=0;j<16;j++){
                        if(4*i+7*j==0)
                                a = 101;
                        else
                                a = 4*i+7*j;
                        a = n % a;
                        if(a==0){
                                printf("Yes\n");
                                return 0;
                        }
                }
        }

        printf("No\n");
        return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack> 
#include<set>
#include<map>
#define gc getchar()
#define ll long long
using namespace std;
#define mem(a,b) memset(a,b,sizeof a)
#define fup(i,a,b) for(int i=a,i##e=b;i<=i##e;++i)
#define hh putchar(10)

int mp[3][103];
void Main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>mp[1][i];
	for(int i=1;i<=n;++i)
		cin>>mp[2][i];
	for(int i=2;i<=n;++i)
		mp[1][i]+=mp[1][i-1];
	for(int i=1;i<=n;++i)
		mp[2][i]+=max(mp[2][i-1],mp[1][i]);
	cout<<mp[2][n];
}


int main(){Main();return 0;}
/*



*/

Measured memory_bytes: 256
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]

from operator import itemgetter
st = sorted([[x - l, x + l] for x, l in xl], key=itemgetter(1))

#from operator import itemgetter
#xl = sorted(xl, key=itemgetter(1))
last = -float('Inf')
ans = 0
for s, t in st:
    #print(x, l)
    if s >= last:
        ans += 1
        last = t
print(ans)

Measured memory_bytes: 43688
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, k = mi()
    ans = 0
    for i in range(k, n+2):
        low = i * (i + 1) // 2
        high = i * (2 * n + 3 - i) // 2
        ans += (high-low+1) % mod
        # print(ans)
    print(ans % mod)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9232
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	string s;
	cin>>s;
	if(atoi(&s[0])<2019 || (atoi(&s[0])==2019 && atoi(&s[5])<4) || (atoi(&s[0])==2019 && atoi(&s[5])==4 && atoi(&s[8])<31)){
		cout<<"Heisei"<<endl;
	}
	else cout<<"TBD"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
n, k = [int(x) for x in input().strip().split(" ")]
m=~-n*(n-2)//2
if k>m:
    print(-1)
else:
    m-=k
    print(m+n-1)
    for i in range(1, n):
        print(i, n)
    for i in range(1, n):
        for j in range(i+1, n):
            if m==0:
                break
            print(i, j)
            m-=1


Measured memory_bytes: 42736
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    
    
        
    int a,b;
    int d,r;
    double f;
    
    cin>>a>>b;
    
    d=a/b;
    r=a%b;
    f=(double)a/b;
    
    printf("%d %d %f\n",d,r,f);
    
    return 0;
}



Measured memory_bytes: 3148
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < N - 1; i++) {
            int n = in.nextInt();
            if(map.containsKey(n)) {
                map.put(n, map.get(n) + 1);
            } else {
                map.put(n, 1);
            }
        }
        for(int i = 0; i < N; i++) {
            int n = i + 1;
            if(map.containsKey(n)) {
                System.out.println(map.get(n));
            } else {
                System.out.println(0);
            }
        }
    }

}


Measured memory_bytes: 68980
#include<cstdio>
#include<algorithm>
#include<vector>
#define M_ 201000
#define N_ 10100
using namespace std;

struct MinimumCostFlow {
	struct Edge {
		int b, e, f;
		long long c;
	}E[M_];
	int EC, source, sink, n, Q[M_*2], InQ[N_], Path[N_], flow;
	vector<int>G[N_];
	long long D[N_], INF = 4e18, res;

	void init(int N, int S, int T) {
		n = N, source = S, sink = T;
		flow = EC = 0;
		res = 0;
		for (int i = 0; i <= n; i++)G[i].clear();
	}

	void Add_Edge(int b, int e, int f, long long c) {
		G[b].push_back(EC);
		G[e].push_back(EC + 1);
		E[EC++] = { b,e,f,c };
		E[EC++] = { e,b,0,-c };
	}

	bool SPFA() {
		int i, head = 0, tail = 0;
		for (i = 0; i <= n; i++)D[i] = -INF, Path[i] = 0, InQ[i] = 0;
		D[source] = 0; Q[++tail] = source, InQ[source] = 1;
		while (head < tail) {
			int x = Q[++head];
			InQ[x] = 0;
			for (auto &t : G[x]) {
				if (E[t].f) {
					if (D[E[t].e] < D[E[t].b] + E[t].c) {
						D[E[t].e] = D[E[t].b] + E[t].c;
						Path[E[t].e] = t;
						if (!InQ[E[t].e]) {
							InQ[E[t].e] = 1;
							Q[++tail] = E[t].e;
						}
					}
				}
			}
		}
		if (D[sink] == -INF)return false;
		int x = sink;
		while (x != source) {
			E[Path[x]].f--;
			E[Path[x] ^ 1].f++;
			x = E[Path[x]].b;
		}
		res += D[sink];
		return true;
	}

	void MCMF() {
		while (SPFA())flow++;
	}

}MCF;

struct point {
	int x, y;
	long long c;
}w[81];
struct Query {
	char ch;
	int a, c;
}U[320];
int n, m, L1[110], R1[110], L2[110], R2[110];

long long Solve(int K) {
	int i, j;
	for (i = 0; i <= K + 1; i++) {
		L1[i] = L2[i] = 0;
		R1[i] = R2[i] = 100;
	}
	for (i = 1; i <= m; i++) {
		if (U[i].c >= K)continue;
		if (U[i].ch == 'L') {
			L1[U[i].c + 1] = max(L1[U[i].c + 1], U[i].a + 1);
		}
		if (U[i].ch == 'R') {
			R1[K - U[i].c] = min(R1[K - U[i].c], U[i].a - 1);
		}
		if (U[i].ch == 'D') {
			L2[U[i].c + 1] = max(L2[U[i].c + 1], U[i].a + 1);
		}
		if (U[i].ch == 'U') {
			R2[K - U[i].c] = min(R2[K - U[i].c], U[i].a - 1);
		}
	}
	for (i = 1; i <= K; i++) {
		L1[i] = max(L1[i - 1], L1[i]);
		L2[i] = max(L2[i - 1], L2[i]);
	}
	for (i = K; i >= 1; i--) {
		R1[i] = min(R1[i + 1], R1[i]);
		R2[i] = min(R2[i + 1], R2[i]);
	}
	MCF.init(2 + K * 2 + 100 * 2, 1 + K * 2 + 100 * 2, 2 + K * 2 + 100 * 2);
	for (i = 1; i <= K; i++) {
		MCF.Add_Edge(MCF.source, i, 1, 0);
		MCF.Add_Edge(i + K, MCF.sink, 1, 0);
		for (j = L1[i]; j <= R1[i]; j++) {
			MCF.Add_Edge(i, K + K + j, 1, 0);
		}
		for (j = L2[i]; j <= R2[i]; j++) {
			MCF.Add_Edge(K + K + 100 + j, K + i, 1, 0);
		}
	}
	for (i = 1; i <= n; i++) {
		MCF.Add_Edge(K + K + w[i].x, K + K + 100 + w[i].y, 1, w[i].c);
	}
	MCF.MCMF();
	if (MCF.flow == K)return MCF.res;
	return 0ll;
}

int main() {
	int i;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d%lld", &w[i].x, &w[i].y, &w[i].c);
	}
	scanf("%d", &m);
	for (i = 1; i <= m; i++) {
		char pp[3];
		int a, b;
		scanf("%s%d%d", pp, &a, &b);
		U[i] = { pp[0],a,b };
	}
	long long res = 0;
	for (i = 1; i <= n; i++)res = max(res,Solve(i));
	printf("%lld\n", res);
}

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

void main_()
{
    int N, M;
    map<string, int> ss, ts;
    cin >> N;
    for (size_t i = 0; i < N; i++) {
        string s;
        cin >> s;
        ss[s]++;
    }
    cin >> M;
    for (size_t i = 0; i < M; i++) {
        string s;
        cin >> s;
        ss[s]--;
    }

    auto max_num = max_element(begin(ss), end(ss),
        [](auto&& a, auto&& b) { return a.second < b.second; })
                       ->second;

    cout << max(max_num, 0) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp
#include <bits/stdc++.h>
using namespace std;

#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;

int main() {
    // 入力
    ll N, W; cin >> N >> W;
    vector<ll> weight(N), price(N);
    vector<vector<ll>> dp(110, vector<ll>(10010));
    for( ll i = 0; i < N; i++ ) cin >> price.at(i) >> weight.at(i);
    for( ll i = 0; i <= W; i++) dp.at(0).at(i) = 0;

    // for( ll i = 0; i < N; i++ ) {
    //     for( ll w = 0; w <= W; w++ ) {
    //         if( w >= weight[i] ) dp[i+1][w] =
    //             max(dp.at(i).at(w-weight.at(i))+price.at(i),dp.at(i).at(w));
    //         else dp[i+1][w] = dp[i][w];
    //     }
    // }

    for (int i = 0; i < N; ++i) {
        for (int w = 0; w <= W; ++w) {
            if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + price[i], dp[i][w]);
            else dp[i+1][w] = dp[i][w];
        }
    }

    // for (int i = 0; i <= N; ++i) {
    //     for (int w = 0; w <= W; ++w) {
    //         cout << dp[i][w] << ' ';
    //     }
    //     cout << endl;
    // }
    cout << dp[N][W] << endl;
    return 0;
}




Measured memory_bytes: 11580
import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    a = [int(input()) for i in range(N)]

    nums = []

    for i in a:
        if len(nums) > 0:
            if i <= nums[-1]:
                ind = bisect.bisect_left(nums, i)
                if nums[ind] == i:
                    nums.pop(ind)
                else:
                    nums.insert(ind, i)
            else:
                nums.append(i)
        else:
            nums.append(i)
    
    print(len(nums))


if __name__ == "__main__":
    main()

Measured memory_bytes: 7844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const ll MOD=1e9+7;

int N;
int A[2005];
ll ct[2005];
ll K, ki;
void input(){
	cin>>N>>K;
	rep(i,N){
		cin>>A[i];
		ct[A[i]]++;
	}
}

ll ans;
void solve(){
	ll t=0;
	rep(i,N)rep(j,N)if(i<j){
		if(A[i]>A[j])t++;
	}

	ll ans1=0;
	rep1(i,2000)rep1(j,2000)if(i<j){
		ans1+=ct[i]*ct[j];
	}

	ll ans2=K*(K-1)/2;
	ans=((ans1%MOD)*(ans2%MOD))%MOD;
	ans=(ans+(t*K))%MOD;
	cout<<ans<<endl;
}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 1000000007;
const int MX = 2e3+1;
bitset<MX*MX>bs;
int main(){
    bs[0]=1;
    int n,s=0,sc;scanf("%d",&n);for(int i=1;i<=n;i++){
        scanf("%d",&sc);bs=bs|(bs<<sc);s+=sc;
    }
    for(int i=(s+1)/2;i<=s;i++)if(bs[i]){printf("%d",i);break;}
    return 0;
}


Measured memory_bytes: 2176
n,m,l=[int(k) for k in input().split()]
a=[[]]*n
b=[[]]*m
for i in range(n):
    a[i]=[int(k) for k in input().split()]
for i in range(m):
    b[i]=[int(k) for k in input().split()]
c=[[0 for i in range(l)] for k in range(n)]
for i in range(n):
    for j in range(l):
        ans=0
        for k in range(m):
            ans+=a[i][k]*b[k][j]
        c[i][j]=str(ans)
for i in range(n):
    print(' '.join(c[i]))





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

#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int h,w; cin>>h>>w;
  vector<string> s(h);
  for (int i=0; i<h; i++) {
    cin>>s[i];
  }
  vector<vector<int>> d1(h, vector<int>(w, 0));
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (s[i][j]=='#') {
        continue;
      }
      int k = 0;
      while (k+j<w&&s[i][j+k]=='.') {
        k++;
      }
      for (int l=j+k; j<min(l,w); j++) {
        d1[i][j] = k;
      }
      j--;
    }
  }
  vector<vector<int>> d2(h, vector<int>(w, 0));
  for (int i=0; i<w; i++) {
    for (int j=0; j<h; j++) {
      if (s[j][i]=='#') {
        continue;
      }
      int k = 0;
      while (k+j<h&&s[j+k][i]=='.') {
        k++;
      }
      for (int l=j+k; j<min(l,h); j++) {
        d2[j][i] = k;
      }
      j--;
    }
  }
  int ans = 0;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      ans = max(ans, d1[i][j]+d2[i][j]-1);
    }
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 37760
# https://atcoder.jp/contests/abc067/tasks/arc078_a
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


INF = 10 ** 15

N = a_int()
A = ints()

# 山札の上から取るから位置を全探索可能
x = 0  # すぬけくんのカードの合計
y = sum(A)
ans = INF
for a in A[:-1]:
    x += a
    y -= a
    ans = min(ans, abs(x - y))
print(ans)


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

int main()
{
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> scores(N + 1, K - Q);
	
	int A;
	for (int i = 0; i < Q; ++i)
	{
		cin >> A;
		scores[A]++;
	}
	
	for (int i = 1; i <= N; ++i)
		if (scores[i] > 0)
			cout << "Yes\n";
		else
			cout << "No\n";
}


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

#define ll long long

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

	ll r, d, x, temp;
	cin >> r >> d >> x;
	temp = x;
	for (int i = 0; i < 10; i++)
	{
		cout << r * temp - d << endl;
		temp = r * temp - d;
	}
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;

char A[4];

void DFS(int depth,int value,string op){
    if(depth==4){
        if(value==7){
            for(int i=0;i<4;++i){
                cout<<A[i];
                if(i<3)cout<<op[i];
            }
            cout<<"=7"<<endl;
            exit(0);
        }
    }
    else{
        DFS(depth+1,value+A[depth]-'0',op+"+");
        DFS(depth+1,value-(A[depth]-'0'),op+"-");
    }
    return ;
}


signed main(){
    for(int i=0;i<4;++i)cin>>A[i];
    DFS(1,A[0]-'0',"");
}


Measured memory_bytes: 256
#include<stdio.h>

void sort(int p[], int n);
int main(void){
    int n, k, p[1000], i;
    int x=0;

    scanf("%d%d", &n, &k);
    for(i=0; i<n; i++){
        scanf("%d", &p[i]);
    }
    sort(p, n);
    for(i=0; i<k; i++){
        x = x + p[i];
    }
    printf("%d\n", x);
    return 0;
}

void sort(int p[], int n){
    int i, j, index, min;

    for(i=0; i<n-1; i++){
        index = i; min = p[i];
        for(j=i+1; j<n; j++){
            if(min > p[j]){
                index = j;  min = p[j];
            }
        }
        p[index] = p[i];
        p[i] = min;
    }
}

Measured memory_bytes: 1700
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
  n = int(input())
  a = list(map(int, input().split()))
  c = collections.Counter(a)
  s = 0
  for i in list(c.values()):
    s += i*(i-1)//2
  for i in a:
    print(s-(c[i]-1))
  return 0
 
if __name__ == "__main__":
  solve()


Measured memory_bytes: 36308
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end
n,k=inp
kk = [k]
hi = 2
k.to_s(2).size.times do |i|
  kk.push(k/hi*hi + hi/2 - 1) if(k[i] == 1)
  hi *= 2
end
tab = na(kk.size,0)

n.times do
  a,b = inp
  kk.each.with_index do |d,i|
    tab[i] += b if((a | d)==d)
  end
end
p tab.max
#puts ()? "Yes" : "No"
#puts ()? "YES" : "NO"
#puts ()? "yes" : "no"

Measured memory_bytes: 1916
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

int main() {
  int h, n, a, sum = 0;
  cin>>h>>n;
  for(int i = 0; i<n; i++) {
    cin>>a;
    sum += a;
  }

  if(h > sum){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


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

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

    vector<int>A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    int count = 0;
    bool shift = true;

    while(true){
        for(int i = 0; i < N; i++){
            if(A.at(i) % 2 == 0)
                A.at(i) = A.at(i) / 2;
            else {
                shift = false;
                break;
            }
        }

        if(shift == false) break;
        count++;

    } 
    cout << count << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a),q(b),r(c);
    rep(i,0,a-1)cin >> p[i];
    rep(i,0,b-1)cin >> q[i];
    rep(i,0,c-1)cin >> r[i];
    vector<int> mnum(3);
    mnum[0] = x;mnum[1] = y;mnum[2] = INF;
    vector<int> num(3);
    priority_queue<P> pq;
    rep(i,0,a-1)pq.push(make_pair(p[i],0));
    rep(i,0,b-1)pq.push(make_pair(q[i],1));
    rep(i,0,c-1)pq.push(make_pair(r[i],2));

    ll ans = 0;
    while(num[0]+num[1]+num[2] < x+y){
        P now = pq.top();pq.pop();
        if(num[now.second] < mnum[now.second]){
            ans += now.first;
            num[now.second]++;
        }
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 7536
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll a, b;
    cin >> a >> b;
    if (a + b == 15) {
        cout << '+';
    } else if (a * b == 15){
        cout << '*';
    } else {
        cout << 'x';
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;

class Main{

	public static void main (String[] args) {

		Main main = new Main();

		java.util.Scanner sc = new java.util.Scanner(System.in);

		int N = sc.nextInt();
		int[] list = new int [N];

		for (int index=0; index<N; index++) {
			list[index]=sc.nextInt();
		}

		int [] choice = {0,0,0};

		System.out.println(main.get(list,N,0,choice, 0,0));

		sc.close();
	}

	int get (int[] list, int N, int count, int[] choice, int answer, int nowplace) {
		try {
			if (count==3) {
				Arrays.sort(choice);
				if (choice[0]+choice[1]>choice[2]&&choice[0]!=choice[1]&&choice[1]!=choice[2]&&choice[0]!=choice[2]) {
					answer++;
				}
				return answer;
			} else if ((N-nowplace)<(3-count)) {
				choice[count-1]=0;
				return answer;
			}
	
			for (int index=nowplace; index<N; index++) {
				int[]temp = new int [3];
				temp[0] = choice[0];
				temp[1] = choice[1];
				temp[2] = choice[2];
				temp[count]=list[index];
				answer = get (list,N,count+1,temp,answer,index+1);
			}
		} catch (Exception e) {
			return answer;
		}
			return answer;
	}
}

Measured memory_bytes: 42652
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;


int main()
{
	int n;
	cin >> n;
	vector<int> num;
	for (int i = 0; i < n; i++) {
		int nin;
		cin >> nin;
		num.push_back(nin);
	}
	sort(num.begin(), num.end());
	long long ans = 0;
	
	int a = num[n - 1];
	int b = num[0];
	for (int i = 1; i < n - 1; i++) {
		if (num[i] >= 0) {
			ans = ans + num[i];
		}
		else {
			ans = ans - num[i];
		}
	}
	
	ans = ans + a - b;
	cout << ans << endl;


	for (int i = 1; i < n - 1; i++) {
		if (num[i] >= 0) {
			cout << b << " " << num[i] << endl;
			b =  b - num[i];
		}
		else {
			cout << a << " " << num[i] << endl;
			a = a - num[i];
		}
	}
	cout << a << " " << b << endl;
	
	return 0;

}


Measured memory_bytes: 2424
import itertools
import copy
h,w,k=[int(x) for x in input().split()]
mh=[]
for i in range(h):
  s=list(input())
  mh.append(s)
mg=copy.deepcopy(mh)

l_h=[]
l_w=[]
a=itertools.product(range(2),repeat=h)
for i in a:
  l_h.append(i)
b=itertools.product(range(2),repeat=w)
for i in b:
  l_w.append(i)

ans=0
for y in range(2**h):
  for x in range(2**w):
    c=0
    mas=copy.deepcopy(mg)
    for j in range(h):
      if l_h[y][j]==1:
        for r in range(w):
          mas[j][r]="."
    for i in range(w):
      if l_w[x][i]==1:
        for l in range(h):
          mas[l][i]="."
    for m in mas:
      c+=m.count("#")
    if c==k:
      ans+=1
print(ans)

Measured memory_bytes: 9360
fun main(args:Array<String>) {
	val (n,y) = readLine()!!.split(" ").map{ it.toLong() }
	for(a in 0..n)for(b in 0..n-a){
		val c=n-a-b
		if(10000*a+5000*b+1000*c==y){
			println("$a $b $c")
			return
		}
	}
	println("-1 -1 -1")
	
}

Measured memory_bytes: 37852