akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {

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

        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0; i < n; i++) {
            if (map.containsKey(A[i])) {
                map.put(A[i], map.get(A[i]) + 1);
            } else {
                map.put(A[i], 1);
            }
        }
        ArrayList<Map.Entry<Integer, Integer>> arr = new ArrayList<Map.Entry<Integer, Integer>>(map.entrySet());
        Collections.sort(arr, new SortEntry());
        int count = 0;
        int l = arr.size();
        for (Map.Entry<Integer, Integer> e: arr) {
            if (l <= k) break;
            count += e.getValue();
            l--;
        }
        System.out.println(count);
    }
    public static class SortEntry implements Comparator<Map.Entry<Integer, Integer>> {
        public int compare(Map.Entry<Integer, Integer> a, Map.Entry<Integer, Integer> b) {
            return a.getValue() - b.getValue();
        }
    }
}


Measured memory_bytes: 70724
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
int main()
{
 ll a,b,n;
 cin>>a>>b>>n;

 ll p=min(n,(b-1));

  cout<<((a*p)/b)-(p/b)<<"\n";
return 0;
}


Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.FileReader;
import java.io.FileWriter;

import java.util.*;
import java.util.stream.LongStream;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /* 標準入力数値配列用 long */
    static long[] inputLongArr() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        long[] longarray = new long[strarray.length];
        for (int i = 0; i < longarray.length; i++) {
            longarray[i] = Long.parseLong(strarray[i]);
        }
        return longarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer 降順ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /*標準入力long*/
    static long inputLong() throws Exception {
        return Long.parseLong(br.readLine());
    }

    /*標準入力long*/
    static int inputInt() throws Exception {
        return Integer.parseInt(br.readLine());
    }




    public static void main(String[] args) throws Exception {
        // write your code here
        int n = inputInt();
        Map<Long, Integer> map = new HashMap<>();
        int ans = 0;
        for (int i = 0; i<n; i++){
            long a = inputLong();
            map.put(a, map.getOrDefault(a,0) + 1);
        }
        for(int cnt : map.values()){
            if (cnt % 2 == 1){
                ans ++;
            }
        }

        System.out.println(ans);



    }

}



Measured memory_bytes: 52276
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=50;
const int MAXLEN=50;

int n;
char s[MAXLEN+1];
int cnt[26];
int mn[26];

void run() {
	REP(i,26) mn[i]=INT_MAX;
	scanf("%d",&n);
	REP(i,n) { scanf("%s",s); int len=strlen(s); REP(j,26) cnt[j]=0; REP(j,len) cnt[s[j]-'a']++; REP(j,26) mn[j]=min(mn[j],cnt[j]); }
	REP(i,26) REP(j,mn[i]) printf("%c",'a'+i); puts("");
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main()
{//　入力
  int n,d;
 cin >> n >> d;
vector<vector<int>> x(n,vector<int>(d));
 
 
 rep(i,n){
 rep(j,d){
 cin >> x.at(i).at(j) ;
 }
 }
 
 
 
 int count = 0;
 rep(i,n-1){    
   for (int k = i+1 ;k < n;k++){
   int sum = 0;
   double a;
   double b;
   
 
  
   rep(j,d){
  sum += (x.at(i).at(j) - x.at(k).at(j))*(x.at(i).at(j) - x.at(k).at(j));   
 }
  
 

   
   a = sqrt(sum);
   b = ceil(a);
   
  
   
   if (a == b) count++;
   }
 }
 
 
 
 

 
  
 cout << count << endl;
 
 
}

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

int main() {

    int N;
    cin >> N;

    if (N==1 || N==2 || N==3 || N==5 || N==6 || N==9 || N==10 || N==13 || N==17) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S; ll K;
vector <pair<char, ll> > V;

int main(){
  cin >> S >> K;
  ll N = S.length();

  int cnt = 1;
  for (int i = 1; i < N; i++){
    if (S[i] == S[i-1]){
      cnt++;
    }else{
      V.push_back({S[i-1], cnt});
      cnt = 1;
    }
  }
  V.push_back({S[N-1], cnt});

  if (V.size() == 1){
    cout << N * K / 2 << endl;
    return 0;
  }

  int v = V.size();
  if (V[0].fi == V[v-1].fi){
    ll ans = 0;
    for (int i = 1; i < v-1; i++) ans += V[i].se / 2;
    ans *= K;
    ans += (V[0].se + V[v-1].se) / 2 * (K - 1);
    ans += V[0].se / 2 + V[v-1].se / 2;
    cout << ans << endl;
    return 0;
  }

  ll ans = 0;
  for (int i = 0; i < v; i++) ans += V[i].se / 2;
  ans *= K;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3564
Scanf.scanf "%d %d" (fun n m ->
    let par = Array.init n (fun i -> i) in
    let count = Array.make n 1 in
    let ab = Array.init m (fun _ -> Scanf.scanf " %d %d" (fun a b -> a - 1, b - 1)) in

    let rec root x =
        if x = par.(x) then x else
            let r = root par.(x) in
            let () = par.(x) <- r in
            r
    in

    let merge a b =
        if root a <> root b then (
            count.(par.(a)) <- count.(par.(a)) + count.(par.(b));
            par.(par.(b)) <- par.(a);
        )
    in
    let inc = Array.make m 0 in

    let rec loop i cur =
        if i < 0 then inc else (
            inc.(i) <- cur;
            let a, b = ab.(i) in
            if root a <> root b then (
                let ca = count.(par.(a)) in
                let cb = count.(par.(b)) in
                merge a b;
                loop (i - 1) (cur - ca * cb)
            ) else loop (i - 1) cur
        )
    in
    Array.iter (Printf.printf "%d\n") @@ loop (m - 1) (n * (n - 1) / 2)
)

Measured memory_bytes: 11992
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#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(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];

signed main(){
	IOS;
	ll n;
	cin >> n;
	set<ll> s;
	vec<ll> a(n + 1);
	REP(i,n){
		int x;
		cin >> x;
		a[x] = i;
	}
	ll ans = 0;
	s.insert(-1);
	s.insert(n);
	for(ll i = 1;i <= n;i++){
		auto it = s.upper_bound(a[i]);
		ll r = *it,l = *(--it);
		ans += i * (r - a[i]) * (a[i] - l);
		s.insert(a[i]);
	}
	dump(ans);
}

Measured memory_bytes: 11264
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>

#define INF 100000000
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 namespace std;

int main(){
  int i,j,k,m,n=0,d,a[100];
  cin >>m>>d;

  for(i=1;i<=m;i++){
    for(j=1;j<=d;j++){
      if( (j%10) * (j/10)  == i && j%10 >=2 &&j/10>=2) {

	n++;
      }
    }

  }
  cout << n << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[101];
ll b[101];
ll dp[4][301][101];
ll sum[4][101];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n; ll w;
	cin>>n>>w;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	ll ans=0;
	for(int i=0;i<=n;i++)
	{
		vector<ll> vec[4];
		memset(dp,0,sizeof(dp));
		memset(sum,0,sizeof(sum));
		ll ww = w-ll(i)*a[0];
		ww=min(ww,3LL*i);
		if(ww<0) continue;
		for(int j=0;j<n;j++)
		{
			vec[a[j]-a[0]].pb(b[j]);
		}
		for(int j=0;j<4;j++) sort(vec[j].rbegin(),vec[j].rend());
		for(int j=0;j<4;j++)
		{
			for(int k=0;k<vec[j].size();k++)
			{
				sum[j][k]=vec[j][k];
				if(k>0) sum[j][k]+=sum[j][k-1];
			}
		}
		for(int j=0;j<vec[0].size();j++)
		{
			dp[0][0][j+1] = sum[0][j];
		}
		for(int j=0;j<3;j++)
		{
			for(int k=0;k<=ww;k++)
			{
				for(int l=0;l<=i;l++)
				{
					//cerr<<j<<' '<<k<<' '<<l<<' '<<dp[j][k][l]<<'\n';
					ll val = dp[j][k][l];
					dp[j+1][k][l]=max(dp[j+1][k][l],val);
					for(int m=0;m<vec[j+1].size();m++)
					{
						if(l+m+1<=i&&k+(j+1)*(m+1)<=ww)
						{
							dp[j+1][k+(j+1)*(m+1)][l+m+1]=max(dp[j+1][k+(j+1)*(m+1)][l+m+1],val+sum[j+1][m]);
						}
					}
				}
			}
		}
		ll an=0;
		for(int k=0;k<=ww;k++)
		{
			an=max(an,dp[3][k][i]);
		}
		//cerr<<i<<' '<<ww<<' '<<an<<'\n';
		ans=max(ans,an);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 1280
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
using ll = long long;
//#define int ll
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
int dx[] = {0,0,-1,1};
int dy[] = {1, -1,0,0};
signed main(){
    int w,h; cin >> h>> w;
    vector<vector<char>>v(h,vector<char>(w));
    rep(i,h)rep(j,w) cin >> v[i][j];
    bool flag = true;
    rep(i,h)rep(j,w){
        if(v[i][j] != '#')continue;
        bool temp  = false;
        rep(k,4){
            int x = j+dx[k];
            int y = i+dy[k];
            if((0 <= x && x < w) &&( 0<=y && y<h)){
                if(v[y][x] == '#')
                    temp = true;
            }
        }
        if(temp == false)flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int n,m;cin>>n>>m;

    VI r(n,-1);

    REP(i,m){
        int s,c;
        cin>>s>>c;
        s--;

        if(r[s] == -1){
            r[s] = c;
        }
        else if(r[s] == c){

        }
        else{
            cout << -1 << endl;
            return ;
        }
    }

    if(n != 1 && r[0] == 0){
        cout << -1 << endl;
        return ;
    }

    REP(i,n){
        if(n == 1 && i == 0 && r[i] == -1){
            cout << 0;
        }
        else if(i == 0 && r[i] == -1){
            cout << 1;
        }
        else if(r[i] == -1){
            cout << 0;
        }
        else{
            cout << r[i];
        }
    }
    cout << endl;





	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
import math
n=int(input())
l=list()
for _ in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
su=0
for i in range(n):
  for j in range(n):
    if i!=j:
      su+=math.sqrt((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)
      # print(su)
# su=su*2
print(su/n)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main (int argc,char **argv)
{
	int a,b;
	int c ,d;
	int fare = 0;
 
	scanf("%d %d %d %d",&a,&b,&c,&d);
 
	if (((1 <= a)&&(a <= 1000))&&((1 <= b)&&(b <= 1000))&&((1 <= c)&&(c <= 1000))&&((1 <= d)&&(d <= 1000)))
	{
	if ((a <= b) && (c <= d))
	{
		fare = a + c;
	}
 
	else if((a < b)&&(c > d))
	{
		fare = a + d;
	}
 
	else if ((a > b) && (c < d))
	{
		fare = b + c;
	}
 
	else
	{
		fare = b + d;
	}
 
	printf("%d\n",fare);
}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  string s;
  cin >> n >> s;
  mat dp(n+1,vec(n+1));
  for(ll i=0;i<n;i++) dp[0][i]=1;
  for(ll i=0;i<n-1;i++) {
    vec sum(3010);
    for(ll j=0;j<n-i;j++) {
      sum[j+1]=(sum[j]+dp[i][j])%mod;
    }
    for(ll j=0;j<n;j++) {
      if(s[i]=='>') {
        dp[i+1][j]=sum[j+1];
      }
      else {
        dp[i+1][j]=(sum[n-i]-sum[j+1]+mod)%mod;
      }
    }
  }
  cout << dp[n-1][0] << endl;
}

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

int main() {
  int n, ans;
  ans = 0;
  cin >> n;
  vector<int> a(n);
  bool loop = true;

  for (int i = 0; i < n; i++) cin >> a.at(i);

  while(loop == true) {
    
    for (int i = 0; i < n; i++) {
      if (a.at(i) % 2 == 0) a.at(i) /= 2;
      else {
        loop = false;
        break;
      }
    }
    if (loop != false) ans += 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);
		String str1 = scan.next();


		if(str1.equals("a") || str1.equals("i") ||str1.equals("o") ||str1.equals("u") ||str1.equals("e"))
			System.out.println("vowel");
		else
			System.out.println("consonant");

	}
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int h = Integer.parseInt(str[0]);
    int w = Integer.parseInt(str[1]);

    for(int i=0; i<w+2; i++) {
      System.out.print("#");
    }

    System.out.println();
    
    for(int i=0; i<h; i++) {
      String a = in.readLine();
      System.out.print("#");
      System.out.print(a);
      System.out.println("#");
    }

    for(int i=0; i<w+2; i++) {
      System.out.print("#");
    }
  }
}

Measured memory_bytes: 33288
import java.util.*;import java.io.*;import java.math.*;

public class Main
{

    public static void process()throws IOException
    {
        int n=ni(),arr[]=new int[n+1];
        for(int i=1;i<=n;i++)
            arr[i]=ni();

        int mx1=0,mx2=0;

        for(int i=1;i<=n;i++){
            if(arr[i]>=mx1){
                mx2=mx1;
                mx1=arr[i];
            }
            else if(arr[i]>mx2)
                mx2=arr[i];
        }

        for(int i=1;i<=n;i++)
            pn((arr[i]==mx1)?mx2:mx1);
    }


    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();

        long s = System.currentTimeMillis();
        int t=1;
        //t=ni();
        while(t-->0)
            process();

        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }
    
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;
    static long mod=(long)1e9+7l;

    static<T> void r_sort(T arr[],int n){
        Random r = new Random(); 
        for (int i = n-1; i > 0; i--){ 
            int j = r.nextInt(i+1); 
                  
            T temp = arr[i]; 
            arr[i] = arr[j]; 
            arr[j] = temp; 
        } 
        Arrays.sort(arr); 
    }
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } 
            catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

Measured memory_bytes: 48192
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

#n,m = ips()
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
b = []
for i in range(n):
    b.append(iprow())
a = []
for i in range(n):
    c = [sum(b[i]),b[i][0],b[i][1]]
    a.append(c)
a.sort(reverse=True)
s = 0
ct = 0
for i in range(n):
    a[i][2]*=-1
for i in a:
    s+=i[ct+1]
    ct+=1
    ct%=2
print(s)

Measured memory_bytes: 47844
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n;cin>>n;
    vll a(n+2);
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    a[0]=0;
    a[n+1]=0;
    ll ans=0;
    rep(i,n+1){
        ans+=abs(a[i+1]-a[i]);
    }

    for(int i=1;i<=n;i++){
        ll sum=ans;
        sum=sum+abs(a[i-1]-a[i+1])-abs(a[i-1]-a[i])-abs(a[i+1]-a[i]);
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,h,m;
  cin >> a >> b >> h >> m;
  double bdeg = 6 * m;
  double brad = bdeg * M_PI / 180.0;
  double adeg = 30 * h + 0.5 * m;
  double arad = adeg * M_PI / 180.0;

//  cout << "bdeg" << bdeg << endl << "adeg" << adeg << endl;
  double bx = b * cos(brad);
    double by = b * sin(brad);
  double ax = a * cos(arad);
  double ay = a * sin(arad);
  cout << fixed;

  cout << setprecision(20) << sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by)) << endl;
}


Measured memory_bytes: 4120
import collections

n = int(input())
v = list(map(int, input().split()))
even_odd_length = n / 2
replace_total = 0

list_odd = v[0::2]
list_even = v[1::2]

dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))
dict_c_even_bk = dict_c_even.copy()
dict_c_odd_bk = dict_c_odd.copy()

replace_total_tmp = 0
replace_total_tmp2 = 0
max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even
max_c_odd_keys = [k for k, v in dict_c_odd.items() if v == max_count_c_odd]
max_c_even_keys = [k for k, v in dict_c_even.items() if v == max_count_c_even]

if len(set(v)) == 1:
    print(int(even_odd_length))
else:    
    if max_c_odd_keys[0] in dict_c_even:
        del dict_c_even[max_c_odd_keys[0]]
    max_count_c_even = max(dict_c_even.values())
    replace_total_tmp = (n - max_count_c_odd - max_count_c_even)
    
    dict_c_even = dict_c_even_bk
    max_count_c_even = max_count_c_even_bk
    
    if max_c_even_keys[0] in dict_c_odd:
        del dict_c_odd[max_c_even_keys[0]]
    max_count_c_odd = max(dict_c_odd.values())
    replace_total_tmp2 = (n - max_count_c_odd - max_count_c_even)
    
    if replace_total_tmp >= replace_total_tmp2:
         replace_total = replace_total_tmp2
    else:
         replace_total = replace_total_tmp
    print(replace_total)

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int safe(int x, int T) {
    return max(0, min(x, T));
}

void fill(vector<vector<int>> &v, int x, int y, int K) {
    int right = safe(x + 1, 2*K);
    int left = safe(x + 1 - K, 2*K);
    int top = safe(y + 1, 2*K);
    int bot = safe(y + 1 - K, 2*K);

    v[right][top]++;
    v[left][bot]++;
    v[left][top]--;
    v[right][bot]--;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<vector<int>> diff(2*K + 1, vector<int>(2*K + 1, 0));

    REP(i, N) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        if(c == 'W') {
            x += K;
        }
        x %= 2*K;
        y %= 2*K;
        FOR(s, -2, 3) {
            FOR(t, -2, 3) {
                if((s + t + 334)%2 == 0) {
                    fill(diff, x + s*K, y + t*K, K);
                }
            }
        }
    }
    vector<vector<int>> s(2*K + 1, vector<int>(2*K + 1, 0));
    s[0][0] = diff[0][0];
    int res = s[0][0];
    FOR(i, 1, 2*K + 1) {
        s[i][0] = diff[i][0] + s[i - 1][0];
        s[0][i] = diff[0][i] + s[0][i - 1];
        res = max({res, s[i][0], s[0][i]});
    }

    FOR(i, 1, 2*K + 1) {
        FOR(j, 1, 2*K + 1) {
            s[i][j] = diff[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
            res = max(res , s[i][j]);
        }
    }
    cout << res << endl;
    return 0;
}


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

int main() {
  int n; ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<int> s;
  vector<int> ord(n+1,-1);
  int c = 1, l = 0;
  {
    int v = 1;
    while (ord[v] == -1) {
      ord[v] = s.size();
      s.push_back(v);
      v = a[v-1];
    }
    c = s.size() - ord[v];
    l = ord[v];
  }

  if (k < l) cout << s[k] << endl;
  else {
    k -= l;
    k %= c;
    cout << s[l+k] << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

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

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

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

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

string dp[10010];

ll cost[10] = {8, 2, 5, 5, 4, 5, 6, 3, 7, 6};

string max_string(string a, string b){
    if(a.size() > b.size()){
        return a;
    }
    else if(a.size() < b.size()){
        return b;
    }
    // 同じ長さ
    else{
        if(a[0] > b[0]){
            return a;
        }else{
            return b;
        }
    }
}

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

    // input
    ll N, M;
    cin >> N >> M;

    // pn(N);

    vector<ll> A(M);
    FOR(i, 0, M){
        cin >> A.at(i);
    }
    sort(ALL(A));
    // vprint(A);
    
    dp[0] = "";
    dp[1] = "";
    FOR(i, 2, 10010){
        // if(i==3){
        //     break;
        // }

        dp[i] = "";
        for(ll a : A){
            // pn(a);
            ll c = cost[a];
            if(i>=c){

                // pn(a);
                // pn(c);
                // pn(i);
                // pn(i>=c);
                // pn(to_string(a) + dp[i-c]);
                // return 0;
                
                // コストピッタリ
                if(i==c){
                    dp[i] = max_string(dp[i], to_string(a));
                    
                }else{
                    if(dp[i-c]==""){
                        //
                    }else{
                        dp[i] = max_string(dp[i], to_string(a) + dp[i-c]);
                    }

                }
            }
        }
    }

    // string s = max_string("1", "71");
    // pn(s);

    // p("");
    // p("result");
    // FOR(i, 0, 21){
    //     cout << i << " " << dp[i] << endl;
    // }

    p(dp[N]);
    
    return 0;
}

Measured memory_bytes: 32512
from operator import itemgetter as get

class UnionFind():
	def __init__(self, n):
		self.n = n
		self.root = [-1] * (n + 1)
		self.rank = [0] * (n + 1)

	def find(self, x):
		if self.root[x] < 0:
			return x
		else:
			self.root[x] = self.find(self.root[x])
			return self.root[x]

	def unite(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return 0
		elif self.rank[x] > self.rank[y]:
			self.root[x] += self.root[y]
			self.root[y] = x
		else:
			self.root[y] += self.root[x]
			self.root[x] = y
			if self.rank[x] == self.rank[y]:
				self.rank[y] += 1

	def isSame(self, x, y):
		return self.find(x) == self.find(y)

	def size(self, x):
		return -self.root[self.find(x)]


def main():
	n, *L = map(int, open(0).read().split())
	x_order = sorted([(x, y, i) for i, (x, y) in enumerate(zip(*[iter(L)] * 2))])
	con = []
	for p1, p2 in zip(x_order, x_order[1:]):
		con.append((p1[2], p2[2], min(abs(p1[0] - p2[0]), abs(p1[1] - p2[1]))))
	y_order = sorted(x_order, key=get(1))
	for p1, p2 in zip(y_order, y_order[1:]):
		con.append((p1[2], p2[2], min(abs(p1[0] - p2[0]), abs(p1[1] - p2[1]))))
	uf = UnionFind(n)
	ans = 0
	for i, j, c in sorted(con, key=get(2)):
		if uf.isSame(i, j):
			continue
		ans += c
		uf.unite(i, j)
	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 54788
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

const int mod = 1000000007;
int N;
int dp[305][305][305];
vector<int> ed[305][4];
int m;

bool chk(int x,int y,int z)
{
	int maxn = 0;
	for(auto i : ed[x][1])
		if(i <= y) return false;
	for(auto i : ed[x][2])
		if(i <= z || i > y) return false;
	for(auto i : ed[x][3])
		if(i > z) return false;
	return true;
}

int main()
{
	scanf("%d%d",&N,&m);
	for(int i = 1;i <= m; ++ i)
	{
		int l,r,c; scanf("%d%d%d",&l,&r,&c);
		ed[r][c].push_back(l);
	}
	for(int i = 1;i <= N; ++ i)
		for(int j = 1;j <= 3; ++ j)
			sort(ed[i][j].begin(),ed[i][j].end());
	dp[0][0][0] = 1;
	long long ans = 0;
	for(int i = 0;i <= N; ++ i)
		for(int j = 0;j <= i; ++ j)
			for(int k = 0;k <= j; ++ k)
			{
				if(!chk(i,j,k)) dp[i][j][k] = 0;
				if(i == N) ans = (ans + dp[i][j][k]) % mod;
				dp[i + 1][j][k] += dp[i][j][k];
				dp[i + 1][i][k] += dp[i][j][k];
				dp[i + 1][i][j] += dp[i][j][k];
				dp[i + 1][j][k] %= mod;
				dp[i + 1][i][k] %= mod;
				dp[i + 1][i][j] %= mod;
			}
	printf("%lld\n",ans);
}

Measured memory_bytes: 108928
import java.util.*;
public class Main {
	public static void main(String args[]){
    	Scanner s = new Scanner(System.in);
    	int N = s.nextInt();
      	int arr[][] = new int[N][3];
      	for(int i=0;i<N;i++){
        	arr[i][0] = s.nextInt();
          	arr[i][1] = s.nextInt();
          	arr[i][2] = s.nextInt();
        }
      	int ans = ans(arr,N);
      	System.out.println(ans);
    }
  	public static int ans(int[][] arr, int N){
      	if(N<=0)
          	return 0;
      	
      	for(int i=1;i<N;i++){
        	arr[i][0] += Math.max(arr[i-1][1],arr[i-1][2]);
          	arr[i][1] += Math.max(arr[i-1][0],arr[i-1][2]);
          	arr[i][2] += Math.max(arr[i-1][0],arr[i-1][1]);
        }
      	
    	int max = 0;
      	for(int k=0;k<3;k++){
        	max = Math.max(max, arr[N-1][k]);
        }
      	return max;
    }
}

Measured memory_bytes: 94964
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

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

using mint = Mint<>;

int main() {

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

	Int N;
	cin >> N;

	vector<Int> A(N);
	for (Int i = 0; i < N; i++) {
		cin >> A[i];
	}

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

	Int temp = A[0];
	Int cnt = 0;
	Int num = 0;
	Int diff = 0;
	//vector<Int> card(N);
	for (Int i = 0; i < N; i++) {
		if (A[i] == temp) {
			cnt++;
		}
		if(A[i]!=temp){
			//card[num] = cnt;
			diff += cnt - 1;
			temp = A[i];
			num++;
			cnt = 1;
		}
		//if (i == N - 1) {
		//	//card[num] = cnt;
		//	diff += cnt - 1;
		//}
	}

	diff += cnt - 1;

	/*Int diff = 0;
	for (Int i = 0; i <= num; i++) {
		diff += card[i] - 1;
	}*/

	cout << (diff % 2 ? num : num + 1) << "\n";

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  if((B-A)%2==0){
    cout << (B-A)/2 << endl;
  }else{
    if(N-A<=B-1){
      cout << N+1-B + (N-(A+(N+1-B)))/2 << endl;
    }else{
      cout << A + ((B-A)-1)/2 << endl;
    }
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

main(){
    int n=in(),m=in();
    vecll a;
    rep(i,n)a.pb(in());
    UnionFind uf(n);
    rep(i,m){
        int x=in(),y=in();
        uf.unite(x,y);
    }
    vector<vecll> v(n);
    int sz=0;
    rep(i,n){
        v[uf.find(i)].pb(a[i]);
        if(uf.find(i)==i)sz++;
    }
    sz=(sz-1)*2;
    if(sz==0){
        cout<<0<<endl;return 0;
    }
    // cout<<sz<<endl;
    vecll s;
    ll ans=0;
    rep(i,n){
        if(v[i].size()==0) continue;
        sort(all(v[i]));
        ans+=v[i][0];
        sz--;
        rep2(j,1,v[i].size()-1)s.pb(v[i][j]);
    }
    sort(all(s));
    if(s.size()<sz)cout<<"Impossible\n";
    else{
        rep(i,sz)ans+=s[i];
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    string s;
    cin>>s;
    string ans="Sunny";
    if(s=="Sunny"){
        ans="Cloudy";
    }else if(s=="Cloudy"){
        ans="Rainy";
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define mod 1e9+7

int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);    
              int n;
                cin>>n;
             vector<int>v(n),p(n),q(n);
             for(int i=0; i<n; i++)
               {cin>>p[i];
                  v[i]=i+1;
               }
               for(int i=0; i<n; i++)
               {
                   cin>>q[i];
               }
            int k=0,pi,qi;   
        do{
           k++;
           if(v==p)
             {  pi=k;
             }
             if(v==q)
              qi=k;
        }while(next_permutation(v.begin(),v.end()) );
        
        cout<<abs(pi-qi)<<endl;
    }


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int  N; cin >> N;
    int ans = 0;
    int base = 0;

    int cnt[3] = {0}; // 0: B**A, 1: B***, 2: ***A

    for (int i = 0;i < N;i++){
        string s; cin >> s;
        if(s[0] == 'B' && s[s.size()-1] == 'A') cnt[0]++;
        else if(s[0] == 'B') cnt[1]++;
        else if(s[s.size()-1] == 'A') cnt[2]++;
        for (int j = 0;j < s.size()-1;j++){
            if(s[j] == 'A' && s[j+1] == 'B') base++;
        }
    }

    if(cnt[2] != 0){
        if(cnt[1] != 0) ans = max(ans, cnt[0]+1+min(cnt[1]-1,cnt[2]-1));
        else ans = max(ans,cnt[0]);
    }else if(cnt[0] != 0){
        if(cnt[1] != 0) ans = max(ans, cnt[0]);
        else ans = max(ans, cnt[0]-1);
    }

    if(cnt[1] != 0){
        if(cnt[2] != 0) ans = max(ans, cnt[0]+1+min(cnt[1]-1,cnt[2]-1));
        else ans = max(ans,cnt[0]);
    }else if(cnt[0] != 0){
        if(cnt[2] != 0) ans = max(ans, cnt[0]);
        else ans = max(ans, cnt[0]-1);
    }

    cout << ans+base << endl;

    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n, s;
    scanf("%d", &n);
    int ns[n];
    for (int i=0; i<n; i++) {
        scanf("%d", &ns[i]);
    }
    
    scanf("%d", &s);
    int ss[s];
    for (int i=0; i<s; i++) {
        scanf("%d", &ss[i]);
    }
    
    int c = 0;
    int left, mid, right;
    
    for (int i=0; i<s; i++) {
        left = 0;
        right = n-1;
        while (left <= right) {
            mid = (left+right)/2;
            if (ss[i] == ns[mid]) {
                c++;
                break;
            } else if (ss[i] < ns[mid]) {
                right = mid-1;
            } else if (ss[i] > ns[mid]) {
                left = mid+1;
            }
        }
    }
    
    printf("%d\n", c);
}



Measured memory_bytes: 2252
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long N, M;
        public long[] S;
        public long[] A;
        public Dictionary<long, long> Dic;
        public void Run()
        {
            // インプット
            {
                var line = Input.ReadLongArray();
                N = line[0];
                M = line[1];
            }

            A = Input.ReadLongArray();

            // 累積和
            S = new long[N+1];
            S[0] = 0;
            for (long i = 0; i < N; i++)
            {
                S[i + 1] = A[i] + S[i];
                S[i + 1] %= M;
            }

            // カウント
            long ret = 0;
            Dic = new Dictionary<long, long>();
            for (int i = 0; i <= N ; i++)
            {
                long v = S[i];
                if (!Dic.ContainsKey(v))
                    Dic.Add(v, 0);
                Dic[v]++;
            }

            for (int i = 0; i <= N; i++)
            {
                long v = S[i];
                if (Dic.ContainsKey(S[i])) ;
                ret += Dic[v];
            }

            ret -= (N + 1);
            Console.WriteLine(ret / 2);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 25952
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x)
{
  if(x<0)PUT('-'),x=-x;
  int d[40],i=0;do{d[i++]=x%10;}while(x/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
const int MOD=1e9+7;
int fact[1000001]={0},inv[1000001]={0};
static inline int ModPow(int a,int b){return b?1l*ModPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
static inline void init(int sz)
{
  sz++;fact[0]=1;rep(i,sz-1)fact[i+1]=1l*fact[i]*(i+1)%MOD;
  inv[sz-1]=ModPow(fact[sz-1],MOD-2);
  rep(i,sz-1)inv[sz-2-i]=1l*inv[sz-1-i]*(sz-1-i)%MOD;
}
static inline int comb(const int n,const int k){if(k<0||n<k){return 0;}return 1l*fact[n]*inv[n-k]%MOD*inv[k]%MOD;}
static inline int P(const int n,const int k){if(k<0||n<k){return 0;}return 1l*fact[n]*inv[n-k]%MOD;}
int main(void)
{
  int S=IN();long A=0;init(S);
  rep(i,S/3){A=(A+1l*comb(S-(i+1)*3+i,S-(i+1)*3))%MOD;}
  return OUT(A),0;
}

Measured memory_bytes: 1544