akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#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 ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }

template<int mod> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % mod) {
        if (val < 0) val += mod;
    }
    constexpr int getmod() { return mod; }
    constexpr Fp operator - () const noexcept {
        return val ? mod - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= mod) val -= mod;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % mod;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % mod;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream &is, const Fp<mod>& x) noexcept {
        int val; is >> val;
        x = Fp<mod>(val);
        return is;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<mod>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<mod> modpow(const Fp<mod> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int mod = 998244353;
using mint = Fp<mod>;

int main(){
    int n,s; cin >> n >> s;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<mint> p(s+1);
    mint ans = 0;
    rep(i,n){
        p[0] += 1;
        vector<mint> next(s+1);
        rep(j, s+1){
            next[j] += p[j];
            if(j + a[i] <= s) next[j + a[i]] += p[j];
        }
        p = next;
        ans += p[s];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
s = input()
u, v = [], []
q = int(input())
cur = 0
for _ in range(q):
    t, *c = input().split()
    t = int(t)
    if t == 1:
        cur ^= 1
    else:
        f = (int(c[0]) - 1) ^ cur
        if f:
            v.append(c[1])
        else:
            u.append(c[1])
if cur:
    print(''.join(reversed(v)) + ''.join(reversed(s)) + ''.join(u))
else:
    print(''.join(reversed(u)) + s + ''.join(v))

Measured memory_bytes: 74840
#include <cstdio>
#include <vector>

std::vector<bool> primes(1000000, true);

void sieve() {
  primes[0] = false;
  primes[1] = false;
  for (int i = 2; i < primes.size(); ++i) {
    if (!primes[i]) { continue; }
    for (int j = 2, m = i * j; m < primes.size(); m = i * ++j) {
      primes[m] = false;
    }
  }
}

int main() {
  sieve();

  int n;
  while (true) {
    if (scanf("%d", &n) != 1) { break; }
    int count = 0;
    for (int i = 0; i <= n; ++i) { if (primes[i]) { ++count; } }
    printf("%d\n", count);
  }

  return 0;
}

Measured memory_bytes: 932
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.Ruined_Square
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(null).Select(x => int.Parse(x)).ToArray();
            var length = 0;

            var point = new List<Point>
            {
                new Point { X = input[0], Y = input[1] },
                new Point { X = input[2], Y = input[3] },
            };

            point.Add(new Point
            {
                X = point[1].X - (point[1].Y - point[0].Y),
                Y = point[1].Y + (point[1].X - point[0].X)
            });

            point.Add(new Point
            {
                X = point[2].X - (point[1].X - point[0].X),
                Y = point[2].Y - (point[1].Y - point[0].Y)
            });

            Console.Write(point[2].X + " " + point[2].Y + " " + point[3].X + " " + point[3].Y);
        }

        public class Point
        {
            public int X { get; set; }
            public int Y { get; set; }
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
using namespace std;
int main()
{
  int n, k;
  int a[200000];
  cin >> n >> k;
  unsigned long long int prev = 1;
  unsigned long long int crr = 1;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++)
  {
    if (i < k)
    {
      crr *= a[i];
    }
    else
    {
      crr /= a[i - k];
      crr *= a[i];
      if (a[i] > a[i - k])
      {
        cout << "Yes" << endl;
      }
      else
      {
        cout << "No" << endl;
      }
    }
    prev = crr;
  }
}

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

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k; cin>>n>>k; double p[n], s[n+1];
    double sum = 0;

    for(int i=0; i<n; i++) {
        cin>>p[i];
        p[i] = 1.0*(1+p[i])/2;
        sum += p[i];
        s[i+1] = sum;
    }
    
    double ans = 0;
    for(int i=0; i<n-k+1; i++) {
        ans = max(ans, s[i+k] - s[i]);
    }
    cout<<fixed<<setprecision(8)<<ans;
    return 0;
}

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

int main()
{
	int N, x;
	cin >> N >> x;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	int res = 0;
	for (int i = 0; i < N; i++) {
		if (x >= v[i]) {
			++res;
			x -= v[i];
		}
		else {
			break;
		}
	}
	if (res == N && x > 0) {
		--res;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main ()
{int a,b,c,wu=0,qi=0;
scanf("%d%d%d",&a,&b,&c);
if(a==5)
wu++;
if(a==7)
qi++;
if(b==5)
wu++;
if(b==7)
qi++;
if(c==5)
wu++;
if(c==7)
qi++;
if(wu==2&&qi==1)
printf("YES");
else
printf("NO");
}

Measured memory_bytes: 128
def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            for k in range(1, j):
                if sum([i, j, k]) == x:
                    result += 1
    return str(result)

ans = []
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    ans.append(calc(n, x))

print("\n".join(ans))


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

int n, a[100000], s = 0;
ll x = 0, y = 0;
bool b = 0;

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	for (int i = 0; i < n; ++i, b = !b) {
		s += a[i];
		if (b) {
			if (s <= 0) {
				x += 1 - s;
				s = 1;
			}
		} else if (s >= 0) {
			x += s + 1;
			s = -1;
		}
	}

	b = 1;
	s = 0;
	swap(x, y);
	for (int i = 0; i < n; ++i, b = !b) {
		s += a[i];
		if (b) {
			if (s <= 0) {
				x += 1 - s;
				s = 1;
			}
		} else if (s >= 0) {
			x += s + 1;
			s = -1;
		}
	}
	cout << min(x, y) << endl;
}


Measured memory_bytes: 3964
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


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

    	try{
    		InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(isr);

			while(true){
				String buf = br.readLine();
				StringTokenizer st=new StringTokenizer(buf," ");
				int H = Integer.parseInt(st.nextToken());
				int W = Integer.parseInt(st.nextToken());

				if(W==0 && H==0)	break;
				if(H>=300 && W>=300)	break;;
				for(int i=1;i<=H;i++){
					for(int j=1;j <= W;j++){
						if(i>1 && i<H && j>1 && j<W)	System.out.print(".");
						else
						System.out.print("#");
					}
				System.out.println();
				}
				System.out.println();
			}
		} catch(IOException e) {
    		System.err.println(e);
		}
    }
}

Measured memory_bytes: 24532
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s;
    rep(i,Size(s)){
        if(s[i]=='1')ans++;
    }
    Cout(ans);
    return 0;
}


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


int main(){
    string s; cin >> s;
    int n = s.size();
    int res = 0;
    rep(i,n-1){
        if(s[i]!=s[i+1]) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 3752
package main

import "fmt"

func check(s string) bool {
	m := make(map[rune]int)
	for _, r := range s {
		m[r]++
	}
	for _, cnt := range m {
		if cnt%2 != 0 {
			return false
		}
	}
	return true
}

func main() {
	var s string
	fmt.Scan(&s)

	if check(s) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int n = 100;
        /*
        long n = long.Parse(Console.ReadLine());
        long[] input = new long[5];
        for(int a = 0; a < 5; a++)
        {
            input[a]=long.Parse(Console.ReadLine());
        }
        */
        //int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        string input= Console.ReadLine();
        int total = 0;
        for(int a = 0; a < input.Length; a++)
        {
            if (input[a].ToString()=="+")
            {
                total++;
            }
            else
            {
                total--;
            }
        }
        Console.WriteLine(total);


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

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

using namespace std;

int
main(void){
	int r, c;
	cin >> r >> c;
	vector<vector<pair<char, bool> > >vec(r, vector<pair<char, bool> >(c, make_pair('o', true)));
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			cin >> vec[i][j].first;
		}
	}
	for(int i = 0; i < r; i++){
		bool ch = true;
		for(int j = 0; j < c; j++){
			if(vec[i][j].first == '#')
				ch = false;
		}
		if(ch){
			for(int j = 0; j < c; j++){
				vec[i][j].second = false;
			}
		}
	}
	
	for(int j = 0; j < c; j++){
		bool ch = true;
		for(int i = 0; i < r; i++){
			if(vec[i][j].first == '#')
				ch = false;
		}
		if(ch){
			for(int i = 0; i < r; i++){
				vec[i][j].second = false;
			}
		}
	}
	
	for(int i = 0; i < r; i++){
		bool ch = false;
		for(int j = 0; j < c; j++){
			if(vec[i][j].second == true){
				ch = true;
				cout << vec[i][j].first;
			}
		}
		if(ch) cout << "\n";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  vector<string> A={"AKIHABARA","AKIHABAR","AKIHABRA","AKIHABR","AKIHBARA","AKIHBAR","AKIHBRA","AKIHBR","KIHABARA","KIHABAR","KIHABRA","KIHABR","KIHBARA","KIHBAR","KIHBRA","KIHBR"};
  for(string &T:A)
    if(S==T){
      cout<<"YES"<<endl;
      return 0;
    }
  cout<<"NO"<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    string S;
    cin >> S;
    int i = 0;
    bool can = true;
    /*   while (S[i] == 'x' and i < S.size())
    {
        i++;
    }
    int first = i;
    i = S.size() - 1;
    while (S[i] == 'x' and i >= 0)
    {
        i--;
    }
    int end = i;
    string s = S.substr(first, end - first + 1);
    */
    int F = 0, E = S.size() - 1,ans=0;
    while (F < E)
    {
        if ((S[F] != 'x' and S[E] != 'x') and S[F] != S[E])
        {
            can = false;
            break;
        }
        else if (S[F] == S[E])
        {
            F++;
            E--;
        }
        else if (S[F] == 'x')
        {
            S.insert(S.begin() + E + 1, 'x');
            ans++;
            F++;
        }
        else if (S[E] == 'x')
        {
            S.insert(S.begin()+ F, 'x');
            ans++;
            E++;
        }
        
    }
    if(can)
        cout << ans;
        else
        {
            cout << -1;
        }

        return 0;
}

Measured memory_bytes: 720
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int test=in.nextInt();
        double a[]=new double [test];
        double b[]=new double [test];
        for (int i = 0; i <test; i++) {
            a[i]=in.nextDouble();
        }
        for (int i = 0; i <test; i++) {
            b[i]=in.nextDouble();
        }
        double ans1=0,ans2=0,max=0,ans3=0,ans4=-999999999;
        for (int i = 0; i < test; i++) {
            ans1=ans1+(Math.abs((a[i]-b[i])));
            ans2=ans2+(((a[i]-b[i]))*((a[i]-b[i])));
            ans3=ans3+((Math.abs(a[i]-b[i]))*(Math.abs(a[i]-b[i]))*(Math.abs(a[i]-b[i])));
            max=Math.abs(a[i]-b[i]);
            if(ans4<max){
                ans4=max;
            }
        }
        System.out.printf("%.6f\n",ans1);
        System.out.printf("%.6f\n",Math.sqrt(ans2));
        System.out.printf("%.6f\n",Math.pow(ans3, (1.0/3.0)));
        System.out.printf("%.6f\n",ans4);
    }
}


Measured memory_bytes: 29172
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++){
		if(a[i]-1>=a[i-1])a[i]--;
		if(a[i-1]>a[i]){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
}

Measured memory_bytes: 640
#include <iostream>
#include <map>

using namespace std;

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

    map<long long, int> mp;
    long long a, ans = 0, sum = 0;
    ++mp[0];
    for (int i = 0; i < n; ++i) {
        cin >> a;
        sum += a;
        ans += mp[sum];
        ++mp[sum];
    }
    cout << ans << endl;
}
/*
累積和が等しい2点間の、連続する部分列の和は０になる。
ある累積和がn個存在するとき、n個の中から2点を選ぶ組み合わせはnC2通り。

累積和１が３回現れる場合。
1回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 0 <- 初回の累積和はカウントされない
    ++mp[sum];  // mp[1] = 1

2回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 1 <- 累積和１が２回出たのでansがカウントされる。2C2=1通り
    ++mp[sum];  // mp[1] = 2 <- 累積和１が２点に存在する

3回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 2 <- 累積和１が３回出たのでansがカウントされる。3C2=3通り
    ++mp[sum];  // mp[1] = 3 <- 累積和１が３点に存在する
*/

Measured memory_bytes: 12800
#include<iostream>
#include<cstdio>
const int N=2e5+5;
int n,a[N];
long long pre[N];
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",a+i),pre[i]=pre[i-1]+a[i];
    long long now=0;
    long long ans=1e18;
    for(int i=n;i;i--) {
        ans=std::min(ans,std::max(now-pre[i],pre[i]-now));
        now+=a[i];
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
  int N,M;
  cin>>N>>M;
  int D;
  for(int i=0;i<M;i++){
    cin>>D;
    N-=D;
  }

  if(N<0)cout<<-1<<endl;
  else cout<<N<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int a,b;

    cin >> a >> b;



    int ansi = a / b;
    double ansd = 1.000000 * a / b;
    double remainder =  a % b;

    cout << ansi << " "
         << remainder << " "
         << fixed << setprecision(10) << ansd << endl;

    return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x,y,g[15]={0,1,3,1,2,1,2,1,1,2,1,2,1};
	cin>>x>>y;
	if(g[x]==g[y])cout<<"Yes\n";
	else cout<<"No\n";	
}

Measured memory_bytes: 256
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
	int n;
	cin >> n;
	long long int a[100000];
	long long int suma = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		suma += a[i];
	}
	long long int tmp = 0;
	for (int i = 1; i < n; i += 2) {
		tmp += a[i];
	}
	long long int ans[100000];
	ans[0] = suma - 2 * tmp;
	for (int i = 1; i < n; i++) {
		ans[i] = 2 * a[i - 1] - ans[i - 1];
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i];
		if (i == n - 1)
			cout << endl;
		else
			cout << " ";
	}
}

Measured memory_bytes: 2816
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#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 << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

//自作関数 a^n mod MODを求める
int m_pow(int a, int n){
  if(n == 0) return 1;
  if(n % 2 == 0){
    int t = m_pow(a, n / 2);
    return t * t % MOD;
  }
  return a * m_pow(a, n - 1) % MOD;
}

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

    mat a(3,vec(3));
  REP(i,3)REP(j,3) cin >> a[i][j];
  
  int n;
  cin >> n;

  vector<int> b(n);
  REP(i,n) cin >> b[i];

  vec c(3,0);
  vec d(3,0);
  int e = 0;
  int f = 0;
  
  REP(i,n){
    REP(j,3)REP(k,3){
      if(b[i] == a[j][k]){
        c[k]++;
        d[j]++;
        if(j == k) e++;
        if((j == 1 && k == 1) || fabs(j - k) == 2) f++;
      }
    }
  }

  REP(i,3){
    if(c[i] >= 3 || d[i] >= 3 || e >= 3 || f >= 3){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}

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

int N;
string S;

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

  int ans = 0;
  for(int i = 1; i < N - 1; i++) {
    set<char> x, y, z;
    for(int j = 0; j < N; j++) {
      if(j < i) {
        x.insert(S[j]);
      } else {
        y.insert(S[j]);
      }
    }
    set_intersection(x.begin(), x.end(), y.begin(), y.end(), inserter(z, z.end()));
    ans = max(ans, (int)z.size());
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
A = []
B = []

if len(a) % 2 == 1:
	A.append(min(a))
	a.remove(min(a))

while len(a) > 0:
	A.append(max(a))
	a.remove(max(a))
	B.append(max(a))
	a.remove(max(a))

print(sum(A) - sum(B))

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

using namespace std;

typedef long long int ll;

const int N = 3e3 + 5;
const int mod = 998244353;

ll dp[N][N];
ll pref[N];

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

  int n, s;
  cin >> n >> s;
  vector < int > a (n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];

  for (int i = 1; i <= n; i++) {
    dp[i][a[i]] = i;
    for (int j = a[i] + 1; j < N; j++) {
      dp[i][j] = pref[j - a[i]];
    }
    for (int j = a[i]; j < N; j++) {
      pref[j] = (pref[j] + dp[i][j]) % mod;
    }
  }

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (n - i + 1) * dp[i][s];
    ans %= mod;
  }

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


Measured memory_bytes: 74064
#include <iostream>

using namespace std;

int main(void)

{
	string input;
	
	long long int i,check[26]={0},k=0;
	
	cin >> input;
	
	for(i=0;i<input.size();i++)
	{
		check[char(input[i])-97] = 1;
	}
	
	for(i=0;i<26;i++)
	{
		if(check[i]==0)
		{
			cout << char(i+97) << "\n";
			
			k++;
			
			break;
		} 
	}
	
	if(k==0)
	{
		cout << "None\n";
	}
	
	return 0;
}

Measured memory_bytes: 512
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Mon Dec 31 17:10:03 2018
//
package main

import "fmt"

func main() {
	var A, B, C, X int
	_, _ = fmt.Scan(&A, &B, &C, &X)

	ans := 0
	for i := 0; i <= A; i++ {
		for j := 0; j <= B; j++ {
			for k := 0; k <= C; k++ {
				if X == i*500+j*100+k*50 {
					ans++
				}
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    string s;
    cin >> s;

    ll l = s.length();
    ll t = 0;
    for(ll i = 0; i < l; i++){
        t += (int)(s[i]-'0');
    }

    cout << ((t % 9 == 0) ? "Yes" : "No") << endl; 
}


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

int pow(int x){
	return x*x*x;
}

int main(void) {
	int x;
	cin >> x; //cin: console input ??\???
	cout << pow(x) << endl;//cout:console output ?????? endl:??????
	return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        int totala = 0;
        int totalb = 0;
        for (int i = a.length - 1; i >= 0; i -= 2) {
            totala += a[i];
            if (i > 0) {
                totalb += a[i - 1];
            }
        }

        System.out.println(totala - totalb);
    }
}


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

Measured memory_bytes: 1792
program ABC133B
    implicit none
    integer::N,D,i,j,d_calc,d_sqrt,ans=0
    integer,allocatable::X(:,:)
    read*,N,D
    allocate(X(D,N))
    read*,X
    do i=1,N-1
        do j=i+1,N
            d_calc=sum((X(:,i)-X(:,j))**2)
            d_sqrt=int(sqrt(real(d_calc)))
            if(mod(d_calc,d_sqrt)==0.and.d_sqrt**2==d_calc)ans=ans+1
        end do
    end do
    print'(i0)',ans
end program ABC133B

Measured memory_bytes: 2836
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define be(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int main()
{
    int n,y,m,d;
    cin>>n;
    REP(i,n)
    {
        cin>>y>>m>>d;
        int sum=196471;
        bool flag=0;
        if(y%3==0)flag=1;
        y--;
        sum-=(y/3)*200;
        sum-=(y-y/3)*195;
        m--;
        if(flag)sum-=m*20;
        else
        {
            sum-=(m/2)*39;
            if(m%2)sum-=20;
        }
        sum-=d;
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
int a[MAXN];
int main()
{
   // freopen("input.txt", "r", stdin);
    int n, l;
    scanf("%d %d", &n, &l);
    int pos = -1;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i < n; i++)
    {
        if (a[i] + a[i + 1] >= l)
        {
            pos = i;
        }
    }
    if (pos == -1)
    {
        puts("Impossible");
        return 0;
    }
    puts("Possible");
    for (int i = 1; i < pos; i++)
    {
        printf("%d\n", i);
    }
    for (int i = n - 1; i >= pos + 1; i--)
    {
        printf("%d\n", i);
    }
    printf("%d\n", pos);
}


Measured memory_bytes: 1152
// https://atcoder.jp/contests/abc176/tasks/abc176_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  string N;
  cin >> N;

  ll sum = 0;

  for (char c : N) {
    sum += c - '0';
  }

  string res = sum % 9 == 0 ? "Yes" : "No";
  cout << res << "\n";
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
const int max_N=100010;
long long K,N,ans;
int main()
{
    cin>>N>>K;
    vector<long long>A(N),S(N+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
        S[i+1] = S[i] + A[i];
    }
    map<int,int>mp;
    queue<int>q;
    for(int i=0;i<=N;i++)
    {
        long long now=(S[i]-i)%K;
        ans+=mp[now];
        mp[now]++;
        q.push(now);
        if(q.size()==K)
        {
            mp[q.front()]--;
            q.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 13568
#include <stdio.h>
int main(void){
  char s[5];
  int ac,wa,tle,re;
  ac=wa=tle=re=0;
  int n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    if('A'==s[0]){
      ac++;
    }else if('W'==s[0]){
      wa++;
    }else if('T'==s[0]){
      tle++;
    }else if('R'==s[0]){
      re++;
    }
  }
  printf("AC x %d\n",ac);
  printf("WA x %d\n",wa);
  printf("TLE x %d\n",tle);
  printf("RE x %d\n",re);
  }

Measured memory_bytes: 1736
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
 
int main() {
    int n;
    cin >> n;
    
    int a[n], b[n], c[n - 1];
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
        cin >> a[ctr1], --a[ctr1];
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
        cin >> b[ctr1];
    for (int ctr1 = 0; ctr1 + 1 < n; ++ctr1)
        cin >> c[ctr1];
     
    int rez = 0, last = n;
    for (int ctr1 = 0; ctr1 < n; ++ctr1) {
        rez += b[a[ctr1]];
        if (last + 1 == a[ctr1])
            rez += c[last];
        last = a[ctr1];
    }

    cout << rez << "\n";
    return 0;
}

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

const int MAX_N = 1000000;

int par[MAX_N];
int dep[MAX_N];

void init(int n) {
    for(int i = 0; i < n; i++) {
        par[i] = i;
        dep[i] = 0;
    }
}

int find(int x) {
    if(par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y)
        return;
    
    if(dep[x] < dep[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if(dep[x] == dep[y])
            dep[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int n, m;
    cin >> n >> m;
    
    init(n);
    
    //vector<int> a(m), b(m);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        
        unite(a,b);
    }
    
    vector<int> cnt(n);
    rep(i,n) {
        cnt[find(i)]++;
    }
    int ans = 0;
    rep(i,n) {
        ans = max(ans,cnt[i]);
    }
    
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 5596
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    string S; cin >> S;
    int N = S.size();
    string ans = "Good";
    FOR(i,1,N) {
        if (S[i-1]==S[i]) {
            ans = "Bad";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int binarySearch(int A[], int n, int key) {
    int left = 0;
    int right = n;

    int mid;
    while(left < right) {
        mid = (left + right) / 2;
        if (A[mid] == key) {
            return 1;
        } else if (key < A[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return 0;
}

int main(void)
{
    int n, q, i, count;
    int S[100000] = {};
    int T[50000] = {};

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }

    count = 0;
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &T[i]);
        if (binarySearch(S, n, T[i])) count++; 
    }
    
    printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 2400
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,m,first[100010],cnte=-1,col[100010],vis[200010];ll cnt[3],cntn,cntm;
struct edge{
	int to,next;
}a[200010];
inline void add(int u,int v){
	a[++cnte]=(edge){v,first[u]};first[u]=cnte;
	a[++cnte]=(edge){u,first[v]};first[v]=cnte;
}
bool dfs(int u,int f,int type){
	int i,v,re=1,w;col[u]=(col[f]+type+3)%3;cnt[col[u]]++;cntn++;
//	cout<<"dfs "<<u<<' '<<f<<' '<<type<<' '<<col[u]<<' '<<cntn<<'\n';
	for(i=first[u];~i;i=a[i].next){
		v=a[i].to;w=(i%2?1:-1);
		if(vis[i]||vis[i^1]) continue;
		else cntm++,vis[i]=vis[i^1]=1;
		if(col[v]==-1) re&=dfs(v,u,w);
		else{
//			cout<<"vis before "<<u<<' '<<f<<' '<<w<<' '<<col[u]<<' '<<col[v]<<'\n';
			if(col[v]!=(col[u]+w+3)%3) re=0,cnt[0]=cnt[1]=cnt[2]=1e9;
		}
	}
	return re;
}
int main(){
//	freopen("in.in","r",stdin);
	memset(first,-1,sizeof(first));
	n=read();m=read();int i,t1,t2;ll ans=0;
	for(i=1;i<=m;i++){
		t1=read();t2=read();
		add(t1,t2);
	}
	memset(col,-1,sizeof(col));
	for(i=1;i<=n;i++){
		if(~col[i]) continue;
//		cout<<"enter "<<i<<'\n';
		memset(cnt,0,sizeof(cnt));cntn=cntm=0;
		if(dfs(i,0,1)){
			if(!cnt[0]||!cnt[1]||!cnt[2]) ans+=cntm;
			else ans+=cnt[0]*cnt[1]+cnt[1]*cnt[2]+cnt[2]*cnt[0];
		}
		else{
			if(!cnt[0]||!cnt[1]||!cnt[2]) ans+=cntm;
			else ans+=cntn*cntn;
		}
//		cout<<cntn<<' '<<cntm<<'\n';
	} 
	cout<<ans;
}

Measured memory_bytes: 8064
object Main extends App {
  val x =  scala.io.StdIn.readLong()
  var loopFlg = true
  var count = 0
  var temp = 100L

  while(loopFlg) {
    temp = (temp * 1.01d).toLong
    count = count + 1
    if(temp >= x) {
      loopFlg = false
    }
  }
  println(count)
}

Measured memory_bytes: 54664
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    aa=LI()

    if 0 in aa:
        print(0)
        exit()

    ans=1
    for a in aa:
        ans*=a
        if ans>10**18:
            ans=-1
            break
    print(ans)

main()

Measured memory_bytes: 21652
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,x,tot;
int a[101];
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	{
		if(x>=a[i]) tot++,x-=a[i];
		else break;
	}
	if(tot==n&&x) tot--;
	printf("%d",tot);
}

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

#define int long long
//typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif



signed main() {
    string S;
    cin >> S;
    int N = S.size();
    
    int ans=0;
    rep(i,N/2){
        if(S[i]!=S[N-i-1]) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{
  int N,K;
  cin>>N>>K;
  vector<vector<int> > MAT(N);
  for (int i = 0; i < N; i++)
  {
    int T,D;
    cin>>T>>D;
    MAT[T-1].push_back(D);
  }
  vector<int> A{0},B{0};
  for (auto &e : MAT)
  {
    if(e.empty())continue;
    sort(ALL(e));
    A.push_back(e.back());
    for (auto it = begin(e); it != end(e)-1; it++)
    {
      B.push_back(*it);
    }
    
  }
  sort(rbegin(A),rend(A)-1);
  sort(rbegin(B),rend(B)-1);


  for (int i = 0; i < A.size()-1; i++)
  {
    A[i+1] += A[i];
  }

  
  for (int i = 0; i < B.size()-1; i++)
  {
    B[i+1] += B[i];
  }
  int ANS = 0;
  //   DEBUG(A);
  // DEBUG(B);
  for (int x = max(1LL,K - ((int)B.size()-1)); x <= min(K,(int)A.size()-1) ;x++)
  {
    /* code */
    ANS = max(ANS,A[x] + B[K-x] + x*x);
    // DEBUG(x);
  }
  
  cout<<ANS<<endl;
  
 
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 6904
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<cstring>
#include<cmath>
#define maxn 2007
#define SDOI2020 RP++ 
using namespace std;
int a,b,c; 
inline int read()
{
	int x=0;
	int flag=0;
	char ch;
	ch=getchar();
	while(!isdigit(ch)) 
	{
		if(ch=='-') flag=1;
	ch=getchar();	
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
		}
		if(flag==1) x=-x;	
		return x;
}


int main()
{
	a = read();
	b = read();
	for(register int i = 1;i <= 10100;i++)
	{
		int t = floor(i * 0.08);
		int t2 = floor(i * 0.1);
		if(t == a && t2 == b)
		{
			printf("%d\n",i);
			return 0;
		} 
	} 
	printf("-1\n");
	
	return 0;
} 

Measured memory_bytes: 256
import java.util.*;
import java.util.function.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int u = sc.nextInt();
    int v = sc.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 1; i < N; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    sc.close();

    List<Integer>[] tree = new List[N + 1];
    for (int i = 1; i < tree.length; i++) tree[i] = new ArrayList<>();
    for (int i = 1; i < N; i++) {
      tree[A[i]].add(B[i]);
      tree[B[i]].add(A[i]);
    }
/*
    IntFunction<int[]> dist = r -> {
      int[] ds = new int[N + 1];
      Deque<Integer> stack = new ArrayDeque<>();
      stack.push(r);
      while (0 < stack.size()) {
        int i = stack.pop();
        for (int t : tree[i])
          if (ds[t] == 0 && t != r) {
            ds[t] = ds[i] + 1;
            stack.push(t);
          }
      }
      return ds;
    };
    int[] dist_u = dist.apply(u);
    int[] dist_v = dist.apply(v);
*/
    int[] dist_u = dist(u, N, tree);
    int[] dist_v = dist(v, N, tree);

    int d = 0;
    for (int i = 1; i < N + 1; i++)
      if (dist_u[i] < dist_v[i] && dist_v[d] < dist_v[i]) d = i;

    long ans = dist_v[d] - 1;
    System.out.println(ans);
  }
  
  private static int[] dist(int r, int N, List<Integer>[] tree) {
      int[] ds = new int[N + 1];
      Deque<Integer> stack = new ArrayDeque<>();
      stack.push(r);
      while (0 < stack.size()) {
        int i = stack.pop().intValue();
        for (Integer tr : tree[i]) {
          int t = tr.intValue();
          if (ds[t] == 0 && t != r) {
            ds[t] = ds[i] + 1;
            stack.push(t);
          }
        }
      }
      return ds;
  }
}

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int getNumOfX(int value, int x)
{
	int result = 0;
	int raw_value = value;
	while( value % x == 0 )
	{
		value /= x;
		result++;
	}
	return result;
}

int main()
{
	int numOfFive;
	int numOfTwo;
	int n;

	while( true )
	{
		n = in();
		if( n == 0 )break;

		numOfFive = 0;
		numOfTwo = 0;
		for(int i = 1; i <= n; i++)
		{
			numOfFive += getNumOfX(i, 5);
			numOfTwo += getNumOfX(i, 2);
		}
		printf("%d\n", numOfFive > numOfTwo ? numOfTwo : numOfFive);
	}
	return (0);
}

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



int main()
{
int x;
cin>>x;
int a=x/500;
if(x%500==0)x=0;
while(x>500)x-=500;
int b=x/5;
int y=(a*1000)+(b*5);
cout<<y;
		return 0;
}


Measured memory_bytes: 256
#pragma region header
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr ll inf = INT32_MAX / 2;
constexpr ll INF = LLONG_MAX / 2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }

    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int A, P;
    cin >> A >> P;
    cout << (A * 3 + P) / 2 << endl;
}


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

int main(){
    int n;
    double a,t;
    cin >> n >> t >> a;
    vector<vector<double>> data(n,vector<double>(2));
    for(int i = 0; i < n; i++){
        double h; cin >> h;
        data[i][0] = t-h*0.006;
        data[i][1] = i+1;
    }
    double d = 99999;
    int ans;
    for(int i = 0; i < n; i++){
        if(d > min(d,abs(a-data[i][0]))){
            d = min(d,abs(a-data[i][0]));
            ans = data[i][1];
        }
    }
    cout << ans;
}

Measured memory_bytes: 256