akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int main(void) {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    vector<int> c(N+1);
    for(int i=1; i<=N; i++) {
        cin >> c[i];
    }
    vector< tuple<int,int,int> > v(Q);
    for(int j=0; j<Q; j++) {
        int l, r;
        cin >> l >> r;
        v[j] = make_tuple(r, l, j);
    }

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

    vector<int> ans(Q), last(N+1);
    BinaryIndexedTree<int> bit(N+1);

    int i = 1;
    for(auto [r, l, j]: v) {
        while(i <= r) {
            bit.add(last[c[i]], -1);
            last[c[i]] = i;
            bit.add(i, 1);
            ++i;
        }
        ans[j] = bit.sum(r) - bit.sum(l-1);
    }

    for(auto e: ans) {
        cout << e << '\n';
    }
    return 0;
}


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

int H, W, A, B;

int main()
{
    cin>>H>>W>>A>>B;

    for (int i=1; i<=B; i++)
    {
        for (int j=1; j<=A; j++)
        {
            cout<<0;
        }

        for (int j=1; j<=W-A; j++)
        {
            cout<<1;
        }

        cout<<endl;
    }

    for (int i=1; i<=H-B; i++)
    {
        for (int j=1; j<=A; j++)
        {
            cout<<1;
        }
        
        for (int j=1; j<=W-A; j++)
        {
            cout<<0;
        }

        cout<<endl;
    }
}

Measured memory_bytes: 3568
import networkx as nx

H, W = map(int, input().split())
maze = [input() for _ in range(H)]

G = nx.Graph()
# 辺を加えていく
for h in range(H):
    for w in range(W - 1):
        if maze[h][w] == maze[h][w + 1] == '.':
            G.add_edge((h, w), (h, w + 1))
for h in range(H - 1):
    for w in range(W):
        if maze[h][w] == maze[h + 1][w] == '.':
            G.add_edge((h, w), (h + 1, w))


def bfs(sy, sx):
    d = dict()
    d[(sy, sx)] = 0
    for coordinate_from, coordinate_to in nx.bfs_edges(G, (sy, sx)):
        d[coordinate_to] = d[coordinate_from] + 1
    return max(d.values())


ans = 0
for y in range(H):
    for x in range(W):
        if maze[y][x] == '.':
            ans = max(ans, bfs(y, x))
print(ans)


Measured memory_bytes: 53664
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    B = inputList()
    C = inputList()
    
    A.sort()
    B.sort()
    C.sort()
    
    tmplist = []
    for i,val in enumerate(B):
        target1 = bisect_left(C, val+1)
        tmp = N - target1
        tmplist.append(tmp)
            
    for i in range(N-2, -1, -1):
        tmplist[i] = tmplist[i] + tmplist[i+1]
        
    #print(tmplist)
    
    ans = 0
    for i,val in enumerate(A):
        target1 = bisect_left(B, val+1)
        if target1 == N:
            continue
        ans += tmplist[target1]
        
    print(ans)
    
    
            	
if __name__ == "__main__":
	main()


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

int main() {
	long long s, c;
	cin >> s >> c;
	if (2 * s >= c) {
		cout << min(s, c / 2) << endl;
		return 0;
	}
	long long a = (c - 2 * s) / 4;
	cout << s + a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

int digits(int x) {
	int y = 0;
	while (x) {
		y += x % 10;
		x /= 10;
	}
	return y;
}

int main(){
	int N, a, mn = INT32_MAX;
	cin >> N;
	for (int i = 1;i < N;i++) {
		a = N - i;
		mn = min(digits(a) + digits(i), mn);
	}
	cout << mn << endl;
}

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

int main()
{
  int a,b,c,d;

  cin>>a>>b;

  c=min(a,b);
  d=max(a,b);

  if(c<=0 && 0<=d)cout<<"Zero"<<endl;
  else if(c<0){
    int tmp=c;
    if(d<0)tmp-=(d-1);
    if(tmp%2==0)cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
  }
  else cout<<"Positive"<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while (true) {
			String sz_input = br.readLine();
			String[] sz_num = sz_input.split(" ");
			
			int H = Integer.parseInt(sz_num[0]);
			int W = Integer.parseInt(sz_num[1]);
			
			if (H == 0 && W == 0) break;
			
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			
			System.out.println();
		}
	}
}

Measured memory_bytes: 34480
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);++i)
#define erep(i,j,n) for(int i=(j);i<=(n);++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vvi f(n, vi(10));
	rep(i, 0, n) rep(j, 0, 10) cin >> f[i][j];
	vvi p(n, vi(11));
	rep(i, 0, n) rep(j, 0, 11) cin >> p[i][j];

	int ans = -INF;
	rep(bit, 1, 1 << 10) {
		int sum = 0;
		rep(i, 0, n) {
			int cou = 0;
			rep(j, 0, 10) {
				if (bit&(1 << j) && f[i][j]) cou++;
			}
			sum += p[i][cou];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    map<ll, vector<ll>> mp;
    priority_queue<ll> pq;
    rep(i,n) {
        ll a,b;
        cin>>a>>b;
        mp[a].push_back(b);
    }
    ll ans = 0;

    for (int i = m-1; i >= 0; --i) {
        for (auto &&e: mp[m-i]) {
            pq.push(e);
        }
        if (pq.empty()) continue;
        ll x = pq.top();pq.pop();
        ans += x;
    }

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

Measured memory_bytes: 10880
#include<stdio.h>
#include<ctype.h>

int sp = 0;
int stack[200];
void push(int a);
int pop();

int main(void){
	int c;
	int flag=0;
	int x=0,y=0;
	
	while ((c=getchar())!='\n'){
		//printf("\nsp = %d\n",sp);
		switch(c){
			
		case ' ':
			//printf("c =  \n");
			if(flag){
				flag=0;
			}
			break;
			
		case '+':
			//printf("c = +\n");
			y=pop();
			x=pop();
			push(x+y);
			break;
			
			
		case '-':
			//printf("c = -\n");
			y=pop();
			x=pop();
			push(x-y);
			break;
			
		case '*':
			//printf("c = *\n");
			y=pop();
			x=pop();
			push(x*y);
			break;
			
		default:
			//printf("c = %d\n",c-'0');
			if(flag){
				push( pop() * 10 + (c-'0'));
			}else{
				push(c-'0');
				flag++;
			}
		}
		
	}
	//printf("\nsp = %d\n",sp);
	printf("%d\n",pop());
	return 0;
}

void push(int a){
	//printf("push %d\n",a);
	stack[sp++]=a;
}

int pop(){
	//printf("pop %d\n",stack[--sp]);
	//sp++;
	return stack[--sp];
}

Measured memory_bytes: 524
#include <iostream>

using namespace std;

int main() {
    long long int A, B, C;
    cin >> A >> B >> C;

    if(A==B && B==C) {
        if(A%2) {
            cout << 0 << endl;
        } else {
            cout << -1 << endl;
        }
    } else {
        int cnt=0;
        while(A%2==0 && B%2==0 && C%2==0) {
            long long int tmpA=(B+C)/2, tmpB=(A+C)/2;
            C = (A+B)/2;
            A = tmpA;
            B = tmpB;
            cnt++;
        }
        cout << cnt << endl;
    }


    return 0;
    
}

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

int main() {
  long long N;
  long long a, b, c, d, e;
  cin >> N;
  cin >> a >> b >> c >> d >> e;

  long long minmove = min({a,b, c, d, e});

  long long ans = ((N + minmove - 1) / minmove) + 4;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


int main() {
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i,n){
        cout << s.at(i) << t.at(i);
    }
    br;

}


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

main() {
  int N; cin >> N;
  vi a(N); rep(i, N) cin >> a[i];
  sort(a.begin(), a.end());

  int pair, nopair;
  nopair = 0;
  rep(i, a.size()) {
    if (a[i] > a[0]) break;
    nopair++;
  }
  pair = N - nopair;

  bool ind;
  switch (a[N - 1] - a[0]) {
    case 0 :  ind = (a[0] == N - 1 or a[0] <= N / 2) ? true : false;
              break;
    case 1 :  ind = (nopair + 1 <= a[N - 1] and a[N - 1] <= nopair + pair / 2) ? true : false;
              break;
    default : ind = false;
  }
  cout << ((ind) ? "Yes" : "No") << endl;
}

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

void build_ok(const string& a, const string& b, vector<bool>& out, ll maxl){
    out.resize(maxl);
    fill(out.begin(), out.end(), true);
    REP(i, min(maxl, (ll)a.size())){
        REP(j, min((ll)b.size(), (ll)a.size() - i)){
            if(a.at(i + j) != '?' && b.at(j) != '?' && a.at(i + j) != b.at(j)){
                out.at(i) = false;
                break;
            }
        }
    }
}

ll solve(const vector<string>& s){
    ll lsum = 0;
    REP(i, 3){
        lsum += s.at(i).size();
    }

    vector<bool> ok_01, ok_12, ok_02;
    build_ok(s.at(0), s.at(1), ok_01, lsum);
    build_ok(s.at(1), s.at(2), ok_12, lsum);
    build_ok(s.at(0), s.at(2), ok_02, lsum);

    ll ret = numeric_limits<ll>::max();
    REP(x, s.at(0).size() + 1){
        REP(y, max((ll)s.at(1).size() + 1, (ll)s.at(0).size() - x + 1)){
            if(ok_01.at(x) && ok_12.at(y) && ok_02.at(x + y)){
                ll tmp = s.at(0).size();
                tmp = max(tmp, x + (ll)s.at(1).size());
                tmp = max(tmp, x + y + (ll)s.at(2).size());
                ret = min(ret, tmp);
            }
        }
    }
    return ret;
}

int main(){
    vector<string> s(3);
    REP(i, 3){
        cin >> s.at(i);
    }
    sort(s.begin(), s.end());
    ll ans = numeric_limits<ll>::max();
    do{
        ans = min(ans, solve(s));
    }while(next_permutation(s.begin(), s.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


int bs(vector<int> &v,int k)
{
	int low = 0;
	int high = v.size()-1;

	if(v[high] <= k)return v.size();
	if(v[0] > k)return 0;

	while(low <= high)
	{
		int mid = low + (high-low)/2;
		if(v[mid] <= k)
		{
			low = mid + 1;
		}
		else
		{
			high = mid -1;
		}
	}

	return low;
}
int32_t main()
{


    IOS


   	int n,m,k;
   	cin >> n >> m >> k;

   	vector<int> v1(n),v2(m);

   	for(int i = 0; i < n; i++)cin >> v1[i];
   	
   	for(int i = 0; i < m; i++)cin >> v2[i];
   	


   	for(int i = 1; i < n; i++)v1[i] += v1[i-1];

   	for(int i = 1; i < m; i++)v2[i] += v2[i-1];


 
	
	int ans = max(bs(v1,k),bs(v2,k));


	for(int i = 0; i < n; i++)
	{
		int sum = k-v1[i];
		if(sum < 0)break;
		ans = max(ans,bs(v2,sum) + i + 1);
	}


	for(int i = 0; i < m; i++)
	{
		int sum = k-v2[i];
		if(sum < 0)break;
		ans = max(ans,bs(v1,sum) + i + 1);
	}

	cout << ans;
  

    return 0;
}


Measured memory_bytes: 6244
// Problem : A - Payment
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/**
 * @author dwij
 */

#include <bits/stdc++.h>

#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>

using namespace std;

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

typedef long long ll;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<ll, ll>

#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define endl "\n"

void solution() {
    // deb() << log();
    int n;
    cin >> n;
    int k = n / 1000;
    if (n % 1000) {
        k = (1 + n / 1000);
    }
    cout << k * 1000 - n << endl;
}

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

    int T = 1;
    // cin >> T;
    // cin.ignore(); must be there when using getline(cin, s)
    for (int tt = 1; tt <= T; tt++) {
        // cout << "Case #" << tt << ": ";
        solution();
    }

    return 0;
}


Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat(next());
    }
}

public class Main {
    //static final int MOD=1000000007;
    public static void main(String[] args) throws IOException {
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        Reader.init(System.in);
        int test = 1;
        for (int ii = 0; ii < test; ii++) {
            int n = Reader.nextInt();
            int num = n % 10;
            if (num == 2 || num == 4 || num == 5 || num == 7 || num == 9) {
                out.write("hon\n");
            } else if (num == 0 || num == 1 || num == 6 || num == 8) {
                out.write("pon\n");
            } else if (num == 3) {
                out.write("bon\n");
            }
        }
        out.flush();
        out.close();
    }
}



Measured memory_bytes: 32596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=305;
const ll INF=1LL<<33;

ll DFS(vector<ll> &dif,ll rem,int now){
    int N=dif.size();
    ll res=0;
    
    if(now==N){
        if(rem==0) return 1;
        else return 0;
    }
    if(abs(rem)>dif[now]*11) return 0;
    
    if(now==0){
        //res+=9*DFS(dif,rem,now+1);
        for(ll i=0;i<=9;i++){
            res+=(9-i)*DFS(dif,rem-dif[now]*i,now+1);
        }
    }else{
        //res+=10*DFS(dif,rem,now+1);
        for(ll i=-9;i<=9;i++){
            //if(i==0) continue;
            //if(dif[now]>=INF) break;
            res+=(10-abs(i))*DFS(dif,rem-dif[now]*i,now+1);
        }
    }
    
    return res;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll D;cin>>D;
    if(D%9){
        cout<<0<<endl;
        return 0;
    }
    
    ll cnt=0;
    
    vector<ll> dif;
    dif.push_back(9);
    
    for(int t=2;t<=18;t++){
        if(t%2) cnt+=10*DFS(dif,D,0);
        else cnt+=DFS(dif,D,0);
        
        for(int i=0;i<dif.size();i++){
            dif[i]*=10;
            ll p=9;
            for(int j=0;j<i;j++){
                p*=10;
            }
            dif[i]+=p;
        }
        
        if(t%2){
            ll p=9;
            for(int j=0;j<t/2;j++){
                p*=10;
            }
            dif.push_back(p);
        }
        
        //cout<<t<<" "<<cnt<<endl;
    }
    
    cout<<cnt<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  int ans1 = 0;
  vp lr(N);
  rep(i,N) {
    int l,r;
    cin >> l >> r;
    r++;
    lr[i] = P(l,r);
    ans1 = max(ans1,r-l);
  }

  int lm=-INF,rm=INF;
  rep(i,N) {
    lm = max(lm,lr[i].first);
    rm = min(rm,lr[i].second);
  }
  ans1 += max(0,rm-lm);

  sort(rng(lr));
  int ans2 = 0;
  int rr = lr[N-1].second;
  drep(i,N-1) {
    ans2 = max(ans2,rr-lr[i].first);
    rr = min(rr,lr[i].second);
  }
  ans2 += rm-lm;
  
  cout << max(ans1,ans2) << endl;
  return 0;
}

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

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

    vector<int> cnt(N + 1, 1000000);

    cnt.at(0) = 0;

    for (int i = 1; i < N + 1; i++)
    {
        cnt.at(i) = cnt.at(i - 1) + 1;

        int j = 6, k = 9;

        while (i - j >= 0)
        {
            cnt.at(i) = min(cnt.at(i - j) + 1, cnt.at(i));
            j *= 6;
        }

        while (i - k >= 0)
        {
            cnt.at(i) = min(cnt.at(i - k) + 1, cnt.at(i));
            k *= 9;
        };
    }

    /*
    for (int i = 0; i < N + 1; i++)
    {
        cout << cnt.at(i) << " ";
    }
    */

    cout << cnt.at(N) << endl;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long x1, x2, x3, x4, y1, y2, y3, y4;
		double factor = 100000;
		int n = scanner.nextInt();
		
		for(int i = 0; i < n; i++) {
			x1 = Math.round(scanner.nextDouble() * factor);
			y1 = Math.round(scanner.nextDouble() * factor);
			x2 = Math.round(scanner.nextDouble() * factor);
			y2 = Math.round(scanner.nextDouble() * factor);
			x3 = Math.round(scanner.nextDouble() * factor);
			y3 = Math.round(scanner.nextDouble() * factor);
			x4 = Math.round(scanner.nextDouble() * factor);
			y4 = Math.round(scanner.nextDouble() * factor);
		
			long v1_x, v1_y, v2_x, v2_y;
			v1_x = x2 - x1;
			v1_y = y2 - y1;
			v2_x = x4 - x3;
			v2_y = y4 - y3;
			long op = v1_x * v2_y - v1_y * v2_x;
			
			if (op == 0) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 31748
import java.util.*;

public class Main {
    static boolean[][] graph;
    static boolean[] visited;
    static int n;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int m = sc.nextInt();
        graph = new boolean[n][n];
        visited = new boolean[n];
        int[] a = new int[m];
        int[] b = new int[m];

        for(int i = 0; i < m; i++) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }

        for(int i = 0; i < m; i++) {
            graph[a[i]][b[i]] = true;
            graph[b[i]][a[i]] = true;
        }

        int count = 0;
        for (int i = 0; i < m; i++) {
            graph[a[i]][b[i]] = false;
            graph[b[i]][a[i]] = false;
            dfs(0);

            for(int j = 0; j < n; j++) {
                if (!visited[j]) {
                    count++;
                    break;
                }
            }

            graph[a[i]][b[i]] = true;
            graph[b[i]][a[i]] = true;
            Arrays.fill(visited, false);
        }

        System.out.println(count);
    }

    static void dfs(int x) {
        if(visited[x]) return;
        visited[x] = true;
        for(int i = 0; i < n; i++) {
            if(graph[x][i]) dfs(i);
        }
    }
}


Measured memory_bytes: 23380
#include <stdio.h>
#include <math.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
using namespace std;

int sort(int *a,int n){
    int count=0;
    for(int i=0;i<n;i++){
        int mi=*(a+i);
        int k=i;
        for(int t=i;t<n;t++){
            if(mi>*(a+t)){mi=*(a+t); k=t;}
        }
        swap(*(a+k),*(a+i));
        if(*(a+k)!=*(a+i)){count++;}
    }
    return count;
}


int main(){
    int n,a[1000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int c=sort(a,n);
    
    for(int i=0;i<n;i++){
        cout<<a[i];
        if(i!=n-1){cout<<" ";}
    }
    cout<<endl<<c<<endl;
    
    return 0;
}


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

int N;

void _main() {
  cin >> N;

  int max_n = 1;
  int max_sum = 0;
  rep(i, 1, N+1) {
    int tmp_sum = 0;
    for (int j=i; j%2 == 0 && j >= 2; j/=2) tmp_sum++;
    if (tmp_sum > max_sum) {
      max_n = i;
      max_sum = tmp_sum;
    }
  }

  cout << max_n << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[200000];
signed main(){
	int n, x, ans = 0;
	scanf("%lld%lld", &n, &x);
	ans += n;
	int a = x, b = n-x;
	while(a != 0 and b != 0){
		if(a > b)swap(a, b);
		ans += 2*a*(b/a);
		if(b%a == 0)ans -= a;
		b = b%a;
	}
	printf("%lld\n", ans);
	return 0;
}







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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b;
    cin >> a >> b;
    if(a < 10 && b < 10){
        cout << a*b;
    }else{
        cout << -1;
    }
}

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

using namespace std;
using lint = int64_t;
using P = pair<int, int>;

#define rep(i, n) for (lint i = 0; i < (n); ++i)
#define rep1(i, n) for (lint i = 1; i < (n); ++i)
#define repn(i, a, b) for(lint i = (a); i < (b); ++i)
#define Rep(i, n) for (lint i = (n); i >= 0; --i)
#define All(vec) vec.begin(), vec.end()
#define cend printf("\n")

//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1000'000'007LL;
constexpr lint inf = 3LL * mod * mod;
constexpr double Pi = 3.141592653589793;

template<class T> using prique     = priority_queue<T>;
template<class T> using prique_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& rhs) { return is >> rhs.first >> rhs.second; }
template<class T, class U>inline ostream& operator<<(ostream& os, const pair<T, U>& rhs) { return os << rhs.first << " " << rhs.second; }
template<class InputIterator> void arrin(InputIterator first, InputIterator last) { for (; first != last; ++first) cin >> (*first); }
template<class InputIterator> void arrout(InputIterator first, InputIterator last) {
	for (; first != last; ++first) {
		cout << (*first) << ((first + 1) != last ? " " : "\n");
	}
}

constexpr bool pri(lint x) { for (lint i = 2; i * i <= x; ++i) if (x % i == 0) return false; return 1 < x; }

lint fact[3000000];
void fact_init(lint n, lint m = mod) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1] % m;
	}
}

lint modpow(lint x, lint n, lint m = mod) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

lint intpow(lint x, lint n) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r, lint m = mod) {
	if (r == 0 || r == n) return 1;
	lint res = fact[n] * modpow(fact[n - r], m - 2, m) % m * modpow(fact[r], m - 2, m) % m;
	return res < 0 ? res + m : res;
}

map<lint, lint> factring(lint n) {
	map<lint, lint> res;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++res[i];
		}
	}
	if (n != 1) ++res[n];
	return res;
}

lint n, m, k, ans;
int main() {
	cin >> n >> m >> k;
	fact_init(n * m + 10);
	rep(i, n) {
		rep(j, m) {
			if (i == 0 && j == 0) continue;
			lint cnt1 = 2 * (n - i) * (m - j) * (i + j);
			if (i == 0 || j == 0) cnt1 >>= 1;
			ans += cnt1 % mod;
			ans %= mod;
		}
	}
	cout << ans * comb(n * m - 2, k - 2) % mod << endl;
}

Measured memory_bytes: 5164
/*
??°??????????????£???????????????????????°???????????????????????????????????????????¢?????????????????????????.
*/
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

#define MAX_V 10001

int V, E; //??????????????°??¨?????°
vector<int> G[MAX_V];  // ??°???????????£??\???????????¨???
vector<int> rG[MAX_V]; // ????????????????????????????????°??????
vector<int> vs;        // ??°?????????????????°??????
int used[MAX_V];       // ?????¨??????????????????
int cmp[MAX_V];        // ?±????????????£????????????????????????????????????


void add_edge(int from, int to){
    // ??°?????????????????£??\????????????
    // ????????????DAG?????????
    G[from].push_back(to);
    rG[to].push_back(from);
}


void dfs(int v){
    // ??°?????????????????§??±???????????¢?´¢?????????????????????
    used[v] = 1;
    for(int i = 0; i < G[v].size(); i++){
        if (!used[G[v][i]]) dfs(G[v][i]);
    }
    vs.push_back(v);
}

void rdfs(int v, int k){
    // ??????????????±???????????¢?´¢???????????????
    used[v] = 1;
    cmp[v] = k; // ????????????????±??????´????????????k??¨??????
    for(int i = 0; i < rG[v].size(); i++){
        if (!used[rG[v][i]]) rdfs(rG[v][i], k);
    }

    // ??\?¶??????????????????????????????????????????£??????????????§??????????????¢??????
}


int scc() {
    memset(used, 0, sizeof(used));
    vs.clear();
    for(int i = 0; i < V; i++){
        if (!used[i]) dfs(i);
    }
    memset(used, 0, sizeof(used));
    int k = 0;
    for(int i = vs.size() - 1; i >= 0; i--){
        if(!used[vs[i]])  rdfs(vs[i], k++);
    }
    return k;   //?????£???????????°?????????
}


int main(){
    cin >> V >> E;
    int from, to;
    for(int i = 0; i < E; i++){
        cin >> from  >> to;
        add_edge(from, to);
    }
    int how_many_graph;
    how_many_graph = scc();

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> from >> to;
        if(cmp[from] == cmp[to]) cout << "1" << endl;
        else cout << "0" << endl;
    }
    return 0;
}

Measured memory_bytes: 2804
n=int(input())
a,b=map(int, input().split())
p=list(map(int, input().split()))
c=[0]*3
for i in p:
       if i <=a:
        c[0] +=1
       elif i>b:
        c[2] +=1
       else:
        c[1]+=1
print(min(c))

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

int power(ll a, ll b){
 ll res=1;
 while(b>0){
   if(b & 1) res=res*a%mod;
    a=a*a%mod;
    b>>=1;
  }
return res;
}

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll>a(n);
  for(int i=0; i<n; i++) cin >>a[i];
  sort(a.begin(),a.end());
  ll ans=0,K=1;
  vector<ll>all(n+1,1);
  for(int i=1; i<=k-1; i++){
    K*=i;
    K%=mod;
  }
  all[k-1]=K;
  for(int i=k; i<=n; i++){
    all[i]=all[i-1];
    all[i]*=i;
    all[i]%=mod;
    all[i]*=power(i-k+1,mod-2);
    all[i]%=mod;
  }
  
  K=power(K,mod-2);
  
  for(int i=k-1; i<n; i++){
    ll x = a[i];
    x *=all[i];
    x%=mod;
    x *= K;
    x%=mod;
    ans+=x;
    ans%=mod;
  }
  
  for(int i=0; i<n-k+1; i++){
    ll y = a[i];
    y*=all[n-i-1];
    y%=mod;
    y*=K;
    y%=mod;
    ans-=y;
    ans%=mod;
  }
  
  if(ans<0)ans+=mod;
  
  
  cout << ans << endl;
  
  
  
}
  


Measured memory_bytes: 4700
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD  1000000007
#define ll long long
#define int long long
#define INF 1e18
#define ar array
#define MAX 1000004
#define wt(x) int x;cin>>x;while(x--)

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 
}
ll power(ll a,ll b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    ll res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 

 int32_t main() {

c_p_c();
int n;
cin>>n;
vector<ll>a(n+1);
for(int i=0;i<=n;i++)cin>>a[i];
    if(a[0]>=2){
        cout<<-1;
        return 0;
    }
    
        vector<ll>pref(n+2);
        for(int i=1;i<=n+1;i++){
            pref[i]=pref[i-1]+a[i-1];
        }
        vector<ll>n_leaf(n+1);
        n_leaf[0]=1-a[0];
        for(int i=1;i<=n;i++){
            n_leaf[i]=(2LL *n_leaf[i-1])-a[i];
            n_leaf[i]=min(n_leaf[i],(pref[n+1]-pref[i+1]));
            if(n_leaf[i]<0){
                cout<<-1;
                return 0;
            }
        }
    
    ll ans=0;
    for(int i=0;i<=n;i++){
        ans+=n_leaf[i]+a[i];
    }
    cout<<ans;


return 0;

}
 


   

        



Measured memory_bytes: 5504
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<ctime>
#include<random>
#include<map>
#define ll long long
using namespace std;
char c;
int n;
ll sumLoc=0;
ll sumB=0;

int main()
{
    int loc=0;
    while (true)
    {
        scanf("%c",&c);
        if (c!='B' && c!='W') break;
        n++;
        loc=n-1;
        if (c=='B')
        {
            sumLoc+=loc;
            sumB+=1;
        }
    }
    ll startLoc = loc-sumB+1;
    ll finalLoc = loc;
    cout<<(finalLoc+startLoc)*sumB/2-sumLoc<<endl;
    return 0;
}




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

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = seer.nextInt();
		}
		int tot = 0;
		for(int i = 0; i < n; i++){
			int c = seer.nextInt();
			if(arr[i] > c) tot += arr[i]-c;
		}
		System.out.println(tot);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define _GLIBCXX_DEBUG

int main(){
  
  queue<char> qa, qb, qc;

  string a, b, c;
  cin >> a;
  rep(i, (int)a.size()){
    qa.push(a[i]);
  }
  cin >> b;
  rep(i, (int)b.size()){
    qb.push(b[i]);
  }
  cin >> c;
  rep(i, (int)c.size()){
    qc.push(c[i]);
  }

  char now = qa.front();
  qa.pop();

  while(true){
    if(now == 'a'){
      if(qa.empty()) break;
      else{
        now = qa.front();
        qa.pop();
      }
    }
    else if(now == 'b'){
      if(qb.empty()) break;
      else{
        now = qb.front();
        qb.pop();
      }
    }
    else{
      if(qc.empty()) break;
      else{
        now = qc.front();
        qc.pop();
      }
    }
  }
  
  cout << (char)(now - 32) << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;

    cin >> N;
    int t[N+1], x[N+1], y[N+1];
    t[0] = 0, x[0] = 0; y[0] = 0;
    for(int i=1;i<=N;i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    int f = 1;
    for(int i=1;i<=N;i++){
        int sub_t = t[i] - t[i-1];
        int sub_x = x[i] - x[i-1];
        int sub_y = y[i] - y[i-1];
        //cout << sub_t << sub_x << sub_y <<"\n";
        if(sub_x + sub_y > sub_t){
            f = 0;
            break;
        }
        else {
            if((sub_t - (sub_x + sub_y))%2==1){
                f = 0;
                break;
            }
        }
    }
    if(f==0) cout << "No" <<"\n";
    else cout << "Yes" <<"\n";
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;
const int MAXN = 1e5 + 10;
vector<int> grafo[MAXN];
int dp[MAXN],vis[MAXN],N,M; 
void dfs(int node, vector<int> adj[], int dp[], bool vis[]) 
{ 
    vis[node] = true; 
    for (int i = 0; i < adj[node].size(); i++) { 
        if (!vis[adj[node][i]]) 
            dfs(adj[node][i], adj, dp, vis); 
 
        dp[node] = max(dp[node], 1 + dp[adj[node][i]]); 
    } 
} 
int main()
{
        cin>>N>>M;
        for(int i = 1;i<=M;i++){
		int u,v;
		cin>>u>>v;
		grafo[u].push_back(v);
	}
        int dp[N+ 1]; 
        memset(dp, 0, sizeof dp); 
        bool vis[N + 1]; 
         memset(vis, false, sizeof vis); 
  
    for (int i = 1; i <= N; i++) { 
        if (!vis[i]) 
            dfs(i,grafo, dp, vis); 
    } 
  
    int ans = 0; 

    for (int i = 1; i <= N; i++) { 
        ans = max(ans, dp[i]); 
    } 
     
        cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12952
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define All(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(int, n);
  Cins(int, n, d);

  int ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) ans += d[i] * d[j];
  }
  cout << ans << endl;
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
from collections import*
n,k=map(int,input().split())
sushi=sorted([tuple(map(int,input().split()))for i in range(n)],key=lambda x:x[1],reverse=1)
first=defaultdict(list)
second=defaultdict(list)
menu=set()

for _,v in sushi[:k]:
    menu.add(_)
    first[_].append(v)
second=sushi[k:][::-1]
score=sum(map(sum,first.values()))
change=[]
for _,v in first.items():
    for i in v[1:]:
        change.append((_,i))
change.sort(key=lambda x:x[1],reverse=1)

#print(first,change,second)
ans=[score+len(first)**2]
while change and second:
    _,s=change.pop()
    score-=s
    try:
        while second[-1][0] in menu:
            pp,ss=second.pop()
        pp,ss=second.pop()
        menu.add(pp)
        score+=ss
        ans.append(score+len(menu)**2)
    except:
        break
print(max(ans))



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

using namespace std;
using ll = long long;

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

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

  set<string> g;
  rep(i, n) {
    string s;
    cin >> s;
    g.insert(s);
  }
  int ans = g.size();
  cout << ans << endl;
  return 0;
}


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

int main() {
  string b;
  cin >> b;
  if(b == "A"){
    cout << "T" << endl;
  }
  if(b == "T"){
      cout << "A" << endl;
  }
  if(b == "G"){
        cout << "C" << endl;
  }
  if(b == "C"){
          cout << "G"<< endl;
  }
}
          

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
string s;

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

	cin >> s;
	if(s[s.size()-1] == 's'){
		cout << (s + "es") << endl;
		return 0;
	}

	cout << (s + 's') << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3636
import numpy as np
N, K = map(int, input().split())
A = np.array([0] * (10**5 + 1))
for _ in range(N):
    a, b = map(int, input().split())
    A[a] += b
cumsum = A.cumsum()
ans = (cumsum >= K).nonzero()[0].min()
print(ans)


Measured memory_bytes: 22508
#include<cstdio>
#include<iostream>
#include<cmath>
#include<ctype.h>
#include<vector>
#include<cstdlib>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<stack>
#include<map>

#define ll long long
#define LL long long
#define ULL unsigned long long 
#define ull unsigned long long 
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)

using namespace std;

int main()
{
	int N, M;
	pair<bool,int> x[100000];
	int tmp_1, tmp_2;
	int count=0;
	cin >> N >> M;
	REP(i, N) {
		x[i].first = 1;
		x[i].second = 1;
	}
	x[0].first = 0;
	REP(i, M) {
		cin >> tmp_1 >> tmp_2;
		x[tmp_2-1].first = x[tmp_1-1].first*x[tmp_2-1].first;
		x[tmp_1-1].second--;
		x[tmp_2-1].second++;
		if (x[tmp_1 - 1].first == 0 && x[tmp_1 - 1].second == 0) {
			x[tmp_1-1].first = 1;
		}
	}
	REP(i, N) {
		if (x[i].first == 0 && x[i].second >= 1) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1024
N=int(input())
pret=0
prex=0
prey=0
for i in range(N):
    t,x,y=map(int, input().split())
    d=abs(x-prex)+abs(y-prey)
    dt=t-pret
    if dt >= d and (dt-d)%2==0:
        prex=x
        prey=y
        pret=t
    else:
        
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 70012
import bisect
from collections import deque

def xins(x):
    if not x in xlist:
        insp = bisect.bisect(xlist,x)
        xlist.insert(insp,x)
        for lst in zaatu:
            ins = 1 if insp == 0 else lst[insp-1]
            lst.insert(insp,ins)

def yins(y):
    if not y in ylist:
        insp = bisect.bisect(ylist,y)
        ylist.insert(insp,y)
        a = [1]*(len(xlist)+1)
        if insp > 0:
            for i in range(len(xlist)):
                a[i] = zaatu[insp-1][i]
        zaatu.insert(insp,a)

def addmask(x1,y1,x2,y2):
    xins(x1)
    yins(y1)
    xins(x2)
    yins(y2)
    x1 = xlist.index(x1)
    y1 = ylist.index(y1)
    x2 = xlist.index(x2)
    y2 = ylist.index(y2)

    for i in range(y1,y2):
        for j in range(x1,x2):
            zaatu[i][j] = 0

def printcolor(zaatu,no,x,y,xlen,ylen,stack):
    if zaatu[y][x] == 1:
        zaatu[y][x] = no
        if x > 0:
            stack.append([x-1,y])
        if x < xlen-1:
            stack.append([x+1,y])
        if y > 0:
            stack.append([x,y-1])
        if y < ylen-1:
            stack.append([x,y+1])

def doprint(zaatu,no,xlen,ylen,stack):
    while len(stack) != 0:
        x,y = stack.popleft()
        printcolor(zaatu,no,x,y,xlen,ylen,stack)


while True:
    xlist = []
    ylist = []
    zaatu = [[1]]
    h,w = map(int, input().split())
    if h == 0: break
    masn = int(input())
    for i in range(masn):
        a,b,c,d = map(int,input().split())
        addmask(a,b,c,d)

    if xlist[0] != 0: xins(0)
    if ylist[0] != 0: yins(0)
    if xlist[-1] == h: xlist.pop()
    if ylist[-1] == w: ylist.pop()
    zaatu.pop()
    xlen = len(xlist)
    ylen = len(ylist)
    no = 2

    for y in range(ylen):
        for x in range(xlen):
            if zaatu[y][x] == 1:
                d = deque([[x,y]])
                doprint(zaatu,no,xlen,ylen,d)
            if zaatu[y][x] == no: no += 1

    mx = 0
    for lst in zaatu:
        mx = max(mx,max(lst))
    print(mx-1)

Measured memory_bytes: 10792
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

// http://drken1215.hatenablog.com/entry/2019/03/28/014100

int main() {
    int N;
    cin >> N;
    vector<int> L(2 * N);
    REP(i, 2 * N) { cin >> L[i]; }
    sort(L.begin(), L.end());
    //大きいすぎる値と
    //小さすぎる値を
    //ペアにすると
    //損する
    // print(L);
    ll res = 0;
    REP(i, 2 * N) {
        if(i % 2 == 0) {
            res += L[i];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NK = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (N, K) = (NK[0], NK[1]);
            var H = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var dp = Enumerable.Repeat((int)1e9, N + 1).ToArray();
            dp[0] = 0;
            for (var i = 0; i < N; i++)
            {
                for (var k = 1; k <= K; k++)
                {
                    if (i + k < N) dp[i + k] = Math.Min(dp[i + k], dp[i] + Math.Abs(H[i] - H[i + k]));
                }
            }

            Console.WriteLine(dp[N - 1]);
        }
    }
}


Measured memory_bytes: 36576