akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int pop_count(int bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main(){
    int N;
    cin >> N;
    string str;
    cin >> str;
    reverse(str.begin(), str.end());
    vector<int> S(N);
    for(int i=0; i<N; i++) S[i] = (str[i]-'0');

    int64_t cnt = accumulate(S.begin(), S.end(), 0);
    int64_t V = 1;
    for(auto a : {cnt+1, cnt-1}) if(a > 0) V *= a;

    int64_t R = 0, B = 1;
    for(int i=0; i<N; i++){
        if(S[i]) R = (R+B) % V;
        B = B*2 % V;
    }

    auto calc = [&](auto&& calc, int v)->int{
        if(v == 0){
            return 0;
        }else{
            return calc(calc, v % pop_count(v)) + 1;
        }
    };

    B = 1;
    vector<int> ans(N);
    for(int i=0; i<N; i++){
        int64_t v = cnt + (S[i] ? -1 : 1);
        if(v == 0) continue;
        int64_t r = (R + B%v * (S[i]%v ? v-1 : 1)) % v;
        ans[N-1-i] = 1 + calc(calc, r);
        B = B*2 % V;
    }

    for(int a : ans) cout << a << endl;
    return 0;
}


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

int main() {
  string s;
  cin>>s;
  int mn = 999;//C++＋＋では数値と文字列の変換はそう簡単にはできない。
  rep(i,s.size()-2){
    int x = (s[i]-'0')*100+(s[i+1]-'0')*10+s[i+2]-'0';//s[i]はstringだがs[i]-'0'はint!!!
    if(min(mn,abs(753-x))!=mn) mn=abs(753-x);
  }
  cout << mn << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    _ = input()
    li = [int(x) for x in input().split(' ')]
    out = countingSort(li, max(li))
    print(*out)


def countingSort(A, k):
    B = []
    for _ in range(len(A)):
        B.append(0)

    C = []
    for _ in range(k + 1):
        C.append(0)

    for a in A:
        C[a] += 1

    for i in range(1, k + 1):
        C[i] = C[i] + C[i - 1]

    for j in range(len(A) - 1, -1, -1):
        B[C[A[j]] - 1] = A[j]
        C[A[j]] -= 1

    return B


main()

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

#define FOR(i,b,e) for(ll i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(ll i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    VI seq(n);
    FOR(i,0,n-1) cin >> seq[i];
    
    int all = 1;
    FOR(i,1,n) all *= 3;
    
    int oddOnly = 1;
    FOR(i,0,n-1) if (seq[i] % 2 == 0) {
        oddOnly *= 2;
    }
    
    cout << all - oddOnly;

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
//using System.Numerics;
class Item
{
    public int A {get; set;}
    public int B {get; set;}
    public int Cost {get; set;}
    public Item(string[] args)
    {
        A = int.Parse(args[0]);
        B = int.Parse(args[1]);
        Cost = int.Parse(args[2]);
    }
    public Item(int a, int b, int c)
    {
        A = a;
        B = b;
        Cost = c;
    }
    public static Item operator+(Item item1, Item item2)
    {
        return new Item(item1.A + item2.A, item1.B + item2.B, item1.Cost + item2.Cost);
    }
}
class Program
{     
    static int MinCost(int index, Item[] items, Item item, ref int min, int ma, int mb)
    {
        if(item.Cost >= min)
            return int.MaxValue;
        if(items.Length == index)
        {
            if(item.A > 0 && item.A * mb == item.B * ma)
            {
                min = Math.Min(min, item.Cost);
                return item.Cost;
            }
            else
            {
                return int.MaxValue;
            }
        }
        return Math.Min(
            MinCost(index + 1, items, item, ref min, ma, mb),
            MinCost(index + 1, items, item + items[index], ref min, ma, mb)
        );
    }
    public void Slove()
    {
        var inputs = Console.ReadLine().Split();
        int n = int.Parse(inputs[0]);
        int ma = int.Parse(inputs[1]);
        int mb = int.Parse(inputs[2]);
        var items = Enumerable.Range(0, n)
            .Select(x => Console.ReadLine().Split())
            .Select(x => new Item(x))
            .ToArray();
        int min = int.MaxValue;
        MinCost(0, items, new Item(0, 0, 0), ref min, ma, mb);
        if(min == int.MaxValue)
            min = -1;
        System.Console.WriteLine(min);
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}


Measured memory_bytes: 15440
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
		String s = sc.next();
		boolean a = false;
		boolean b = false;
		boolean c = false;

		for (int i = 0; i < s.length(); i++) {
			switch (s.charAt(i)) {
				case 'a':
					a = true;
					break;
				case 'b':
					b = true;
					break;
				case 'c':
					c = true;
					break;
				default:
					break;
			}
		}

		if (a && b && c) {
    	System.out.println("Yes");
		} else {
			System.out.println("No");
		}
  }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
struct pos{long double x,y;};
pos sub(pos p1,pos p2){pos p;p.x=p1.x-p2.x;p.y=p1.y-p2.y;return p;}
pos cent(pos p1,pos p2){pos p;p.x=(p1.x+p2.x)/2;p.y=(p1.y+p2.y)/2;return p;}
long double D2(pos p){return p.x*p.x+p.y*p.y;}
long double D(pos p){return sqrt(D2(p));}
long double dot(pos p1,pos p2){return p1.x*p2.x+p1.y*p2.y;}
long double cross(pos p1,pos p2){return abs(p1.x*p2.y-p1.y*p2.x);}
long double R(pos p1,pos p2,pos p3){
  //鋭角三角は正弦定理
  if(dot(sub(p2,p1),sub(p3,p1))>0
     &&dot(sub(p3,p2),sub(p1,p2))>0
     &&dot(sub(p1,p3),sub(p2,p3))>0){
    pos v1=sub(p1,p3);pos v2=sub(p2,p3);
    long double sin=cross(v1,v2)/(D(v1)*D(v2));
    return D(sub(v2,v1))/(sin*2);
  }
  //鈍角三角は距離の最大値の半分
  return max(max(D(sub(p1,p2)),D(sub(p2,p3))),D(sub(p3,p1)))/2;
}
int main(){
  cout<<fixed<<setprecision(20);
  long N;cin>>N;
  vector<pos>P(N);for(int i=0;i<N;i++)cin>>P[i].x>>P[i].y;
  if(N==2){cout<<D(sub(P[0],P[1]))/2<<endl;return 0;}
  long double M=0;
  for(int i=0;i<N-2;i++)for(int j=i+1;j<N-1;j++)for(int k=j+1;k<N;k++){
    M=max(M,R(P[i],P[j],P[k]));
  }
  cout<<M<<endl;

}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int number = Integer.parseInt(line);
        
        int[] array = new int[number];
        String line2 = sc.nextLine();
        String[] line2sp = new String[number];
        line2sp=line2.split(" ");
        
        for(int i=0;i<number;i++){
        	array[i]=Integer.parseInt(line2sp[i]);
        }       
        
        int count=0;
        int save=-1;
        
        for(int i=0;i<number;i++){
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        }
        
        for(int i=0;i<number-1;i++){
        	System.out.print(array[i]+" ");
        }
        
        System.out.println(array[number-1]);
        System.out.println(count);
    }   
}

Measured memory_bytes: 26172
#include <stdio.h>
#include <stdlib.h>
 
typedef struct{
    int num;
    char mark;
    int no;
}Card;

int partition(Card *A,int p, int r)
{
    int i, j;
    Card x, tmp;
    x = A[r];
    i = p - 1;
    for(j = p; j < r; j++)
    {
        if(A[j].num <= x.num)
        {
            i = i + 1;
            tmp = A[i];
            A[i] = A[j];
            A[j] = tmp;
        }
    }
    tmp = A[i + 1];
    A[i + 1] = A[r];
    A[r] = tmp;
    return i + 1;
}

void quickSort(Card *A,int p, int r)
{
    int q;
    if(p < r)
    {
        q = partition(A, p, r);
        quickSort(A, p, q - 1);
        quickSort(A, q + 1, r);
    }
}
 
int main()
{
    int n, i;
    scanf("%d",&n);
    Card *c = malloc(sizeof(Card)*n);
    for(i = 0; i < n; i++)
    {
        scanf(" %c%d",&c[i].mark,&c[i].num);
        c[i].no = i;
    }
    quickSort(c,0,n-1);
    for(i = 1; i < n; i++)
    {
        if((c[i-1].num == c[i].num) && (c[i-1].no > c[i].no))   break;
    }
    if(i == n) printf("Stable\n");
    else printf("Not stable\n");
    
    for(i = 0; i < n; i++)
        printf("%c %d\n",c[i].mark,c[i].num);
    return 0;
}


Measured memory_bytes: 2872
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>

using namespace std;

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

string S;

int main()
{
  cin >> S;
  if (S[2] == S[3] && S[4] == S[5])
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
int is_prime(int n){
	int i;
	for(i=2;i*i<=n;i++){
		if(!(n%i))
			return 0;
	}
	return 1;
}
int main(void){
	int i,n,c,s;
	while(scanf("%d",&n),n){
		s=c=0;
		for(i=2;;i++){
			if(is_prime(i)){
				s+=i;
				c++;
			}
			if(c==n)
				break;
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 596
// Last Change: 03/28/2020 22:10:16.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vector<ll> p(A), q(B), r(C);
  for (auto &&e : p) {
    cin >> e;
  }
  for (auto &&e : q) {
    cin >> e;
  }
  for (auto &&e : r) {
    cin >> e;
  }

  sort(p.begin(), p.end(), greater<ll>());
  sort(q.begin(), q.end(), greater<ll>());
  sort(r.begin(), r.end(), greater<ll>());

  ll maxVal = 0;
  for (ll i = 0; i < X; ++i) {
    maxVal += p[i];
  }
  for (ll i = 0; i < Y; ++i) {
    maxVal += q[i];
  }

  ll posA = X - 1, posB = Y - 1;
  for (ll i = 0; i < C; ++i) {
    if (r[i] <= p[posA] and r[i] <= q[posB])
      break;

    if (posA < 0 and posB < 0) {
      break;
    }

    if (posA < 0) {
      if (q[posB] < r[i]) {
        maxVal -= q[posB--];
        maxVal += r[i];
      }
      continue;
    }

    if (posB < 0) {
      if (p[posA] < r[i]) {
        maxVal -= p[posA--];
        maxVal += r[i];
      }
      continue;
    }

    if (p[posA] >= q[posB]) {
      maxVal -= q[posB--];
      maxVal += r[i];
      continue;
    }
    if (q[posB] >= p[posA]) {
      maxVal -= p[posA--];
      maxVal += r[i];
      continue;
    }
  }

  cout << maxVal << endl;
}


Measured memory_bytes: 2560
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int n, q;
  cin >> n >> q;
  vector<vector<int>> v(n);
  while (q--) {
    int c = in();
    if (c == 0) {
      int t, x;
      cin >> t >> x;
      v[t].emplace_back(x);
    }
    if (c == 1) cout << v[in()] << endl;
    if (c == 2) v[in()].clear();
  }
}



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

int main()
{
  int n, m;

  while (cin >> n >> m, n + m){
    bool fd[505][505] = {false};
    int a, b;
    for (int i = 0; i < m; i++){
      cin >> a >> b;
      fd[a][b] = true;
      fd[b][a] = true;
    }

    bool mem[505] = {false};
    for (int i = 2; i <= n; i++){
      if (fd[1][i]){
        mem[i] = true;
        for (int j = 2; j <= n; j++){
          if (fd[i][j]) mem[j] = true;
        }
      }
    }
    int ct = 0;
    for (int i = 2; i <= n; i++){
      if (mem[i]) ct++;
    }
    cout << ct << endl;
  }
  return (0);
}

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

using namespace std;

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

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

    sort(h.begin(), h.end());

    int m = h.at(N-1);

    for(i = 0; i < N-K+1; i++){
        m = min(m, h.at(N-1-i) - h.at(N-K-i));
    }

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 640
n,m = map(int,input().split())
S = [list(map(int,input().split()))[1:] for _ in range(m)]
P = list(map(int,input().split()))
ans = 0

for i in range(2**n):
    light = 0
    
    for j in range(m):
        on = 0
        
        for k in S[j]:
            k -= 1
            
            if (i >> k) & 1:  #### k番目のスイッチがonか確認
                on += 1
                
        if on % 2 == P[j]:
            light += 1
            
    if light == m:
        ans += 1
        
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}


signed main(){
  double R,G;
  cin>>R>>G;
  // (R + X)/2 = G
  // X = 2G - R
  double X = 2 * G - R;
  cout<<X<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  string s;
  cin >> n >> s;
  map<char, ll> mp;
  mp['R'] = 0, mp['G'] = 0, mp['B'] = 0;
  rep(i, 0, n) mp[s[i]]++;

  ll ans = mp['R'] * mp['G'] * mp['B'];

  rep(i, 0, n) {
    for (int k = i + 2; k < n; k += 2) {
      int j = i + (k - i) / 2;
      if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
        ans--;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3616
# ABC119C - Synthetic Kadomatsu
import sys

sys.setrecursionlimit(10 ** 9)


def dfs(cur: int, x: int, y: int, z: int) -> int:
    if cur == N:
        if min(x, y, z):
            return abs(x - A) + abs(y - B) + abs(z - C) - 30
        else:
            return 1 << 60
    patterns = []
    patterns.append(dfs(cur + 1, x, y, z))
    patterns.append(dfs(cur + 1, x + L[cur], y, z) + 10)
    patterns.append(dfs(cur + 1, x, y + L[cur], z) + 10)
    patterns.append(dfs(cur + 1, x, y, z + L[cur]) + 10)
    return min(patterns)


def main():
    global N, A, B, C, L
    N, A, B, C, *L = map(int, open(0).read().split())
    ans = dfs(0, 0, 0, 0)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

#include <functional>
#include <climits>

//SegmentTree<int> seg(N,[](int a,int b){return min(a,b);},INT_MAX);
template< typename T>
class SegmentTree{
public:

  using F = function<T(T,T)>;

  int n;
  vector<T> tree;
  const F operation;
  const T def;

  SegmentTree(int size,F _operation,T _def):operation(_operation),def(_def){
    n=1;
    while(n<size) n*=2;
    tree.resize(2*n-1,def);
  }

  void initialize(vector<T> v){
    int vSize=v.size();
    n=1;
    while(n<vSize) n*=2;
    tree.resize(2*n-1,def);

    for(int i=0;i<vSize;i++) tree[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--) tree[i]=operation(tree[2*i+1],tree[2*i+2]);
  }

  void update(int index,T value){
    index+=n-1;

    tree[index]=value;
    while(index>0){
      index=(index-1)/2;
      tree[index]=operation(tree[2*index+1],tree[2*index+2]);
    }
  }

  T query(int a,int b,int k=0,int l=0,int r=-1){//[a,b),getMin(a,b,0,0,-1)
    if(r<0) r=n;

    if(r<=a||b<=l) return def;
    else if(a<=l&&r<=b) return tree[k];
    else{
      T lval=query(a,b,2*k+1,l,(l+r)/2);
      T rval=query(a,b,2*k+2,(l+r)/2,r);
      return operation(lval,rval);
    }
  }
};


int N,K,Q;
vector<ll> A;

int main(){
  cin>>N>>K>>Q;
  A.resize(N);
  rep(i,N) cin>>A[i];

  vector<pair<ll,int>> v;
  for(int i=0;i<N;i++) v.push_back(mkp(A[i],i));
  sort(v.begin(),v.end());

  ll ans=v.back().first-v[0].first;
  for(int i=0;i<N;i++){
      int now=v[i].second;
      SegmentTree<int> seg(N+2,[](int a,int b){return a+b;},0);
      int sum=0;
      int last=0;
      set<int> se;
      se.insert(-1);
      se.insert(N);
      for(int j=0;j<i;j++) se.insert(v[j].second);

      for(int j=i;j<N;j++){
          if(sum>=Q) break;
          int tar=v[j].second;
          auto itr=se.lower_bound(tar);
          int r=*itr;
          itr--;
          int l=*itr;

          int used=seg.query(l+1,r);
          int num=r-l-1-used;
          if(num>=K){
              last=A[tar];
              sum++;
              seg.update(tar,1);
          }else{
              se.insert(tar);
          }
      }
      if(sum>=Q) ans=min(ans,last-A[now]);
  }

  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b,c;
    cin >> a >> b >> c;

    int cnta = 1,cntb = 0,cntc = 0;
    char d = a[cnta - 1];

    while(1){
        if(d == 'a'){
            cnta++;
            if(cnta > a.size()){
                cout << "A" << endl;
                return 0;
            }
            d = a[cnta - 1];
        }
        if(d == 'b'){
            cntb++;
            if(cntb > b.size()){
                cout << "B" << endl;
                return 0;
            }
            d = b[cntb - 1];
        }
        if(d == 'c'){
            cntc++;
            if(cntc > c.size()){
                cout << "C" << endl;
                return 0;
            }
            d = c[cntc - 1];
        }
    }

}


Measured memory_bytes: 256
import itertools
n = int(input())

lst1 = [0]*5
lst2 = [ "M","A","R","C","H" ]
for i in range(n):
    s = input()
    for j in range(5):
        if s[0] == lst2[j]:
            lst1[j] += 1
            break
    
l = (itertools.combinations(lst1,3))
ans = 0
for i in l:
    ans += i[0]*i[1]*i[2]
print(ans)

Measured memory_bytes: 48360
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1]; for (int i = 0; i < n + 1; i++) { a[i] = 1; }for (int i = 2; i < n + 1; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;


signed main() {
	string s;
	cin >> s;
	int ans = 0;
	int tmp = 0;
	REP (i,s.size()) {
		if (i %2 == 0) {if (s[i] == '1') ans++;else tmp++;}
		if (i %2 == 1) {if (s[i] == '1') tmp++;else ans++;}
	}
	cout << min(ans,tmp) << endl;
}


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

tmp = {}
for i, a in enumerate(A):
  if a not in tmp: tmp[a] = 0
  tmp[a] += 1

total = 0
map = {}
for a, v in tmp.items():
  n = v * (v - 1) // 2
  total += n
  map[a] = (n, n - max(0, (v - 1) * (v - 2) // 2))

for k in range(N):
  a = A[k]
  print(total - map[a][1])


Measured memory_bytes: 39676
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

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

    int L, R;
    int Lmax = 1, Rmin = N;

    for(int i = 0; i < M; i++){
        cin >> L >> R;
        if(L > Lmax){
            Lmax = L;
        }
        if(R < Rmin){
            Rmin = R;
        }
    }

    if(Rmin - Lmax + 1 < 0){
        cout << 0 << endl;
    }else{
        cout << Rmin - Lmax + 1 << endl;
    }

    return 0;
}


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

using namespace std;

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

    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    long long maxn = 1000000000000000000;
    long long ans = 1;
    for(int i = 0; i < N; i++) {
        if(A[i] > maxn / ans) {
            cout << -1 << endl;
            return 0;
        } else {
            ans *= A[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4052
import sys

input = sys.stdin.readline


def main():
    X, Y = map(int, input().split())

    ans = 0
    for i in [X, Y]:
        if i == 1:
            ans += 300000
        elif i == 2:
            ans += 200000
        elif i == 3:
            ans += 100000

    if X == Y == 1:
        ans += 400000

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9112
import sys

N, W = map(int, input().split())
WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
'''
w = [0]*N
v = [0]*N
for i in range(N):
        w[i], v[i] = map(int, sys.stdin.readline().split())
'''
INF = 10**11+1
dp = [[INF]*(N+1) for j in range(N*(10**3)+10)]
i = 1
ans = INF
while(True):
        for j in range(1, N+1):
                #print(i, j)
                w = WV[j-1][1]
                if i-w > 0:
                        dp[i][j] = min(dp[i][j-1], dp[i-w][j-1]+WV[j-1][0])
                        #dp[i][j] = max(dp[i-WV[j-1][0]][j-1]+WV[j-1][1], dp[i][j-1])
                else:
                        dp[i][j] = min(dp[i][j-1], WV[j-1][0])
        #print(dp[i][N])
        #print(i, dp[i][N])
        if dp[i][N] > W and ans <= W:
                print(i-1)
                exit()
        ans = dp[i][N]
        '''
        if dp[i][N] >= W:
                if ans == 0:
                        ans = dp[i][N]
                elif ans < dp[i][N]:
                        print(i)
                        exit()
                print(i, ans)
        '''
        i += 1

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

using namespace std;

long long n, m, d;

void hawawa()
{
	cin >> n >> m >> d;
	if (d == 0) {
		cout << fixed << (1. * m - 1) * (n - d) / n / n;
		return;
	}
	double ans = (1. * m - 1) * 2. * (n - d) / n / n;
	cout << fixed << ans << "\n";
}

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


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

int main(){
    int N,M;cin >> N >> M;
    vector<int> foods(M+1,0);
    rep(i,N){
        int k;cin >> k;
        rep(j,k){
            int a;cin>>a;
            foods[a]++;
        }
    }
    int res = 0;
    for(auto e : foods){
        if(e == N)res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = [[0 for i in range(n)] for j in range(8)]
for i in range(n):
    x,y,z = map(int,input().split())
    a[0][i] = x+y+z
    a[1][i] = x+y-z
    a[2][i] = x-y+z
    a[3][i] = x-y-z
    a[4][i] = -x+y+z
    a[5][i] = -x+y-z
    a[6][i] = -x-y+z
    a[7][i] = -x-y-z
for i in range(8):
    a[i].sort()
    a[i].reverse()
ma = 0
for j in range(8):
    b=0
    for i in range(m):
        b += a[j][i]
    if(b>ma) :ma = b
print(ma)


Measured memory_bytes: 3316
#include <stdio.h>

//int Bubsort(int *x,int n);
void show(int *x,int n);

int main()
{
	int n;

	scanf("%d",&n);
	
	int i,j,temp;
	int num[10000];
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
	}

	int cont=0;
	for (i = 0; i < n; ++i)
	{
		for (j = n-1; j > i; j--)
		{
			if (num[j-1]>num[j])
			{
			temp=num[j];
			num[j]=num[j-1];
			num[j-1]=temp;
			cont++;
			}
		}
	}

	show(num,n);
	printf("%d\n",num[n-1] );
	printf("%d\n",cont);

	return 0;

}

/*int Bubsort(int *x,int n){
	int i,j,temp;
	int cont=0;
	for (i = 0; i < n; ++i)
	{
		for (j = n-1; j > i; j--)
		{
			if (x[j-1]>x[j])
			{
			temp=x[j];
			x[j]=x[j-1];
			x[j-1]=temp;
			cont++;
			}
		}
	}
	return cont;
}*/

void show(int *x,int n){
	int i;
	for (i = 0; i < n-1; ++i)
	{
		printf("%d ", x[i]);
	}
}
	

Measured memory_bytes: 608
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define int long long

#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

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

const int N = 2e5 + 123;

int n , m , k , a[N] , d;

main(){                                                                   	
	cin >> n ;
	deque < int > dq;
	for(int i = 1 ; i <= n ; i++)
		scanf("%lld" , a + i);
	for(int i = 1 ;i <= n; i++){
		if(i % 2 == 1)
			dq.push_front(a[i]);
		else dq.push_back(a[i]);
	}
	if(n % 2 == 0){
		while(sz(dq) != 0){
			cout << dq.back() << ' ';
			dq.pop_back();
		}
	}
	else {
		while(sz(dq) != 0){
			cout << dq.front() << ' ';
			dq.pop_front();
		}
    }
}

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

int main() {
	string s;
	cin >> s;
	int z;
	for (int i = 0; i < 3; i++) {
		if (s.at(i) == s.at(i + 1)) {
			cout << "Bad" << endl;
			break;
		}
		z++;
	}
	if (z == 3) {
		cout << "Good" << endl;
	}
}

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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(void){
  ll N,K;
  cin >> N >> K;
  
  ll ans=0;
  for(ll i=K; i<=N; i++){
    ll min,max;
    min=i*(i-1)/2;
    max=N*i-min;
    //ans += max-min+1;4
    ans += i*(N-i+1)+1;
    ans %= 1000000007;
  }
  cout << ans+1;
  
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io
	string s; cin>>s;
	reverse(all(s));
	int b=0;
	string p="";
	rep(i,s.size()){
		if(s[i]=='B') b++;
		else if(b>0) b--;
		else p+=s[i];
	}
	reverse(all(p));
	rep(i,p.size()){
		cout<<p[i];
	}
	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;
// }}} End Header

int main()
{
	lli x, a, b, ans;
	cin >> x;
	b = x/11;
	a = x%11;
	if(a == 0) ans = b*2;
	else if(a >= 1 && a <= 6) ans = b*2+1;
	else ans = b*2+2;
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define _start  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb 		push_back
#define ss 		second
#define ff 		first
#define int     long long
#define ll		long long
#define mk      make_pair
#define ld 		long double
#define vi 		vector<int>
#define pi		pair<int,int>
#define mod 	1000000007
#define pqg     priority_queue<int>
#define pqs     priority_queue<int,vi,greater<int> >
#define forn(p,n) for(int i=p;i<=n;i++)
#define w(t) 	int t; cin>>t; while(t--)
#define kick(t) int t; cin>>t; for(int p=0;p<t;p++)
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> oset;
ll powmod(ll base,ll exp,ll MOD=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 mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}


int32_t main() {
    _start
    int n;
    cin>>n;
    int cur=0,ans=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(i==0){
            cur=a;
        }else {
            if(a>=cur){
                cur=a;
            } else {
                ans+=(cur-a);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int a,z;
  for(int i=0;i<s.size();i++){
    if(s[i]=='Z') z=i;
    if(s[s.size()-i-1]=='A') a=s.size()-i-1;
  }
  cout<<z-a+1<<endl;
}

Measured memory_bytes: 644
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=2010;
int sccno[maxn],pre[maxn],low[maxn],scc_cnt=0,dfs_clk=0;
stack<int>S;
vector<int>G[maxn];
vector<int>sccp[maxn];
int choose[maxn];
void Tarjan(int u){
    pre[u]=low[u]=++dfs_clk;
    int sz=G[u].size();
    S.push(u);
    for(int i=0;i<sz;i++){
        int v=G[u][i];
        if(!choose[v])continue;
        if(!pre[v]){
            Tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else if(!sccno[v])
            low[u]=min(low[u],pre[v]);
    }
    if(low[u]==pre[u]){
        ++scc_cnt;
        for(;;){
            int x=S.top();S.pop();
            sccno[x]=scc_cnt;
            sccp[scc_cnt].push_back(x);
            if(x==u)break;
        }
    }
}
void find_scc(int n){
    scc_cnt=0;dfs_clk=0;
    memset(low,0,sizeof low);
    memset(pre,0,sizeof pre);
    memset(sccno,0,sizeof sccno);
    for(int i=0;i<n;i++)sccp[i].clear();
    for(int i=0;i<n;i++)
        if(choose[i]&&!pre[i])Tarjan(i);

}
int n,m;
vector<int>ans;
vector<int>nowset;
int solve(int cnt){
    find_scc(n);
    if(scc_cnt==cnt)return -1;//没有环
    for(int i=1;i<=scc_cnt;i++){
        if(sccp[i].size()==1)continue;
        memset(choose,0,sizeof choose);nowset.clear();
        for(int j=0;j<sccp[i].size();j++){
            choose[sccp[i][j]]=1;
            nowset.push_back(sccp[i][j]);
        }
        break;
    }
    return scc_cnt;
}
int main(){
    #ifdef DanDan
    freopen("in.txt","r",stdin);
    #endif // DanDan
    int u,v;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d%d",&u,&v);
        u--;v--;
        G[u].push_back(v);
    }
    for(int i=0;i<n;i++)choose[i]=1;
    if(solve(n)==-1)printf("-1\n");
    else{
        while(1){
            int circle=0;
            for(int i=0;i<nowset.size();i++){
                choose[nowset[i]]=0;
                if(solve(nowset.size()-1)!=-1){
                    ans.clear();
                    circle=1;break;
                }
                else{
                    ans.push_back(nowset[i]);
                }
                choose[nowset[i]]=1;
            }
            if(!circle)break;
        }
        printf("%d\n",(int)ans.size());
        for(int i=0;i<ans.size();i++){
            cout<<ans[i]+1<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 512
//abc116_b.cpp
//Sat Feb  2 17:01:40 2019

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int prevnum = s;
	int i = 1;
	int num = -1;
	unordered_map<int,int> mp;
	mp[s] = 1;
	while (prevnum != num){
		i++;
		if (prevnum%2==0){
			num = prevnum/2;
		}else {
			num = prevnum*3+1;
		}
		auto itr = mp.find(num);
		if (itr != mp.end()){
			cout << i << endl;
			return 0;
		}
		prevnum = num;
		mp[num] = i;
		num = -1;
	}

}

Measured memory_bytes: 384
class doubling:
    # A: 各頂点の親の番号 (0-indexed)
    # 頂点SのK個上の親の番号を返す．

    # 構築
    def __init__(self, A, K):
        self.M = 0
        temp = K
        N = len(A)
        self.Kb = []
        # 2^(M-1)乗まで計算
        while temp>0:
            self.M += 1
            self.Kb.append(temp&1)
            temp>>=1

        # 初期化
        self.nexts = [[-1]*N for _ in range(self.M)]
        for i in range(N):
            self.nexts[0][i] = A[i]

        # ダブリング計算
        for t in range(1,self.M):
            for i in range(N):
                self.nexts[t][i] = self.nexts[t-1][self.nexts[t-1][i]]

    def query(self, S, K):
        res = S
        for i in reversed(range(self.M)):
            if self.Kb[i]:
                res = self.nexts[i][res]
        return res

N,K = map(int,input().split())
At = list(map(int,input().split()))
A = [a-1 for a in At]

Double = doubling(A, K)
ans = Double.query(0,K)+1
print(ans)

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s;
  cin >> s;
  cout << s.front() << s.size() - 2 << s.back() << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;  
long INF=1000000000000000;
int main() {
    string  S;
    cin>>S;
    long ans=0;
    for(int i=0;i<4;i++) ans+=2*(S.at(i)=='+')-1;
    cout<<ans<<endl;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<ll, ll> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

bool comp(P a, P b){
    return a.second < b.second;
}

int main(void){
    ll N,K; cin >> N >> K;
    vector<P> v(N); REP(i,N){cin >> v[i].first >> v[i].second; v[i].first--;}
    sort(ALL(v), comp); REVERSE(v);
    vector<vector<ll>> n(N);
    ll sum = 0, x = 0;
    REP(i,K){
        sum += v[i].second;
        if(n[v[i].first].size() == 0) x++;
        n[v[i].first].push_back(v[i].second);
    }
    vector<ll> f(N+1,-LL_INF);
    f[x] = sum;

    priority_queue<P,vector<P>,greater<P>> q;
    REP(i,N){
        if(n[i].size() > 1) REP(j,n[i].size()-1) q.push(P(n[i][j+1], i));
    }

    FOR(i,K,N){
        ll t = v[i].first, d = v[i].second;
        if(n[t].size()) continue;
        if(q.empty()) break;
        P p = q.top(); q.pop();
        sum -= p.first;
        sum += d;
        x++;
        f[x] = sum;
        n[t].push_back(d);
    }

    ll ans = 0;
    REP(i,N) chmax(ans, f[i+1]+((ll)i+1)*((ll)i+1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8060
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcountll(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define BACK(x) prev((x).end())
#define HASK(x, y) ((x).find(y) != (x).end())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 20003, INF = 1000000000;

int dp[maxN];

void solve()
{
	int h, n;
	scanf ("%d%d", &h, &n);
	fill(dp+1, dp+maxN, INF);
	while (n--)
	{
		int a, b;
		scanf ("%d%d", &a, &b);
		FOR(i, a, maxN)
			dp[i] = min(dp[i], dp[i-a] + b);
	}
	
	int res = INF;
	FOR(i, h, maxN)
		res = min(res, dp[i]);
	printf("%d\n", res);
}
 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}





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

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define mp          make_pair
#define endl        "\n"
#define m9          1000000009
#define m7          1000000007
#define inf         1e18
#define sz(x)       (ll)x.size()
#define all(s)      (s).begin(),(s).end()
#define rall(s)     (s).rbegin(),(s).rend()
#define __lcm(a,b)  (a*b)/__gcd(a,b)
#define fori(i,p,n) for(i=p;i<n;i++)
#define ford(i,p,n) for(i=p;i>=n;i--)
#define FAST_IO     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res =(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

void solve() {
    ll i, j, k;
    ll n,m;
    cin>>n>>m;
    ll arr[n];
    ll s=0;
    fori(i,0,n){
        cin>>arr[i];
        s+=arr[i];
    }
    ll val=(ll)ceil((double)s/(4*m));
    ll cnt=0;
    fori(i,0,n){
        if(arr[i]>=val){
            cnt++;
        }
    }
    if(cnt>=m){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
}

int main() {
    FAST_IO;
    ll t = 1;
    //cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = [""] * n
for i in range(n):
    s[i] = input()
s = sorted(s)
t = 1
tmax=1
for i in range(1, n):
    if s[i-1] == s[i]:
        t += 1
        tmax=max(tmax,t)
    else:
        t = 1
        tmax = max(tmax, t)
t = 1
if tmax == 1:
    for i in range(n):
        print(s[i])
    exit()
if tmax == n:
    print(s[0])
    exit()
for i in range(1,n):
    if s[i-1] == s[i]:
        t += 1
    else:
        t=1
    if t == tmax:
        print(s[i])


Measured memory_bytes: 19420
#include <cstdio>
#include <cmath>
const int MAX = 21;
typedef double D;
 
D dis(D x1,D y1,D x2,D y2){
  D d;
  d = sqrt(pow(x2-x1,2)+pow(y2-y1,2));
  return d;
}
 
int main(){
  D x[MAX],y[MAX];
  int t = 0;
  D S = 0.0,z,a,b,c;
 
  while(true){
    if(scanf("%lf,%lf",&x[t] ,&y[t]) == EOF) break;
    t++;
  }
 
  for(int i = 2 ; i < t ; i++){
    a = dis(x[0],y[0],x[i-1],y[i-1]);
    b = dis(x[0],y[0],x[i],y[i]);
    c = dis(x[i-1],y[i-1],x[i],y[i]);
    z = (a + b + c) / 2;
 
    S += sqrt(z*(z-a)*(z-b)*(z-c));
  }
  
  printf("%.6f\n",S);
 
  return 0;
}

Measured memory_bytes: 1084
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int ans = 0;
        for (int i = B; i >= A; i -= A) {
            if (ans == C) break;
            ans++;
        }
        WriteLine(ans);
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 11220
import math
while True:
  n = int(input())
  if n == -1:
    break
  x, y = 1, 0
  for _ in range(n - 1):
    angle = math.atan2(y, x) + math.pi / 2
    x += math.cos(angle)
    y += math.sin(angle)
  print(x, y)


Measured memory_bytes: 5796
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
const double pi = acos(-1);
const int sz = 200002;
int n1, m, k;
vector<int>present;
vector<int>a;
int ans = 0;
bool count(int n) 
{ 
	bool can = true;
    // Note that this loop runs till square root 
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            // If divisors are equal, print only one 
            if (n/i == i) {
            	if(present[i] != 0) {
            		if(i == n && present[i] > 1)can = false;
            		else if(i != n) can = false;
            	}
            }
  
            else  {
            	if(present[i] != 0) {
            		if(i == n && present[i] > 1) can = false;
            		else if(i != n) can = false;
            	}	
            	if(present[n/i] != 0) {
            		if(n/i == n && present[n/i] > 1) can = false;
            		else if(n/i != n) can = false;
            	}
            }// Otherwise print both 
        } 
    } 
    return can;
} 
int main() {
	io
	cin>>n1;
	a.resize(n1);
	present.assign(1000001, 0);
	for(int i = 0; i<n1; i++) {
		cin>>a[i];
		present[a[i]]++;
	}
	for(int i = 0; i<n1; i++) {
		if(count(a[i])) ans++;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 7920
#include<iostream>

using namespace std;

int main(){
    int array[3];
    for(int i = 0; i < 3; i++){
        cin >> array[i];
    }

    int count5 = 0, count7 = 0;

    for(int i = 0; i < 3; i++){
        if(array[i] == 5) count5++;
        if(array[i] == 7) count7++;
    }
    if(count5 == 2 && count7 == 1) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256