akhauriyash/Code-Regression huggingface dataset:
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::cmp::max;

fn main() {
    let nk: Vec<u32> = read_vec();
    let n = nk[0];
    let k = nk[1];
    let s: String = read();
    let cv: Vec<char> = s.chars().collect();
    let mut unhappy: u32 = 1;
    for i in 0..(cv.len() - 1) {
        if cv[i] != cv[i + 1] {
            unhappy += 1;
        }
    }
    println!("{}", n - (max(unhappy, 2 * k + 1) - 2 * k));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int p, q, r;

  cin >> p >> q >> r;

  cout << min(p + q, min(p + r, r + q)) << endl;

  return 0;
}


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

int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	double mxv = 0;
	int mxa = a*100, mxb = 0;
	for(int i=0; i<=30; i++) {
		for(int j=0; j<=30; j++) {
			if(!i && !j) j++;
			int w = i*a*100+j*b*100;
			if(w >= f) continue;
			int suglim = min(e*(w/100), f-w);
			for(int x=0;x*c <= suglim;x++) {
				int sug = x*c;
				sug += ((suglim - sug) / d) * d;
				if(sug <= suglim && w+sug <= f && sug*1.0/(w+sug) > mxv) {
					mxv = sug*1.0/(w+sug);
					mxa = w;
					mxb = sug;
				}
			}
		}
	}
	cout << mxa+mxb << ' ' << mxb;
}

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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl


int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    ll r, D, x2k; cin >> r >> D >> x2k;
    
    ll x, x_prev = x2k;
    for (int i = 2001; i <= 2010; i++) {
        x = r * x_prev - D;
        cout << x << endl;
        x_prev = x;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a[4],i,j,k;
	scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]);
	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				int t=6-i-j-k;
				if(i!=j&&j!=k&&k!=i){
					if(a[i]*1000+a[j]*100+a[k]*10+a[t]==1974){
						puts("YES");
						return 0;
					}
				}
			}
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
	public static void main(String args[]){
    	Scanner scan = new Scanner(System.in);

    	int N = scan.nextInt();
    	String S = scan.next();
    	String T = scan.next();

    	for(int i = 0 ; i < N ; i++) {
			String s = S.substring(i,i+1);
			String t = T.substring(i,i+1);
    		System.out.print(s+t);
		}
    	System.out.println();
	}
}


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

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
string dc = "RDLU";

int main() {
    int g[11][11] = {};
    char c;
    for (int i=1; i<10; ++i) {
        if (i % 2 == 1) {
            for (int j=2; j<=8; j+=2) {
                cin >> c;
                g[i][j] = c - '0';
                g[i][j-1] |= g[i][j];
                g[i][j+1] |= g[i][j];
            }
        } else {
            for (int j=1; j<=9; j+=2) {
                cin >> c;
                g[i][j] = c - '0';
                g[i-1][j] |= g[i][j];
                g[i+1][j] |= g[i][j];
            }
        }
    }
    int x = 1, y = 1, d = 0;
    do {
        for (int t=3; t<=6; ++t) {
            if (g[y + dy[(d + t) % 4]][x + dx[(d + t) % 4]]) {
                d = (d + t) % 4;
                break;
            }
        }
        x += dx[d] * 2;
        y += dy[d] * 2;
        cout << dc[d];
    } while ( ! (x == 1 && y == 1));
    cout << endl;
    return 0;
}

Measured memory_bytes: 1184
// AOJ 1620 Boolean Expression Compressor
// 2018.2.12 bal4u

#include <stdio.h>
#include <string.h>

typedef struct { char w; int p; } TBL;
TBL tbl[1 << 16];
char w[3000], exp[3000][17]; int top, end;
char buf[20], *p;

int eval()
{
    char c = *p; if (*p) p++;
	if      (c == '0') return 0;
	else if (c == '1') return 0xffff;
	else if (c == 'a') return 0xff00;
	else if (c == 'b') return 0xf0f0;
	else if (c == 'c') return 0xcccc;
	else if (c == 'd') return 0xaaaa;
	else if (c == '-') return (~eval()) & 0xffff;
	else if (c == '(') {
		int y, x = eval();
		if (*p++ == '^') { y = eval(); p++;	return x ^ y; }
		else             { y = eval(); p++;	return x & y; }
	}
	return 0;
}

void insert(char *s, int sz)
{
    int id;

	if (sz > 16) return;
	p = s, id = eval();
	if (sz < tbl[id].w) w[tbl[id].p] = 0, tbl[id].w = 0;
    if (tbl[id].w == 0) tbl[id].w = sz, tbl[id].p = end;
	else return;
	w[end] = sz, memcpy(exp[end], s, sz), end++;
}

void mktbl()
{
	int i, _top, __top, _end;
    char buf[100], *p, *q;

    insert("0", 1), insert("1", 1);
	insert("a", 1), insert("b", 1), insert("c", 1), insert("d", 1);

    while (top < end) {
		__top = top, _end = end;
		for (_top = __top; _top < _end; _top++) {
			if (w[_top] == 0 || w[_top] > 15 || *exp[_top] == '-') continue;
			p = exp[_top], q = buf;
			*q++ = '-'; while (*p) *q++ = *p++; *q = 0;
			insert(buf, q-buf);
		}

		for (_top = __top; _top < _end; _top++) {
			if (w[_top] == 0 || w[_top] > 13) continue;
			for (i = 0; i < _end; i++) {
				if (w[i] == 0 || w[i] > 13) continue;

				q = buf;
				*q++ = '(', p = exp[_top]; while (*p) *q++ = *p++;
				*q++ = '^', p = exp[i];    while (*p) *q++ = *p++;
				*q++ = ')', *q = 0;
                insert(buf, q-buf);

				q = buf;
				*q++ = '(', p = exp[_top]; while (*p) *q++ = *p++;
				*q++ = '*', p = exp[i];    while (*p) *q++ = *p++;
				*q++ = ')', *q = 0;
                insert(buf, q-buf);
			}
		}
		top = _end;
    }
}    

int main()
{
	mktbl();

	while (fgets(p=buf, sizeof(buf), stdin) && *p != '.') {
		printf("%d\n", tbl[eval()].w);
	}
    return 0;
}



Measured memory_bytes: 2240
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  string s;
  cin>>s;
  int n = sz(s);
  ll ans = 1;
  vi a(256);
  rep(i,n) {
    ans += i-a[s[i]];
    a[s[i]]++;
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 640
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

Bsize = 700

def Mo_argsort(LR):
    L = LR[:, 0]
    R = LR[:, 1]
    key1 = L // Bsize
    key2 = np.where(key1 & 1, -R, R)
    key = (key1 << 32) + key2
    return np.argsort(key)

def main(A, LR):
    N = len(A)
    Q = len(LR)
    ind = Mo_argsort(LR)
    count = np.zeros(N + 1, np.int64)
    ans = 0

    def add(x):
        nonlocal ans
        if not count[x]:
            ans += 1
        count[x] += 1

    def rem(x):
        nonlocal ans
        count[x] -= 1
        if not count[x]:
            ans -= 1

    answers = np.empty(Q, np.int64)
    nl, nr = 0, 0
    for i in ind:
        l, r = LR[i]
        l -= 1
        # 区間 [l, r) に対する計算
        while nl > l:
            nl -= 1
            add(A[nl])
        while nr < r:
            add(A[nr])
            nr += 1
        while nl < l:
            rem(A[nl])
            nl += 1
        while nr > r:
            nr -= 1
            rem(A[nr])
        #  答を求めて ans[i] に格納する
        answers[i] = ans
    return answers

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i4 = numba.int32
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    Mo_argsort = cc_export(Mo_argsort, (i8[:,:],))
    main = cc_export(main, (i8[:], i8[:, :]))
    cc.compile()

from my_module import main

N, Q = map(int, readline().split())
A = np.array(readline().split(), np.int64)
LR = np.array(read().split(), np.int64).reshape(Q, 2)

ans = main(A, LR)
print('\n'.join(map(str, ans.tolist())))

Measured memory_bytes: 102172
N,M= map(int,input().split())
R = []
for _ in range(M):
    R.append(tuple(input().split()))
for n in range(10**(N-1) if N!=1 else 10**(N-1)-1,10**N):
    isa = True
    for (s,c) in R:
        if str(n)[int(s)-1] != c:
            isa = False
    if isa:
        print(n)
        exit()
print(-1)

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ll n;
	cin>>n;
	cout<<n*(n - 1)/2<<endl;

	return 0;
}

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

struct Node {
    int key;
    unique_ptr<Node> left, right;
    Node(const int value):key(value) {
        
    }
};

void insert(unique_ptr<Node>& node, int key) {
    if(node == nullptr) {
        node = make_unique<Node>(key);
    } else {
        if(key < node->key) {
            insert(node->left, key);
        } else {
            insert(node->right, key);
        }
    }
}

void printInorder(unique_ptr<Node>& node) {
    if(node == nullptr) {
        return;
    }
    printInorder(node->left);
    cout << " " << node->key;
    printInorder(node->right);
}

void printPreorder(unique_ptr<Node>& node){
    if (node == nullptr) {
        return;
    }
    cout << " " << node->key;
    printPreorder(node->left);
    printPreorder(node->right);
}

bool find(unique_ptr<Node>& node, int key) {
    if(node == nullptr) {
        return false;
    }
    if(node->key == key) {
        return true;
    }
    if(key < node->key) {
       return find(node->left, key);
    } else {
       return find(node->right, key);
    }
}

int main() {
    int num;
    cin >> num;
    unique_ptr<Node> t(nullptr);

    for(int i=0; i<num; i++) {
        string command;
        cin >> command;
        if(command == "insert") {
            int key;
            cin >> key;
            insert(t, key);
        } else if(command == "print") {
            printInorder(t);
            cout << endl;
            printPreorder(t);
            cout << endl;
        } else if(command == "find"){
            int key;
            cin >> key;
            bool result = find(t, key);
            if(result) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
}


Measured memory_bytes: 15508
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {

		String[] in=br.readLine().split(" ");
		int len=Integer.parseInt(in[0]);
		int order=Integer.parseInt(in[1]);

		String[] str = br.readLine().split("");
		String[] result = new String[len];

		for(int i=0; i<len; i++) {
			if(i==order-1) {
				result[i]=str[i].toLowerCase();
			}else {
				result[i]=str[i];
			}
		}
		String re = "";
		for(String s:result) {
			re=re+s;
		}
		System.out.println(re);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


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

int main()
{
    int num;
    char mark[52];
    int no[52];
    
    cin >> num;
    
    for (int i = 0; i < num; ++i)
    {
        cin >> mark[i] >> no[i];
    }
    
    for (int k = 0; k < 4; ++k)
    {
        char comp;
        if (k == 0)
        {
            comp = 'S';
        }
        else if (k == 1)
        {
            comp = 'H';
        }
        else if (k == 2)
        {
            comp = 'C';
        }
        else
        {
            comp = 'D';
        }
        
        for (int j = 1; j <= 13; ++ j)
        {
            bool bFound = false;
            for (int i = 0; i < num; ++i)
            {
                if ((mark[i] == comp) && (no[i] == j))
                {
                    bFound = true;
                    break;
                }
            }
            
            if (!bFound)
            {
                cout << comp << " " << j << endl;
            }
            
        }
    }
    
    return 0;
}


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

const long long MOD = 998244353;

long long pow(long long x, long long n, long long mod) {
    long long ans = 1;
    while (n) {
        if (n % 2) ans *= x;
        x *= x;
        x %= mod;
        ans %= mod;
        n >>= 1;
    }
    return ans;
}

long long inv = pow(2, MOD - 2, MOD);

long long dp[3010][3010];

void solve(long long N, long long S, std::vector<long long> A) {
    dp[0][0] = pow(2, N, MOD);
    if (A[0] <= S) {
        dp[0][A[0]] = pow(2, N - 1, MOD);
    }

    for (int i = 1; i < N; i++) {
        for (int j = 0; j <= S; j++) {
            dp[i][j] += dp[i - 1][j];
            if (j - A[i] >= 0) {
                dp[i][j] += dp[i - 1][j - A[i]] * inv;
            }
            dp[i][j] %= MOD;
        }
    }

    cout << dp[N - 1][S] << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main() {
    long long N;
    scanf("%lld", &N);
    long long S;
    scanf("%lld", &S);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, S, std::move(A));
    return 0;
}


Measured memory_bytes: 74224
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

const RED_OVER_INDEX = 8;

int score2index(int score) {
    foreach (i, s; [400, 800, 1200, 1600, 2000, 2400, 2800, 3200]) {
        if (score < s) {
            return cast(int)i;
        }
    }
    return RED_OVER_INDEX;
}

void main() {
    readint;
    auto a = readints;

    auto d = new int[9];
    foreach (x; a) {
        d[score2index(x)]++;
    }

    int x = cast(int) d[0..RED_OVER_INDEX].count!(e => e > 0);
    int minAns = x;
    int maxAns = x;
    int zero = cast(int) d[0..RED_OVER_INDEX].count!(e => e == 0);

    if (d[RED_OVER_INDEX] > 0) {
        if (minAns == 0) minAns++;

        maxAns += d[RED_OVER_INDEX];
    }

    writeln(minAns, " ", maxAns);
}


Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		String SS = in.next();
		String T = in.next();
		
		int index = SS.length() - T.length();
		
		while(index >= 0){
			String s = SS.substring(index, index + T.length());
			
			boolean tf = true;
			for(int i = 0; i < T.length(); i++){
				if(s.charAt(i) != '?' && s.charAt(i) != T.charAt(i)){
					tf = false;
					break;
				}
			}
			
			if(tf){
				SS = new StringBuilder(SS).replace(index, index + s.length(), T).toString();
				SS = SS.replace('?', 'a');
				System.out.println(SS);
				return;
			}else{
				index--;
			}
		}
		
		System.out.println("UNRESTORABLE");
	}
}

Measured memory_bytes: 21844
// In the name of Allah the Most Merciful.

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

typedef long long ll;

int main(void)
{
    ll a , b , c, d;
    cin >> a >> b >> c >> d;

    if(a*b>c*d)cout << a*b << endl;
    else cout << c*d << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
#define pcii pair<char, pair<int, int>>
using namespace std;

const ll N = 105, mod = 1e9 + 7;
const int inf = 1e9;

void solve(){
    int n, c;
    cin >> n >> c;
    vi w(n), v(n);
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }
    vector<vl> dp(n + 1, vl(c + 1, 0));

    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= c; j++){
            if(w[i - 1] <= j){
                dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]);
            }
            else{
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    cout << dp[n][c] << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 83084
#include <stdio.h>
int main (void){
  int N,M,i,count=0;
  int d[101]={0};
 
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&M);
    if(d[M]==0)
      count++;
    d[M]=1;
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  ll N,T,t[200000];
  cin>>N>>T;
  for (int i(0);i<N;i++){
    cin>>t[i];
  }
  ll ans(0);
  for (int i(0);i<N-1;i++){
    if (t[i+1] - t[i] >= T) ans += T;
    else ans += t[i+1] - t[i];
  }
  ans += T;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
x,y = map(int,input().split())
if x*y == 0:
    if x<0:
        print(-x)
    elif x>0:
        print(1+x)
    else:
        if y >= 0:
            print(y)
        else:
            print(1-y)
elif x*y >0:
    if x>y:
        print(2+abs(x-y))
    else:
        print(abs(y-x))
else:
    print(1+abs(x+y))

Measured memory_bytes: 38480
s = input()
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != "L":
            pass
        else:
            print("No")
            break
    elif i % 2 == 1:
        if s[i] != "R":
            pass
        else:
            print("No")
            break
    if i == len(s)-1:
        print("Yes")


Measured memory_bytes: 2940
import copy
import numpy as np
n,m = map(int, input().split())
cakes = []
for i in range(n):
    cakes.append(list(map(int, input().split())))

def rec(i, k, s, obj):
    if i==k:
        obj.append(s)
        return
    rec(i+1, k, copy.deepcopy(s), obj)
    s[i]=1
    rec(i+1, k, copy.deepcopy(s), obj)
    s[i]=-1


def makeCombination(k):
    s=[-1 for i in range(k)]
    obj = []
    rec(0, k, s, obj)
    return obj

comb = makeCombination(3)
max = 0
for c in comb:
    sum_list = []
    nc = np.array(c)
    for cak in cakes:
        cake = np.array(cak)
        total = cake.dot(nc)
        sum_list.append(total)
    ssum_list = sorted(sum_list)
    sum_mm = sum(ssum_list[n-m:])
    if(max < sum_mm):
        max = sum_mm

print(max)


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

typedef long long ll;
ll mod=1e9+7;

ll modpow(ll a,ll b){
  ll ans=1;
  a%=mod;
  while(b){
    if(b&1) ans=ans*a%mod;
    a=a*a%mod;
    b>>=1;
  }
  return ans;
}

ll dp[100000][101];
ll sum[100000][101];

int main(){
  ll n,k;
  cin >> n >> k;
  ll t=sqrt(n);
  for(ll i=1;i<=t;i++) dp[i][1]=1;
  ll now=t+1;
  ll s;
  if((t+1)*t>n) s=t-1;
  else s=t;
  for(ll i=s;i>=1;i--){
    dp[now][1]=n/i-n/(i+1);
    now++;
  }
  for(ll i=2;i<=k;i++){
    for(ll j=1;j<now;j++){
      sum[j][i-1]=(sum[j-1][i-1]+dp[j][i-1])%mod;
    }
    for(ll j=1;j<now;j++){
      dp[j][i]=(sum[now-j][i-1]*dp[j][1])%mod;
    }
  }
  ll ans=0;
  for(ll i=1;i<now;i++){
    ans=(ans+dp[i][k])%mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 102656
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int mod = 1000000007;
const int N = 200005;

LL F[N], IF[N];

LL _pow(LL a, LL b) {
  if(!b) return 1;
  if(b == 1) return a;
  if(b == 2) return a * a % mod;
  if(b & 1) {
    return a * _pow(a,b-1) % mod;
  }
  return _pow(_pow(a,b/2),2);
}

void pre() {
  F[0] = 1;
  rep(i,1,N) {
    F[i] = F[i-1] * i % mod;
  }
  IF[N-1] = _pow(F[N-1], mod-2);
  for(int i = N - 2; i >= 0; i--) {
    IF[i] = IF[i+1] * (i + 1) % mod;
  }
}

LL nCr(int n, int r) {
  if(n < r) return 0;
  return F[n] * (IF[n-r] * IF[r] % mod) % mod;
}

int main() {
  pre();
  int h,w,a,b;
  scanf("%d%d%d%d",&h,&w,&a,&b);

  LL tot = nCr(h + w - 2, h - 1);
  rep(i,1,b+1) {
    LL tmp = nCr(h-a-1 + i-1, i-1) * nCr(a-1 + w-i, a-1) % mod;
    tot -= tmp;
    if(tot < 0) tot += mod;
  }
  cout << tot << "\n";

  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int N;
  cin>>N;
  ll answer=0;
  for(int i=1; i<=N; i++) {
      if(i%3!=0&&i%5!=0) answer+=i;
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define F first
#define S second
#define MP make_pair
#define PB push_back
typedef long long ll;
const int oo = 1e9;

int main() {_
ll i,n;
 cin >> n >> i;
 cout << n-i+1;
}


Measured memory_bytes: 256
def solve(string):
    n, *uvw = map(int, string.split())
    g = [[] for _ in range(n + 1)]
    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        g[u].append((v, w))
        g[v].append((u, w))
    s = [(1, 0)]
    w = [-1] * (n + 1)
    while s:
        _s, _w = s.pop()
        w[_s] = _w % 2
        for _t, _w_ in g[_s]:
            if w[_t] == -1:
                s.append((_t, _w + _w_))
    return "\n".join(str(_w) for _w in w[1:])


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n - 1)])))


Measured memory_bytes: 50988
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}

int main() {
  int n; cin>>n;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  ll sz=a[0], lf=0;
  for(int i=1;i<n;i++) {
    if (sz*2<a[i]) lf=i;
    sz+=a[i];
  }
  cout<<n-lf<<endl;
}

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

int main () {
  ll x, y;
  cin >> x >> y;
  if (x > y) {
    swap(x, y);  
  }
  if (x == 0) {
    if (y <= 1) {
      cout << "Brown" << endl;  
    }    
    else {
      cout << "Alice" << endl;  
    }
    return 0;
  }
  if (x == 1) {
    if (y <= 2) {
      cout << "Brown" << endl;  
    }  
    else {
      cout << "Alice" << endl;  
    }
    return 0;
  }
  if (y > x) {
    swap(x, y);  
  }
  if (x >= y + 2) {
    cout << "Alice" << endl;
    return 0;  
  }
  if (x - y <= 1) {
    cout << "Brown" << endl;
    return 0;  
  }
  cout << "Alice" << endl;
}


Measured memory_bytes: 888
N,M=map(int,input().split())
ab=[]
for _ in range(N):
    ab.append([int(i) for i in input().split()])

ab.sort()

count=0
cost=0

while count!=M:
    for i in range(N):
        if count+ab[i][1]<=M:
            cost=cost+ab[i][0]*ab[i][1]
            count+=ab[i][1]
        else:
            cost=cost+(M-count)*ab[i][0]
            count=M

print(cost)

Measured memory_bytes: 21616
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  int K, S; cin >> K >> S;

  i64 cnt = 0;
  for (int x = 0; x <= K; ++x) {
    for (int y = 0; y <= K; ++y) {
      int z = S - x - y;
      if (0 <= z && z <= K) ++cnt;
    }
  }

  cout << cnt << endl;

  return 0;
}



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

int main(){
	
	int A[3];

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

	if (A[0]+A[1]+A[2] >= 22){
		cout << "bust" << endl;
	}else{
		cout << "win" << endl;

	}
	return 0;	
}

Measured memory_bytes: 256
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF (1LL<<60)
#define fs first
#define sc second
#define int 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(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
#define MSB(x) (63-__builtin_clzll(x))
#define pcnt(x) (__builtin_popcountll(x))
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  FOR(i,1,n+1){
    if(n == i*108/100){
      cout << i << endl;
      return 0;
    }
  }

  cout << ":(" << endl;

  return 0;
}

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

int main(){
    int n;
    cin>>n;
    int a[110];
    for(int i=0;i<n;i++)cin>>a[i];
    int cnt=0;
    //SelectionSort
    for(int i=0;i<n-1;i++){
        int mini=i;
        for(int j=i+1;j<n;j++){
            if(a[j]<a[mini]){
                mini=j;
            }
        }
        if(i!=mini){
            cnt++;
            swap(a[i],a[mini]);
        }
    }
    //Output
    for(int i=0;i<n;i++){
        cout<<a[i];
        if(i<n-1)cout<<" ";
        else cout<<""<<endl;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3108
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

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

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007
#define PI acos(-1)

void Solve()
{
    double n;
    cin >> n;
    if (n == 1)
        cout << 0 << endl;
    else if (n == 0)
        cout << 1 << endl;
}
int32_t main()
{
    // int t;
    // cin >> t;
    // while (t--)
    // {
    Solve();
}
//     }
//     return 0;
// }

Measured memory_bytes: 3776
from collections import deque

q = deque(range(1,10))
K = int(input())

for i in range(K):
    x = q.popleft()
    r =  x % 10
    if r != 0:
        q.append((10 * x) + (r - 1))
    q.append((10 * x) + r)
    if r != 9:
        q.append((10 * x) + (r + 1))

print(x)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  
  if(k<u->key)return treeSearch(u->left,k);
  else return treeSearch(u->right,k); 

}



void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key< y->key) y->left=z;
  else y->right=z;

}

void inorder(Node u){
  if(u!=NIL) {
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }


}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 

    
   
  }

  return 0;
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:

#define error(args...) { vector<string> _debug = split(#args, ',');err(begin(_debug), args);}

vector<string> split(const string& s, char c){
	vector<string> v;stringstream ss(s);string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {cerr << endl;}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a,Args... args){
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << " ",err(++it, args...);
}

const int limit = 100010;
int n, a[limit];

bool check(int x,int k){
	const int val = a[n - k - 1];
	const int len = val - x;
	const int num = upper_bound(a, a + n, x + len) - lower_bound(a, a + n, x - len);
	return k >= num;
}

int get_idx(int x,int k){
	const int val = a[n - k - 1];
	const int len = val - x;
	const int num = upper_bound(a, a + n, x + len) - lower_bound(a, a + n, x - len);
	const int idx = lower_bound(a, a + n, x - len) - a - (k - num);
	return idx - 1;
}

ll lsum[limit];
ll hsum[limit];

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

	hsum[0] = 0LL;
	rrep(i, n){
		const int idx = n - i;
		hsum[idx] = hsum[idx - 1] + a[i];
	}

	rep(i, n){
		if(i - 2 >= 0) lsum[i] += lsum[i - 2];
		lsum[i] += a[i];
	}

	rep(loop,q){
		int x;
		cin >> x;
		int ng = 0, ok = (n + 1) /2;
		while(ok - ng > 1){
			const int mid = (ng + ok) / 2;
			if(check(x,mid))
				ok = mid;
			else
				ng = mid;
		}
		const int idx = get_idx(x, ok);
		// error(ok, idx);
		ll ans = 0LL;
		ans += hsum[ok];
		if(idx >= 0) ans += lsum[idx];
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3712
#include<iostream>
 
using namespace std ;
int main()
{
    int a,b;
     cin>>a>>b;
 
     if(a%2==1 && b%2==1){
        cout<<"Yes"<<endl;
     }
     else {
        cout<<"No"<<endl;
     }
 
 
    return 0;
}

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

int N, K;
vector<P> l;
set<int> s;
vector<int> rem;
vector<int> add;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K;
    rep(i, N) {
        int t, d; cin >> t >> d;
        l.pb(P(d, t));
    }
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    
    int now_tast = 0;
    rep(i, K) {
        now_tast += l[i].first;
        if (s.find(l[i].second)!=s.end()) rem.pb(l[i].first);
        else s.insert(l[i].second);
    }
    int now_vari = s.size();
    for (int i=K; i<N; i++) {
        if (s.find(l[i].second)==s.end()) {
            add.pb(l[i].first);
            s.insert(l[i].second);
        }
    }
    
    sort(rem.begin(), rem.end());
    sort(add.begin(), add.end());
    reverse(add.begin(), add.end());
    int ans = now_tast+now_vari*now_vari;
    rep(i, min(rem.size(), add.size())) {
        now_tast += add[i]-rem[i];
        now_vari++;
        ans = max(ans, now_tast+now_vari*now_vari);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6896
N, K ,Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

test = {}
for i in A:
  if i in test:
    test[i]+=1
  else:
    test[i]=1

for j in range(1,N+1):
    if j in test:
        if test[j]+K-Q >= 1:
            print("Yes")
        else:
            print("No")
    else:
        if K-Q >= 1:
            print("Yes")
        else:
            print("No")
            

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

int main() {
    int A[3][3];
    int B[3][3];
    for(int i=0; i < 3; i++ ){
        for(int j=0; j < 3; j++ ){
            cin >> A[i][j];
            B[i][j] = 1;
        }
    }

    int N;
    cin >> N ;
    int b;
    for(int k = 0; k < N; k++){
        cin >> b; 
        for(int i=0; i < 3; i++ ){
            for(int j=0; j < 3; j++ ){
                if (b == A[i][j]){
                    B[i][j] = 0;
                };
            }
        }
    }

    bool isBingo = false;
    // tate
    for(int i = 0; i < 3; i++){
        if (B[i][0] + B[i][1] + B[i][2] == 0){
            isBingo = true;
        }
    }
    // yoko
    for(int j = 0; j < 3; j++){
        if (B[0][j] + B[1][j] + B[2][j] == 0){
            isBingo = true;
        }
    }  
    // naname
    if (B[0][0] + B[1][1] + B[2][2] == 0){
        isBingo = true;
    }
    if (B[2][0] + B[1][1] + B[0][2] == 0){
        isBingo = true;
    }

    if (isBingo){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    } 

    return 0;
}



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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	int A, B;
	cin >> A >> B;
	if ((A + B) % 2 == 0) cout << (A + B) / 2 << endl;
	else cout << "IMPOSSIBLE" << endl;
}


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

int main(){
	char input[1024],word[32],word2[32],c_word[128],*p;
	char s_al[]="abcdefghijklmnopqrstuvwxyz",b_al[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int i,j,count=0,size;
	
	fgets(word,sizeof word,stdin);
	sprintf(word2,"%s",word);
	size=strlen(word2);
	
	for(i=0;i<size;i++){
		for(j=0;j<26;j++){
			if(word[i]==b_al[j]){
				word[i]=s_al[j];
				word2[i]=s_al[j];
				
			}
			
		}
		
		
	}
	
	word[size-1]='\0';
	
	while(1){
		fgets(input,sizeof input,stdin);
		
		p=strtok(input," ");
		sprintf(c_word,"%s",p);
		//printf("%s\n",c_word);
		size=strlen(c_word);
		
		if(strcmp(c_word,"END_OF_TEXT\n")==0||strcmp(c_word,"END_OF_TEXT\0")==0){
			break;
		}
		for(i=0;i<size;i++){
			for(j=0;j<26;j++){
				if(c_word[i]==b_al[j]){
					c_word[i]=s_al[j];
					
				}
				
			}
			
			
		}
		
		
		if(strcmp(c_word,word)==0||strcmp(c_word,word2)==0){
				count++;
				//printf("%d\n",count);
		}
		
		while(1){
			p=strtok(NULL," ");
			if(p==NULL){
				break;
			}
			sprintf(c_word,"%s",p);
			size=strlen(c_word);
			for(i=0;i<size;i++){
				for(j=0;j<26;j++){
					if(c_word[i]==b_al[j]){
						c_word[i]=s_al[j];
						
					}
					
				}
				
				
			}
			//printf("%s\n",c_word);
			if(strcmp(c_word,word)==0||strcmp(c_word,word2)==0){
				count++;
				//printf("%d\n",count);
			}
		}
	}
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> A(3, vector<int>(3, 0));
vector<vector<bool>> C(3, vector<bool>(3, false));

int main()
{
  int N, M, s, l;
  char c;
  bool ok;
  string is;
  cin >> N >> M;
  vector<pair<int, char>> sc(M);
  for (int i = 0; i < M; i++)
  {
    cin >> s >> c;
    sc.at(i) = make_pair(s, c);
  }
  l = pow(10, N - 1);
  if (N == 1)
    l = 0;
  for (int i = l; i <= pow(10, N) - 1; i++)
  {
    ok = true;
    is = to_string(i);
    for (int j = 0; j < M; j++)
    {
      s = sc.at(j).first;
      c = sc.at(j).second;
      if (is.at(s - 1) != c)
      {
        ok = false;
      }
    }
    if (ok)
    {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL
int n,m;
//vector<int> a,b;
vector<int> gidx;
vector<set<int>> g;

void g_merge(int a, int b) {
//printf("merge(%d, %d)\n", a, b);
  int ga = gidx[a];
  int gb = gidx[b];
//printf("ga = %d, gb = %d\n", ga, gb);
  if (ga == gb) return;

  if (g[ga].size() > g[gb].size()) {
    for (auto it=g[gb].begin(); it!=g[gb].end(); it++) {
//printf("gidx[%d] = %d\n", *it , gidx[a]);
      gidx[*it] = ga;
//printf("g[gidx[%d]].insert(%d)\n", a, *it);
      g[ga].insert(*it);
    }
    g[gb].clear();
  } else {
    for (auto it=g[ga].begin(); it!=g[ga].end(); it++) {
//printf("gidx[%d] = %d\n", *it , gidx[a]);
      gidx[*it] = gb;
//printf("g[gidx[%d]].insert(%d)\n", a, *it);
      g[gb].insert(*it);
    }
    g[ga].clear();
  }
}

int main()
{
  int a,b;
  ll ans;

  cin >> n >> m;

  g.resize(n+1);
  gidx.resize(n+1);
  for (int i=1; i<=n; i++) {
    set<int> gx;
    gx.insert(i);
    g[i] = gx;
    gidx[i] = i;
  }
  for (int i=0; i<m; i++) {
    cin >> a >> b;
    g_merge(a, b);
  }

  ans=0;
  for (auto it=g.begin(); it!=g.end(); it++) {
    if (ans<(ll)it->size()) ans = it->size();
  }

  cout << ans << endl;
  return 0;
}
/*
  {1,2,3,4}

  {1,3,4}{5,9}{2,6}
  */


Measured memory_bytes: 24204
n, k, *p = map(int, open(0).read().split())

for i, p_i in enumerate(p):
  p[i] = (1+p_i)/2

c_sum = [0]
v_sum = 0
for p_j in p:
  v_sum += p_j
  c_sum.append(v_sum)

a_max = 0
for i in range(n-k+1):
  if a_max < (c_sum[i+k] - c_sum[i]):
    a_max = (c_sum[i+k] - c_sum[i])
  
print(a_max)

Measured memory_bytes: 82468
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N, K, sum = 0;
    cin >> N >> K;
    vector<int> l(N);
    for(int i = 0; i < N; i++){
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    for(int j = 0; j < K; j++){
        sum += l[j];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3572
n = int(input())

m = int((n*2) ** 0.5)
if m*(m-1) >= n*2:
    m -= 1
elif m*(m+1) < n*2:
    m += 1

for i in range(m, 0, -1):
    if n-i >= 0:
        print(i)
        n -= i
    if n == 0:
        break


Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstring>
using namespace std;

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

struct Node {
  int l, r;
  int id;
  int leaf;
  Node() {
    l = r = 0;
    leaf = -1;
  }
};
vector<Node> tree;
int okasi[16];

int parse(string s, int &p) {
  int n = tree.size();
  int temp;
  if( s[p] == '(' ) {
    tree.push_back( Node() );
    p++;
    temp = parse(s, p);
    tree[n].l = temp;
    p++;
    temp = parse(s, p);
    tree[n].r = temp;
    p++;
  }
  else if( isdigit( s[p]) ) {
    int num = 0;
    while( isdigit( s[p] ) ) {
      num = num * 10 + s[p] - '0';
      p++;
    }
    tree.push_back( Node() );
    tree[n].leaf = num - 1;
  }
  return n;
}


int pattern[16];
int run(int p) {
  if( tree[p].leaf >= 0 ) return okasi[ tree[p].leaf ];
  int l = run( tree[p].l);
  int r = run( tree[p].r);

  int res = 15;
  if( pattern[ tree[p].id ] == 0 )
    res = res & (l & r);
  if( pattern[ tree[p].id ] == 1 )
    res = res & (l | r);
  if( pattern[ tree[p].id ] == 2 )
    res = res & (l ^ r);
  return res;
}

int ans = 0;
void rec(int depth, int max_depth) {
  if( depth == max_depth ) {
    int get = run(0);
    if( get == 15 ) ans++;
  } else {
    for(int i = 0; i < 3; i++) {
      pattern[depth] = i;
      rec( depth + 1, max_depth);
    }
  }
}

int main() {
  for(;;) {
    memset(okasi, 0, sizeof(okasi));
    string str;
    cin >> ws;
    getline(cin, str);
    if( str == "END" ) break;
    tree.clear();
    int p = 0;
    parse(str, p);

    int N; cin >> N;
    REP(i, N) {
      int num = 0;
      REP(k, 4) {
        int x;
        cin >> x;
        num = num * 2 + x;
      }
      okasi[i] = num;
    }

    int inner = 0;
    REP(i, tree.size()) if( tree[i].leaf == -1 ) {
      tree[i].id = inner;
      ++inner;
    }
    memset(pattern, 0, sizeof(pattern));
    ans = 0;    
    rec(0, inner);
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	int A,B;
	cin>>A>>B;
	
	int keta1[100000];
	int keta2[100000];
	int keta3[100000];
	int keta4[100000];
	int keta5[100000];
	
	int ans=0;
	for(int i=A;i<=B;i++){
		keta1[i]=i%10;
		keta2[i]=(i/10)%10;
		keta3[i]=(i/100)%10;
		keta4[i]=(i/1000)%10;
		keta5[i]=(i/10000)%10;
		if(keta1[i]==keta5[i]&&keta2[i]==keta4[i])
			ans++;
			
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fi first
#define se second
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
    ll n,m;
    cin>>n>>m;
    
    ll ans = n*(n-1)/2;
    ans = ans + m*(m-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256