akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  int a1=0,a2=0,a4=0;
  rep(i,a){
  if(b[i]%2==0&&b[i]%4==2)
    a2++;
  else if(b[i]%4==0)
    a4++;
  else
    a1++;
  }
  if(a1<=a4||(a2==0&&a1<=a4+1))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int N;
  cin >> N;
  ll power = 1;
  rep(i, N) {
    ll multi = i + 1;
    power = (power * multi) % MOD;
  }
  cout << power << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int in(int t,vector<pair<int,int>>& sch){
  if(!sch.size()) return 0;
  auto itr=upper_bound(sch.begin(),sch.end(),pair<int,int>({t,1000000}));
  if(itr==sch.begin()) return 0;
  itr--;
  int f=t<=itr->second;
  if(f and df)print(t,"in",*itr);
  return f;
}

void squize(vector<pair<int,int>>& sch){
  
  sort(sch.begin(),sch.end());
  vector<pair<int,int>> tmp;
  int j=0;
  while(j<sch.size()){
    tmp.push_back(sch[j]);
    while(j+1<sch.size() and sch[j].second==sch[j+1].first){
      tmp.rbegin()->second=sch[++j].second;
    }
    j++;
  }
  sch=tmp;
  if(df)print(sch);
}

int main(){
  int n,c; cin >>n >>c;
  vector<pair<int,int>> sch[c];
  rep(i,n){
    int s,t,k; cin >>s >>t >>k; k--;
    sch[k].push_back({s,t});
  }
  if(df)rep(i,c) print(sch[i]);
  
  rep(i,c){
    squize(sch[i]);
  }
  int wid=1;
  rep(t,100000){
    int cnt=0;
    rep(i,c){
      if(in(t,sch[i]))cnt++;
    }
    if(chmax(wid,cnt) and df) print(t,wid);
  }
  print(wid);
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>                                                      
using namespace std;
int main()
{
  int N;
  cin >> N;
  while(1){
    int hu=N/100;
    int te=N%100/10;
    int on=N%100%10;
    if(hu==te && te==on && hu==on){
      cout << N << endl;
      break;
    }
    N++;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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

	string N, A, B , C;

	cin >> N >> A >> B >>  C;

	ll ans = 0 ;
	rep(i, A.size()){
		vector<char> inp;
		inp.pb(A[i]);
		inp.pb(B[i]);
		inp.pb(C[i]);

		rmsame(inp);
		ans += (inp.size()-1);
	}
	cout << ans << endl;

	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


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

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> x(n);
	for(int i = 0; i < n; ++i) {
		cin >> x[i];
	}

	ll ans = LLONG_MAX;
	for(ll i = 1; i <= 100; ++i) {
		ll tmp = 0LL;
		
		for(auto& v : x) {
			tmp += (i - v) * (i - v);
		}
		
		ans = min(ans, tmp);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


def main():
    h, w, m = [int(i) for i in input().split()]
    d_h = defaultdict(int)
    d_w = defaultdict(int)
    bom = set()
    for _ in range(m):
        h, w = [int(i) for i in input().split()]
        bom.add((h, w))
        d_h[h] += 1
        d_w[w] += 1
    H = sorted(d_h.items(), key=lambda x: -x[1])
    W = sorted(d_w.items(), key=lambda x: -x[1])
    ans = 0
    for k_h, v_h in H:
        for k_w, v_w in W:
            tmp = v_h + v_w
            if (k_h, k_w) in bom:
                tmp -= 1
                ans = max(tmp, ans)
            else:
                ans = max(tmp, ans)
                break
        else:
            continue
        break

    for k_w, v_w in W:
        for k_h, v_h in H:
            tmp = v_h + v_w
            if (k_h, k_w) in bom:
                tmp -= 1
                ans = max(tmp, ans)
            else:
                ans = max(tmp, ans)
                break
        else:
            continue
        break
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 183824
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
	    char[] s=sc.nextLine().toCharArray();
	    for(int i=0;i<s.length;i++)s[i]=Character.toUpperCase(s[i]);
	    System.out.println(s);
	}
}
//by Tuvshee 12.05.2012
//Capitalize

Measured memory_bytes: 12000
import java.util.*;
public class Main {
	static Scanner s = new Scanner(System.in);
	public static void main(String __[]){
		long in[]=new long[s.nextInt()];
		for(int i=0;i<in.length;i++) in[i]=s.nextInt();
		long min=9114514114514114514L;
		for(int i=-100;i<=100;i++) {
			final int v=i;
			min=Math.min(min,
					Arrays.stream(in).parallel()
						.map(o->(o-v)*(o-v))
						.sum()
					);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 31052
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
ll x;
int main() {
  cin >> x;
  ll sum = 0;
  ll left,right;
  left = 0;
  right = 1LL << 60;
  while (right - left > 1){
    ll med = (right + left) / 2LL;
    ll a,b;
    a = med / 2;
    b = med / 2;
    if (med % 2 != 0){
      b++;
    }
    ll sum = 5LL * a + 6LL * b;
    if (sum >= x){
      right = med;
    }else{
      left = med;
    }
  }
  cout << right << endl;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

// int getidx(int x, int n) { return x + n; }
bool can(vl& xs, ll x) {
  vector<bool> dp(40001, false);
  dp[20000] = true;
  for (auto& dx : xs) {
    vector<bool> ndp(40001, false);
    rep(i, 40001) {
      if (dp[i]) {
        if (i - dx >= 0) ndp[i - dx] = true;
        if (i + dx < 40001) ndp[i + dx] = true;
      }
    }
    dp = ndp;
  }
  return dp[20000 + x];
}

int main() {
  //
  string s;
  cin >> s;
  int n = s.size();
  ll X, Y;
  cin >> X >> Y;
  bool xmove = true;
  bool first = true;
  vl dx, dy;
  ll cnt = 0;
  rep(i, s.size()) {
    if (s[i] == 'F') {
      cnt++;
    } else {
      if (xmove) {
        if (first) {
          first = false;
          X -= cnt;
        } else {
          dx.push_back(cnt);
        }
      } else {
        dy.push_back(cnt);
      }
      xmove = !xmove;
      cnt = 0;
    }
  }
  if (cnt > 0) {
    if (xmove) {
      if (first) {
        X -= cnt;
      } else {
        dx.push_back(cnt);
      }
    } else {
      dy.push_back(cnt);
    }
  }
  if (can(dx, X) && can(dy, Y)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans=0;
  REP(i,N){
    string str=S.substr(i,N-i);
    
    vector<int> Z(str.size());
    Z[0] = str.size();
    int j = 1, k = 0;
    while(j < str.size()){
      while(j + k < str.size() && str[k] == str[j + k]) k++;
      Z[j] = k;

      if(k == 0){
        j++;
        continue;
      }
      int l = 1;
      while(l < k && l + Z[l] < k){
        Z[j + l] = Z[l];
        l++;
      }
      j += l;
      k -= l;
    }

    int MAX=0;
    REP(j,sz(str)){
      MAX=max(MAX,min(j,Z[j]));
    }
    ans=max(ans,MAX);
  }

  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair < pair <int, int> , int> ppi;
typedef pair < pair <int, int> , ll> ppll;
typedef pair <ll, ll> pll;
typedef string str;

# define endl		 '\n'
# define sep		 ' '
# define F 			 first
# define S 			 second
# define pb			 push_back
# define fast_io 	 ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll md = 1e9+7;

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);}
ll pw(ll a, ll b){
	if (b == 1) return (a+md)%md;
	if (b%2 == 0) return (pw(a*a, b/2)+md)%md;
	else return (a*pw(a*a, b/2)+md)%md;
}

const int xn = 1e6+10;
const int xm = 5e4+10;

int cnt[5];

int main(){
	fast_io;
	
	int n;
	string a, b, c = "";
	cin >> n >> a >> b;
	
	for (int i=0; i<n; i++){
		c += a[i];
		c += b[i];
	}
	cout << c << endl;
	
	return 0;
}



Measured memory_bytes: 256
n=int(input())
a=0
b=0
c=0
d=0

for x in range(n):
  k=input()
  if k=="AC":
    a+=1
  elif k=="WA":
    b+=1
  elif k=="TLE":
    c+=1
  else:
    d+=1

print("AC x {}".format(a))
print("WA x {}".format(b))
print("TLE x {}".format(c))
print("RE x {}".format(d))
    
    
    

Measured memory_bytes: 9140
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    string S;
    cin >> S;

    int aCount = 0;
    rep(i, 3) if (S[i] == 'A') ++aCount;

    cout << ((aCount == 0 || aCount == 3) ? "No" : "Yes") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <algorithm>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::map<int, int> A;
  for (size_t i = 0; i < N; ++i) {
    int a;
    scanf("%d", &a);
    ++A[a];
  }

  size_t res = 0;
  for (const auto& p: A)
    res += p.second-1;

  printf("%zu\n", N-(res+1)/2*2);
}


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

static const int MAX_ELEM = 500000;

int MergeElem(int elem[], int start, int mid, int end)
{
    int i, j, k, l;
    int num = 0;
    int left[MAX_ELEM/2 + 1], right[MAX_ELEM/2 + 1];

    i = mid - start;
    j = end - mid;
    l = (i > j) ? i : j;

    /* ???????????¢??????????????? */
    for (k = 0; k < l; k++) {
        left[k]  = elem[start + k];
        right[k] = elem[mid + k];
    }
    /* ??????????????§????????\?????? */
    left[i]  = 0x7FFFFFFF;
    right[j] = 0x7FFFFFFF;

    i = 0;
    j = 0;
    for (k = start; k < end; k++) {
        ++num; /* ?????? */

        if (left[i] <= right[j]) {
            elem[k] = left[i];
            ++i;
        }
        else {
            elem[k] = right[j];
            ++j;
        }
    }

    return num;
}

/* end ???????±??????????????????????????????§???????´???°???????????? */
int MergeSort(int elem[], int start, int end)
{
    int mid;
    int cnt = 0;

    /* end ???????±????????????????????±????1????????´????????????????????? */
    if ((start + 1) >= end) {
        return 0;
    }

    mid = (start + end) / 2;
    cnt += MergeSort(elem, start, mid);
    cnt += MergeSort(elem, mid,   end);
    cnt += MergeElem(elem, start, mid, end);

    return cnt;
}

int main(void)
{
    int i;
    int num;
    int cnt;
    int elem[500002];

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

    cnt = MergeSort(elem, 0, num);

    printf("%d", elem[0]);
    for (i = 1; i < num; i++) {
        printf(" %d", elem[i]);
    }
    printf("\n%d\n", cnt);

    return 0;
}

Measured memory_bytes: 5092
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    int x,n;cin>>x>>n;
    vei p(n);
    int ans=1000;
    int kotae=0;
    rep(i,n) {cin>>p[i];
    }
    vei memo(102,0);
    rep(i,n){
        memo[p[i]]++;
    }
    for(int i=101;0<=i;i--){
        int kari;
        if(memo[i]==0) {
            kari=abs(x-i);
            ans=min(ans,kari);
            if(ans==kari) kotae=i;
        }
    }
    cout<<kotae<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const string W[8] = { "","SAT","FRI","THU","WED","TUE","MON","SUN" };

string S;

int main() {
	cin >> S;
	for (int i = 1; i <= 7; i++) {
		if (W[i] == S)cout << i << endl;
	}
}

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

int main() {
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;

	int a[40], b[40], c[40];
	for (int i=0; i<N; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	int dp[401][401];
	for (int i=0; i<=400; i++) {
		for (int j=0; j<=400; j++) {
			dp[i][j] = 0;
		}
	}

	for (int i=0; i<N; i++) {
		for (int j=400-a[i]; j>=0; j--) {
			for (int k=400-b[i]; k>=0; k--) {
				if (dp[j][k] || (!j && !k)) {
					if (dp[j+a[i]][k+b[i]]) {
						dp[j+a[i]][k+b[i]] = min(dp[j+a[i]][k+b[i]], dp[j][k] + c[i]);
					} else {
						dp[j+a[i]][k+b[i]] = dp[j][k] + c[i];
					}
				}
			}
		}
	}

	int ans = 1<<30;
	for (int p=1; p*Ma<=400 && p*Mb<=400; p++) {
		if (dp[p*Ma][p*Mb]) {
			ans = min(ans, dp[p*Ma][p*Mb]);
		}
	}
	cout <<  (ans == 1<<30 ? -1 : ans) << endl;
	return 0; 
}


Measured memory_bytes: 896
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn f() -> usize {
    input! {
        n:usize,
        a:[usize;n],
        s:Chars
    }

    let mut dp = vec![];
    for i in (0..n).rev() {
        let mut tmp = a[i];
        for j in &dp {
            tmp = std::cmp::min(tmp, tmp ^ *j);
        }
        if s[i] == '0' {
            if tmp > 0 {
                dp.push(tmp);
            }
        } else {
            if tmp > 0 {
                return 1;
            }
        }
    }
    0
}

#[fastout]
fn main() {
    input! {
        t:usize,
    }
    for _ in 0..t {
        println!("{}", f());
    }
}

Measured memory_bytes: 2532
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin >> n && n)
    {
        int m;
        cin >> m;
        int h[n], w[m];
        int p[n+1], q[m+1]; //h[0]+...+h[i]??????????????????????¨????????????????
        p[0] = 0;
        q[0] = 0;
        for(int i = 0; i < n; i++)
        {
            cin >> h[i];
            p[i+1] = p[i] + h[i];
            
        }
        for(int j = 0; j < m; j++)
        {
            cin >> w[j];
            q[j+1] = q[j] + w[j];
        }
        int t = 0;
        int x[(n+1)*(m+1)+1];
        x[(n+1)*(m+1)] = 0;
        for(int k = 0; k < n+1; k++)
        {
            for(int l = 0; l < m+1; l++)
            {
                x[t] = p[k] + q[l];
                t = t + 1;
            }
        }
        sort(x, x+(n+1)*(m+1));
        int c = 1;
        int d = 0;
        for(int a = 1; a < (n+1)*(m+1)+1; a++)
        {
            if(x[a] == x[a-1])
            {
                c = c + 1;
            }
            else
            {
                d = d + c*(c-1)/2;
                c = 1;
            }
        }
        cout << d << endl;
        
    
    
    
    }



}

Measured memory_bytes: 11956
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()

mod = 10**9+7  # 出力の制限


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


maxn = 10**5+10
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, maxn + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


ans = 0
for i in range(N-K+1):
    x = cmb(N-i, K, mod)-cmb(N-i-1, K, mod)
    ans -= A[i]*x
    ans += A[N-1-i]*x
    ans %= mod
print(ans)


Measured memory_bytes: 76964
#include <stdio.h>

int main(void) {

    long long int num;
    long long int sum = 0;


    scanf("%lld", &num);

    for ( long long int i = 1; i <= num; i++ ){
        if( (i % 3) == 0 ){
            continue;
        } else if ( (i % 5) == 0 ){
            continue;
        }
        sum += i;
    }
    printf("%lld", sum);

}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; ll a, b; cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    ll ans = 0;
    rep(i, n-1) ans += min((x[i+1] - x[i])*a, b);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <map>
using namespace std;

int saisyo(int a,int b, int c){
	int max=1;
	int minnum=a;
	if(a>b){
		minnum=b;
		if(b>c)minnum=c;
	}
	for(int i=1; i<=minnum;i++){
		if(a%i==0&&b%i==0&&c%i==0)max=i;
	}
	return(max);
}

int K;
int wa=0;

int main(){
	cin>>K;
	for(int a=1;a<=K;a++){
		for(int b=1;b<=K;b++){
			for(int c=1;c<=K;c++){
				wa=wa+saisyo(a,b,c);
			}
		}
	}


	cout<<wa<<endl;

}


Measured memory_bytes: 3628
s = str(input())

if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
elif s == "SAT":
    print(1)
    

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

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main() {
	ll l, r;
	int min = 2020;
	cin >> l >> r;
	for(ll i = l; i <= r; i++){
		for(ll j = l+1; j <= r; j++){
			if(j <= i) continue;
			if(((i*j)%2019) < min) min = (i*j)%2019;
			if(min == 0){
				cout << 0 << endl;
				return 0;
			}
		}
	}
	cout << min << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,x,y,ans = 0;
	string	s,ss;

	cin >> s;
	cin >> ss;
	cin >> s;
	
	cout << 'A' << ss[0] << 'C' << endl;

}


Measured memory_bytes: 256
#include<stdio.h>

#define N_MAX 100000
#define Q_MAX 50000

int binarysearch(int n,int* a,int key){
	int l=0;
	int r=n;
	int mid;
	while(l<r){
		mid=(l+r)/2;
		if(a[mid]==key){
			return mid;
		}else if(key<a[mid]){
			r=mid;
		}else{
			l=mid+1;
		}
	}return N_MAX+1;
}

int main(void){

	int A[N_MAX+1];
	int n;
	int B[Q_MAX+1];
	int q;
	int s=0;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d",&B[i]);
	}
	
	for(int i=0;i<q;i++){
		if(binarysearch(n,A,B[i])!=N_MAX+1)s++;

	}
	
	printf("%d\n",s);
	
	return 0;
}


Measured memory_bytes: 2288
package main

import (
  "fmt"
  "strconv"
)

type card struct {
  suit string
  number int
}

func bubbleSort(cards []card, n int) {
  for i := 0; i < n; i++ {
    for j := n - 1; j > i; j-- {
      if cards[j].number < cards[j-1].number {
        cards[j], cards[j-1] = cards[j-1], cards[j]
      }
    }
  }
}

func selectionSort(cards []card, n int) {
  for i := 0; i < n; i++ {
    minj := i
    for j := i; j < n; j++ {
      if cards[j].number < cards[minj].number {
        minj = j
      }
    }
    cards[i], cards[minj] = cards[minj], cards[i]
  }
}

func outputCards(cards []card, n int) {
  for i := 0; i < n; i++ {
    fmt.Printf("%s%d", cards[i].suit, cards[i].number)
    if i < n - 1 {
      fmt.Print(" ")
    } else {
      fmt.Println()
    }
  }
}

func checkStability(sorted, original []card, n int) {
  for i := 1; i <= 9; i++ {
    tmp_s := ""
    tmp_o := ""

    for j := 0; j < n; j++ {
      if sorted[j].number == i {
        tmp_s = tmp_s + sorted[j].suit
      }
      if original[j].number == i {
        tmp_o = tmp_o + original[j].suit
      }
    }

    if tmp_s != tmp_o {
      fmt.Println("Not stable")
      return
    }
  }

  fmt.Println("Stable")
}

func main() {
  var n int
  fmt.Scanf("%d", &n)

  cards := make([]card, n)
  for i := 0; i < n; i++ {
    var tmp string
    fmt.Scanf("%s", &tmp)
    cards[i].suit = tmp[:1]
    cards[i].number, _ = strconv.Atoi(tmp[1:])
  }

  b_cards := make([]card, n)
  s_cards := make([]card, n)
  _ = copy(b_cards, cards)
  _ = copy(s_cards, cards)

  bubbleSort(b_cards, n)
  outputCards(b_cards, n)
  checkStability(b_cards, cards, n)

  selectionSort(s_cards, n)
  outputCards(s_cards, n)
  checkStability(s_cards, cards, n)
}


Measured memory_bytes: 1176
import java.util.*;
class Main
{
	
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in); 
        int n = s.nextInt();
        int[] a = new int[n];
        int A = s.nextInt();
        int B = s.nextInt();
        int o =0,p=0,m=0;
        for(int i=0;i<n;i++)
        {
            a[i] = s.nextInt();
            if(a[i]<=A)
            {
                o++;
            }
            else if(a[i]<=B)
            {
                p++;
            }
            else
            {
                m++;
            }
        }
        System.out.println(Math.min(Math.min(o,p),m));

    }    



    
    
}



Measured memory_bytes: 23892
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int32_t main()
{
	FIO;
	int n; cin >> n;
	map<int, int> dp[n];

	mk(arr, n, int);

	for (int i = 0; i < n; ++i)
		cin >> arr[i];

	if (n == 2)
		cout << max(arr[0], arr[1]) << '\n';

	else
	{
		dp[0][0] = dp[1][0] = dp[2][0] = 0;
		dp[0][1] = arr[0];
		dp[1][1] = max(arr[1], arr[0]);
		dp[2][1] = max({arr[0], arr[1], arr[2]});
		dp[2][2] = arr[0] + arr[2];

		for (int i = 3; i < n; ++i)
		{
			dp[i] = dp[i - 1];

			vi rm;

			for (auto el : dp[i - 2])
			{
				if (dp[i].count(el.ff + 1))
					dp[i][el.ff + 1] = max(dp[i][el.ff + 1], el.ss + arr[i]);

				else
					dp[i][el.ff + 1] = el.ss + arr[i];

			}

			for (auto el : dp[i])
				if (el.ff < (i + 1) / 2 - 10 || el.ff > (i + 1) / 2 + 10)
					rm.pb(el.ff);

			for (int id : rm)
				dp[i].erase(id);
		}

		int ans = -inf;

		for (int i = 0; i < n; ++i)
		{
			//cout << dp[i].size() << '\n';
			if (dp[i].count(n / 2))
				ans = max(ans, dp[i][n / 2]);
		}

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

Measured memory_bytes: 158292
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s; cin >> s;
        mp[s]++;
    }
    vector<int> a(4);
    for(const auto& m: mp) {
        if (m.fi=="AC") a[0] = m.se;
        else if (m.fi=="WA") a[1] = m.se;
        else if (m.fi=="TLE") a[2] = m.se;
        else a[3] = m.se;
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#define MAX 100000
#define SENTINEL 9999999

 struct Card{
  char suit;
  int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right){
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;

  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1].value=R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value<=R[j].value)A[k]=L[i++];
    else A[k]=R[j++];
  }
}

                                                                     
void mergeSort(struct Card A[], int n, int left, int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}


int partition(struct Card A[], int n, int p, int r){
  int i,j;
  struct Card t,x;

  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}


void quickSort(struct Card A[], int n, int p, int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}


int main(){
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable=1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d", S, &v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit!=B[i].suit)stable=0;
  }

  if(stable==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}



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

using namespace std;

ifstream f("input.in");
ofstream g("output.out");

int main(int argc, char **argv)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //cout<<fixed<<setprecision(10)<<;
    //cout.unsetf(ios::fixed);

    int a, b, c;
    string str;

    //f>>n>>ws;
    cin>>a>>b>>c;

    int time = 0;

    for(int i = min(a,b); i > 0 ; --i)
    {
        if(a % i == 0 && b % i == 0)
            time++;
        if(time == c){
            cout<<i;
            break;
        }
    }

    /*
    for(int i = 0; i < n; ++i)
    {
        //getline(f, str);

    }*/

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define SANKOU(n, a, b) cout << ((n) ? (#a) : (#b)) << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>

int N;

struct edge {
    int to, cost;
};
vector<edge> G[100010];
int c[100010];

bool flag = true;
void s(int n)
{
    for (int i = 0; i < (int)G[n].size(); i++) {
        if (c[G[n][i].to] == -1) {
            if (G[n][i].cost % 2) {
                c[G[n][i].to] = (c[n] + 1) % 2;
                flag = false;
            } else {
                c[G[n][i].to] = (c[n]);
            }
            s(G[n][i].to);
        }
    }
}

void solve()
{
    c[0] = 0;
    s(0);
    if (flag)
        c[0] = 1;
    for (int i = 0; i < N; i++) {
        cout << c[i] << endl;
    }
}

signed main()
{
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back(edge{v, w});
        G[v].push_back(edge{u, w});
    }
    for (int i = 0; i < N; i++) {
        c[i] = -1;
    }
    solve();
    return 0;
}


Measured memory_bytes: 10240
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	ll n;
	cin>>n;
	if(n==1){
		cout << 1<<endl;
	}
	else if(n==2||n==3){
		cout << 2<<endl;
	}
	else if(n>=4&&n<8){
		cout << 4<<endl;
	}
	else if(n>=8 && n<16){
		cout<<8<<endl;
	}
	else if(n>=16 && n<32){
		cout << 16<<endl;	
	}
	else if(n>=32 && n<64){
		cout << 32<<endl;
	}
	else{
		cout << 64<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
def main():
    x, k, d = map(int, input().split())
    x = abs(x)
    if k % 2 == 1:
        x = abs(x-d)
        k -= 1
    if x > d*k:
        print(x-d*k)
    else:
        print(min(x % (2*d), abs(x % (2*d)-2*d)))


main()


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

int main() {
  int n,k,x,y,c=0;
  cin >> n >> k >> x >> y;
  if(n <= k){
    cout << n * x;
    return 0 ;
  }
  c = k * x + (n - k) * y;
  cout << c;
}


Measured memory_bytes: 3512
import java.util.*;
import java.text.*;

public class Main {
    public static void main(String[] args) throws Exception{
      Scanner sc = new Scanner(System.in);
      String s = sc.nextLine();
      String[] list = s.split("/");
      if (Integer.parseInt(list[0]) < 2019) {
        System.out.println("Heisei");
        System.exit(0);
      }
      if (Integer.parseInt(list[0]) == 2019 && Integer.parseInt(list[1]) < 4) {
        System.out.println("Heisei");
        System.exit(0);  
      }
      if (Integer.parseInt(list[0]) == 2019 && Integer.parseInt(list[1]) <= 4 && Integer.parseInt(list[2]) < 31) {
        System.out.println("Heisei");
        System.exit(0);  
      }

      System.out.println("TBD");
    }
}

Measured memory_bytes: 21716
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

struct Edge {
	ll from;
	ll to;
};

void calc_parent(ll v, vector<ll>& parent, const vector<vector<Edge>>& graph) {
	for (Edge e : graph[v]) {
		if (parent[e.to] == -1) {
			parent[e.to] = v;
			calc_parent(e.to, parent, graph);
		}
	}
}

void visit(ll v, const vector<vector<Edge>>& graph, vector<bool>& visited) {
	visited[v] = true;
	for (Edge e : graph[v]) {
		if (!visited[e.to]) {
			visit(e.to, graph, visited);
		}
	}
}

int main() {
	ll N;
	cin >> N;
	vector<vector<Edge>> graph(N);
	rep(i,0,N-1) {
		ll A, B;
		cin >> A >> B;
		A--;
		B--;
		graph[A].push_back({A, B});
		graph[B].push_back({B, A});
	}
	vector<ll> parent(N, -1);
	calc_parent(0, parent, graph);
	vector<ll> path;
	ll v = N-1;
	while (v != 0) {
		path.push_back(v);
		v = parent[v];
	}
	path.push_back(0);
	reverse(path.begin(), path.end());
	ll f_root = path[path.size()/2+path.size()%2-1];
	ll s_root = path[path.size()/2+path.size()%2];
	// cout << f_root << endl;
	// cout << s_root << endl;
	for (auto it = graph[f_root].begin(); it != graph[f_root].end(); ++it) {
		if (it->to == s_root) {
			graph[f_root].erase(it);
			break;
		}
	}
	for (auto it = graph[s_root].begin(); it != graph[s_root].end(); ++it) {
		if (it->to == f_root) {
			graph[s_root].erase(it);
			break;
		}
	}
	vector<bool> visited(N);
	visit(s_root, graph, visited);
	ll s_cnt = 0;
	rep(i,0,N) {
		if (visited[i]) {
			s_cnt++;
		}
	}
	ll f_cnt = N - s_cnt;
	if (f_cnt > s_cnt) {
		cout << "Fennec" << endl;
	} else {
		cout << "Snuke" << endl;
	}
}


Measured memory_bytes: 13948
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int N;
	int p = 1e9 + 7;
	while(cin >> N) {
		long long ans = 1;
		for(int i = 1; i <= N; ++i) {
			ans = (ans * i) % p;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,m;
    cin>>n>>m;
    vi q(m+1);
    rep(i,n){
        int k;
        cin>>k;
        while(k--){
            int a;
            cin>>a;
            q[a]++;
        }
    }
    int ans=0;
    REP(i,1,m){
        if(q[i]==n)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
// #define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
const ll INF = 1LL << 40;

int main(){	
	long long K;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&K);
	vector< vector<ll> > v(N);
	for(int i = 0 ; i <= N-1 ; i++){
		ll t,d;
		scanf("%lld",&t);
		scanf("%lld",&d);
		v[t-1].push_back(d);
	}
	rep(i,N) {
		if (v[i].empty()) v[i].push_back(-INF);
	}
	rep(i,N) {
		sort(v[i].begin(),v[i].end(),greater<ll>());
	}
	sort(v.begin(), v.end(), [&](vector<ll> a, vector<ll> b) {
    	return a[0] > b[0];});
	priority_queue<ll, vector<ll>, greater<ll> > que1;
	ll c = 0;
	rep(i,K) {
		que1.push(v[i][0]);
		c += v[i][0];
	}
	priority_queue<ll> que2;
	rep(i,K) {
		repn(j,v[i].size()-1) {
			que2.push(v[i][j]);
		}
	}
	for(ll i = K; i < N; i++) {
		rep(j,v[i].size()) {
			que2.push(v[i][j]);
		}
	}
	ll res = c + K*K;
	rep(i,K) {
		// cout << i << ": " << que1.top() << " " << que2.top() << endl;
		if (!que2.empty() && que2.top() > que1.top()) {
			c += que2.top() - que1.top();
			que1.pop();
			que1.push(que2.top());
			que2.pop();
			// que2.push(-INF);
			res = max(res, c + (K-i-1)*(K-i-1));
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 8692
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n,k;
    int cnt[200003] = {};

    int a;
    Scd2(n,k);
    Rep(i,n){
        Scd(a);
        cnt[a]++;
    }

    sort(cnt,cnt+200002);


    int ans = 0;
    Rep(i,200002-k){
        ans += cnt[i];
    }

    printf ("%d\n", ans);

    return 0;
}



Measured memory_bytes: 1024
n = gets.to_i
datas = gets.split("")
dp = Array.new(n+100,0)
dp[0] = datas.count("E")
if datas[0] == "E"
  dp[0] -= 1
end
min = dp[0]
for i in 0..(n-2)
  dp[i+1] = dp[i]
  dp[i+1] += 1 if datas[i] == "W"
  dp[i+1] -= 1 if datas[i+1] == "E"
  if dp[i+1] < min
    min = dp[i+1]
  end
end
#ラスト一個はDPだと無理なので手動
dp[n-1] = dp[n-2]
dp[n-1] += 1 if dp[n-2] == "W"
if dp[n-1] < min
  min = dp[n-1]
end



puts min.to_s

Measured memory_bytes: 29452
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N = int(input())
    S = str(input())
    left_over = 0
    right_over = 0

    for i in range(N):
        if S[i] == '(':
            left_over += 1
        else:
            left_over -= 1
            if left_over < 0:
                right_over = max(right_over, -left_over)

    SS = '('*right_over+S

    left_over = 0
    for i in range(len(SS)):
        if SS[i] == '(':
            left_over += 1
        else:
            left_over -= 1

    print(SS+')'*left_over)


resolve()

Measured memory_bytes: 38256
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		int N = in.i();
		int[] H = new int[N + 1];
		int cnt = 0;
		loop: for (int i = 1; i <= N; i++) {
			H[i] = in.i();

			for (int j = 1; j < i; j++)
				if (H[j] > H[i])
					continue loop;

			cnt++;
		}

		out.println(cnt);
	}


	static PrintStream out = System.out;
	static FastReader in = new FastReader();
}

class FastReader {
	final private int BUF_SIZE = 1 << 16;
	private DataInputStream din;
	private byte[] buffer = new byte[BUF_SIZE];
	private int bufferPointer, bytesRead;

	FastReader() {
		din = new DataInputStream(System.in);
	}

	String s() throws IOException {
		byte[] buf = new byte[64];
		int cnt = 0, c;
		while ((c = read()) != -1) {
			if (c == '\n') break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	int i() throws IOException {
		int ret = 0;
		byte c = read();
		while (c <= ' ') c = read();
		boolean neg = (c == '-');
		if (neg) c = read();
		do {
			ret = ret * 10 + c - '0';
		}
		while ((c = read()) >= '0' && c <= '9');
		return neg ? -ret : ret;
	}

	long l() throws IOException {
		long ret = 0;
		byte c = read();
		while (c <= ' ') c = read();
		boolean neg = (c == '-');
		if (neg) c = read();
		do {
			ret = ret * 10 + c - '0';
		}
		while ((c = read()) >= '0' && c <= '9');
		return neg ? -ret : ret;
	}

	double d() throws IOException {
		double ret = 0, div = 1;
		byte c = read();
		while (c <= ' ') c = read();
		boolean neg = (c == '-');
		if (neg) c = read();
		do {
			ret = ret * 10 + c - '0';
		}
		while ((c = read()) >= '0' && c <= '9');
		if (c == '.')
			while ((c = read()) >= '0' && c <= '9')
				ret += (c - '0') / (div *= 10);
		return neg ? -ret : ret;
	}

	private void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUF_SIZE);
		if (bytesRead == -1) buffer[0] = -1;
	}

	private byte read() throws IOException {
		if (bufferPointer == bytesRead) fillBuffer();
		return buffer[bufferPointer++];
	}

	void close() throws IOException {
		if (din != null) din.close();
	}
}



Measured memory_bytes: 20948
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;

int n;
int a[100010];
int ans=0;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
	if(a[i]%2==1)ans++;
    }	
	
	
    
    puts(ans%2==0 ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<numeric>
#include<vector>
#include<tuple>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
typedef long long ll;

const int MOD = 1e9 + 7;
ll N, X[1009], Y[1009], H[1009]; vector<tuple<ll, ll, ll>>vec;

int main(void)
{
	cin >> N; tuple<ll, ll, ll>G = make_tuple(-1, -1, -1);
	FOR(i,1,N+1){
		cin >> X[i] >> Y[i] >> H[i];
		if (H[i] >= 1)G = make_tuple(X[i], Y[i], H[i]);
	}
	FOR(i, 0, 101) {
		FOR(j, 0, 101) {
			ll V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j); V = max(V, 0LL); bool flag = true;
			FOR(k, 1, N + 1) {
				ll VV = V - abs(X[k] - i) - abs(Y[k] - j); VV = max(VV, 0LL);
				if (H[k] != VV)flag = false;
			}
			if (flag == true)vec.push_back(make_tuple(i, j, V));
		}
	}
		if (vec.size() == 1) {
			cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
		}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,p[5555],a[5555],jc[5555],used[5555],sze[5555],szv[5555],pa[5555],cnt,cr,ans;
int dp[5555][5555];
int root(int x)
{
	if (pa[x]!=x) pa[x]=root(pa[x]);
	return pa[x];
}
void Union(int x,int y)
{
	int rx=root(x),ry=root(y);
	if (rx==ry)
	{
		sze[rx]++;
		return;
	}
	szv[ry]+=szv[rx];sze[ry]+=(sze[rx]+1);
	pa[rx]=ry;
}
int binpow(int a,int t)
{
	int res=1,p=a;
	for (int i=t;i;i>>=1)
	{
		if (i&1) res=1ll*res*p%mod;
		p=1ll*p*p%mod;
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) 
	{
		scanf("%d",&p[i]);
	}
	for (int i=1;i<=n;i++)
	{
		pa[i]=i;
		sze[i]=0;szv[i]=1;
	}
	for (int i=1;i<=n;i++)
	{
		if (p[i]!=-1) Union(i,p[i]);
		else ++cr;
	}
	for (int i=1;i<=n;i++)
	{
		if (root(i)==i && sze[i]==szv[i]-1) 
		{
			a[++cnt]=szv[i];
		}
		else if (root(i)==i)
		{
			ans=(binpow(n-1,cr)+ans)%mod;
		}
	}
	dp[0][0]=1;
	for (int i=0;i<cnt;i++)
	{
		for (int j=0;j<=i;j++)
		{
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			dp[i+1][j+1]=(1ll*dp[i][j]*a[i+1]+dp[i+1][j+1])%mod;
		}
	}
	jc[0]=1;
	for (int i=1;i<=n;i++) jc[i]=1ll*jc[i-1]*i%mod;
	dp[cnt][1]=(dp[cnt][1]-cnt)%mod;
	for (int i=2;i<=cnt;i++) dp[cnt][i]=1ll*dp[cnt][i]*jc[i-1]%mod;
	for (int i=1;i<=cnt;i++)
	{
		ans=(1ll*dp[cnt][i]*binpow(n-1,cr-i)+ans)%mod;
	}
	ans=(1ll*binpow(n-1,cr)*n-ans)%mod;
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 72260