akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
 int N,M;
 cin >> N >> M;
  vector<long long> price(N);
  for(int i = 0; i < N; i++){
   cin >> price.at(i);
  }
  priority_queue<long long> kakaku;
  for(int i = 0; i < N; i++){
   kakaku.push(price[i]);
  }
   while(M > 0){
    int a = kakaku.top();
    kakaku.pop();
    kakaku.push(a/2);
     M--;
   }
  long long sum = 0;
   while(!kakaku.empty()){
   sum += kakaku.top();
   kakaku.pop();
  }
  cout << sum << endl;
}


Measured memory_bytes: 2168
#include "bits/stdc++.h"
using namespace std;
template<typename T> struct Dinitz{
	int n, source, sink;
	vector<vector<T>> adj;
	struct edge {
		int u;
		T flow, cap;
	};
	vector<edge> edges;
	Dinitz(int n, int source, int sink): n(n), source(source), sink(sink), adj(n) {}
	int add_edge(int a, int b, T abcap, T bacap = 0) {
		int result = edges.size();
		adj[a].push_back(edges.size());
		edges.push_back({b, 0, abcap});
		adj[b].push_back(edges.size());
		edges.push_back({a, 0, bacap});
		return result;
	}
	vector<int> mindist, position;
	bool bfs() {
		queue<int> q;
		fill(mindist.begin(), mindist.end(), INT_MAX / 2);
		mindist[source] = 0;
		q.push(source);
		while (!q.empty()) {
			int v = q.front();
			q.pop();
			for (int edid: adj[v]) {
				edge &ed = edges[edid];
				if (ed.flow < ed.cap && mindist[ed.u] > mindist[v] + 1) {
					mindist[ed.u] = mindist[v] + 1;
					q.push(ed.u);
				}
			}
		}
		return mindist[sink] < n;
	}
	T dfs(int v, T maxf) {
		if (v == sink) return maxf;
		for (int &pos = position[v]; pos < (int)adj[v].size(); ++pos) {
			int edid = adj[v][pos];
			edge &ed = edges[edid], &reved = edges[edid ^ 1];
			if (ed.flow < ed.cap && mindist[ed.u] == mindist[v] + 1) {
				T f = dfs(ed.u, min(maxf, ed.cap - ed.flow));
				if (f > 0) {
					ed.flow += f;
					reved.flow -= f;
					return f;
				}
			}
		}
		return 0;
	}
	T maxflow() {
		T result = 0;
		mindist.resize(n);
		position.resize(n);
		while (bfs()) {
			T extra;
			do {
				fill(position.begin(), position.end(), 0);
				extra = dfs(source, numeric_limits<T> :: max());
				result += extra;
			} while (extra > 0);
		}
		return result;
	}
};
const int maxn = 222;
int x[maxn], y[maxn];
int main(){
    int n;
    cin >> n;
    for(int e = 0; e < 2 * n; e++) cin >> x[e] >> y[e];
    int sourc = 2 * n, sink = 2 * n + 1;
    Dinitz<int> cn(2 * n + 2, sourc, sink);
    for(int e = 0; e < n; e++){
        for(int f = n; f < 2 * n; f++){
            if(x[e] < x[f] && y[e] < y[f]){
                cn.add_edge(e, f, 1);
            }
        }
    }
    for(int e = 0; e < n; e++) cn.add_edge(sourc, e, 1);
    for(int e = n; e < 2 * n; e++) cn.add_edge(e, sink, 1);
    cout << cn.maxflow() << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n = s.size();
    int f = n/2;
    int l = f+1;

    string s1 = s;
    reverse(s.begin(),s.end());
    bool b = true;
    if(s1==s){
        s1 = s.substr(0,f);
        string s2 = s.substr(l,n);
        reverse(s1.begin(),s1.end());
        reverse(s2.begin(),s2.end());
        //cout << s1 << " " << s2 << endl;
        if(s1 == s.substr(0,f) && s2 == s.substr(l,n)) {
            cout << "Yes\n";
            b=false;
        }
    }
    if(b) {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;
const double PI = (acos(-1));
const long long MOD = pow(10, 9) + 7;
long long kaizyou(int N);
long long POW(int J);

int main()
{
    int N,A,B;
    cin >> N >> A >> B;

    int j,k;
    j = A*N;
    k = B;

    if(j > k)
    {
        cout << k;
    }  else
    {
        cout << j;
    }
    
    

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b;map<int,int>M[220000];
int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;M[a][b]=1;M[b][a]=1;
    }
    for(int i=2;i<=n-1;i++){
        if(M[1][i]==1 && M[i][n]==1){cout<<"POSSIBLE"<<endl;return 0;}
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 38656
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int mod_exp(ll x,ll pow)
{
    if(pow==0) return 1;
    ll res=mod_exp((x*x)%mod,pow/2);
    if(pow%2)res*=x;
    return res%mod;
}


ll EE(ll a, ll b, ll *x, ll *y)
{
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = EE(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

ll inverse(ll a, ll m)
{
    ll x,y;
    EE(a,m,&x,&y);
    if(x<0) x += m;
    return x;
}

ll choose(ll n,ll k)
{
	ll i;
	ll num=1,den=1;
	for(i=2;i<=k;i++)
	{
		den*=i;
		den%=mod;
	}
	for(i=n-k+1;i<=n;i++)
	{
		num*=i;
		num%=mod;
	}
	i=num*inverse(den,mod);
	i%=mod;
	return i;
}

int main()
{
    
    int n,i,j,t;
    boost;
    int a,b;
    cin>>n>>a>>b;

    ll ans=mod_exp(2,n)-1-choose(n,a)-choose(n,b);
    ans%=mod;
    if(ans<0)ans+=mod;
    cout<<ans;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };





signed main() {
	int l, m, n, cnt = 0, maxn=-19999999, minn=199999999;
	string s;
	vector<int>listb;
	vector<int>list;
	vector<string>slist;
	int h, w, c;
	vector<vector<int>>mat(33, vector<int>(33, 0));

	
	cin >> n >> m >> c;

	for (int i = 0; i < m; i++) {
		int num;
		cin >> num;
		listb.push_back(num);
	}


	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int num;
			cin >> mat[i][j];
		}
	}


	for (int i = 0; i < n; i++) {
		int num = 0;

		for (int j = 0; j < m; j++) {
			
			 num += mat[i][j] * listb[j];

		}
		num += c;

		if (num > 0) {
			cnt++;
		}
	}

	cout << cnt << endl;



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  cin >> n >> m;
  vector<string> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<vector<int>> up(n, vector<int>(m, 0)), left(n, vector<int>(m, 0));
  vector<vector<int>> down(n, vector<int>(m, 0)), right(n, vector<int>(m, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '.') {
        up[i][j] += (i ? up[i - 1][j] : 0) + 1;
      }
      else {
        up[i][j] = 0;
      }
      if (a[n - 1 - i][j] == '.') {
        down[n - 1 - i][j] += (i ? down[n - i][j] : 0) + 1;
      }
      else {
        down[n - 1 - i][j] = 0;
      }
      if (a[i][j] == '.') {
        left[i][j] += (j ? left[i][j - 1] : 0) + 1;
      }
      else {
        left[i][j] = 0;
      }
      if (a[i][m - 1 - j] == '.') {
        right[i][m - 1 - j] += (j ? right[i][m - j] : 0) + 1;
      }
      else {
        right[i][m - 1 - j] = 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      ans = max(ans, up[i][j] + down[i][j] + left[i][j] + right[i][j] - 3);
    }
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 67328
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    int a,b;
    char c;
    while(true){
        cin>>a>>c>>b;
        if(c=='+'){
            cout<<a+b<<endl;
        }
        if(c=='-'){
            cout<<a-b<<endl;
        }
        if(c=='*'){
            cout<<a*b<<endl;
        }
        if(c=='/'){
            cout<<a/b<<endl;
        }
        if(c=='?'){
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;


signed main(){
  ios::sync_with_stdio(false);cin.tie(0);
  int A , B;
  cin >> A >> B;
  int G = __gcd(A,B);
  int ans = 1;
  vector<int>d;

  for(int i=1;i*i <= G;i++){
    if(G % i == 0){
       d.push_back(i);
       if(G / i != i){
         d.push_back(G/i);
       }
    }
  }
  sort(d.begin() , d.end());
  dg(d);
  vector<int>vis(2e6 , 0);
  for(int i=1;i<sz(d);i++){
    if(vis[i]) continue;
    ans++;
    for(int j=i;j<sz(d);j++){
      if(d[j] % d[i] == 0) {
        vis[j] = 1;
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 16128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, i;
  unsigned long long int count = 0;
  cin >> N;
  for(i = 1; i <= N; i++){
    if(i % 3 != 0 && i % 5 != 0) count += i;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

int main(){
   string s;
   cin >> s;
   s[s.size() + 1] = 'F';
   int ans[s.size()];
   rep(i, s.size()) ans[i] = 0;
   int point;
   int c = 0,cr = 0, cl = 0;
   while(c <= s.size()){
       if(s[c] == 'R') cr++;
       else if(s[c] == 'L') cl++;
       if(s[c] == 'R' && s[c+1] == 'L') point = c;

       if((s[c] == 'L' && s[c+1] == 'R')|| (s[c] == 'L' && s[c+1] == 'F')){
           if((cl + cr) % 2 == 0){
               ans[point] = (cl + cr) / 2;
               ans[point+1] = (cl + cr) / 2;
           }
           else{
               if(cr % 2 == 0){
                   ans[point] = (cl + cr -1) / 2;
                   ans[point + 1] = ((cl + cr -1) / 2) + 1;
               }else{
                   ans[point + 1] = (cl + cr -1) / 2;
                   ans[point] = ((cl + cr -1) / 2) + 1;
               }
           }
           cr = 0;
           cl = 0;
       }
       if(c == s.size()){
           if((cl + cr) % 2 == 0){
               ans[point] = (cl + cr) / 2;
               ans[point+1] = (cl + cr) / 2;
           }
           else{
               if(cr % 2 == 0){
                   ans[point] = (cl + cr -1) / 2;
                   ans[point + 1] = ((cl + cr -1) / 2) + 1;
               }else{
                   ans[point + 1] = (cl + cr -1) / 2;
                   ans[point] = ((cl + cr -1) / 2) + 1;
               }
               cr = 0;
               cl = 0; 
            }
       }
       c++;
   }
   rep(i, s.size()){
       cout << ans[i];
       cout << " ";
   }
}

Measured memory_bytes: 1024
# coding:utf-8


def main():
    N = int(input())
    value = list(map(int, input().split()))
    cost = list(map(int, input().split()))
    ans = 0
    for i in range(len(value)):
        if value[i] > cost[i]:
            ans += (value[i]-cost[i])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
//FactorsofFactorial.cpp (C)
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
  int N;
  long long Ans = 1;
  cin >> N;
  map<int, int> G;
  for(int i = 2; i <= N; i++){
    int a = i;
    do{
      for(auto x: G){
        if(a%x.first==0){
          a /= x.first;
          ++G[x.first];
          break;
        }
      }
    }while(a>1&&a!=i);

    if(a==i) ++G[a];
  }

  for(auto x: G){
    Ans *= x.second+1;
    if(Ans >= 1000000007) Ans %= 1000000007;
  }

  printf("%lld\n",Ans);
  return 0;


}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int cnt = 0;
        String ptn = scn.next();
        while(scn.hasNext()) {
            cnt += ptn.equalsIgnoreCase(scn.next()) ? 1 : 0;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 26108
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A = sorted(A, reverse=True)
    if N==2:
        print(A[0])
        return

    i = 0
    while(pow(2,i)<N): i+=1
    # print(A)

    rem = N-2**(i-1)
    if rem%2 == 1: od = 1
    else: od = 0
    # print(A[:2**(i-2)])
    ans = sum(A[:2**(i-2)])*2 - A[0]
    # print(ans)
    # print(A[2**(i-2):2**(i-2)+rem//2])
    ans+= sum(A[2**(i-2):2**(i-2)+rem//2])*2
    # print(ans)

    if od:
        ans+= A[2**(i-2)+rem//2]
    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

typedef long long lglg;

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

	string msg; cin >> msg;
	string result = "Yes";
	for (int i=0; i<msg.size(); i+=2) {
		if (msg[i] == 'L') {
			result = "No";
			break;
		}
	}
	if (result == "Yes") {
		for (int i=1; i<msg.size(); i+=2) {
			if (msg[i] == 'R') {
				result = "No";
				break;
			}
		}
	}
	cout << result;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n;
  
  scanf("%d",&n);
  
  int ans;
  
  ans=sum(n);
  
  printf("%d\n",ans);
  
  return 0;
}

int sum(int x)
{
  if(x==1)
  {
    return 1;
  }
  else
  {
return x+sum(x-1);
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
int main()
{
  int a,b,c;
  double PI=acos(-1);
  
  cin>>a>>b>>c;
  double radc=PI*c/180;
  double s,l,h;
  s=a*b*sin(radc)/2;
  l=a+b+fabs(sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(radc)));
  h=2*s/a;
  printf("%f\n%f\n%f\n",s,l,h);
  return 0;
}


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


void solve(string X){
	ll sc = 0, c = 0, N = X.length();
	rep(i, N) {
		if (X[i] == 'S') sc++; else {
			if (sc > 0) {
				sc--;
				c++;
			}
		}
	}
	cout << N-2*c << endl;
}

int main(){	
	string X;
	cin >> X;
	solve(X);
	return 0;
}



Measured memory_bytes: 772
x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

sumAB = sorted([ai + bi for ai in a for bi in b],reverse=True)[:k]
final_ans = sorted([ci + abi for ci in c for abi in sumAB],reverse = True)[:k]

for i in range(k):
    print(final_ans[i])

Measured memory_bytes: 186200
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, n; cin >> k >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  ll mx = (k-A[n-1])+A[0];
  rep(i, n-1) chmax(mx, A[i+1]-A[i]);
  cout << k-mx << endk;
  return 0;
}


Measured memory_bytes: 4764
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int cnt[101010];
int a[101010];

int main() {
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		cnt[a[i]]++;
		cnt[a[i]-1]++;
		cnt[a[i]+1]++;
	}
	int ans = 0;
	REP(i, 101010)ans = max(ans, cnt[i]);
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int v[500500],w[500500];;
vvi rn;
int nz[1050000];
bitset<1050000> bs;
const ll M = 1e9+7;
ll mul(ll a, ll b) {return a*b%M;}
ll bp(ll b, ll p) {
	ll ac = 1;
	while(p) {
		if(p&1) {ac = mul(ac,b);}
		b = mul(b,b);
		p >>= 1;
	}
	return ac;
}
int main() {
	ios::sync_with_stdio(0);
	memset(nz,0,sizeof(nz));
	vvi rn(1048577,vi(1,0));
	int n;
	cin >> n;
	int x = 0;
	int ct = 0;
	for(int i=0;i<n;i++) {
		int t;
		cin >> t;
		v[i] = t;
		x ^= t;
		w[i] = x;
		if(x == 0) {ct++;} else {
			if(nz[x] < ct) {rn[x].push_back(ct-nz[x]);rn[x].push_back(0);}
			rn[x][rn[x].size()-1]++;
			nz[x] = ct;
		}
	}
	ll f = w[n-1];
	ll tot = 0;
	if(f != 0) {
		ll dp[2] = {0,1};
		int cu = 0;
		for(int i=rn[f].size()-2;i>=0;i--) {
			dp[cu] += rn[f][i]*dp[1-cu];
			dp[cu] %= M;
			cu = 1-cu;
		}
		tot += dp[1-cu];
	} else {
		tot += bp(2,ct-1);
		for(int i=0;i<n;i++) {
			if(!w[i]) continue;
			if(bs[w[i]]) continue;
			bs.set(w[i]);
			int val = w[i];
			ll dp[2] = {0,1};
			ll cu = 0;
			for(int i=rn[val].size()-1;i>=0;i--) {
				dp[cu] += rn[val][i]*dp[1-cu];
				dp[cu] %= M;
				cu = 1-cu;
			}
			tot += dp[1-cu];
			tot %= M;
		}
	}
	tot = ((tot%M)+M)%M;
	cout << tot << '\n';

}


Measured memory_bytes: 70400
//@source : 
//@create : 15:17:48 Tuesday 30/06/2020
//@author : nghethuat102
//@status : 
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int x, y;
    cin >> x >> y;
    for (int crane = 0; crane <= x; ++crane) {
        if (crane * 2 + (x - crane) * 4 == y) {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    while (t--) {
        solve();
    }
   // cerr << fixed << setprecision(5) << double(clock()) * 1000 / CLOCKS_PER_SEC << " ms\n";
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, s);
  rep(i, 0, (int)s.length() - 1) {
    if (s[i] == s[i + 1]) {
      i++;
      print(i, i + 1);
      return;
    }
  }
  rep(i, 0, (int)s.length() - 2) {
    if (s[i] == s[i + 2]) {
      i++;
      print(i, i + 2);
      return;
    }
  }
  print("-1 -1");
}


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG //test only

#include<bits/stdc++.h>
using namespace std;

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
typedef pair<ll,ll> P;
#define MIN -12345678901234567

int main()
{
  int n;
  ll c;
  cin >> n >> c;
  vector<ll> x(n);
  vector<ll> y(n);
  int i;
  rep(i,n) cin >> x[i] >> y[i];
  vector<ll> vals(n);
  vals[0] = y[0]-x[0];
  ll now = x[0];
  rep(i,n-1)
  {
    vals[i+1] = vals[i]+y[i+1]-(x[i+1]-now);
    now = x[i+1];
  }
  ll ans = 0;
  ll sl = MIN;
  ll vsum = 0;
  for(i=n-1;i>=0;i--)
  {
    ans = max(ans,vals[i]);
    if(i != n-1)
    {
      ll kans = vals[i]-x[i]+sl; 
      ans = max(ans,kans);
    }
    vsum += y[i];
    ll val = vsum-(c-x[i]);
    sl = max(sl,val);
  }
  

  vector<ll> lvals(n);
  lvals[n-1] = y[n-1]-(c-x[n-1]);
  ll sval = y[n-1];
  for(i=n-2;i>=0;i--)
  {
    lvals[i] = sval+y[i]-(c-x[i]);
    sval += y[i];
  }
  ll sr = MIN;
  vsum = 0;
  rep(i,n)
  {
    ans = max(ans,lvals[i]);
    if(i != 0)
    {
      ll kans = lvals[i]-(c-x[i])+sr; 
      ans = max(ans,kans);
    }
    vsum += y[i];
    ll val = vsum-x[i];
    sr = max(sr,val);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6364
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef struct ANS Ans;
struct ANS{
	int ch;	//?????????
	int pa;	//?????????
};

int Main();
int GCM(int a, int b);	//??£?????´??°a??¨b????????§??¬?´???°????????????

int main(int argc, char *argv[]){
	while( Main() == 0 );
	return 0;
}

int Main(){
	int a = 0, b = 0, c = 0, d = 0, p = 0, q = 0, r = 0, s = 0, gcm = 0;	//ax^2+bx+c=(px+q)(rx+s)=0??¨??????????????????p???s????±??????????d???sqrt(b^2-4ac)??§?????????
	Ans x[2];	//?????????p,r??§????????????q,s??¨?????????
	if( scanf("%d %d %d", &a, &b, &c) != 3 ){ return -1; }
	if( a == 0 && b == 0 && c == 0 ){ return 1; }
	//?§£???????´???°??§????????????????????°?§£????????¨????????????
	if( b * b - 4 * a * c < 0 ){
		printf("Impossible\n");
		return 0;
	}
	d = sqrt(b * b - 4 * a * c);
	//d?????´??°??§?????????
	if( d * d != b * b - 4 * a * c ){ 
		printf("Impossible\n");
		return 0;
	}
	//?§£????±????????´?????????????
	gcm = GCM(abs(-b-d), 2*a);
	x[0].ch = (-b - d) / gcm;
	x[0].pa = (2 * a) / gcm;
	gcm = GCM(abs(-b+d), 2*a);
	x[1].ch = (-b + d) / gcm;
	x[1].pa = (2 * a) / gcm;
	//?????¶???????????????????????????????????????
	if( x[0].pa > x[1].pa ){
		p = x[0].pa;
		q = (-1) * x[0].ch;
		r = x[1].pa;
		s = (-1) * x[1].ch;
	}else if( x[0].pa == x[1].pa ){
		p = x[0].pa;
		r = x[0].pa;
		q = (-1) * (x[0].ch <= x[1].ch ? x[0].ch : x[1].ch);
		s = (-1) * (x[0].ch <= x[1].ch ? x[1].ch : x[0].ch);
	}else if( x[0].pa < x[1].pa ){
		p = x[1].pa;
		q = (-1) * x[1].ch;
		r = x[0].pa;
		s = (-1) * x[0].ch;
	}
	printf("%d %d %d %d\n", p, q, r ,s);
	return 0;
}

int GCM(int a, int b){
	if( a <= 0 || b <= 0 ){ return (a>0?a:(b>0?b:1)); }	//?????§??¬?´???°???1??¨???????????????
	int m = (a>=b?a:b), n = (a>=b?b:a), r = m % n;	//m>=n
	while( r != 0 ){
		m = n;
		n = r;
		r = m % n;
	}
	return n;
}

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

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

		Arrays.sort(a);
		Arrays.sort(b);
		for (int i = 1; i < n; i++) {
			if (a[i - 1] == a[i]) {
				System.out.println(0);
				return;
			}
		}
		for (int i = 1; i < m; i++) {
			if (b[i - 1] == b[i]) {
				System.out.println(0);
				return;
			}
		}

		int mod = 1000000007;
		int nm = n * m;
		long ans = 1;
		for (int i = nm; i > 0; i--) {
			boolean fa = true;
			int ia = Arrays.binarySearch(a, i);
			if (ia < 0) {
				ia = ~ia;
				fa = false;
			}
			boolean fb = true;
			int ib = Arrays.binarySearch(b, i);
			if (ib < 0) {
				ib = ~ib;
				fb = false;
			}

			int na = n - ia;
			int nb = m - ib;
			int fix = nm - i;
			if (fa) {
				if (fb) {
					if (na * nb < fix + 1) {
						System.out.println(0);
						return;
					}
				} else {
					int val = nb - Math.max(fix - (na - 1) * nb, 0);
					if (val <= 0) {
						System.out.println(0);
						return;
					}
					ans *= val;
					ans %= mod;
				}
			} else {
				if (fb) {
					int val = na - Math.max(fix - (nb - 1) * na, 0);
					if (val <= 0) {
						System.out.println(0);
						return;
					}
					ans *= val;
					ans %= mod;
				} else {
					int val = na * nb - fix;
					if (val <= 0) {
						System.out.println(0);
						return;
					}
					ans *= val;
					ans %= mod;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 29156
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    ll a;
    const ll MOD=1e9+7;
    modint(ll a_=0){
        a=((a_%MOD)+MOD)%MOD;
    }
    modint inv()const{
        ll n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y(a+x.a);
        return y;
    }
    modint operator-(const modint& x){
        modint y(a-x.a);
        return y;
    }
    modint operator*(const modint& x){
        modint y(a*x.a);
        return y;
    }
    modint operator/(const modint& x){
        return *this * x.inv();
    }
    modint& operator+=(const modint& x){
        *this=*this+x;
        return *this;
    }
    modint& operator-=(const modint& x){
        *this=*this-x;
        return *this;
    }
    modint& operator*=(const modint& x){
        *this=*this*x;
        return *this;
    }
    modint& operator/=(const modint& x){
        *this=*this/x;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    ll a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(ll a,ll b){
    modint n(1),A(a);
    while(b){
        if(b&1) n*=A;
        A*=A;
        b>>=1;
    }
    return n;
}

class BKleeneInversion {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,k;
        in>>n>>k;
        vector<int> a(n);
        modint t,s;
        for(auto&i:a) in>>i;
        fr(j,n){
            fr(i,n){
                if(i<j&&a[i]>a[j]) t+=1;
                if(i!=j&&a[i]<a[j]) s+=1;
            }
        }
        out<<t*k+s*k*(k-1)/2<<endl;
    }
};

int main() {
    BKleeneInversion solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut a : i32 = read();
    let b : i32 = read();
    let mut c : i32 = read();
    let d : i32 = read();
    let mut ans = String::from("No");

    loop {
        if c > 0 {
            c = c - b;
        } else {
            ans = "Yes".to_string();
            break;
        }
        if a > 0 {
            a = a - d;
        } else {
            break;
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
const int MAXM = 200100;
typedef long long ll;

struct node{ll u, v; node(ll au = 0, ll av = 0){u = au; v = av;}};

ll n;
node ed[MAXM];
ll ans = 0;

int main(){
	scanf("%lld", &n);
	for(int i = 1; i <= n - 1; i++){
		scanf("%lld %lld", &ed[i].u, &ed[i].v);
		if(ed[i].u > ed[i].v) swap(ed[i].u, ed[i].v);
	}
	for(ll i = 1; i <= n; i++) ans = ans + i * (n - i + 1);
	for(ll i = 1; i <= n - 1; i++) ans = ans - ed[i].u * (n - ed[i].v + 1);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6928
#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#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;
const int INF = 1001001001;

int main() {
    int R;
    cin >> R;
    cout << 3*pow(R, 2) << endl;

    return 0;
}

Measured memory_bytes: 3756
#include<stdio.h>
#include<algorithm>
using namespace std;
bool cmp(long long a,long long b){
	return a>b;
}
int main(){
	int n;
	long long a[100005];  
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%lld",&a[i]);
	sort(a,a+n,cmp);
	long long x=0,y=0,f=0,p=0;
	for(int i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			if(f==0)
				x=a[i];
			else
				y=a[i];	
			f=1;
			i++;
			p++;
		}
		if(p==2)break;
	}
	printf("%lld\n",x*y);	
}


Measured memory_bytes: 896
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
 
def main():
    n,l = inpm()
    a = inpl()
    ans = []
    for i in range(n-1):
        if a[i]+a[i+1] >= l:
            x = i+1
            ans.append(i+1)
            break
    if ans == []:
        print('Impossible')
    else:
        print('Possible')
        for i in range(x+1,n):
            ans.append(i)
        for i in range(x-1,0,-1):
            ans.append(i)
        ans.reverse()
        for i in range(len(ans)):
            print(ans[i])
    
if __name__ == "__main__":
    main()

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

int main(){

	int n, W; cin >> n >> W;
	vector<int> v(n);
	vector<int> w(n);
	for(int i = 0; i < n; i++) cin >> v[i] >> w[i];


	//�悭�킩��񏉊�����Ă݂�
	vector<vector<int> > dp(n + 1, vector<int> (n * 100 + 110, W + 1));
	dp[0][0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= n * 100; j++){
			//take
			dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
			//no
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		}
	}
	int ans = 0;
	for(int j = 0; j <= 100*n; j++) if(dp[n][j] <= W) ans = j;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 6812
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    long long int N,x;
    cin>>N;
    int A[100001],B[100001];
    memset(A,0,sizeof(A));
    memset(B,0,sizeof(B));
    for(int i=0;i<N;i++){
        cin>>x;
        if(i%2==0){A[x]++;}
        else{B[x]++;}
    }
    N=N/2;
    long long int temp1=-1,count1=0;
    long long int temp2=-1,count2=0;
    long long int Temp1=-1,Count1=0;
    long long int Temp2=-1,Count2=0;
    for(int i=0;i<100001;i++){
        if(A[i]>=count1){count1=A[i]; temp1=i;}
        if(B[i]>=Count1){Count1=B[i]; Temp1=i;}
    }
    A[temp1]=-1;
    B[Temp1]=-1;
    for(int i=0;i<100001;i++){
        if(A[i]>count2){count2=A[i]; temp2=i;}
        if(B[i]>Count2){Count2=B[i]; Temp2=i;}
    }
    if(A[temp2]==-1){count2=0;}
    if(B[Temp2]==-1){Count2=0;}
    
    long long int ans=0;
    if(temp1!=Temp1){
       ans+=(2*N-count1-Count1); 
    }
    else{
        ans=min((2*N-count1-Count2),(2*N-count2-Count1));
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4356
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var s = br.readLine();

      System.out.println(s.equals("ABC") ? "ARC" : "ABC");
    }
  }
}


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

using namespace std;

const int INF = 1 << 30;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

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

template< typename T >
T kruskal(Edges< T > &edges, int V) {
  sort(begin(edges), end(edges), [](const edge< T > &a, const edge< T > &b) {
    return (a.cost < b.cost);
  });
  UnionFind tree(V);
  T ret = 0;
  for(auto &e : edges) {
    if(tree.unite(e.src, e.to)) ret += e.cost;
  }
  return (ret);
}


int main() {
  int V, E;
  scanf("%d %d", &V, &E);
  Edges< int > edges;
  for(int i = 0; i < E; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    edges.emplace_back(a, b, c);
  }
  printf("%d\n", kruskal(edges, V));
}


Measured memory_bytes: 4520
n = gets.chomp.to_i
Node = Struct.new(:num, :parent, :left, :right)

class BinSearchTree
  attr_accessor :root
  def initialize
    @root = nil
  end

  def inorder(r, order)
    if r.nil?.!
      inorder(r.left, order)
      order << r.num
      inorder(r.right, order)
    end
  end
  
  def preorder(r, order)
    if r.nil?.!
      order << r.num
      preorder(r.left, order)
      preorder(r.right, order)
    end
  end
  
  def find(k)
    x = @root
    y = nil
    flag = false
    until x.nil?
       y = x
      if k == x.num
        flag = true
        break
      elsif k < x.num
        x = x.left
      elsif x.num < k
        x = x.right      
      end
    end
    ans = flag ? "yes" : "no"
    puts ans
  end

  def insert(k)
    x = @root
    y = nil
    z = Node.new
    z.num = k
    until x.nil?
      y = x
      if z.num < x.num
        x = x.left
      else
        x = x.right
      end
    end
    z.parent = y
    if y.nil?
      @root = z
    else
      if z.num < y.num
        y.left = z
      else
        y.right = z
      end
    end
  end
end

bst = BinSearchTree.new

n.times do
  cmd, i = gets.chomp.split.map{|t| t.match?(/\d/) ? t.to_i : t}
  case cmd
  when "insert"
    bst.insert(i)
  when "print"
    root = bst.root
    in_res, pre_res = [], []
    bst.inorder(root, in_res)
    puts " " + in_res.map(&:to_s).join(' ')
    bst.preorder(root, pre_res)
    puts " " + pre_res.map(&:to_s).join(' ')
  when "find"
    bst.find(i)
  end
end


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

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

Measured memory_bytes: 256
n, k = map(int, input().split())
score_dict = dict(zip("spr", map(int, input().split())))
t = list(input())

score = sum([score_dict[h] for h in t[:k]])
for i in range(k, n):
    if t[i] != t[i - k]:
        score += score_dict[t[i]]
    else:
        t[i] = None

print(score)

Measured memory_bytes: 5284
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100100100;//10^17
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

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



int main(){
    ll N, M;
    cin >> N >> M;
    if(N == 1 || M == 1){
        if(N == 1 && M == 1){
            cout << 1 << endl;
            return 0;
        }
        int t = max(N, M);
        cout << t - 2 << endl;
        return 0;
    }
    if(N > 2 && M > 2){
        cout << (N - 2) *  (M - 2) << endl;
        return 0;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
a=input()
alphabet=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
b=alphabet.index(a)+1
print(alphabet[b])


Measured memory_bytes: 2940
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>

#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main() {
    int n, l;
    string s[105];
    cin >> n >> l;
    for (int i = 0; i < n; i++)cin >> s[i];
    sort(s, s + n);
    for (int i = 0; i < n; i++)cout << s[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   ll x;
   cin>>x;
   unordered_map<ll,ll> m;
   for(ll i=1;i<=6000;i++)
   {
       ll a=pow(i,5);
       m[a]=i;
       m[-1*a]=-1*i;
       ll b=a-x;
       if(b==0||m[b]!=0)
       {
           cout<<i<<" "<<m[b];
           break;
       }
    //   cout<<a<<" "<<b<<endl;
   }
   return 0;
}


Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,a,f;cin>>n;
  deque<int> d;
  for(int i=0;i<n;i++){
    cin>>a;
    if((n-i)%2==0){d.push_back(a);}
    else{d.push_front(a);}
  }
  for(int i=0;i<n;i++){
    f=d.front();d.pop_front();
    cout<<f;
    if(i!=n-1){cout<<' ';}
  }
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};
const int M = 110000;
mint perm[M];
void make_perm() {
  perm[0].x = 1;
  rep1(i, M-1) {
    perm[i] = (mint)i * perm[i-1];
  }
}

int main()
{
  int n;cin >> n;
  string s;cin >> s;
  mint res(1);
  if(s[0] == 'W') {
    cout << 0 << "\n";
    return 0;
  }
  int cnt = 1;
  for(int i = 1;i < 2*n;++i) {
    if(s[i] == 'W') {
      if(cnt % 2 == 0) {
	res *= (mint)cnt;
	cnt--;
	if(cnt < 0) {
	  cout << 0 << "\n";
	  return 0;
	}
      }
      else cnt++;
    }
    else {
      if(cnt % 2 == 0) cnt++;
      else {
	res *= (mint)cnt;
	cnt--;
	if(cnt < 0) {
	  cout << 0 << "\n";
	  return 0;
	}
      }
    }    
  }
  if(cnt != 0) {
    cout << 0 << "\n";
    return 0;
  }
  make_perm();
  res *= perm[n];
  cout << res.x << "\n";
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if (a>b)  swap(a,b);
	if (a==1&&b==2)  cout<<3<<endl;
	else if (a==1&&b==3)  cout<<2<<endl;
	else if (a==2&&b==3)  cout<<1<<endl;
	return 0;
} 

Measured memory_bytes: 256