akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r;
    cin >> r;
    if (r < 1200)
        cout << "ABC" << endl;
    else if (r < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  
  size_t size = S.length();
  const char* cstr = S.c_str();
  
  for(int i = 0; i < size; i++){
    if(cstr[i] == 'U' || cstr[i] == 'D') {
      continue;
    }
  	if( i%2 == 0 && cstr[i] == 'L'){
      cout << "No";
      return 0; 
    }
    if( i%2 == 1 && cstr[i] == 'R'){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
import sys
import copy
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

# print(A)
med = N//2

B = copy.deepcopy(A)
B.sort()
l_m = B[med-1]
h_m = B[med]

for a in A:
	if a > l_m:
		print(l_m)
	else:
		print(h_m)

Measured memory_bytes: 119624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int n, m, q;

void create(vi &num, vii &nums)
{
    if(num.size() == n)
    {
        nums.push_back(num);
    }
    else
    {
        if(num.empty())
        {
            for(int i=1; i<=m; i++)
            {
                vi n = num;
                n.push_back(i);
                create(n, nums);
            }
        }
        else
        {
            for(int i=num.back(); i<=m; i++)
            {
                vi n = num;
                n.push_back(i);
                create(n, nums);
            }
        }
    }
}

int main()
{
    cin >> n >> m >> q;
    vii abcds;
    abcds.resize(q);
    for(int i=0; i<q; i++)
    {
        vi abcd;
        abcd.resize(4);
        for(int j=0; j<4; j++)
        {
            cin >> abcd.at(j);
        }
        abcds.at(i) = abcd;
    }
    vii nums;
    vi nnn;
    create(nnn, nums);
    // for(auto &num : nums)
    // {
    //     for(auto n : num)
    //     {
    //         cout << n << " ";
    //     }
    //     cout << endl;
    // }

    ll mxans = 0;
    for(auto &num : nums)
    {
        ll ans = 0;
        for(auto &abcd : abcds)
        {
            if(num.at(abcd.at(1)-1) - num.at(abcd.at(0)-1) == abcd.at(2)) ans += abcd.at(3);
        }
        mxans = max(ans, mxans);
    }
    cout << mxans << endl;

    return 0;
}


Measured memory_bytes: 9864
k,n = gets.chomp.split(" ").map(&:to_i)
ary1 = gets.chomp.split(" ").map(&:to_i)
max1 = k-ary1[n-1] + ary1[0]
dist = 0
(n-1).times do |i|
  dist = ary1[i+1]-ary1[i]
  if max1 < dist
    max1 = dist
  end
end
puts k-max1


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

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

    string str[n];
    for(int i=0;i<n;++i){
        string s; cin >> s;
        str[i] = s;
    }

    sort(str, str+n);

    string res = "";
    for(string s: str){
        res += s;
    }

    cout << res << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





int main() {
  ll n,m;
  cin>>n>>m;

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  ll l=p[0]/2;
  repo(i,n){
    l=lcm(l,p[i]/2);
  }

  int memo=0;
  while(p[0]%2==0){
    p[0]/=2;
    memo++;
  }

  repo(i,n){
    int cnt=0;
    while(p[i]%2==0){
      p[i]/=2;
      cnt++;
    }
    if(cnt!=memo) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << m/l-m/(2*l) << endl;

}


Measured memory_bytes: 1024
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

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

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}
#define ll long long
ll gcd (ll a, ll b) {
    while (b > 0) {
        ll t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm (int a, int b) {
    return (a / gcd (a, b)) * b;
}

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int has[maxx], cnt[maxx];
int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m, a, b;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cnt[i] = 1;
    }
    has[1] = 1;
    for (int i = 1; i <= m; i++) {
        cin >> a >> b;
        if (has[a] == 1) {
            has[b] = 1;
        }
        cnt[a]--, cnt[b]++;
        if (cnt[a] == 0) {
            has[a] = 0;
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        res += has[i];
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int R,G,B,K;
  cin>>R>>G>>B>>K;
  rep(i,K){
    if(G<=R)G*=2;
    else B*=2;
  }
  if(R<G&&G<B)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b) {
    if(a%b==0) return(b);
    else return(gcd(b,a%b));
}

int main() {
    int a,b,k;
    cin >> a >> b >> k;
    int c=gcd(a,b);
    int ans=0;
    int cnt=0;
    for(int i=c;i>=1;--i) {
        if(a%i==0 && b%i==0) {
            cnt+=1;
            if(cnt==k) {
                ans=i;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        List<Integer> b = new ArrayList<>();
        List<Integer> c = new ArrayList<>();
        for(int i = 0;i < n;i++){
            a.add(sc.nextInt());
        }
        for(int i = 0;i < n;i++){
            b.add(sc.nextInt());
        }
        for(int i = 0;i < n;i++){
            c.add(sc.nextInt());
        }
        Collections.sort(a);
        Collections.sort(c);
        long count = 0;
        for(int i= 0;i < n;i++){
            long k = lower_bound(n,a,b.get(i));
            long j = n - upper_bound(n,c,b.get(i));
            count += k*j;
        }
        System.out.println(count);
    }
    public static long lower_bound(int n,List x,int k){
        int lb = -1;
        int ub = n;

        while(ub - lb > 1){
            int mid = (ub + lb) / 2;
            int m = (int) x.get(mid);
            if(m >= k){
                ub = mid;
            }
            else{
                lb = mid;
            }
        }
        return ub;
    }
    public static long upper_bound(int n,List x,int k){
        int lb = -1;
        int ub = n;

        while(ub - lb > 1){
            int mid = (ub + lb) / 2;
            int m = (int) x.get(mid);
            if(m <= k){
                lb = mid;
            }
            else{
                ub = mid;
            }
        }
        return ub;
    }
}


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

int main(){
    int i,min1=0,ans=0;
    int taimu[5];
    for(i=0;i<5;i++){
        cin >> taimu[i];
    }
    for(i=0;i<5;i++){
        if(taimu[i]%10!=0 && taimu[i]%10<taimu[min1]%10){
            min1=i;
        }
    }
    for(i=0;i<5;i++){
        if(i==min1){
            continue;
        }
        if(taimu[i]%10!=0){
            taimu[i] += 10 - (taimu[i]%10);
        }
    }
    for(i=0;i<5;i++){
        ans +=taimu[i];
    }

    cout << ans;
    
}

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

int main(){
	string s;
	cin >> s;
	for (int i = 0; i < s.size()-2; ++i)
	{
		if(s[i]==s[i+1]){
			cout << i+1 << " " << i+2 << endl;
			return 0;
		}
		if(s[i]==s[i+2]){
			cout << i+1 <<" "<<i+3 << endl;
			return 0;
		}
	}
	if(s[s.size()-2]==s[s.size()-1]){
		cout << s.size()-1 << " " << s.size() << endl;
		return 0;		
	}
	
	cout << "-1 -1"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
signed main() {
    int N,K,L;
    cin >> N >> K >> L;
    UnionFind X(N);
    UnionFind Y(N);
    for(int i = 0; i < K; i++) {
        int p,q;
        cin >> p >> q;
        p--;q--;
        X.unite(p,q);
    }
    for(int i = 0; i < L; i++) {
        int r,s;
        cin >> r >> s;
        r--;s--;
        Y.unite(r,s);
    }
    map<P,int> Map;
    for(int i = 0; i < N; i++) {
        Map[make_pair(X.root(i),Y.root(i))]++;
    }
    for(int i = 0; i < N; i++) {
        cout << Map[make_pair(X.root(i),Y.root(i))];
        if(i+1 != N) {
            cout << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 17604
a=int(input())
counter=0
for i in range(1,a+1):
    for j in range(i,a+1):
        for k in range(j,a+1):
            if i==j and j==k:
                times=1
            elif i!=j and j!=k and k!=i:
                times=6 
            else:
                times=3
            
            for l in range(i,0,-1): 
                if i%l==0 and j%l==0 and k%l==0:
                    counter+=(l*times)
                    break
print(counter)

Measured memory_bytes: 74104
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] input1 = Console.ReadLine().Split(' ');
        int M = int.Parse(input1[0]);
        int D = int.Parse(input1[1]);
        int count = 0;
        int d1 = 0;
        int d10 = 0;

        for(int i = 1; i <= M; i++)
        {
            for(int j = 10; j <= D; j++)
            {
                if (j % 10 == 0)
                    continue;
                d1 = j % 10;
                d10 = j / 10;
                if (d1 < 2)
                    continue;
                if (d10 < 2)
                    continue;

                if (d1 * d10 == i)
                {
                    count++;
                }
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13140
#pragma region
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
#pragma endregion

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  reverse(all(a));
  i64 ans = 0;
  rep(i, n) {
    ans += a[i];
    int now = a[i];
    int idx = i;
    while (true) {
      if (idx + 1 == n) break;
      if (now - 2 >= a[idx + 1]) {
        cout << -1 << endl;
        return;
      }
      if (now - 1 == a[idx + 1]) {
        idx++;
        now--;
        continue;
      }
      break;
    }
    if (idx + 1 == n) {
      if (now == 0) break;
      cout << -1 << endl;
      return;
    }
    i = idx;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define sz(a) (int)((a).size())
#define fuck() cout<<"--------"<<endl
#define see(x) cout<<#x<<" = "<<x<<endl
const int hell=1000000007;
typedef pair<int,int> pii;
const int N=2e7;
bool dp[N];
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<1000;i++){
        string str=to_string(i);
        if(sz(str)==1)str="00"+str;
        else if(sz(str)==2)str="0"+str;
        int idx=0,turn=0;
        while(idx<n){
            if(s[idx]==str[turn]){
                idx++;
                turn++;
            }
            else{
                idx++;
            }
            if(turn==3){
                ans++;
                break;
            }
        }
    }
    cout<<ans;
    cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n';
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
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;
}

#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w;
    cin >> h >> w;
    if(h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }
    ll sum = h * w;
    cout << sum / 2 + (sum % 2) << endl;
}

Measured memory_bytes: 3596
open Batteries
open Printf
let () =
  let s,t = Scanf.scanf "%s %s " (fun a b -> a,b) in
  let ss = s^s in
  let res =
    try (
      let _ = String.rfind ss t in true
    ) with _ -> false
  in
  Printf.printf "%s\n" @@
  if res then "Yes" else "No"


Measured memory_bytes: 1024
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		double EPS=1e-4;
		while(N-->0)
		{
			double QR=in.nextDouble();
			double RP=in.nextDouble();
			double PQ=in.nextDouble();
			int n=in.nextInt();
			Point p[]=new Point[n];
			for(int i=0;i<n;i++)
				p[i]=new Point(in.nextDouble(),in.nextDouble(),in.nextDouble());

			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					for(int k=0;k<n;k++)
					{
						if(i==j||j==k||k==i)
							continue;
						double dis1=distance(p[i],p[j]);
						double dis2=distance(p[j],p[k]);
						double dis3=distance(p[k],p[i]);
						boolean judge=false;
						if(dis1/dis2-PQ/QR<EPS)
							if(dis2/dis3-QR/RP<EPS)
								if(dis3/dis1-RP/PQ<EPS)
									judge=true;
						if(judge)
						{
							System.out.println((i+1)+" "+(j+1)+" "+(k+1));
							break;
						}
					}

		}
	}

	static double distance(Point p1,Point p2)
	{
		double d1=Math.hypot(p1.x-p2.x,p1.y-p2.y);
		double dis=Math.hypot(d1,p1.z-p2.z);
		return dis;
	}

	static public void debug(Object... o)
	{
		System.err.println(Arrays.deepToString(o));
	}
}

class Point
{
	double x,y,z;
	Point(double x,double y,double z)
	{
		this.x=x;
		this.y=y;
		this.z=z;
	}
}

Measured memory_bytes: 24800
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n,option) f(i,0,n)cout<<v[i]<<option;
#define all(a) a.begin(),a.end()
#define size(s) ((int)s.size())
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 10000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<int>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0) {
			return false;
		}
	}
	return true;
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}

#pragma endregion

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

	st x;
	cin >> x;
	int n = size(x);
	sc s;
	f(i, 0, n) {
		if (x[i] == 'S') {
			s.push(x[i]);
		}
		if (x[i] == 'T' && (s.empty() || s.top() == 'T')) {
			s.push(x[i]);
		}
		if (x[i] == 'T'&&s.top() == 'S') {
			s.pop();
		}
	}
	cout << size(s);
	return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n,m;
  cin>>n>>m;
  int arr[n];
  for(int i=0; i<n; i++) cin>>arr[i];
  int total = 0;
  for(int i=0; i<n; i++) total+=arr[i];
  int ret = 0;
  for(int i=0; i<n; i++){
  	if(arr[i]*4*m>=total) ret++;
  }
  if(ret>=m) cout<<"Yes";
  else cout<<"No";
}

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

int main()
{
  int n, w;
  scanf("%d%d", &n, &w);
  vector<long long> dp(w + 1);
  for(int i = 0; i < n; i++)
  {
    int x, y;
    scanf("%d%d2", &x, &y);
    for(int weight = w; weight >= x; weight--)
    {
      dp[weight] = max(dp[weight], dp[weight - x] + y);
    }
  }
  cout << dp[w];
  
  return 0;
}


Measured memory_bytes: 1152
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    A,B = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = A*B
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61668
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    from itertools import permutations
    def dot(a,b):
        return sum(list(map(lambda x : x[0]*x[1], zip(a,b))))

    n = I()
    p = LIR(n)
    ans = float("inf")
    for l in permutations(range(n),n):
        x,y = [0,0]
        m = 0
        v = [1,0]
        for i in l:
            s,t = p[i]
            nv = [s-x,t-y]
            m += math.acos(dot(v,nv)/(dot(v,v)*dot(nv,nv))**0.5)
            x,y = s,t
            v = [nv[0],nv[1]]
        s,t = 0,0
        nv = [s-x,t-y]
        m += math.acos(dot(v,nv)/(dot(v,v)*dot(nv,nv))**0.5)
        ans = min(ans, m)
    print(ans*180/math.pi)
    return


if __name__ == "__main__":
    solve()



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


int main() {
  int N;
  string data;
  cin >> N;
  cin >> data;
  if ( data.size() <= N){
    for (int i = 0; i < data.size(); i++){
      cout << data.at(i);
    }
  }
  if ( data.size() > N){
    for ( int i = 0; i < N; i++){
      cout << data.at(i);
    }
    cout << "..." << endl;
  }
  
  
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-

def main():
    """Function."""
    n, k = map(int, input().split())
    hight = [0 for i in range(n)]
    for i in range(n):
        hight[i] = int(input())
    hight.sort()

    check = [0 for i in range(n - k + 1)]
    for i in range(n - k + 1):

        check[i] = hight[i+k-1] - hight[i]

    print(min(check))

if __name__ == "__main__":
    main()


Measured memory_bytes: 11280
#include<stdio.h>
#include<math.h>
int main(void)
{
    double amount, x1, x2, y1, y2;
    scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
    amount = ((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
    printf("%f\n",sqrt(amount));
    return 0;
}

Measured memory_bytes: 652
cards = list()
n = int(input())
for i in range(n):
    x,y = input().split()
    y = int(y)
    if x == 'S' :
        cards.append(y + 0)
    elif x == 'H':
        cards.append(y + 13)
    elif x == 'C':
        cards.append(y + 26)
    elif x == 'D':
        cards.append(y + 39)
mark = ['S','H','C','D']
for x in range(1,53):
    if not (x in cards):
        print(mark[(x-1)//13], (x-1)%13+1)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	sort(all(a));

	int ans = 1000000000;
	for (int i = -100; i <= 100; ++i) {
		int b = 0;
		rep(j, n) {
			b += (i - a[j]) * (i - a[j]);
		}
		ans = min(ans, b);
	}

	dunk(ans);

	return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL s, c;

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


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

int n;
char buff[20485];

int main() {
  scanf("%d", &n);
  scanf("%s", buff);
  int r=0, b=0;
  for (int i = 0; i < n; i++) {
    if (buff[i] == 'R') {
      r++;
    }
    else if (buff[i] == 'B') {
      b++;
    }
  }
  if (r > b) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
  return 0;
}


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

int check_odd(int x){
    int n=0,k=x;
    for(n=0;k%2==0;n++){
        k/=2;
    }
    return n;
}

int main(){
    int num;
    cin>>num;
    int *a=new int[num];
    for(int i=0;i<num;i++){
        cin>>a[i];
    }
    int count=0;
    for(int i=0;i<num;i++){
        count+=check_odd(a[i]);
    }
    cout<<count;
    return 0;



}

Measured memory_bytes: 256
#include <stdio.h>

int a,b,c;
int d=0;
//int w,h,x,y,r;

int main(void) {
  scanf("%d %d %d",&a,&b,&c);
  for(int k=a;k<=b;k++){
    if(c%k==0){
      d++;
    }
    else;
    //printf("%d %d\n",num[1][k],num[2][k]);
  }
  printf("%d\n",d);
}



Measured memory_bytes: 2104
import bisect

N, M = map(int, input().split())
cities = []
prefectures = [[] for _ in range(N+1)]

for i in range(M):
  p, y = map(int, input().split())
  cities.append((y, p))

for (y, p) in sorted(cities, key=lambda x: x[0]):
  prefectures[p].append(y)

for (y, p) in cities:
  x = bisect.bisect_right(prefectures[p], y) 
  pid = "00000" + str(p)
  xid = "00000" + str(x)
  print(pid[::-1][:6][::-1] + xid[::-1][:6][::-1])

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

using namespace std;

#define MAX 20
#define INF 1e9

vector<int> vec,v[MAX],a[MAX];

void init(int N){
  vec.clear();
  for(int i = 0 ; i < MAX ; i++){
    v[i].clear();
  }
  for(int i = 1 ; i < 1<<N ; i++){
    int idx = __builtin_popcount(i);
    v[idx-1].push_back(i);
  }
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < (int)v[i].size() ; j++){
      vec.push_back(v[i][j]);
    }
  }
}

int main(){
  int N,U,c[MAX],k,r;
  bool used[MAX] = {false};

  while(cin >> N >> U, (N | U)){
    if(!used[N-1]){
      init(N);
      a[N-1] = vec;
      used[N-1] = true;
    }else{
      vec = a[N-1];
    }
    int arr[MAX];
    for(int i = 0 ; i < N ; i++){
      cin >> c[i] >> k;
      int S = 0;
      for(int j = 0 ; j < k ; j++){
        cin >> r;
        S |= 1<<r;
      }
      arr[i] = S;
    }
    int ans = INF;
    for(int i = 0 ; i < (int)vec.size() ; i++){
      int S = vec[i];
      int cnt = 0, total = 0;
      bool flg = true;
      for(int j = 0 ; j < N ; j++){
        if(S >> j & 1){
          if((S & arr[j]) == arr[j]){
            cnt += c[j]; total++;
          }else{
            flg = false;
            break;
          }
        }
      }
      if(flg && cnt >= U){
        ans = total;
        break;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 14580
#include<stdio.h>

int main() {
    int n, q, i, j, key, a;
    int left, mid, right;
    int s[100000];
    int t[50000];
    int count = 0;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &s[i]);
    
    scanf("%d", &q);
    for (i = 0; i < q; i++)
        scanf("%d", &t[i]);
    
    for (i = 0; i < q; i++) {
        left = 0;
        right = n;
        a = 0;
        key = t[i];
        j = 0;
        while (left < right && a == 0) {
            mid = (left + right) / 2;
            if (s[mid] == key)
                a = 1;
            else if (key < s[mid])
                right = mid;
            else
                left = mid + 1;
        }
        if (a == 1)
            count++;
    }
    
    printf("%d\n", count);
    
}

Measured memory_bytes: 2380
def main():
    N = int(input())
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in range(N):
        s = input()
        if s[0] == 'M':
            m += 1
        elif s[0] == 'A':
            a += 1
        elif s[0] == 'R':
            r += 1
        elif s[0] == 'C':
            c += 1
        elif s[0] == 'H':
            h += 1
    ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h
    print(ans)
main()
       


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int main(){
  vector<int> lot;
  int n,m;
  cin >>n>>m;
  for(int i=1; i<=n; i++) lot.push_back(i);
  for(int i=0,a,b; i<m; i++){
    scanf("%d,%d",&a,&b);
    int c = lot[a-1];
    lot[a-1] = lot[b-1];
    lot[b-1] = c;
  }
  for(int i=0; i<n; i++) cout <<lot[i]<<endl;
  return 0;
}

Measured memory_bytes: 1260
#include <iostream>

int main()
{
    int N, X;
    std::cin >> N >> X;

    int Li;
    int L[1000] = {0};
    for (int i = 0; i < N; i++) {
        std::cin >> Li;
        L[i+1] = L[i] + Li;
    }

    int i = 0;
    for (; i <= N; i++) {
        if (L[i] > X) break;
    }

    std::cout << i << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; //10^9

int main(void){
    vector<vector<int> > A(3, vector<int> (3));
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            cin >> A.at(i).at(j);
        }
    }
    int N;
    cin >> N;

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

    vector<vector<bool> > card(3, vector<bool>(3));
    for(int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            card.at(i).at(j) = false;
            for (int k = 0; k < N; k++){
                if(A.at(i).at(j) == B.at(k)){
                    card.at(i).at(j) = true;
                }
            }
        }
    }


    string Ans = "No";
    for (int i = 0; i < 3; i++){
        if(card.at(i).at(0) and card.at(i).at(1) and card.at(i).at(2)){
            Ans = "Yes";
        }
    }
    for (int i = 0; i < 3; i++){
        if(card.at(0).at(i) and card.at(1).at(i) and card.at(2).at(i)){
            Ans = "Yes";
        }
    }
    if(card.at(0).at(0) and card.at(1).at(1) and card.at(2).at(2)){
            Ans = "Yes";
    }
    if(card.at(0).at(2) and card.at(1).at(1) and card.at(2).at(0)){
            Ans = "Yes";
    }
    cout << Ans << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main {

  def pow(x:Long, y:Long, z:Long):Long = {

    def multi(m:Long, n:Long) = { ( (m%z) * (n%z) ) % z }

    def pow2(m:Long, n:Long, odd:Long, b:Long):Long = {
      n match {
        case 0 => 1
        case 1 => multi(m, odd)
        case _ =>
          val t = if(n%2 == 1) multi(odd, b) else odd
          pow2(multi(m,m), n/2, t, multi(b,b))
      }
    }
    pow2(x, y, 1, x)
  }

  def main(args: Array[String]) = {
    val l = readLine().split(" ").map(_.toLong)
    val (m, n) = (l(0), l(1))
    println(pow(m,n,1000000007))
  }
}

Measured memory_bytes: 43700
str = gets.chomp
q_size = gets.to_i
q_size.times do
  q = gets.chomp.split
  q[1] = q[1].to_i
  q[2] = q[2].to_i
  case q[0]
  when "print"
    puts str[q[1]..q[2]]
  when "replace"
    str[q[1]..q[2]] = q[3]
  when "reverse"
    str[q[1]..q[2]] = str[q[1]..q[2]].reverse
  end
end

Measured memory_bytes: 6156
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        NotFound solver = new NotFound();
        solver.solve(1, in, out);
        out.close();
    }

    static class NotFound {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            int[] freq = new int[26];
            for (int i = 0; i < s.length; i++) {
                freq[s[i] - 'a']++;
            }
            for (int i = 0; i < 26; i++) {
                if (freq[i] == 0) {
                    out.println((char) (i + 'a'));
                    return;
                }
            }
            out.println("None");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException ex) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public String next() {
            int c;
            while (isSpaceChar(c = this.read())) {
                ;
            }

            StringBuilder result = new StringBuilder();
            result.appendCodePoint(c);

            while (!isSpaceChar(c = this.read())) {
                result.appendCodePoint(c);
            }

            return result.toString();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }
}



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

using namespace std;

int is_prime(int n)
{
    int m=sqrt(n+0.5);
    for(int i=2; i<=m; i++)
        if(n%i==0)
            return 0;
    return 1;
}

int num[20000];
int pr[100];
int main()
{
    int cnt=0;
    for(int i=3; i<55555; i++)
        if(is_prime(i))
            num[cnt++]=i;
    int k=0;
    for(int i=0; i<cnt; i++)
    {
        if((num[i]-1)%5==0)
            pr[k++]=num[i];
        if(k==60)
            break;
    }
    int n;
    cin >> n;
    
    for(int i=0;i<n;i++)
    {
        if(i!=0)
            cout << ' ';
        cout << pr[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0)break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if((i+j)%2==0)cout<<'#';
                else cout<<'.';
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
int n,l,head,tail;
double nowv,nowt,qt[500010],qv[500010];
int main(){
    scanf("%d%d",&n,&l);
    head=1,tail=0;
    for(int i=1;i<=n;i++){
        double t,v;
        scanf("%lf%lf",&t,&v);
        nowv+=v;
        while(head<tail&&nowv>l&&qv[head]<=nowv-l){
            nowt-=qt[head]*qv[head];
            nowv-=qv[head];
            head++;
        }
        if(nowv>l){
            qv[head]-=nowv-l;
            nowt-=qt[head]*(nowv-l);
            nowv=l;
        }
        qt[++tail]=t;
        qv[tail]=v;
        while(head<tail&&qt[tail]<=qt[tail-1]){
            tail--;
            qt[tail]=(qt[tail+1]*qv[tail+1]+qt[tail]*qv[tail])/(qv[tail+1]+qv[tail]);
            qv[tail]=qv[tail+1]+qv[tail];
        }
        nowt+=v*t;
        printf("%.8lf\n",nowt/l);
    }
    return 0;
}

Measured memory_bytes: 17280
N, A, B = map(int, input().split())
S = input()

count_all = 0
count_f = 0
for i in S:
    if i == 'a':
        if count_all < A + B:
            print('Yes')
            count_all += 1
        else:
            print('No')
    elif i == 'b':
        if count_all < A + B and count_f < B:
            print('Yes')
            count_all += 1
            count_f += 1
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 9216
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

ll N, K;

struct Sushi{
    ll neta;
    ll delicious;

    Sushi(ll a, ll b){
        neta = a;
        delicious = b;
    }

    bool operator<(const Sushi &another) const
    {
        return delicious < another.delicious;
    }

    bool operator>(const Sushi &another) const
    {
        return delicious > another.delicious;
    }
};
vector<Sushi> S;

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

    // input
    cin >> N >> K;

    S.reserve(N);

    FOR(i, 0, N){
        ll t, d;
        cin >> t >> d;
        S.push_back(Sushi(t, d));    
    }
    // おいしさ順にソート
    sort(ALL(S), greater<Sushi>());
    
    vector<Sushi> Sa;
    Sa.reserve(K);
    vector<Sushi> NotSa;
    NotSa.reserve(N-K);

    ll delicious_sum = 0;
    map<int, int> neta_count; // そのネタをいくつ食べたか
    // 食べる
    FOR(i, 0, K){
        auto sushi = S[i];
        delicious_sum += sushi.delicious;
        neta_count[sushi.neta]++;
        Sa.push_back(sushi);
    }
    // 食べない
    FOR(i, K, N){
        auto sushi = S[i];
        NotSa.push_back(sushi);
    }

    ll neta_num = neta_count.size();
    // 美味しさ重視での最大値
    ll max_score = delicious_sum + neta_num * neta_num;
    
    ll j_start = Sa.size()-1;
    // 食べてないネタの中で、ネタ数を増やせる物があるか
    FOR(i, 0, N-K){
        auto sushi = NotSa[i];

        // まだ食べていないネタ
        if(neta_count[sushi.neta]==0){
            
            // Saから１つとりのぞく
            for(int j=j_start; j>=0; j--){
                j_start = j;
                auto bad_taste_sushi = Sa[j];
                if(neta_count[bad_taste_sushi.neta]>1){
                    // とりのぞく
                    neta_count[bad_taste_sushi.neta]--;
                    delicious_sum -= bad_taste_sushi.delicious;

                    // 新ネタを食べる
                    neta_count[sushi.neta]++;
                    neta_num++;
                    delicious_sum += sushi.delicious;

                    // 新スコア
                    ll score = delicious_sum + neta_num * neta_num;
                    max_score = max(max_score, score);

                    j_start = j-1;
                    break;
                }
            }
        }
    }

    p(max_score);
    
    return 0;
}

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

int main() {
    double n,k;
    cin >> n >> k;
    vector<double> dice(n);
    rep(i,n) cin >> dice[i];
    vector<double> sum(n);
    sum[0] = dice[0];
    rep2(i,1,n) sum[i] = sum[i-1]+dice[i];
    double a = sum[k-1];
    double now = 0;
    rep2(i,1,n-k+1) {
        double na = sum[i-1+k]-sum[i-1];
        if(na > a) {
            a = na;
            now = i;
        }
    }
    double ans = k;
    ans += (a-k)/2;
    printf("%.8f",ans);
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;

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

int main()
{
  ll x;
  cin >> x;

  for (int i = -1000; i <= 1000; i++) {
    for (int j = -1000; j <= 1000; j++) {
      if (x == pow(i, 5) - pow(j, 5)) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void setIO(string name = "a") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen((name+".in").c_str(), "r", stdin);
    freopen((name+".out").c_str(), "w", stdout);
}

int main() {
    //setIO();
    int k; cin >> k;
    for (int i = 0; i < k; i++) cout << "ACL";
    cout << "\n";
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    string ans = "YES";
    for(int i=0; i<n-1; i++){
        if(a.at(i) == a.at(i+1)){
            ans = "NO";
            break;
        }
    }
    
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

bool a[40][40];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, k, A;
	cin>>n>>m;
	REP(i, n){
		cin>>k;
		REP(j, k){
			cin>>A;
			a[i][A-1]=true;
		}
	}
	int ans=0;
	REP(i, m){
		bool ok=true;
		REP(j, n){
			if(!a[j][i]){
				ok=false;
				break;
			}
		}
		if(ok){
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "127" ].parse.expand.solve == 4 );
	assert( [ "3" ].parse.expand.solve == 3 );
	assert( [ "44852" ].parse.expand.solve == 16 );
}



import std.algorithm;
import std.conv;
import std.functional;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( int );
	
	return tuple( n );
}

int solve( in int n )
{
	// 6円未満の場合、1円*回数
	if(	n < 6 )
	{
		return n;
	}
	
	// 9円未満の場合、6円 + 1円*回数
	if( n < 9 )
	{
		return 1 + ( n - 6 );
	}
	
	// その他の場合、9円のn乗の単位の最大値と6円のn乗の単位の最大値で比較して回数が少ないほうを選ぶ
	auto su = memoize!( getMaxUnit!( 6 ) )( n );
	auto sc = 1 + memoize!solve( n - su );
	
	auto nu = memoize!( getMaxUnit!( 9 ) )( n );
	auto nc = 1 + memoize!solve( n - nu );
	
	return min( sc, nc );
}

auto getMaxUnit( int u )( in int n )
{
	auto r = 0;
	auto m = u;
	
	while( m <= n )
	{
		r = m;
		m *= u;
	}
	
	return r;
}


Measured memory_bytes: 256