akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S.at(i);
    }
    SORT(S);
    ostringstream os;
    copy(ALL(S), ostream_iterator<string>(os));
    cout << os.str() << endl;
}


Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <numeric>
#include <limits>
#include <utility>
using namespace std;
typedef long long longlong;
typedef long long LL;

int main(void) {
	int a, b, x, y, z;
	x = 20; y = 30; z = 40;
	cin >> a >> b;
	if (a == 2) {
		a = z;
	}
	else if (a == 4 || a == 6 || a == 9 || a == 11) {
		a = y;
	}
	else {
		a = x;
	}
	if (b == 2) {
		b = z;
	}
	else if (b == 4 || b == 6 || b == 9 || b == 11) {
		b = y;
	}
	else {
		b = x;
	}

	if (a == b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
using namespace std;
int main(void){
	int n,i,q,num,ans=0;
	cin>>n;
	list<int> s;
	for(i=0;i<n;i++){
		cin>>num;
		s.push_back(num);
	}
	bool check;
	cin>>q;
	for(i=0;i<q;i++){
		check=false;
		cin>>num;
		for(list<int>::iterator it=s.begin();it!=s.end();it++){
//			cout<<*it<<" "<<i<<endl;
			if(*it==num){
				check=true;
				break;
			}
		}
		if(check==true)ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}



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

int INF = 1001001001;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int h, n;
    cin >> h >> n;
    vector<vector<int>> dp(n+1, vector<int>(h+1));
    rep(i,n+1)rep(j,h+1) {
        /*if (j == 0) dp[i][j] = 0;
        else dp[i][j] = INF;*/
        dp[i][j] = INF;
    }
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        for (int j = 0; j <= h; j++) {
            //chmin(dp[i+1][j], dp[i][j]);
            if (j - a >= 0) chmin(dp[i+1][j], dp[i+1][j-a] + b);
            else chmin(dp[i+1][j], b);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;

const int N = 51;
const int mod = (int) 1e9 + 7;

int n;
ll k;
vector<vector<ll>> mat;

vector<vector<ll>> mult(vector<vector<ll>> mat1, vector<vector<ll>> mat2) {
    vector<vector<ll>> res(mat1.size(), vector<ll>(mat2[0].size()));
    for(int i = 0; i < res.size(); ++i) {
        for(int j = 0; j < res[i].size(); ++j) {
            for(int k = 0; k < mat2.size(); ++k) {
                res[i][j] += mat1[i][k] * mat2[k][j];
                res[i][j] %= mod;
            }
        }
    }
    return res;
}

vector<vector<ll>> identity(int size) {
    vector<vector<ll>> mat(size, vector<ll>(size));
    for(int i = 0; i < size; ++i) mat[i][i] = 1;
    return mat;
}

vector<vector<ll>> expo(vector<vector<ll>> mat, ll e) {
    if(e == 0) return identity(mat.size());
    if(e == 1) return mat;
    vector<vector<ll>> ret = expo(mat, e / 2);
    ret = mult(ret, ret);
    if(e % 2 == 1) ret = mult(ret, mat);
    return ret;
}

void solve() {
    cin >> n >> k;
    mat.resize(n, vector<ll>(n));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> mat[i][j];
        }
    }
    mat = expo(mat, k);
    ll ans = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            ans += mat[i][j];
            ans %= mod;
        }
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    solve();
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int n;
    cin >> n;
    string s;
    cin >> s;


    int r_count=0;
    for (int i=0;i<=n-1;i++)
    {
        if (s[i]=='R')
        {
            r_count++;
        }
    }

    int ans=0;
    for (int i=0;i<=r_count-1;i++)
    {
        if (s[i]=='W')
        {
            ans++;
        }
    }

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

Measured memory_bytes: 3772
n = int(input())
dat = []
for _ in range(n):
    dat.append(input())
cm, ca, cr, cc, ch = 0,0,0,0,0
for i in range(n):
    if dat[i][0] == "M":
        cm += 1
    if dat[i][0] == "A":
        ca += 1
    if dat[i][0] == "R":
        cr += 1
    if dat[i][0] == "C":
        cc += 1
    if dat[i][0] == "H":
        ch += 1
#print(cm,ca,cr,cc,ch)

res = 0
res += cm*ca*cr
res += cm*ca*cc
res += cm*ca*ch
res += cm*cr*cc
res += cm*cr*ch
res += cm*cc*ch

res += ca*cr*cc
res += ca*cr*ch
res += ca*cc*ch

res += cr*cc*ch
print(res)


Measured memory_bytes: 56024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int ans=0;
		for (int i = 0; i < n; i++) {
			if(sc.nextInt()%2==1)ans++;
		}
		if(ans%2==0)System.out.println("YES");
		else System.out.println("NO");
		
		}
		
	}

Measured memory_bytes: 32748
#include<cstdio>
#include<cstring>

const int N = 1e5 + 10;
int n, m, x, y, f[N];
bool mk[N];

int main(){
	while(~scanf("%d %d", &n, &m)){
		memset(mk, 0, sizeof(mk));

		for(int i=1; i<=n; i++){
			f[i] = 1;
		}

		mk[1] = 1;

		while(m--){
			scanf("%d %d", &x, &y);
            f[x]--;
            f[y]++;
            if(mk[x]){
				mk[y] = 1;
            }
            if(f[x]==0){
				mk[x] = 0;
            }
		}

		x = 0;
		for(int i=1; i<=n; i++){
			x += mk[i];
		}
		printf("%d\n", x);
	}
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;
typedef pair<long,long> P;
int main() {
    int n,m;
    long sum=0, now=0;
    cin >> n >> m;

    vector<P> A(n);
    for(int i=0; i<n; i++){
        cin >> A[i].first >> A[i].second;
    }

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

    for(int i=0; i<n; i++){
        if(A[i].second>= m - now){
            sum += A[i].first * (m-now);
            now += m-now;
            break;

        }else{
            sum += A[i].first * A[i].second;
            now += A[i].second;
        }
    }
    printf("%ld\n",sum);

}

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

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1)
                ans = mul(ans, x);
        return ans;
    }
}; // namespace modular

namespace Base {
    template <typename Tp> inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-')
                y = -1;
            c = getchar();
        }
        if (c == EOF)
            return 0;
        while ('0' <= c && c <= '9')
            x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); }
    template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; }
    template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; }
}; // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 300007

int N;
int a[MAX_N];
std::map<ll, ll> mp;

bool check(int lim) {
    mp.clear();
    Rep(i, N) if (a[i] <= a[i - 1]) {
        int tmp;
        while (!mp.empty() && (tmp = mp.rbegin()->first) > a[i]) {
            mp.erase(tmp);
        }
        tmp = a[i];
        while (tmp && mp[tmp] >= lim - 1)
            mp.erase(tmp--);
        if (!tmp)
            return false;
        mp[tmp]++;
    }
    return true;
}

int main() {
#ifdef LOCAL
    FIN("2.in");
#endif
    read(N);
    bool flag = true;
    Rep(i, N) read(a[i]), flag &= (a[i] > a[i - 1]);
    if (flag)
        return puts("1"), 0;
    int l = 2, r = N, mid, ans = -1;
    while (l <= r) {
        mid = l + r >> 1;
        if (check(mid))
            r = mid - 1, ans = mid;
        else
            l = mid + 1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main  {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    int n = Integer.parseInt(a + b);

    int c = (int)Math.sqrt(n);
    if(c * c == n){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }

}
}


Measured memory_bytes: 23892
#include <stdio.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)<(b)?(a):(b))
#define ll long long

int main(void){
	char str[20];
	scanf("%s",str);
	for(int i=0;i<19;i++){
	    if(str[i]!=',') printf("%c",str[i]);
	    else putchar(' ');
	}
	puts("");
    return 0;
}

Measured memory_bytes: 128
h, w = map(int, input().split())
a = []
for _ in  range(h):
    k = input()
    if "#" in k:
        a.append([i for i in k])
        
import numpy as np
for i in np.array([i for i in np.array(a).T if "#" in i]).T.tolist():
    print("".join(i))

Measured memory_bytes: 27240
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  for (auto &x: h) cin >> x;

  sort(h.rbegin(), h.rend());

  ll ans = 0;
  for (int i = k; i < n; i++) ans += h[i];

  cout << ans << endl;

  return 0;
}


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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<int,ll>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N = 2003;
const ll lmod = 1e9+7;

bitset<MAX_N * MAX_N> dp;
int a[MAX_N];

int main(){
  int N; cin >> N ;
  rep(i,N) scanf("%d",a+i);
  int _sum = 0;
  rep(i,N) _sum += a[i];
  dp.set(1);
  rep(i,N) dp |= (dp << a[i]);
  REP(i,(_sum+1)/2+1,_sum+2){
    if(dp[i]){
      cout << i-1 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
#include<functional>
using namespace std;
const int INF=1000000009;
int n,k;
int a[100005];
int l[100005],r[100005];
int par[100005];
int root;
vector<int> edge[100005];
void getara(int x,int prev)
{
	if(a[x]!=-1)
		l[x]=r[x]=a[x];
	for(int i=0;i<edge[x].size();i++)
	{
		int y=edge[x][i];
		if(y!=prev)
		{
			getara(y,x);
			if(l[y]==-INF)
				continue;
			if(l[x]==-INF)
			{
				l[x]=l[y]-1;
				r[x]=r[y]+1;
			}
			else
			{
				if(abs(l[x]%2)==abs(l[y]%2))
				{
					cout<<"No";
					exit(0);
				}
				l[x]=max(l[x],l[y]-1);
				r[x]=min(r[x],r[y]+1);
			}
		}
	}
	if(l[x]>r[x])
	{
		cout<<"No";
		exit(0);
	}
}
void getans(int x,int prev)
{
	for(int i=0;i<edge[x].size();i++)
	{
		int y=edge[x][i];
		if(y!=prev)
		{
			if(a[y]==-1)
			{
				if(l[y]<=a[x]+1&&r[y]>=a[x]+1)
					a[y]=a[x]+1;
				else
					a[y]=a[x]-1;
			}
			getans(y,x);
		}
	}	
}
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	memset(a,-1,sizeof(a));
	cin>>k;
	for(int i=0;i<k;i++)
	{
		int x,v;
		cin>>x>>v;
		x--;
		root=x;
		a[x]=v;
	}
	for(int i=0;i<n;i++)
	{
		l[i]=-INF;
		r[i]=INF;
	}
	getara(root,-1);
	getans(root,-1);
	cout<<"Yes"<<endl;
	for(int i=0;i<n;i++)
		cout<<a[i]<<endl;
	return 0;
}


Measured memory_bytes: 13824
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <cmath>

#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    double max_node=0;
    int max_satosui=0;
    int max_sato=0;
    int A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;
    
    max_sato=0;
    max_satosui=A*100;
    
    int mizu[301]={};
    mizu[0]=1;
    for(int i=0; i<=300; i++){
        if(mizu[i]==1){
            if(i+A<=300){
                mizu[i+A]=1;
            }
            if(i+B<=300){
                mizu[i+B]=1;
            }
        }
    }
    
    int sato[3001]={};
    sato[0]=1;
    for(int i=0; i<=3000; i++){
        if(sato[i]==1){
            if(i+C<=3000){
                sato[i+C]=1;
            }
            if(i+D<=3000){
                sato[i+D]=1;
            }
        }
    }

    for(int w=1; w<=300; w++){
        if(mizu[w]==0){continue;}
        
        for(int s=1; s<=3000; s++){
            if(100*w+s>F || w*E<s){break;}
            
            if(sato[s]==0){continue;}
            
            if(double(s)/(double)(100*w+s)>max_node){
                max_satosui=100*w+s;
                max_sato=s;
                max_node=double(s)/(double)(100*w+s);
            }
        }
    }
    
    cout<<max_satosui<< ' ' <<max_sato << endl;
    

    return 0;
}


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

int N;
char S[20000];
void Solve()
{
	int len = strlen(S);
	for (int i = 0; i < len; ++i){
		S[i] += N;
		if ((char)S[i] > (char)'Z') S[i] -= 26;
	}
	puts(S);
}

void Input()
{
	cin >> N;
	cin >> S;
}

int main()
{

	Input();
	Solve();

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define inf 1000000000
#define MOD 1000000007 
#define N 100005
#define M 1000000
#define LOG 20
#define KOK 300
#define EPS 0.0000001
using namespace std;

int main() {

	int n;

	scanf("%d",&n);

	vector<int> u(100005,0);
	int cnt[2]={0};

	for(int i=1;i<=n;i++) {

		int x;

		scanf("%d",&x);

		u[x]++;

	}

	for(int i=1;i<=100000;i++) {

		if(u[i]) cnt[u[i]&1]++;

	}

	printf("%d",cnt[0]+cnt[1]-(cnt[0]&1));

}	

Measured memory_bytes: 640
#[allow(unused_imports)]
use {
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::ops::*,
};

fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }

    let mut tot = a[0];
    let mut xor = a[0];
    let mut r = 1;
    while r < n && tot + a[r] == xor ^ a[r] {
        tot += a[r];
        xor ^= a[r];
        r += 1;
    }

    let mut ans = r;
    for i in 1..n {
        tot -= a[i - 1];
        xor ^= a[i - 1];
        while r < n && tot + a[r] == xor ^ a[r] {
            tot += a[r];
            xor ^= a[r];
            r += 1;
        }
        ans += r - i;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4744
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint N;
llint a[100005];
vector< pair<llint, llint> > vec;
llint ans[100005];

int main(void)
{
	cin >> N;
	for(int i = 0; i < N ; i++) cin >> a[i];
	
	llint prev = 0;
	for(int i = 0; i < N; i++){
		if(a[i] > prev){
			vec.push_back( make_pair(a[i], i) );
			prev = a[i];
		}
	}
	sort(a, a+N);
	
	int j = 0; prev = 0;
	for(int i = 0; i < vec.size(); i++){
		if(i > 0) prev = vec[i-1].first;
		while(vec[i].first > a[j]){
			ans[vec[i].second] += a[j] - prev;
			j++;
		}
		ans[vec[i].second] += (N-j) * (vec[i].first - prev);
	}
	
	for(int i = 0; i < N; i++){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4336
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(int a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

ll INF = 10000000;
ll mod = 1000000007;//10^9+7


//番号ズレ注意！！
int main() {
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    int a = (10 - A % 10) % 10;
    int b = (10 - B % 10) % 10;
    int c = (10 - C % 10) % 10;
    int d = (10 - D % 10) % 10;
    int e = (10 - E % 10) % 10;
    int last = a;
    chmax(last, b);
    chmax(last, c);
    chmax(last, d);
    chmax(last, e);
    cout << A + a + B + b + C + c + D + d + E + e - last << endl;


}

Measured memory_bytes: 256
#include<stdio.h>
//23:36
int main(){
  long n = 0;
  long a[100] = {};
  long i = 0;
  long j = 0;
  long min = 0;
  long max = 0;
  long cost = 0;
  long mincost = -1;
  
  scanf("%ld",&n);
  
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
  }
  
  min = a[0];
  max = a[0];
  
  for(i=1;i<n;i++){
    if(min > a[i]){
      min = a[i];
    }
    if(max < a[i]){
      max = a[i];
    }
  }
  //printf("%ld %ld ",min,max);
  for(i=0;min+i<=max;i++){
    cost = 0;
    for(j=0;j<n;j++){
      cost += (a[j] - (min+i))*(a[j] - (min+i));
    }
    //printf("%ld",cost);
    if(mincost > cost || mincost == -1){
      mincost = cost;
    }
  }
  
  printf("%ld",mincost);
  return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 1e5 + 20;

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

    int m, d, d1 = 0, d2 = 0;
    cin >> m >> d;

    int res = 0;
    for(int i = 1; i <= m; i++) {
    	for(int j = 1; j <= d; j++) {
		    d1 = j / 10;
		    d2 = j % 10;
		    if(d1 < 2 || d2 < 2) continue;
		    if(d1 * d2 != i) continue;
		    //cout << i << ' ' << j << endl;
		    res++;
		}
	}
	cout << res << endl;



    return 0;
}











Measured memory_bytes: 256
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define debug(x) {cout<<(#x)<<" "<<x<<endl;}
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

int n,T;

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(),T=read(); 
	int ans=0,last=read();
	rep(i,2,n) {
		int x=read();
		if (x-last>=T) ans+=T;
		else ans+=x-last;
		last=x;
	}
	printf("%d\n",ans+T);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		vector<pl> adj[n+1];
		for(int i=0;i<n-1;i++){
			ll a,b,c;
			cin >> a >> b >> c;
			adj[a].pb(mp(b,c));
			adj[b].pb(mp(a,c));
		}
		vl dist(n+1,0);
		vb vis(n+1,false);
		queue<ll> q;
		q.push((ll)1);
		vis[1] = true;
		while(!q.empty()){
			ll v = q.front();
			q.pop();
			for(auto u:adj[v]){
				if(!vis[u.fi]){
					vis[u.fi] = true;
					dist[u.fi] = dist[v] + u.se;
					q.push(u.fi); 
				}
			}
		}
		for(int i=1;i<=n;i++){
			if(dist[i]&1) cout << "1\n";
			else cout << "0\n";
		}
	}


	return 0;
}


Measured memory_bytes: 11228
#include<stdio.h>
int a[100010];
int book[100010];
int b[100010];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    int sum=0;
    for(int i=0;i<m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(a[x]<=a[y]) book[x]=1;
        if(a[x]>=a[y]) book[y]=1;
    }
   for(int i=1;i<=n;i++)
   {
       if(book[i]==0)
        sum++;
   }
    printf("%d\n",sum);
}

Measured memory_bytes: 2488
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(lli i=1;i<=(lli)(n);i++)

using namespace std;
typedef long long int lli;
const lli MAX=1e18;
lli f(lli a,lli b,lli c){
	if(a>b){
      lli z=a;
      a=b;
      b=z;
    }
	if(c<a)return b-c;
	else if(c<b)return b-a;
	else return c-a;
}
lli g(lli a,lli b){
	if(a>b){
      lli z=a;
      a=b;
      b=z;
    }
    if(a%2==0||b%2==0)return 0;
    else return a;
}
int main(){
	lli H,W;
	cin>>H>>W;
	lli ans=MAX;
	rep1(i,W-1){
		lli diff=g(H,W-i);
		lli X=f(H*i,(H*(W-i)+diff)/2,(H*(W-i)-diff)/2);
		ans=min(ans,X);
	}
	rep1(i,H-1){
		lli diff=g(W,H-i);
		lli Y=f(W*i,(W*(H-i)+diff)/2,(W*(H-i)-diff)/2);
		ans=min(ans,Y);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    string N;
    cin >> N;
    if (N[0] == N[1] && N[1] == N[2]) {
        cout << "Yes" << endl;
    } else if (N[1] == N[2] && N[2] == N[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstring>
using namespace std;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; }

int m, stage;
vector<vector<double> > p;

double dp[(1<<16)+10][20]; // remained member, #. of remained stages
double rec(int bit, int rem) {
    if (dp[bit][rem] >= -1e-10) return dp[bit][rem];
    if (rem == 0) return 1.0;
    
    double res = 0.0;
    int start = stage - rem;
    for (int i = 0; i < m; ++i) {
        if (!(bit & (1<<i))) continue;
        int nbit = bit & ~(1<<i);
        double tmp = 0.0;
        double prob = 1.0;
        for (int lose = start; lose < stage; ++lose) {
            double loseprob = prob * (1.0 - p[i][lose]);
            tmp += loseprob * rec(nbit, stage - lose);
            prob *= p[i][lose];
        }
        tmp += prob * rec(nbit, 0);
        chmax(res, tmp);
    }
    return dp[bit][rem] = res;
}

int main() {
    while (cin >> m >> stage) {
        p.assign(m, vector<double>(stage, 0.0));
        for (int i = 0; i < m; ++i) for (int j = 0; j < stage; ++j) cin >> p[i][j];

        memset(dp, -1, sizeof(dp));
        cout << fixed << setprecision(10) << rec((1<<m)-1, stage) << endl;
    }
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
int a,b,c;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>a>>b>>c;
    if(c>=a && c<=b) cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 256
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)



priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


void solve(){
    int n,W;
    cin >> n >> W;
    int weight[n],value[n];
    rep(i,0,n)cin >> value[i] >> weight[i];
    int dp[n+1][W+1];
    rep(i,0,W+1)dp[0][i]=0;
    rep(i,0,n){
        rep(w,0,W+1){
            if(w>=weight[i])dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+value[i]);
            else dp[i+1][w]=dp[i][w];
        }
    }
    cout << dp[n][W] << endl;
}

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






Measured memory_bytes: 7076
def main():
    n, m = map(int, input().split())
    gates = [0 for _ in range(n + 1)]
    for _ in range(m):
        l, r = map(lambda x: int(x) - 1, input().split())
        gates[l] += 1
        gates[r + 1] -= 1
    for i in range(1, n + 1):
        gates[i] += gates[i - 1]
    answer = 0
    for i in range(n):
        if gates[i] == m:
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7080
n = int(input())
s = input()

R = s.count('R')
G = s.count('G')
B = n - R - G

err = 0
for i in range(n - 2):
    span = 1
    while i + 2 * span < n:
        if s[i] != s[i + span] and s[i + span] != s[i + 2 * span] and s[i + 2 * span] != s[i]:
            err += 1
        span += 1

print(R * G * B - err)

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

int main() {
  int n, m;
  cin >> n >> m;
  
  int k, l, i, j;
  vector<int> a(m);
  for(i = 0; i < n; i++){
    cin >> k;
    for(j = 0; j < k; j++){
      cin >> l;
      a.at(l - 1)++;
    }
  }
  
  int ans = 0;
  for(i = 0; i < m; i++){
    if(a.at(i) == n) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"regexp"
)

func main() {
	var s string
	fmt.Scan(&s)
	r := regexp.MustCompile(`[a-z]`)
	if r.MatchString(s) {
		fmt.Println("a")
	} else {
		fmt.Println("A")
	}
}


Measured memory_bytes: 2000
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int n, m, a[50], b[50], c[50], d[50], min[50];
	long long tmp;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < m; i++)
		cin >> c[i] >> d[i];
	for (int i = 0; i < n; i++) {
		tmp = 100000000000000000;
		for (int j = 0; j < m; j++) {
			if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < tmp) {
				tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				min[i] = j + 1;
			}
		}
		cout << min[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def make_route a, b
    arr = [[0,0,""]]
    route = []
    until arr.empty?
        x, y, z = arr.shift
        arr << [x+1, y, z+"A"] if x < a && y != 5
        arr << [x, y+1, z+"B"] if y < b && x != 5
        route << z if x == a && y == b
    end
    return route
end

a, b = gets.chomp.split.map(&:to_i)

case [a, b]
when [6, 4]
    route = make_route(5, 4)
    route.map!{|r| r + "A"}
when [4, 6]
    route = make_route(4, 5)
    route.map!{|r| r + "B"}
when [5, 5]
    route = []
    route2 = make_route(4, 4)
    route2.each{|r|
        route << r + "AB"
        route << r + "BA"
    }
else
    route = make_route(a, b)
end
route.sort!
puts route


Measured memory_bytes: 6880
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, count = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);
  
  sort(vec.begin(), vec.end());
  
  for (int i = 0; i < N - 1; i++) {
    if (vec.at(i) == vec.at(i + 1)) count++;
  }
  
  cout << N - count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char a[100000];
int main()
{
cin>>a;
int t=strlen(a);
int n=0;
for(int i=0;i<t;i++)
{
    if(a[i]=='+')
        n++;
    if(a[i]=='-')
        n--;
}
cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n, d;
    cin >> n >> d;
    vvi x(n, vi(d));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> x[i][j];
        }
    }
    int ret = 0;
    set<int> square;
    for (int i = 1; i <= 40 * d; ++i) {
        square.insert(i * i);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int dist = 0;
            for (int k = 0; k < d; ++k) {
                dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            if (square.count(dist) != 0)
                ret++;
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author phantom11
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            String s = in.next();
            out
                    .printLine(s.substring(0, 4) + " " + s.substring(4));
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tokenizer = null;

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(in.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                return null;
            }
        }

    }
}



Measured memory_bytes: 8404
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define prime 1000000007
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    while(true) {
        int h, w;
        cin >> w >> h;
        if(h == 0 && w == 0) return 0;
        bool Tate[h][w - 1], Yoko[h - 1][w];
        rep(i, 2 * h - 1) {
            if(i % 2 == 0) {
                rep(j, w - 1) cin >> Tate[i / 2][j];
            } else {
                rep(j, w) cin >> Yoko[i / 2][j];
            }
        }
        vector<vector<int>> dist(h, vector<int>(w, -1));
        dist[0][0] = 0;
        queue<P> Q;
        Q.push(make_pair(0, 0));
        while(!Q.empty()) {
            P p = Q.front();
            Q.pop();
            int x = p.F, y = p.S;
            int d = dist[x][y];
            if(x + 1 < h) {
                if(!Yoko[x][y] && dist[x + 1][y] == -1) {
                    dist[x + 1][y] = d + 1;
                    Q.push(make_pair(x + 1, y));
                }
            }
            if(x - 1 >= 0) {
                if(!Yoko[x - 1][y] && dist[x - 1][y] == -1) {
                    dist[x - 1][y] = d + 1;
                    Q.push(make_pair(x - 1, y));
                }
            }
            if(y + 1 < w) {
                if(!Tate[x][y] && dist[x][y + 1] == -1) {
                    dist[x][y + 1] = d + 1;
                    Q.push(make_pair(x, y + 1));
                }
            }
            if(y - 1 >= 0) {
                if(!Tate[x][y - 1] && dist[x][y - 1] == -1) {
                    dist[x][y - 1] = d + 1;
                    Q.push(make_pair(x, y - 1));
                }
            }
        }
        cout << dist[h - 1][w - 1] + 1 << endl;
    }
}



Measured memory_bytes: 3160
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<string.h>
using namespace std;
int main(){
string s,a;
int c;
cin>>s;
a=s;
reverse(a.begin(),a.end());
if(a==s){
    c=1;
}
if(c==1){
    int l=s.length();
    int m=l/2;
    for(int i=0;i<m;i++)
    if(s[i]!=s[m+i+1]){
        c=0;
    }
}
if(c==0)
    cout<<"No";
else
    cout<<"Yes";


}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int par[110];
int ranks[110];

int n, m;
vector<T> edge(10010);

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

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

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

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

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

int kruskal(int n){
    int ans=1e9;
    for(int i=0; i<=m-(n-1); i++){
        init(n);
        int maxcost, mincost=0, cnt=0;
        for(int j=i; j<m; j++){
            int cost, cv, nv;
            tie(cost, cv, nv)=edge[j];
            if(j==i) mincost=cost;
            if(!same(cv, nv)){
                unite(cv, nv);
                cnt++;
                maxcost=cost;
            }
        }

        if(cnt==n-1){
            ans=min(ans, maxcost-mincost);
        }
    }
    return ans!=1e9 ? ans : -1;
}

int main(){
    while(1){
        cin>>n>>m;
        if(n==0 && m==0) return 0;
        for(int i=0; i<m; i++){
            int a, b, w; cin>>a>>b>>w;
            a--, b--;
            edge[i]=T(w, a, b);
        }
        sort(edge.begin(), edge.begin()+m);

        cout << kruskal(n) << endl;
    }
}


Measured memory_bytes: 3132
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstring>
#include<functional>
#include<cmath>

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)

using namespace std;

int main(){
	int N,M,C,ans(0),an(0);
	cin >> N >> M >> C;
	vector<int> B(M);
	vector<vector<int> > A(N,vector<int>(M));
	rep(i,0,M) cin >> B[i];
	rep(i,0,N){
		rep(I,0,M){
			cin >> A[i][I];
		}
	}
	rep(i,0,N){
		rep(I,0,M){
			an += A[i][I] * B[I];
		}
		if(0 < an + C) ans++;
		an = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

const int MOD = 1e9 + 7;

int main(){

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

    long long ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            if(A[i] > A[j]){
                ans++;
            }
        }
    }

    ans = (ans * K) % MOD;

    sort(A.begin(), A.end(), greater<int>());

    long long temp = 0;
    int before = 0;
    int beforeCnt = 0;
    int tempCnt = 0;
    for(int i = 0; i < N; i++){
        int a = A[i];
        if(a == before){
            temp = (temp + beforeCnt) % MOD;
            tempCnt++;
        }
        else{
            before = a;
            beforeCnt += tempCnt;
            temp = (temp + beforeCnt) % MOD;
            tempCnt = 1;
        }
    } 

    long long temp2 = ((long long)(K - 1) * K / 2) % MOD;
    int temp3 = (temp * temp2) % MOD;

    ans = (ans + temp3) % MOD;

    cout << ans << endl;

    return 0;
}

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

# define M_PI           3.14159265358979323846

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
int a,b,x;double res;
cin>>a>>b>>x;
if((2*x)>=(a*a*b))
{
  double tp=2.0*((b/(a*1.0))-((x*1.0)/(a*a*a)));
   res=atan(tp)*180.0/M_PI;
}
else
{
  double tp=(1.0*a*b*b)/(2.0*x);
  res=atan(tp)*180.0/M_PI;
}
printf("%0.9f",res);
  return 0;
}


Measured memory_bytes: 256
import sys
from fractions import Fraction
input = sys.stdin.readline


def inverse(f):
    return Fraction(f.denominator, f.numerator)


n = int(input())
a = list(map(int, input().split()))
sum_a = 0
for i in range(n):
    sum_a += Fraction(1, a[i])
print(float(inverse(sum_a)))

Measured memory_bytes: 5600
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    int K, X;
    cin >> K >> X;
    if(K*500>=X) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ATcode131
//
//  Created by didi on 2020/1/16.
//  Copyright © 2020年 didi. All rights reserved.
//

#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cassert>
#include <queue>
#include <list>
using namespace std;

#define ll long long

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    int cnt = 0;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = 1; i + 1 < N; ++i) {
        int a = A[i-1], b = A[i], c = A[i+1];
        if (b > a && b < c || b > c && b < a) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<long long int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  bool X = false;
  for (int i = 0; i < N; i++) {
    if (A.at(i) == 0) X = true;
  }
  if (X) cout << 0 << endl;
  else {
    long long int ans = 1;
    for (int i = 0; i < N; i++) {
      if (log10(ans) + log10(A.at(i)) > 18) {
        ans = -1;
        break;
      }
      else ans *= A.at(i);
    }
    if (ans > 1000000000000000000) ans = -1;
    cout << ans << endl;
  }
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define		fast			ios::sync_with_stdio(false);cin.tie(0);cout.tie(NULL);
#define		rep(i,n)		for(int i = 1; i<=n; i++)
#define		all(p)			p.begin(),p.end()
#define		mem(ar,val)		memset(ar, val, sizeof(ar))
#define		sz(c)			(int)c.size()
#define		pb(x)			push_back(x)
#define		mkp(x,y)		make_pair(x,y)
#define 	deb			cout<<"hehehe\n"
#define		ff			first
#define		ss			second
#define 	pf 			printf
#define 	sf 			scanf
#define		ll			long long
#define		pii			pair<int, int>
#define 	pll			pair<ll, ll>
#define 	vll			vector<long long>
#define 	vi			vector<int>
#define		nl			"\n"
#define		pnl			printf("\n");
#define		S(a)			scanf("%lld",&a)
#define		SS(a,b)			scanf("%lld %lld",&a,&b)
#define		SSS(a,b,c)			scanf("%lld %lld %lld",&a,&b,&c)
#define		P(a)			printf("%lld\n",a)
#define		PP(a,b)			printf("%lld %lld\n",a,b)
#define 	total_bit(a)		__builtin_popcount(a)
#define 	UNIQUE(a)		sort(all(a)); a.erase(unique(all(a)), a.end())
#define		FI			freopen("input.txt", "r", stdin);
#define 	FO			freopen("output.txt", "w", stdout);
using namespace std;
const double pi = acos(-1.0);
const int INF = 0x7f7f7f7f;
const int M = 1e9 + 7;
const int N = 1e6+7;
void solve()
{
	ll n;
	S(n);
	ll ar[n];
	int o[50]={0};
	for(ll i = 0; i<n; i++)
	{
		S(ar[i]);
		ll x = ar[i];
		int idx = 0;
		while(x)
		{
			if(x & 1LL)
				o[idx]++;
			x >>= 1LL;
			idx++;
		}
	}	
	vll ans;
	for(ll i = 0; i<n; i++)
	{
		ll sum = 0;
		for(int j = 0; j<50; j++)
		{
			if(ar[i] & 1LL)
			{
				if(o[j] %2 == 0)
					sum += 1LL << j;
			}
			else
			{
				if(o[j] % 2 != 0)
					sum += 1LL << j;
			}
			ar[i] >>= 1LL;
		}
		ans.push_back(sum);
	}
	for(ll y : ans)
		cout<<y<<" ";
	pnl;
}
int main()
{
 	solve();
	return 0;
}


Measured memory_bytes: 6916
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    ll N,K;
    cin >> N >> K;

    vector<ll> H(N);
    REP(i,N) cin >> H[i];

    sort(ALL(H));
    reverse(ALL(H));

    ll last = K;
    ll ans = 0;
    REP(i,N) {
        // 必殺技
        if ( last > 0) {
            last--;
            continue;
        }
        ans += H[i];
    }


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


Measured memory_bytes: 1792