akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int a; int b; int c;
    cin >> a >> b >> c;
    if (a > b && a > c)
        cout << b + c << endl;
    else if (b > a && b > c)
        cout << a + c << endl;
    else if (c > b && c > a)
        cout << b + a << endl;
    else
        cout << a + b << endl;
}


Measured memory_bytes: 256
from itertools import permutations

n = int(input())
nl = [i for i in range(1, n+1)]
p = list(map(int, input().split()))
q = list(map(int, input().split()))
p = tuple(p)
q = tuple(q)
l = list(permutations(nl))
a = l.index(p)
b = l.index(q)
print(abs(a-b))

Measured memory_bytes: 13640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans;

        if (b >= a || b * 2 >= a) {
            ans = 0;
        }else {
            ans = a - (b * 2);
        }
        // 出力
        System.out.println(Integer.toString(ans));

    }
}


Measured memory_bytes: 23764
import java.util.Scanner;
public class Main{
	String s;

	public Main(String str){
		s = str;
	}
	public int searchA(){
		return s.indexOf("A");
	}
	public int searchZ(){
		return s.lastIndexOf("Z") + 1;
	}

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		Main m = new Main(str);
		int start = m.searchA();
		int end = m.searchZ();
		System.out.println(end - start);

	}
}



Measured memory_bytes: 26176
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
#define int long long
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a,b,c;	
	cin>>a>>b>>c;
	int res = min(c,a) + b + min(((c-a)>0)?(c-a):0,b) + (((c-a)>b)?1:0);
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


def int_input():
    return list(map(int, input().split()))


def get(s):
    return str(s % 9) + '9' * (s // 9)

if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n = int(input())
        A = int_input()

        cur = 0

        for x in A:
            cur = x ^ cur

        res = []
        for x in A:
            res.append(cur ^ x)

        print(*res)




Measured memory_bytes: 33336
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int n;
	cin >> n;
	ll int a[100];
	REP(i, n) cin >> a[i];
	int cnt = 0;
	REP(i, n){
		for(int j = i + 1; j < n; j++){
			for(int k = j + 1; k < n; k++){
				int d[3];
				d[0] = a[i];
				d[1] = a[j];
				d[2] = a[k];
				sort(d, d+3);
				if(d[0] != d[1] && d[1] != d[2]){
					if(d[0] + d[1] > d[2]){
						cnt ++;
					}
				}
			}
		}
	}
	cout << cnt << endl;

	// cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h,w,i,j;
    cin>>h>>w;
    string grid[h];
    for(i=0;i<h;i++)
    {
        cin>>grid[i];
    }
    ll dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    ll cnt=0;
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(grid[i-1][j-1]!='#') 
            {
                //cout<<dp[i-1][j]<<" "<<i<<endl;
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
                
            }
            dp[1][1]=1;
        }
    }
    /*for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            cout<<dp[i][j]<<endl;
        }
    }*/
    cout<<dp[h][w]<<endl;
    
    return 0;
}

Measured memory_bytes: 9088
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
const int mod=1e9+7;
int n;
int a[410],b[410];
int v[410][410];
int js[410],cnt;
int kuai[410],wz=1,zs=2;
int f[410][410][410];
int ya[410];
int yb[410];
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		ya[a[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
		yb[b[i]]=i;
	}
	kuai[0]=1;
	for(int i=1;i<=n;i++)
	{
		kuai[i]=1ll*wz*1ll*zs%mod*1ll*kuai[i-1]%mod;
		wz+=3;
		zs+=3;
	} 
	//C还有i个没选，A选到第K个，B选到第J个
	f[0][1][1]=1;
	for(int j=1;j<=n;j++)
	{
		for(int k=1;k<=n;k++)
		{
			for(int i=0;i<=n/3;i++)
			{
				if(!f[i][k][j])continue;
				if(yb[a[k]]<=j||ya[b[j]]<=k){
					if(a[k]==b[j]){
						if(i==0)
						{
							continue;
						}
						f[i-1][k+1][j+1]=(1ll*f[i-1][k+1][j+1]+1ll*f[i][k][j]*1ll*i%mod)%mod;
						continue;
						//如要打起来，则强行让C选一个,因为和选了什么没有关系，所以剩下的位置随便选 
					}
					if(yb[a[k]]<=j)
					{
						f[i][k+1][j]=(1ll*f[i][k+1][j]+1ll*f[i][k][j])%mod;continue;
					}
					else
					{
						f[i][k][j+1]=(1ll*f[i][k][j+1]+1ll*f[i][k][j])%mod;continue;
					}
				}
				f[i+1][k+1][j+1]=(1ll*f[i+1][k+1][j+1]+1ll*f[i][k][j])%mod;//先不给C位置，等到能安排的时候直接安排C 
				if(i>0)
				{
					f[i-1][k+1][j]=(1ll*f[i][k][j]*i%mod+1ll*f[i-1][k+1][j])%mod;
					f[i-1][k][j+1]=(1ll*f[i][k][j]*i%mod+1ll*f[i-1][k][j+1])%mod;
					//因为选了什么没关系，所以C可以从他两个后面的一个随便选
					if(i>1)f[i-2][k+1][j+1]=(1ll*f[i-2][k+1][j+1]-1ll*f[i][k][j]*(1ll*i*(i-1)%mod)%mod+mod)%mod;//容斥原理 
				}
			}
		}
	}
	int summ=0;
	for(int i=n/3;i<=n;i++)
	{
		summ+=f[0][i][n+1];
		summ%=mod;
	}
	for(int i=n/3;i<=n;i++)
	{
		summ+=f[0][n+1][i];
		summ%=mod;
	}
	printf("%lld",1ll*summ*1ll*kuai[n/3]%mod);
	return 0;
}

Measured memory_bytes: 90368
#include<stdio.h>
#include<math.h>

int main(void)
{
	double avg;
	int n,x,y;
	int xy[9][2];
	int i,j;
	double sum=0;
	
	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		scanf("%d%d",&x,&y);
		xy[i][0]=x;
		xy[i][1]=y;
	}
	
	for(i=1;i<n;i++){
		for(j=1;i+j<=n;j++){
			sum+=sqrt(pow((xy[i][0]-xy[i+j][0]),2)+pow((xy[i][1]-xy[i+j][1]),2));
		}
	}
	
	avg = sum*2 / n;
	printf("%lf",avg);
	
	return 0;
}
	


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}

map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
struct UnionFind {
    vector<int> parent, size;
    UnionFind(int n) {
        parent.resize(n, -1);
        size.resize(n, 1);
    }
    void unite(int x, int y) {
        if (same(x, y)) {
            return;
        }
        x = root(x);
        y = root(y);
        if (size[x] <= size[y]) {
            swap(x, y);
        }
        parent[y] = x;
        size[x] += size[y];
    }
    bool same(int x, int y) { return (root(x) == root(y)); }
    int root(int x) {
        while (parent[x] != -1) {
            x = parent[x];
        }
        return x;
    }
    int getsize(int x) { return size[root(x)]; }
};
int main() {
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    REP(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }
    int maa = 0;
    REP(i, n) { maa = max(maa, uf.getsize(i)); }
    cout << maa << endl;
}

Measured memory_bytes: 4808
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int w,a,b;
  cin >> w >> a >> b;
  int ans;
  if (a <= b) {
     if (a+w <= b) ans=b-a-w;
     else  ans=0;
  }
  else {
     if (b+w <= a) ans=a-b-w;
     else ans=0;
  }
  cout << ans << endl;

   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()

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

  vector<bool> color(8, false);
  int over3200 = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 8; ++j) {
      if (400*j <= a[i] && a[i] < 400*(j+1)) color[j] = true;
    }
    if (3200 <= a[i]) over3200++;
  }

  int cnt = count(ALL(color), true);
  int minc = (cnt == 0 ? 1 : cnt);
  int maxc = cnt+over3200;

  cout << minc << " " << maxc << endl;
}

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


void solve(string S){
	if ((S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) || (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) || (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) ) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll mod = 1e9+7;
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        string s;
        int n;cin>>n>>s;
        s.pb('x');
        s.pb('x');
        int ans=0;
        rep(i,n){
            if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];

    int freq[2][100005] = {};
    for(int i=0; i<n; i+=2) freq[0][a[i]]++;
    for(int i=1; i<n; i+=2) freq[1][a[i]]++;

    int x1=0, x2=0, y1=0, y2=0;
    int nx, ny;
    rep(i, 100005) {
        if(x1 < freq[0][i]){
            x2 = x1;
            nx = i;
            x1 = freq[0][i];
        }else if(x2 < freq[0][i]){
            x2 = freq[0][i];
        }
    }
    rep(i, 100005) {
        if(y1 < freq[1][i]){
            y2 = y1;
            ny = i;
            y1 = freq[1][i];
        }else if(y2 < freq[1][i]){
            y2 = freq[1][i];
        }
    }

    if(nx != ny) pr(n - x1 - y1);
    else pr(min(n-x1-y2, n-x2-y1));
    return 0;}

Measured memory_bytes: 4588
N = int(input())
XL = [tuple(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0]+x[1])
right = -float('inf')
ans = 0
for x,l in XL:
    s,t = x-l, x+l-1
    if s > right:
        right = t
        ans += 1
print(ans)

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

int main(void){ 
    int n, cnt = 0;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> p(1000001);
    for(int i=0; i<n; i++){
        if(!p[a[i]]){
            cnt++;
            if(i != n-1 && a[i] == a[i+1]) cnt--;
            int64_t now = a[i];
            while (now <= 1000000) {
                p[now] = 1;
                now += a[i];
            }
        }
    }
    cout << cnt << '\n';
    return 0;
}

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

int main()
{
	string a,b,c;
	cin >> a >> b >> c;
	if(a.back() == b.front() && b.back() == c.front()){
		cout << "YES\n";
	}else{
		cout << "NO\n";
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int x,a,b;
  scanf("%d\n",&x);
  a=x/100;
  b=x%100;
  a=a*5;
  if(b<=a){
    printf("1\n");
  }
  else{
    printf("0\n");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int s = stdIn.nextInt();
		while(true){
			String input1 = stdIn.next();
			if(input1.equals("=")){
				break;
			}
			int input2 = stdIn.nextInt();
			if(input1.equals("+")){
				s += input2;
			}
			else if(input1.equals("-")){
				s -= input2;
			}
			else if(input1.equals("*")){
				s *= input2;
			}
			else if(input1.equals("/")){
				s /= input2;
			}
		}
		System.out.println(s);
	}
}

Measured memory_bytes: 19648
#include<stdio.h>

int main(){
	long long N;
	scanf("%lld",&N);
	long long maxi;
	for(long long i=1;i*i<=N;i++){
		if(N%i==0)maxi=i;
	}
	long long A=maxi,a=0;
	long long B=N/maxi,b=0;

	while(B!=0){
		B/=10;
		b++;
	}
	printf("%d\n",b);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
#include<vector>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)

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



int main() {

	string s;
	
	cin >> s;
	rep(i, 0, s.size()) {
		if (i % 2 == 0)cout << s[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<math.h>
#include<deque>

using namespace std;

int main(){
	int N,H,W;
    cin>>N>>H>>W;
    int t,y;
    t = N - W;
    y = N - H;

    if(t>=0 && y>=0){
        cout<<(t+1)*(y+1)<<endl;
    }
	
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(int i = 0; i < (n) ; ++i)
#define orep(i,n)   for(int i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(int i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()   // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
  int m,n;
  cin >> n >> m;
  vi a(m,0);
  int tot=0;
  rep(i,m) {
    cin >> a.at(i);
    tot += a.at(i);
  }

  if(tot <= n) cout << (n-tot) << endl;
  else cout << "-1" << endl;



  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
  int n,m;cin>>n>>m;
  vector<ll>G[n];
  rep(i,m){
    ll a,b;cin>>a>>b;a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  deque<ll>ans;
  vector<bool>used(n,false);
  int v=0;
  bool isFirst=false;
  while(1){
    if(!isFirst)ans.push_back(v);
    else ans.push_front(v);
    ll u=-1;
    if(used[v])return true;
    used[v]=true;
    for(auto i:G[ans.back()]){
      if(!used[i]){
        isFirst=false;
        u=i;
      }
    }
    for(auto i:G[ans.front()]){
      if(!used[i]){
        isFirst=true;
        u=i;
      }
    }
    if(u==-1){
      cout<<ans.size()<<endl;
      rep(i,(int)ans.size()-1)cout<<++ans[i]<<" ";
      cout<<ans.back()+1<<endl;
      return ans.size()==1;
    }
    else v=u;
  }

  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  return solve();
}


Measured memory_bytes: 7040
// https://atcoder.jp/contests/abc178/tasks/abc178_a

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

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

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

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

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

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

const ll INF = 1e18;

void solve();

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

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

  return 0;
}
#endif

void solve() {
  ll x;
  cin >> x;

  ll res = 1 - x;
  cout << res << "\n";
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>
#include <functional>

typedef long long ll;
using namespace std;

static int un[200000];
static int ans[200000];

int root(int x){
    if(un[x] == x) return x;
    return un[x] = root(un[x]);
}

void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    if(rx > ry){
        un[rx] = ry;
    } else {
        un[ry] = rx;
    }
}

int main(){
    for(int i  = 0; i < 200000; i++){
        un[i] = i;
    }
    int m, n;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        unite(x - 1, y - 1);
    }

    for(int i = 0; i < n; i++){
        root(i);
    }
    for(int i = 0; i < n; i++){
        ans[un[i]]++;
        
    }
    int mx = -1;
    for(int i = 0; i < n; i++){
        mx = max(mx, ans[i]);
    }
    cout << mx << endl;
}


Measured memory_bytes: 5044
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int main() {
    int N, M;
    cin >> N >> M;
    int b[N];
    int zeros = 0;
    for (int i = 0; i < N; i++) {
        cin >> b[i];
        b[i] = b[i];
        if (b[i] == 0) {
            zeros++;
        }
    }
    int sum[2] = {0, 0};
    int p[M];
    for (int i = 0; i < M; i++) {
        cin >> p[i];
        sum[i % 2] += p[i];
    }
    ll ans = 10000;
    if (zeros == sum[0]) {
        int bb[N];
        for (int i = 0; i < N; i++) {
            bb[i] = b[i];
        }
        int tar[N];
        int num = 0;
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < p[i]; j++) {
                tar[num] = i % 2;
                num++;
            }
        }
        int sum = 0;
        for (int i = 0; i < N - 1; i++) {
            if (bb[i] == tar[i]) {
                continue;
            }
            for (int j = i + 1; j < N; j++) {
                if (bb[j] == tar[i]) {
                    sum += j - i;
                    for (int k = j - 1; k >= i; k--) {
                        swap(bb[k], bb[k + 1]);
                    }
                    break;
                }
            }
        }
        if (sum < ans) {
            ans = sum;
        }
    }
    if (zeros == sum[1]) {
        int bb[N];
        for (int i = 0; i < N; i++) {
            bb[i] = b[i];
        }
        int tar[N];
        int num = 0;
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < p[i]; j++) {
                tar[num] = (i + 1) % 2;
                num++;
            }
        }
        int sum = 0;
        for (int i = 0; i < N - 1; i++) {
            if (bb[i] == tar[i]) {
                continue;
            }
            for (int j = i + 1; j < N; j++) {
                if (bb[j] == tar[i]) {
                    sum += j - i;
                    for (int k = j - 1; k >= i; k--) {
                        swap(bb[k], bb[k + 1]);
                    }
                    break;
                }
            }
        }
        if (sum < ans) {
            ans = sum;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    string s,t="yuiophjklnm";
    while(cin>>s,s!="#"){
        int c=-1,a=0;
        for(auto p:s){
            int tmp=t.find(p)!=string::npos?1:0;
            if(tmp!=c&&c!=-1)a++;
            c=tmp;
        }
        cout<<a<<endl;
    }
}

Measured memory_bytes: 3152
#include<iostream>

using namespace std;

int n;
bool a[100002]{ true },r[100002];

bool solve(int k) {
	a[k+1] = !(!(a[k - 1] ^ r[k])^a[k]);
	if (k == n) {
		if (a[0] == a[n] && a[1] == a[n + 1])
			return true;
		else
			return false;
	}
	else
		return solve(k + 1);
}

int main() {
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'o')
			r[i+1] = true;
		else
			r[i+1] = false;
	}
	a[0] = true; a[1] = true;
	if (solve(1)) {
		for (int i = 1; i <= n; i++) {
			if (a[i])cout << "S";
			else cout << "W";
		}
		cout << endl;
		return 0;
	}
	a[0] = true; a[1] = false;
	if (solve(1)) {
		for (int i = 1; i <= n; i++) {
			if (a[i])cout << "S";
			else cout << "W";
		}
		cout << endl;
		return 0;
	}
	a[0] = false; a[1] = true;
	if (solve(1)) {
		for (int i = 1; i <= n; i++) {
			if (a[i])cout << "S";
			else cout << "W";
		}
		cout << endl;
		return 0;
	}
	a[0] = false; a[1] = false;
	if (solve(1)) {
		for (int i = 1; i <= n; i++) {
			if (a[i])cout << "S";
			else cout << "W";
		}
		cout << endl;
		return 0;
	}
	else
		cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    string s; cin >> s;
    cout << s.substr(0, s.size()-8) << endl;
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;


int main () {
	int W, H, N;
	cin >> W >> H >> N;

	vector<vector<int> > area(H, vector<int>(W, 1));

	vector<vector<int> > pos_con(N, vector<int>(3));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> pos_con.at(i).at(j);
		}
	}

	int condition;
	int xs, xe, ys, ye;
	for (int i = 0; i < N; i++) {
		condition = pos_con.at(i).at(2);
		if (condition == 1) {
			xs = 0;
			xe = pos_con.at(i).at(0);
			ys = 0;
			ye = H;
		}
		else if (condition == 2) {
			xs = pos_con.at(i).at(0);
			xe = W;
			ys = 0;
			ye = H;
		}
		else if (condition == 3) {
			xs = 0;
			xe = W;
			ys = 0;
			ye = pos_con.at(i).at(1);
		}
		else if (condition == 4) {
			xs = 0;
			xe = W;
			ys = pos_con.at(i).at(1);
			ye = H;
		}
		for (int y = ys; y < ye; y++){
			for (int x = xs; x < xe; x++){
				area.at(y).at(x) = 0;
			}
		}
	}

	int sum = 0;
	for (int i = 0; i < H; i++) {
		sum += accumulate(area.at(i).begin(), area.at(i).end(), 0);
		/*
		for (int j = 0; j < W; j++) {
			cout << area.at(i).at(j) << ' ';
		}
		cout << endl;
		*/
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Integer N = input.nextInt();
      	char[] S = input.next().toCharArray();
      	// for condition_1
      	long r = 0;
      	long g = 0;
      	long b = 0;
      	for (int i = 0; i < N; i++) {
        	if (S[i] == 'R') r++;
          	if (S[i] == 'G') g++;
          	if (S[i] == 'B') b++;
        }
      
      	// for condition_2
      	long result = r * g * b;
      	for (int i = 0; i < N; i++) {
        	for (int j = 1; j < N; j++) {
              if (i - j >= 0 && i + j < N) {
                if(S[i] != S[i-j] && S[i] != S[i+j] && S[i-j] != S[i+j]){
                  result--;
                }
              }
            }
        }
 		System.out.println(result);
    }
}

Measured memory_bytes: 36576
import math
A,B,H,M=map(int,input().split())
a=H/12+M/(12*60)
b=M/60
r=2*math.pi*abs(b-a)
r=min(r,2*math.pi-r)
ans=A**2+B**2-2*A*B*math.cos(r)
ans=ans**0.5
print(ans)

Measured memory_bytes: 9528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define pbp(a,b) push_back({a,b})
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define INF 0x3f3f3f3f

ll nextPowerOf2(ll n)   
{ 
	n--; 
	n |= n >> 1ll; 
	n |= n >> 2ll; 
	n |= n >> 4ll; 
	n |= n >> 8ll; 
	n |= n >> 16ll; 
	n++; 
	return n; 
}


int main() {
	
	#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n,t,i,k,sum=0ll,xo=0;

	t=1;
	while(t--)
	{
		cin>>n;
		vector<ll> v(n);

		for(i=0 ; i<n ; i++){cin>>v[i];xo = (xo^v[i]);}

		for(i=0 ; i<n ; i++)cout<<(xo^v[i])<<" ";
	}

	return 0;
}

Measured memory_bytes: 4712
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

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

	int w, d;
	while(cin >> w >> d, w | d) {
		int h1[21] { 0}, h2[21] = { 0 };
		for(int i = 0; i < w; i++) {
			int h;
			cin >> h;
			h1[h]++;
		}
		for(int i = 0; i < d; i++) {
			int h;
			cin >> h;
			h2[h]++;
		}

		int ans = 0;
		for(int i = 1; i <= 20; i++) {
			ans += i * min(h1[i], h2[i]);
			ans += i * (max(h1[i], h2[i]) - min(h1[i], h2[i]));
		}
		cout << ans << endl;
	}
}

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

int main(){
  int S;
  cin >> S;
  int flag1=0;
  int flag2=0;
  if(1<=S%100 && S%100<=12){
    flag1=1;
  }
  if(1<=S/100 && S/100<=12){
    flag2=1;
  }
  if(flag1==1 && flag2==1){
    cout << "AMBIGUOUS" << endl;
    return 0;
  }
  else if(flag1==1 && flag2==0){
    cout << "YYMM" << endl;
    return 0;
  }
  else if(flag1==0 && flag2==1){
    cout << "MMYY" << endl;
    return 0;
  }
  else{
    cout << "NA" << endl;
    return 0;
  }
}

Measured memory_bytes: 3564
def li():
    return [int(x) for x in input().split()]

x, k, d = li()

x = abs(x)

if k * d < x:
    ans = x - k * d
    print(ans)
    exit()

xr = x % d
xl = xr - d

r_parity = (x - xr) // d % 2
k_parity = k % 2
if r_parity == k_parity:
    print(xr)
else:
    print(abs(xl))

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define int long long
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define out(a) cout<<(a)<<endl
typedef long long ll;
typedef string str;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<P> VP;
const int INF = 1LL<<60;
const int MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,q,k;
  cin>>n;
  V a(n-1),b(n-1),c(n-1);
  VP adj[n];
  rep(i,n-1){
    int A,B,C;
    cin>>A>>B>>C;
    A--,B--;
    a[i]=A;
    b[i]=B;
    c[i]=C;
    adj[A].pb(m_p(B,C));
    adj[B].pb(m_p(A,C));
  }
  cin>>q>>k;
  k--;
  
  queue<P> que;
  V cost(n,INF);
  cost[k]=0;
  for(auto i:adj[k])que.push(i);
  while(!que.empty()){
    P to=que.front(); que.pop();
    int pos=to.first,cos=to.second;
    if(cost[pos]>cos){
      cost[pos]=cos;
      for(auto&next:adj[pos])que.push(m_p(next.first,next.second+cos));
    }
  }

  while(q--){
    int x,y;
    cin>>x>>y;
    x--,y--;
    cout<<(cost[x]+cost[y])<<"\n";
  }
  
  return 0;
}



Measured memory_bytes: 13168
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int a[100001];
	int n,m,sum=0;
	cin>>n>>m;
	int total=n;
	for (int i=0; i<n;++i) 
	{
	  cin>>a[i];
       sum+=a[i];
	 }
	      sort(a,a+n);
	m=m-sum;
	total+=(m/a[0]);
	cout<<total<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define spn setprecision
using namespace std;
ll multiply(ll num1, ll num2, ll mod) { // with mod > 1e9
	ll ans = 0;
	num1 %= mod;
	num2 %= mod;
	while (num2) {
		if (num2&1) {
			ans += num1;
			ans %= mod;
		}
		num1 *= 2;
		num1 %= mod;
		num2 /= 2;
	}
	return ans;
}
ll powmod2(ll base,ll exponent,ll mod){ // with mod > 1e9
	ll ans = 1;
	while (exponent) {
		if (exponent&1) {
			ans = multiply(ans, base, mod);
		}
		base = multiply(base, base, mod);
		exponent /= 2;
	}
	return ans;
}
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
struct data
{
	int ind,val;
};
bool cmp(data &a,data &b){
	return(a.val<b.val);
}
const int upperlimit = 1e5;
const int limit = 2e5;
int main() {
	int m,inp,a,b,c,sum,k;
	sd(a);
	sd(b);
	sd(c);
	sd(k);
	sum=a+b+c;
	m=max(a,max(b,c));
	sum-=m;
	for(int i = 1; i <= k; i++){
		m*=2;
	}
	sum+=m;
	pd(sum);
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin >> s;
    int len=s.size();
    if(s[0]==s[len-1])
    {
        if(len%2==1) cout << "Second\n";
        else cout << "First\n";
    }
    else
    {
        if(len%2==1)cout << "First\n";
        else cout << "Second\n";
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct UnionFind {
	vector<int> par;

	UnionFind(int N) : par(N) {
		for (int i = 0; i < N; i++) par[i] = i;
	}

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

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	void merge(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return;
		par[rx] = ry;
	}
};

int main() {
//	cout << fixed << setprecision(15);
	int n, m;
	cin >> n >> m;
	vll s(m), t(m), w(m);
	rep(i, m) cin >> s[i] >> t[i] >> w[i];

	vector<pll> p(m);
	rep(i, m) p[i] = pll(w[i], i);
	sort(p.begin(), p.end());

	UnionFind uf(n);
	ll ans = 0;
	rep(i, m) {
		int j = p[i].second;
		if(uf.issame(s[j], t[j])) continue;
		uf.merge(s[j], t[j]);
		ans += p[i].first;
	}
	cout << ans << endl;
}



Measured memory_bytes: 6808
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int a=in.nextInt();
			int b=in.nextInt();
			int c=in.nextInt();
			if((a|b|c)==0)
				return;
			int A[]=new int[a];
			int B[]=new int[b];
			int C[]=new int[c];
			Arrays.fill(A, 2);
			Arrays.fill(B, 2);
			Arrays.fill(C, 2);
			int judge[][][]=new int[a][b][c];
			int N=in.nextInt();
			for(int I=0;I<N;I++)
			{
				int i=in.nextInt();
				int j=in.nextInt();
				int k=in.nextInt();
				int r=in.nextInt();
				judge[i-1][j-a-1][k-a-b-1]=r;
				if(r==1)
				{
					A[i-1]=1;
					B[j-a-1]=1;
					C[k-a-b-1]=1;
				}
				else 
					judge[i-1][j-a-1][k-a-b-1]=-1;
			}
			for(int i=0;i<a;i++)
				for(int j=0;j<b;j++)
					for(int k=0;k<c;k++)
					{
						if(judge[i][j][k]==-1)
						{
							if(A[i]==1&&B[j]==1&&C[k]==2)C[k]=0;
							if(A[i]==1&&B[j]==2&&C[k]==1)B[j]=0;
							if(A[i]==2&&B[j]==1&&C[k]==1)A[i]=0;
						}
					}
			for(int p:A)
				System.out.println(p);
			for(int p:B)
				System.out.println(p);
			for(int p:C)
				System.out.println(p);
		}
	}

	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 36160
import sys

# print('input >>')
N, M = map(int,(input().split()))
As = list(map(int,(input().split())))

border = sum(As)*1/(4*M)
As_best = sorted(As, reverse=True)[:M]

for A in As_best:
    if A < border:
        print('No')
        sys.exit()
print('Yes')

# print('-----output-----')

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static ConsoleApp.Util;
using static System.Math;

namespace ConsoleApp
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var p = ReadLine().Split().Select(int.Parse).ToArray();
            var q = ReadLine().Split().Select(int.Parse).ToArray();

            List<int> nouse = new List<int>();
            for (int i = 1; i <= n;i++)
                nouse.Add(i);
            var a = Calc(p,n,0,nouse);

            nouse.Clear();
            for (int i = 1; i <= n; i++)
                nouse.Add(i);
            var b = Calc(q,n,0,nouse);

            WriteLine(Math.Abs(a-b));
        }

        static int Calc(int[] p,int n,int x,List<int> nouse)
        {
            
            if (x == n - 1)
                return 1;
            else
            {
                var num = 0;
                for (int i = 0; i < n;i++)
                    if (nouse[i] == p[x])
                    {
                        num = i;
                        nouse.RemoveAt(i);
                        break;
                    }

                return (num) * Fact(n - x- 1) + Calc(p, n, x + 1, nouse);
            }
        }

        static int[] factMemo = new int[10]{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
        static int Fact(int n){
            if(n == 1){
                return 1;
            }
            else{
                if(factMemo[n] != -1)return factMemo[n];

                var res = n * Fact(n - 1);
                factMemo[n] = res;
                return res;
            }
        }
    }


    static class Util
    {
        public static void ChMin(ref int a, int b)
        {

            if (a > b)
            {
                a = b;
            }
        }


        public static void ChMax(ref long a, long b)
        {
            if (a < b)
            {
                a = b;
            }
        }




    }
}


Measured memory_bytes: 13268
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N;
double p[3010];
double dp[3010][3010];

int main () {
  cin >> N;
  rep(i, N) cin >> p[i];

  dp[0][0] = 1.0;

  rep(i, N) {
    Rep(j, i+1) {
      //cout << i << " " << p[i] << "\n";

      if (j >= 0)
        dp[i][j] += (dp[i-1][j-1] * p[i]);

      dp[i][j] += (dp[i-1][j] * (1.0 - p[i]));

      //cout << i << " " << j << " " << dp[i][j] << "\n";
    }
  }

  double ans = 0.0;

  for (int k=N/2+1;k<=N;++k) {
    ans += dp[N][k];
  }

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

Measured memory_bytes: 69120
#include <cstdio>
#include <algorithm>
#define int long long
using namespace std;

int n,m,a[200005];

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')c=getchar(),t=-1;
	while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+(c^48),c=getchar();
	return s*t;
}

bool cmp(int a,int b){
	return a>b;
}

signed main(void){
	n=read();
	m=read();
	for(int i=1;i<=n;i++)
	a[i]=read();
	sort(a+1,a+1+n,cmp);
	int s=0;
	for(int i=m+1;i<=n;i++)
	s+=a[i];
	printf("%lld\n",s);
}

Measured memory_bytes: 1664
N,T=map(int,input().split())
listA=list(map(int,input().split()))
max=-1
count=0
min=listA[0]
for i in range(N-1):
    if listA[1+i]<min:
        min=listA[1+i]
    if listA[1+i]-min>max:
        max=listA[1+i]-min
        count=1
    elif listA[1+i]-min==max:
        count+=1
print(count)

Measured memory_bytes: 14252
def max_heapify(A, i):
  l = i * 2
  r = l + 1
  largest = i
  if l <= H and A[l] > A[i]: largest = l
  if r <= H and A[r] > A[largest]: largest = r
  if largest != i:
    A[i], A[largest] = A[largest], A[i]
    max_heapify(A, largest)

def build_max_heap(A):
  for i in range(H // 2, 0, -1):
    max_heapify(A, i)

H = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
build_max_heap(A)

print(" " + " ".join(map(str, A[1:])))

Measured memory_bytes: 66116
def main():
	N = int(input())
	A = list(map(int, input().split()))
	if 0 in A:
		print(0)
		return
	prod = 1
	for a in A:
		prod *= a
		if prod > 1000000000000000000:
			print(-1)
			return
	print(prod)
main()

Measured memory_bytes: 21584
#include <cstdio>
#define LL long long
using namespace std;
int m,cnt;
int ans;
struct poi{
	int x,y;
	poi(){}
	poi(int xx,int yy){
		x=xx;
		y=yy;
	}
	void read(){
		scanf("%d%d",&x,&y);
	}
	friend poi operator-(poi a,poi b){
		return poi(a.x-b.x,a.y-b.y);
	}
	friend int operator^(poi a,poi b){
		return a.x*b.y-a.y*b.x;
	}
} p[20],s[10];
bool flag[20];
void work(){
	int fst=0;
	for (fst=1;fst<=m;fst++) if (flag[fst]==0){
		flag[fst]=1;
		break;
	}
	if (fst>m){
		int res=0;
		for (int i=1;i<=m/2;i++) for (int j=i+1;j<=m/2;j++){
			if ((s[i]^s[j])==0) res++;
			if (res>ans) ans=res;
		}
		return;
	}
	for (int i=fst+1;i<=m;i++) if (!flag[i]){
		s[++cnt]=p[i]-p[fst];
		flag[i]=1;
		work();
		flag[i]=0;
		cnt--;
	}
	flag[fst]=0;
}
int main(){
	scanf("%d",&m);
	for (int i=1;i<=m;i++) p[i].read();
	work();
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2744
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

ans = 0

# 1つ目の条件を満たす組の総数は
all_1 = r * g * b

# 1つ目の条件を満たすかつ2つ目の条件を満たさない組の個数
for i in range(N):
    for j in range(i + 1, N):
        k = 2*j - i
        if k >= N:
            continue
        if (S[i] is not S[j]) and (S[i] is not S[k]) and (S[j] is not S[k]):
            ans += 1

s = all_1 - ans

print(s)


Measured memory_bytes: 9204