akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <limits.h>

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(N), b(N), c(M), d(M), ans(N);
  for(int i=0;i<N;i++){
    cin >> a[i] >> b[i];
  }
  for(int i=0;i<M;i++){
    cin >> c[i] >> d[i];
  }
  for(int i=0;i<N;i++){
    int distance=INT_MAX;
    for(int j=0;j<M;j++){
      int dis=abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(dis<distance){
        ans[i] = j+1;
        distance = dis; 
      }
    }
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N, D = map(int, readline().split())
  X = [np.array(readline().split(), np.int64) for _ in range(N)]
  ans = 0
  for i in range(N-1):
    for j in range(i+1, N):
      d = (X[i]-X[j])**2
      dist = d.sum()
      r = int(dist**0.5)
      if r**2 == dist:
        ans += 1
      else:
        continue
  print(ans)
  
  
  
  
      
if __name__ == '__main__':
  main()

Measured memory_bytes: 12484
s = list(input())
t = list(input())
ls, lt = len(s), len(t)
#リストを反転させてケツから調べる事で辞書順最小を求める
s.reverse()
t.reverse()
for i in range(ls):
    for j in range(lt): #このfor文が全部回ればt in sである
        if i + j >= ls:
            break
        if s[i+j] != '?' and s[i+j] != t[j]:
            break
    else: 
        for j in range(lt):
            s[i+j] = t[j]
        s = [x if x != '?' else 'a' for x in s]
        s.reverse()
        ans = ''.join(s)
        break
else:
    ans = 'UNRESTORABLE'
print(ans)

Measured memory_bytes: 9088
def popularity(votes, N, M):
    
    total_votes = sum(votes)
    limit = total_votes / (4.0 * M)
    
    cnt = 0
    for vote in votes:
        if vote >= limit:
            cnt += 1
    
    if cnt >= M:
        return "Yes"
    
    return "No"
  
N, M = [int (x) for x in input().split()]
votes = [int (x) for x in input().split()]
print(popularity(votes, N, M))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define for(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll N, K;cin >> N >> K;
long double Ans = 0, sum = 0;
vector<long double> V(N);
for(i, 0, N){
cin >> V[i];
if(i < K)sum += (V[i] + 1)/2;
}
Ans = sum;
for(i, 0, N - K){
sum += (V[K + i] + 1)/2 - (V[i] + 1)/2;
Ans = max(Ans, sum);
}
cout << fixed << setprecision(10) << Ans;
}

Measured memory_bytes: 6404
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> d(k, 0);
    d[0] = 1;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    vector<ll> s(n);
    s[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; --i) {
        s[i] = a[i] + s[i + 1];
    }
    int mx = 0;
    for (int i = 0; i < n; ++i) {
        int st = max(0ll, k - s[i]);
        //cerr << st << endl;
        if (mx < st) {
            cout << n - i << endl;
            return;
        }
        for (int j = k - 1; j >= 0; --j) {
            if (d[j] == 0)
                continue;
            int id = j + a[i];
            if (id < k) {
                d[id] = 1;
                mx = max(mx, id);
            }
        }
    }
    cout << 0 << endl;


}


//#define LOCAL

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



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int someSums = 0;
		for(int i = 1; i <= N; i++){
			int sum = calcSum(i);
			if(sum >= A && sum <= B) someSums += i;	
		}
		System.out.println(someSums);	
	}
	private static int calcSum(int num){
		int sum = 0;
		while(num > 0){
			sum += num % 10;
			num /= 10;
		}
		return sum;
	}
}

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

#define ll long long
#define ar array
#define vi vector<int>
#define INF 1000000000

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	set<string> items;
	int n; cin >> n;
	string item;
	while(n--){
		cin >> item;
		items.insert(item);
	}	

	cout << items.size() << endl;

	return 0;
}


Measured memory_bytes: 19184
def func(a,b,c,d,s):
    if a+b+c+d==7:
        s[1],s[3],s[5]="+","+","+"
    elif a+b+c-d==7:
        s[1],s[3],s[5]="+","+","-"
    elif a+b-c+d==7:
        s[1],s[3],s[5]="+","-","+"
    elif a+b-c-d==7:
        s[1],s[3],s[5]="+","-","-"
    elif a-b+c+d==7:
        s[1],s[3],s[5]="-","+","+"
    elif a-b+c-d==7:
        s[1],s[3],s[5]="-","+","-"
    elif a-b-c+d==7:
        s[1],s[3],s[5]="-","-","+"
    elif a-b-c-d==7:
        s[1],s[3],s[5]="-","-","-"
 
x=str(input())
ans=''
 
a=int(x[0])
b=int(x[1])
c=int(x[2])
d=int(x[3])
 
s=[a,"",b,"",c,"",d]
 
func(a,b,c,d,s)
 
for x in s:
    ans+=str(x)
 
print(ans+"=7")

Measured memory_bytes: 3064
#include<iostream>
#include <climits>
#include<cstring>
using namespace std;
int main()
{
	int l,j,i,n,m,k;
	cin>>n>>m>>k;
	int ara[n][m],set[n],skill[m]={0},cost=0,ans=INT_MAX;
	for(i=0;i<n;i++){
		cin>>set[i];
		for(j=0;j<m;j++){
			cin>>ara[i][j];
		}
	}
	for(i=0;i<(1<<n);i++){
		cost=0;
		memset(skill,0,sizeof(skill));
		for(j=0;j<n;j++){
			if(i&(1<<j)){
				cost+=set[j];
				for(l=0;l<m;l++){
					skill[l]+=ara[j][l];
				}
			}
		}
		int y=1;
		for(j=0;j<m;j++){
			if(skill[j]<k){
				y=0;
				break;
			}
		}
		if(y){
			ans=min(cost,ans);
		}
	}
	if(ans!=INT_MAX){
		cout<<ans<<endl;
	}
	else{
		cout<<-1<<endl;
	}
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e,A,B,C,D,E,cnt=0;
  cin>>a>>b>>c>>d>>e;
  A=a%10;
  B=b%10;
  C=c%10;
  D=d%10;
  E=e%10;
  if(A==0){A=10;
           cnt++;}
  if(B==0){B=10;
           cnt++;}
  if(C==0){C=10;
           cnt++;}
  if(D==0){D=10;
           cnt++;}
  if(E==0){E=10;
           cnt++;}
  int m=min({A,B,C,D,E});
  cout<<(a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10+40+m-10*cnt<<endl;
}


Measured memory_bytes: 384
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static char s[10000][11];

static size_t countIntermediateAB(char* s) {
    size_t cnt = 0;

    while (true) {
        s = strstr(s, "AB");
        if (s == NULL) {
            break;
        }
        if (s[2] == '\0') {
            break;
        }

        s += 2;
        cnt++;
    }

    return cnt++;
}

int main(void) {
    size_t N;

    size_t numABIntermediate = 0;
    size_t numFirstB = 0;
    size_t numLastA = 0;
    size_t numFirstBLastA = 0;

    scanf("%zu", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%s", s[i]);
        if (i < N - 1) {
            scanf("\n");
        }

        if (s[i][0] == 'B') {
            if (s[i][strlen(s[i]) - 1] == 'A') {
                numFirstBLastA++;
            }
            else {
                numFirstB++;
            }
        }
        else if (s[i][strlen(s[i]) - 1] == 'A') {
            numLastA++;
        }
        numABIntermediate += countIntermediateAB(s[i]);
    }

    size_t cnt = numABIntermediate;
    if (0 < numFirstBLastA) {
        cnt += numFirstBLastA - 1;
        if (0 < numFirstB) {
            cnt++;
            numFirstB--;
        }
        if (0 < numLastA) {
            cnt++;
            numLastA--;
        }
    }
    cnt += MIN(MIN(numFirstB, numLastA), N - 1);

    printf("%zu", cnt);

    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double l = sc.nextDouble();
        double a = l * l * l /27.0;
        //BigDecimal ll = BigDecimal.valueOf(a);
        System.out.println(a);
    }
}

Measured memory_bytes: 23124
import java.util.*;
public  class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String str=sc.next();
    if(str.charAt(2)==str.charAt(3) && str.charAt(4)==str.charAt(5))
                       System.out.println("Yes");
                       else
                       System.out.println("No");
                       }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
 
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =5*100001;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}
const int N=10000;


int main()
{
   
  IOS
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll ans=0;
    for(ll i=0;i<n;i++)
    cin>>a[i];
    for(ll bit=50;bit>=0;bit--)
    {
            ll co=0,c1=0;
            for(ll i=0;i<n;i++)
            {
                if(a[i]>>bit & 1ll)
                    c1++;
                else
                {
                    co++;
                }
                
            }
            if(co>c1)
                ans|=(1ll<<bit);
            if(ans>k)

            ans&=~(1ll<<bit);
    }
    ll fin=0;
    for(ll i=0;i<n;i++)
        {
            fin+=(ans^a[i]);
        }
    cout<<fin<<endl;
 
  
 
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>


#define MAX 1000


//99999999999999999999999999999999999999999999999999999999999999999999999999999999

using namespace std;


int main()
{
	int n = 0;
	string in[2];
	char out[MAX] = {NULL};

	cin >> n;

	for (int i = 0; i < n; i++){
		vector<int>v;

		cin >> in[0] >> in[1];

		int len[2];
		len[0] = in[0].size();
		len[1] = in[1].size();

		//けた上がり
		int up = 0;

		for (int i = 0; i < max(len[0] , len[1]) || up == 1; i++){
			
			//足す値
			int push = up;
			up = 0;

			//indexの範囲内
			if(i < len[0]){
				push += in[0][len[0] - i - 1] - '0';
			}
			if (i < len[1]){
				push += in[1][len[1] - i - 1] - '0';
			}
			if (push > 9){
				push -= 10;
				up = 1;
			}

			v.push_back(push);
		}

		if (v.size() > 80){
			cout << "overflow" << endl;
			continue;
		}
		for (int i = v.size() - 1; i >= 0; i--){
			cout << v[i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const ll mod = 998244353;

bool check(int& a, int& b, int& c)
{
    return a + b > c && a + c > b && b + c > a;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    vector<int> v(n);
    trav(i, v) cin >> i;
    int c = 0;
    FOR(i, 0, n - 2)
    {
        FOR(j, i + 1, n - 1)
        {
            FOR(k, j + 1, n)
            {
                if (v[i] == v[j] || v[i] == v[k] || v[j] == v[k]) continue;
                if (check(v[i], v[j], v[k])) c++;
            }
        }
    }
    cout << c;
    return 0;
}





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

using namespace std;

int main(void) {
	int num, k, i = 0, ans = 1000000000;
	cin >> num >> k;
	vector<int> d(num);
	for (; i < num; i++)
		scanf("%d", &d[i]);
	sort(d.begin(), d.end());
	k--;
	for (i = 0; i < num - k; i++)
		ans = min(ans, d[i + k] - d[i]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);

int gcd(int a, int b) {
  if(b == 0) return a;
  return gcd(b, a%b);
}

long int solve(int k) {
  long int res = 0;
  for(int i=1; i<=k; i++) {
    for(int j=1; j<=k; j++) {
      for(int m=1; m<=k; m++) {
        res += gcd(gcd(i, j), m);
      }
    }
  }
  return res;
}

int main() {
  FASTIO
  int k; cin >> k;
  cout << solve(k) << endl;
}

Measured memory_bytes: 3640
import math

# li[0]N,li[1]D
a = input().split()
li = [int(i) for i in a]

#行列
b = [input().split() for i in range(li[0])]
lis = [[int(j) for j in i] for i in b]


an = [[(lis[i][j]-lis[k][j])**2 for j in range(li[1])] for i in range(0,len(lis)-1) for k in range(i+1,len(lis))]
ann = [math.sqrt(sum(i)) for i in an] 
ans = [i for i in ann if (i.is_integer())]
print(len(ans))

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }

  int ans = 0;
  for(int i = 0; i < n-2; i++){
    vector<int> v(3);
    v[0] = p[i];
    v[1] = p[i+1];
    v[2] = p[i+2];
    sort(v.begin(),v.end());
    if(v[1] == p[i+1]) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int d[26] = {};
    rep(i, 0, s.size()) d[s[i] - 'a']++;
    int cnt = 0, MAX = 0;
    rep(i, 0, 26){
        if(d[i] != 0) cnt++;
        chmax(MAX, d[i]);
    }
    if(MAX > (s.size() + 2) / 3) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
#include <set>

typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


/*
 * 最大公約数計算
 */
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


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

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

void unite(int x, int y)
{
	x = find(x);
	y = find(y);

	if (r[x] < r[y])
	{
		par[x] = y;
	}
	else
	{
		par[y] = x;
		if (r[x] == r[y])
		{
			r[x]++;
		}
	}
}

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

};

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,m;
	cin >> n >> m;
	vector<pair<int, int>> e(m);
	for (int i = 0; i < m; i++)
	{
		cin >> e[i].first >> e[i].second;
		e[i].first--;
		e[i].second--;

	}
	int ans = 0;
	for (int i = 0; i < m; i++)
	{
		union_find uf(n);

		for (int j = 0; j < m; j++)
		{
			if (i != j && !uf.same(e[j].first, e[j].second))
			{
				uf.unite(e[j].first, e[j].second);
			}
		}
		set<int> s;
		for (int j = 0; j < n; j++)
		{
			if (uf.par[j] == j)s.insert(uf.par[j]);
		}
		if (s.size() > 1)ans++;

	}

		cout << ans << endl;
	
	
	
	return 0;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL N,M;cin >> N >> M;

    LL ans = N*M - 2*(N-1) - 2*(M-1);
    if(N == 1){
        if(M == 1)ans = 1;
        if(M == 2)ans = 0;
        if(M >= 3)ans = M-2;
    }
    else if(M == 1){
        if(N == 1)ans = 1;
        if(N == 2)ans = 0;
        if(N >= 3)ans = N-2;
    }
    cout << ans << endl;
}

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


int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int cnt = 0;
    rep(i, N-2) {
        if(S[i]=='A') {
            if(S[i+1]=='B'&&S[i+2]=='C') cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int func(int n){
    if(n==1)return 1;
    else return n+func(n-1);
}
int main(){
    int N;cin>>N;
    cout<<func(N)<<endl;
}


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

using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define all(vec) vec.begin(),vec.end()
#define ff first
#define ss second
#define inf 4e18
#define MOD 1000000007
#define push_back emplace_back
#define pb push_back
#define for1(low,high,k) for(int i=low;i<high;i+=k)
#define for2(low,high,k) for(int j=low;j<high;j+=k)
#define rev(high,low,k) for(int i=high;i>=low;i-=k) 

int main(){
	fast;
	lli a,b,n;
	cin>>a>>b>>n;
	if (n>=b) n=b-1;
	cout<<((a*n)/b)-a*(n/b)<<endl;
}

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

string a;
int out;

int main()
{
	cin>>a;
	for(int i = 0,j = a.size() - 1;i < j;i++,j--)
	{
		if(a[i] != a[j])out++;
	}
	cout<<out;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define vi vector<int>
#define pii pair<int,int>
#define se second
using namespace std;
int t,a,b,c,x,y,k,n,q;
vi v(500005);
ll ans;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n ;
	for (int i = 0; i < n; i++) {
		cin >> a;
		ans += a;
		v[a]++;
	}         cin >> q;
	while(q--) {
		cin >> b >> c;
		ans += v[b]*(c-b);
		v[c] += v[b];
		v[b] = 0;
		cout << ans<<'\n';
	}
	
	
}

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

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define SORT(v) sort(v.begin(), v.end())
typedef long long ll;

int main()
{
    int n;
    string s;

    cin >> n;

    vector<int> a(n);
    vector<int> ans(n);

    REP(i, n)
    ans.at(i) = 0;
    FOR(i, 1, n)
    {
        cin >> a.at(i);
        ans.at(a.at(i) - 1)++;
    }
    REP(i, n)
    {
        cout << ans.at(i) << endl;
    }
}


Measured memory_bytes: 4844
#include <iostream> 
#include <vector>
#include <map>
#include <algorithm> 
#include <string>

int gcd(long long a, long long b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  long long n, m;
  std::cin >> n >> m;
  std::string s, t;
  std::cin >> s >> t;

  long long L = n * m / gcd(n, m);
  long long N = L / n;
  long long M = L / m;
  long long NM = N * M;
  bool bad = false;
  for (long long i = 0; i < L; i += NM) {
    if (s[i / N] != t[i / M])
      bad = true;
  }
  std::cout << (bad ? -1 : L) << std::endl;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


int main(){
    string N;
    cin >> N;
    string res = "No\n";
    if (N[0]==N[1] && N[1]==N[2]) res = "Yes\n";
    if (N[1]==N[2] && N[2]==N[3]) res = "Yes\n";
    cout << res;
}


Measured memory_bytes: 256
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) //cerr<<(str)<<endl;
struct interval {
	int index, l, r;
};
//bool lt_left(interval a, interval b) {
//	return a.l < b.l;
//}
//bool gt_right(interval a, interval b) {
//	return a.r > b.r;
//}
int main() {
	int n;
	cin >> n;
	vector<interval>I(n);
	auto lt_left = [](interval a, interval b) {return a.l < b.l; };
	auto gt_right = [](interval a, interval b) {return a.r > b.r; };
	priority_queue<interval, vector<interval>, decltype(lt_left)>leftq(lt_left);
	priority_queue<interval, vector<interval>, decltype(gt_right)>rightq(gt_right);
	rep(i, 0, n) {
		cin >> I[i].l >> I[i].r;
		I[i].index = i;

		leftq.push(I[i]);
		rightq.push(I[i]);
	}
	//rep(i, 0, n) {
	//	//cerr << leftq.top().l << endl;
	//	leftq.pop();
	//}
	////cerr << endl;
	//rep(i, 0, n) {
	//	//cerr << rightq.top().r << endl;
	//	rightq.pop();

	//}

	auto simu = [&](bool rlrl, priority_queue<interval, vector<interval>, decltype(lt_left)>leftq, priority_queue<interval, vector<interval>, decltype(gt_right)>rightq) {
		vector<bool>deleted(n, false);
		ll K = 0;
		int delcnt = 0;
		int pos = 0;
		int i = 0;
		while (delcnt < n) {
			int newpos = 0;
			interval next;
			if (i % 2 == rlrl) {
				next = leftq.top();
				leftq.pop();
				newpos = next.l;
			}
			else {
				next = rightq.top();
				rightq.pop();
				newpos = next.r;
			}
			if (deleted[next.index])continue;
			delcnt++;
			deleted[next.index] = true;
			i++;
			if (next.l <= pos && pos <= next.r)continue;
			K += abs(newpos - pos);
			pos = newpos;
			//cerr << "delcnt:" << delcnt << ", K:" << K << endl;
			//cerr << "selected:(index,l,r)=" << next.index << "," << next.l << "," << next.r<<endl;

		}
		K += abs(pos);
		//cerr << "res of " << rlrl << ": " << K << endl;
		return K;
	};
	ll ans1 = simu(0, leftq, rightq);
	ll ans2 = simu(1, leftq, rightq);
	cout << max(ans1, ans2);




	return 0;
}





Measured memory_bytes: 6444
import java.util.Scanner;

public class Main
{
    public static void main(String [] args)
    {
        Scanner key = new Scanner(System.in);
        String s = key.nextLine();
        int a = 0;
        int b = 0;

        for(int i = 0; i<s.length(); i++)
        {
            char c = s.charAt(i);
            if(c == 'A')
                a++;
            else
                b++;
        }

        if(a == 0 || b == 0)
        {
            System.out.println("No");
        }
        else
            System.out.println("Yes");
    }
}

Measured memory_bytes: 21844
s = int(input())
a = int(s / 100)
b = s % 100

if 1 <= a <= 12:
    if 1 <= b <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= b <= 12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 2940
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

class UnionFind {
private:
	vector<int> data;
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }

public:
	UnionFind(int size) : data(size, -1) { }
	bool is_same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -data[root(x)]; }

	void unify(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
};


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int H, W;
	cin >> H >> W;

	vector<string> S(H);
	for (int i = 0; i < H; i++) cin >> S[i];

	UnionFind row(H*W), col(H*W);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (j != W - 1 && S[i][j] == '.' && S[i][j + 1] == '.') row.unify(i*W + j, i*W + j + 1);
			if (i != H - 1 && S[i][j] == '.' && S[i + 1][j] == '.') col.unify(i*W + j, (i+1)*W + j);
		}
	}

	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans = max(row.size(i*W + j) + col.size(i*W + j) - 1, ans);
		}
	}

	cout << ans << "\n";

	return 0;
}

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

int main(){
  int K,i=1,ten_pow=10,ans;
  cin >> K;
  K = K%7==0 ? 9*K/7 : 9*K;
  if(K%2==0||K%5==0){
    cout << -1 << endl;
  }else{
  	while(true){
      //cout << ten_pow << endl;
    	if(ten_pow%K==1){
          ans=i;
          break;
        }
      ten_pow=ten_pow%K;
      ten_pow=10*ten_pow;
      i++;
  	}
    cout << ans << endl;
  }
}

Measured memory_bytes: 3548
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    int N, M, Q;
    cin>>N>>M>>Q;
    int a[Q], b[Q], c[Q], d[Q];
    for(int i=0;i<Q;++i){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;
        b[i]--;
    }
    queue<vector<int> > que;
    vector<int> tmp;
    for(int i=1;i<=M;++i){
        tmp.clear();
        tmp.push_back(i);
        que.push(tmp);
    }
    vector<int> state;
    ll ans = 0;
    ll tmpans;
    while(!que.empty()){
        state = que.front();que.pop();
        if(state.size()==N){
            tmpans = 0;
            for(int i=0;i<Q;++i){
                if(state[b[i]] - state[a[i]] == c[i]) tmpans += d[i];
            }
            if(ans < tmpans) ans = tmpans;
            continue;
        }
        for(int i=state[state.size()-1];i<=M;++i){
            state.push_back(i);
            que.push(state);
            state.pop_back();
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 9860
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 100000;
typedef long long ll;
int N, M; ll K;
int x[MAXN + 5];
int a[MAXN + 5], b[MAXN + 5], res[MAXN + 5];
void Pow(ll p) {
	for(int i=1;i<N;i++)
		res[i] = i;
	while( p ) {
		if( p & 1 ) {
			for(int i=1;i<N;i++)
				res[i] = a[res[i]];
		}
		p >>= 1;
		for(int i=1;i<N;i++)
			b[i] = a[a[i]];
		for(int i=1;i<N;i++)
			a[i] = b[i];
	}
}
int main() {
	scanf("%d", &N);
	for(int i=0;i<N;i++)
		scanf("%d", &x[i]);
	for(int i=N-1;i>0;i--)
		x[i] = x[i] - x[i-1];
	scanf("%d%lld", &M, &K);
	for(int i=1;i<N;i++)
		a[i] = i;
	for(int i=1;i<=M;i++) {
		int k;
		scanf("%d", &k);
		swap(a[k-1], a[k]);
	}
	Pow(K);
	ll nw = x[0];
	printf("%lld\n", nw);
	for(int i=1;i<N;i++) {
		nw = nw + x[res[i]];
		printf("%lld\n", nw);
	}
}

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

using namespace std;

using ll = long long;

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

    vector<int> v(n);
    vector<bool> flag(10000010, true);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v[i] = a;
    }

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

    
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int num = v[i];
        if (flag[num]) {
            if (i == n - 1 || num != v[i + 1]) ans++;
            for (ll j = num; j < 10000010; j += num) {
                flag[j] = false;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mod 1000000007
#define reset(s,val) memset(s,val,sizeof(s))
#define eps 1e-8
#define pi acos(-1)
#define sqr(x) (x)*(x)
#define two(x) (1<<(x))

long long n,k;

int main( ){
    // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    // ios::sync_with_stdio(0);
    cin>>n>>k;
    long long g=__gcd(n,k);
    cout<<g*3*(n/g-1);
}

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

const int N = 205;
const int INF = 1e9;

struct Edge {
   int v,cap,rev;
   Edge(int v,int cap,int rev) : v(v),cap(cap),rev(rev) {
   }
};

vector<Edge> vt[N];

void addEdge(int u,int v,int cap) {
   vt[u].push_back(Edge(v,cap,vt[v].size()));
   vt[v].push_back(Edge(u,0,vt[u].size()-1));
}

int level[N];

bool bfs(int s,int t) {
   memset(level,-1,sizeof(level));
   level[s] = 0;
   queue<int> q;
   q.push(s);
   while(!q.empty()) {
      int node = q.front();
      q.pop();
      for(int i=0;i<vt[node].size();++i) {
         int there = vt[node][i].v;
         int cap = vt[node][i].cap;
         if(level[there]==-1 && cap>0) {
            level[there] = level[node] + 1;
            q.push(there);
         }
      }
   }
   return level[t]!=-1;
}
int work[N];
int dfs(int here,int minCap,int t) {
   if(here==t) {
      return minCap;
   }
   for(int &i = work[here];i< vt[here].size();++i) {
      int there = vt[here][i].v;
      int cap = vt[here][i].cap;
      if(level[there] == level[here]+1 && cap>0) {
         int c = dfs(there,min(minCap,cap),t);
         if(c>0) {
            int rid = vt[here][i].rev;
            vt[here][i].cap -= c;
            vt[there][rid].cap += c;
            return c;
         }
      }
   }
   return 0;
}
ll findMinCut(int s,int t) {
   ll ret= 0;
   while(bfs(s,t)) {
      memset(work,0,sizeof(work));
      while(true) {
         int r = dfs(s,INF,t);
         ret += r;
         if(r==0) {
            break;
         }
      }
   }
   return ret;
}

int A[N];

void solve() {
   int n;
   scanf("%d",&n);
   for(int i=1;i<=n;++i) {
      scanf("%d",&A[i]);
   }
   int s = n+1,t = n+2;
   ll ret = 0;
   for(int i=1;i<=n;++i) {
      if(A[i]<=0) {
         addEdge(s,i,-A[i]);
         for(int j = i+i;j<=n;j+=i) {
            addEdge(i,j,INF);
         }
      } else {
         ret += A[i];
         addEdge(i,t,A[i]);
      }
   }
   ret -= findMinCut(s,t);
   printf("%lld\n", ret);
}

int main() {
   //freopen("input.txt","r",stdin);
   solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  cin >>N;
  vector<int>vec(N);
  rep(i,N) {
cin >>vec.at(i);
  }
  int count=0;
  int state=1;

  rep(i,N) {
    state=vec.at(state-1);
    count++;
    if(state!=2) {
      
      continue;
    }
    if(state==2) {
      cout<< count<< endl;
      break;
    }
  }
  
  if(state !=2) {
    cout <<"-1"<< endl;
  }
}
    
  

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
OK = []
i = 1
while True:
    OK.append(i*(i+1)//2)
    if OK[-1] > 10**5:
        break
    i += 1
N = int(input())

if N in OK:
    print("Yes")
    W = OK.index(N) + 1
    S = [[] for _ in range(W+1)]
    j = 0
    L = list(range(1, N+1))
    l = 1
    for i, w in enumerate(range(W, 0, -1)):
        for s in range(l, l+w):
            S[i].append(s)
        l = l+w
    l = 1
    for i, w in enumerate(range(W, 0, -1)):
        for j, s in enumerate(range(l, l+w)):
            S[i+1+j].append(s)
        l = l+w
    print(len(S))
    for s in S:
        print(len(s), *s)
else:
    print("No")


Measured memory_bytes: 16556
N = int(input())
A = list(map(int, input().split()))

counts = {}

for a in A:
    if a in counts:
        counts[a] += 1
    else:
        counts[a] = 1
        
    if a - 1 in counts:
        counts[a - 1] += 1
    else:
        counts[a - 1] = 1
        
    if a + 1 in counts:
        counts[a + 1] += 1
    else:
        counts[a + 1] = 1
        
print(max(counts.values()))

Measured memory_bytes: 18752
A = []
task = []
N = int(input())

for i in range(N):
	a, b = (map(int, input().split()))
	A.append([a, b])
	
A = sorted(A, key = lambda x : x[1])
summ = 0
output = 'Yes'

for i in range(N):
	summ += A[i][0]
	if summ > A[i][1]:
		output = 'No'
		break
		
print(output)

Measured memory_bytes: 39584
#include <bits/stdc++.h>
using namespace std;
#define endl "\n";
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define double long double
#define M_PI 3.14159265358979323846 
const int mod = 1e9 + 7;

int findS(int s) 
{ 
    int l = 1, r = (s / 2) + 1; 
  
    // Apply Binary search 
    int res = -1;
    while (l <= r) { 
  
        // Find mid 
        int mid = (l + r) / 2; 
  
        // find sum of 1 to mid natural numbers 
        // using formula 
        int sum = mid * (mid + 1) / 2; 
  
        // If sum is equal to n 
        // return mid
        if (sum == s) 
            return mid; 
  
        // If greater than n 
        // do r = mid-1 
        else if (sum > s) 
            r = mid - 1; 
  
        // else do l = mid + 1 
        else{
            res = mid;
            l = mid + 1; 
        }
    } 
  
    // If not possible, return -1 
    return res; 
}

int32_t main()
{
    fastio;

    int n; cin >> n;
    unordered_map<int,int> mp;
    while (n % 2 == 0)  
    {  
        mp[2]++;  
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            mp[i]++;  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
       mp[n]++;

    int ans = 0;
    for(auto x: mp){
        ans += findS(x.second);
    }

    cout << ans << endl;
    return 0;
}

/*

*/

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

int main() {
    double x1, y1, x2, y2;
  	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

    double dis = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
    double ans = sqrt(dis);

    printf("%.8f\n", ans);
}


Measured memory_bytes: 3176
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()
	r.Scan(true)
	a := r.nextStringArray().toInts()
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	idx := 0
	nc := n
	ans := 0
	nc--

	if nc > 0 {
		ans += a[idx]
		idx++
		nc--
	}

	for i := 1; i < n; i++ {
		if nc <= 0 {
			break
		}
		w := 2
		if w > nc {
			w = nc
		}
		ans += a[idx] * w
		idx++
		nc -= w
	}

	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 15832
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static Scanner cin = new Scanner();

    static void Main(string[] args) {
        const int INF = (int)1e9;
        int N = cin.Int();
        var h = cin.ArrayInt(N);

        var dp = new int[N];
        for (int i = 0; i < N; i++) {
            dp[i] = INF;
        }
        dp[0] = 0;
        dp[1] = Math.Abs(h[1] - h[0]);
        for (int i = 2; i < N; i++) {
            dp[i] = Math.Min(dp[i - 2] + Math.Abs(h[i] - h[i - 2]), dp[i - 1] + Math.Abs(h[i] - h[i - 1]));
        }
        Console.WriteLine(dp[N - 1]);
        Console.ReadLine();
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef long long ll;
typedef pair<int, int> pi;

int main() {
    //freopen("in.txt", "r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

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

    int A[n+2];
    for (int i=1;i<=n;++i) cin>>A[i];

    multiset<int> s;
    int maxi = 0;
    for (int a=0;a<=n;++a){
        for (int b=n+1;b>a;b--){
            s.clear();
            int sum = 0;
            if (a+n+1-b <= min(n, k)){
                for (int i=1;i<=n;++i){
                    if (i<=a || i>=b) {
                        s.insert(A[i]);
                        sum += A[i];
                    }
                }
            }
            int cnt = 0;
            int r = k - (a+1+n-b);
            for (auto e : s){
                if (cnt == r) break;
                if (e<0) sum-=e;
                cnt++;
            }
            maxi = max(maxi, sum);
        }
    }
    cout<<maxi<<endl;
    
    return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;cin >> h >> w;
	vector<string> s(h);
	rep(i,h) cin >> s.at(i);
	vector<string> red(h),blue(h);
	rep(i,h){
		rep(j,w){
			if(j==0 || (j!=w-1 && i%2==0)){
				red[i]+='#';
				blue[i]+='.';
			}
			else{
				red[i]+='.';
				blue[i]+='#';
			}
		}
	}
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='#'){
				red[i][j]='#';
				blue[i][j]='#';
			}
		}
	}
	rep(i,h) cout << red[i] << endl;
	cout << endl;
	rep(i,h) cout << blue[i] << endl;
}


Measured memory_bytes: 1536
#include<stdio.h>

int main(){
  int h1, m1, s1, h2, m2, s2, ans, i;
  for(i = 0;i < 3;i++){
    scanf("%d%d%d%d%d%d", &h1, &m1, &s1, &h2, &m2, &s2);
    ans = (h2 * 3600 + m2 * 60 + s2) - (h1 * 3600 + m1 * 60 + s1); 
    printf("%d %d %d\n", ans / 3600, (ans / 60) % 60, ans % 60);
  }
  return 0;
}

Measured memory_bytes: 596