akhauriyash/Code-Regression huggingface dataset:
#include <list>       // ヘッダファイルインクルード
#include <vector>
#include <iostream>
using namespace std;         //  名前空間指定

int comp_str(string first_str, string second_str, int length){
  int res = 1;
  int count_length = 0;
  while(count_length != length){
    char first_c = first_str[count_length];
    char second_c = second_str[count_length];
    if (first_c < second_c) {
      res = 1;
      break;
    }
    else if (first_c > second_c) {
      res = 2;
      break;
    }
    count_length++;
  }
  
  return res;
}

int main()
{
  int N, L;
  cin >> N;
  cin >> L;
  
  vector<string> s_v(N, ""); 
  list<string> s_list_sorted;
  for (int i=0; i<N; i++){
    cin >> s_v[i];
  }
  
  for (int i=0; i<N; i++){
    string s_first = s_v[0];
    string s_second;
    int min_index = 0;
    for (int j=1; j<N-i; j++){
      s_second = s_v[j];
      int comp_res = comp_str(s_first, s_second, L);
      if (comp_res == 1) {
      }
      else if (comp_res == 2) {
        s_first = s_second;
        min_index = j;
      }
    }
    s_list_sorted.push_back(s_first);
    s_v.erase(s_v.begin() + min_index);  
  }
  for(auto itr = s_list_sorted.begin(); itr != s_list_sorted.end(); ++itr) {
    cout << *itr;
  }
  cout << endl;
}


Measured memory_bytes: 256
N = int(input())
K = list(map(int,input().split()))
K = sorted(K,reverse=True)
"""
#print(K)
before_data = 0
before_data_before = 0
ans = 0 
for i in K :
    ans += before_data
    before_data_before = before_data
    before_data = i
"""
ans = 0 
for i,l in enumerate(K) :
    if (i == 0 ):
        ans += 0
    else :
        ans += K[i // 2]
print(ans)

Measured memory_bytes: 31004
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int n = sc.nextInt();
    int [] lots = new int[w];
    for (int i = 0; i < w; i++) lots[i] = i + 1;

    for (int i = 0; i < n; i++) {
      String [] s = sc.next().split(",");
      int a = Integer.parseInt(s[0]);
      int b = Integer.parseInt(s[1]);
      int temp;

      temp = lots[a - 1];
      lots[a - 1] = lots[b - 1];
      lots[b - 1] = temp;
    }

    for (int i = 0; i < w; i++) {
      System.out.println(lots[i]);
    }
  }
}

Measured memory_bytes: 17344
# C
N = int(input())
S = list(input())


res = 0
for i in range(1, N):
    if S[i] == "E":
        res += 1
res_min = res
for i in range(1, N):
    if S[i-1] == "W":
        res += 1
    if S[i] == "E":
        res -= 1
    res_min = min(res, res_min)
print(res_min)

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

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

    int x, t;
    cin >> x >> t;
    int result = x - t;
    if (t >= x) {
        cout << "0";
        return 0;
    }
    cout << result;
}

Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {

    ll a,b,c;

    cin >> a >> b >> c;

    if((c-a-b)<=0) {
        print("No");
        return 0;
    }

    bool flag = ((c-a-b) * (c-a-b) - 4*a*b) > 0;

    print(flag ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int x,y,cnt=0;
	cin>>x>>y;
	for(int i=x;i<=y;i++)
	{
		if(i/10000==i%10&&i%10000/1000==i%100/10)
			cnt++;
	}
	cout<<cnt;
	return 0;
}

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

int main(){
 int n,m,l;
 
 cin >> n >> m >> l ;

 long long a[n][m],b[m][l],c[n][l];
  
 for(int i=0;i<n;i++){
  for(int j=0;j<l;j++){
   c[i][j]=0;
  }
 } 

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

 for(int i=0;i<m;i++){
  for(int j=0;j<l;j++){
   cin >> b[i][j];
  }
 }
 
 for(int i=0;i<n;i++){
  for(int j=0;j<l;j++){
   for(int k=0;k<m;k++){
    c[i][j]+=a[i][k]*b[k][j];
   }
  }
 }

 for(int i=0;i<n;i++){
  for(int j=0;j<l;j++){
   if(j!=0)cout << " " ;
   cout << c[i][j] ;
  }
  cout << endl ;
 }

 return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a) ;
#define vi vector<int>
#define ull unsigned long long
#define ll long long 
#define db double 
#define fl float
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lrep(i,a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
#define mpr make_pair
#define pb push_back
#define fr first
#define sn second
#define bpp(x) __builtin_popcountll(x)
/*
double squareRoot(long long number, int precision) 
{ 
    long long start = 0, end = number; 
    long long mid; 
    double ans; 
    while (start <= end) { 
        mid = (start + end) / 2; 
        if (mid * mid == number) { 
            ans = mid; 
            break; 
        }  
        if (mid * mid < number) { 
            start = mid + 1; 
            ans = mid; 
        } 
        else { 
            end = mid - 1; 
        } 
    } 
    double increment = 0.1; 
    for (long long i = 0; i < precision; i++) { 
        while (ans * ans <= number) { 
            ans += increment; 
        } 
        ans = ans - increment; 
        increment = increment / 10; 
    } 
    return ans; 
} 
*/
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(NULL);
long long a,b,c; cin>>a>>b>>c;
long long d=c-a-b;
if(d>0 && d*d>4*a*b )
cout<<"Yes";
else
cout<<"No";
}

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

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

    int h, w;
    cin >> h >> w;
    char C[h][w];
    int dp[h][w] = {};
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> C[i][j];
            dp[i][j] = 1e9;
        }
    }

    dp[0][0] = C[0][0] == '#';

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i - 1 >= 0){
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + (C[i][j] != C[i - 1][j]));
            }
            if(j - 1 >= 0){
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + (C[i][j] != C[i][j - 1]));
            }
        }
    }

    int ans = dp[h - 1][w - 1];
    if(C[0][0] == '.' and C[h - 1][w - 1] == '.'){
        ans /= 2;
    }else if(C[0][0] == '.' and C[h - 1][w - 1] == '#'){
        ans = (ans + 1) / 2;
    }else if(C[0][0] == '#' and C[h - 1][w - 1] == '.'){
        ans /= 2;
    }else{
        ans = (ans + 1) / 2;
        
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

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

    int sumxor = 0;
    for (auto &&i : a) {
        sumxor ^= i;
    }

    for (int i = 0; i < n; i++) {
        const int ans = a[i] ^ sumxor;
        cout << ans << " ";
    }

    cout << endl;
}


Measured memory_bytes: 4700
#include<stdio.h>
int main(){
  int i,j,N,count,ch,flag;
  int a[100];
  count=0;
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  flag=1;
  while(flag){
    flag=0;
    for(j=N-1;j>=1;j--){
      if(a[j]<a[j-1]){
	ch=a[j-1];
	a[j-1]=a[j];
	a[j]=ch;
	count++;
	flag=1;
      }
    }
  }

  for(j=0;j<N-1;j++){
    printf("%d ",a[j]);
  }
  printf("%d",a[N-1]);
  printf("\n");
  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int k,d[100005];
bool used[100005];
deque <int> que;
vector <pair<int,int> > ve[100005];
int main(){
	cin>>k;
	for (int i=0;i<k;i++){
		ve[i].push_back(mp((i+1)%k,1));
		ve[i].push_back(mp(i*10%k,0));  
	}
	que.push_back(1); 
	d[1]=1;
	while (!que.empty()){
		int x=que.front();
		que.pop_front();
		if (used[x]) continue;
		used[x]=true;
		for (int i=0;i<ve[x].size();i++){
			if (!used[ve[x][i].first]){
				if (ve[x][i].second==0){
					que.push_front(ve[x][i].first);
					d[ve[x][i].first]=d[x]; 
				}else{
					que.push_back(ve[x][i].first);
					d[ve[x][i].first]=d[x]+1; 
				}
			}
		}
	}
	cout<<d[0];
	return 0;
}

Measured memory_bytes: 6400
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s;
ll ans, pref[N], cnt[N];
main() {
  file("threesum");
  ios;
  cin >> s;
  int n = s.size();
  s = '#' + s;
  ++cnt[0];
  int cur = 1;
  foo(i, n, 1, 1) {
    pref[i] = pref[i + 1] + (s[i] - '0') * cur;
    pref[i] %= 2019;
    ans += cnt[pref[i]]++;
    cur *= 10;
    cur %= 2019;
  }
  cout << ans;
  return 0;
}
/**
pref[r]-pref[l-1]/(10^(l-1))

7
10*7+3
*/


Measured memory_bytes: 5364
#include "algorithm"
#include "iostream"
#include "numeric"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;

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

const ll MOD = 1000000007;
using mint = Fp<MOD>;

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

  ll N;
  cin >> N;
  VL as(N);
  rep(i, N) cin >> as[i];

  VL res(3);

  mint ret = 1;

  for (auto& a : as) {
    ll ct = 0;
    ll i = -1;
    rep(j, res.size()) {
      if (res[j] == a) {
        ct++;
        i = j;
      }
    }
    if (ct == 0) {
      cout << 0 << endl;
      return 0;
    }
    res[i]++;
    ret *= ct;
  }

  cout << ret << endl;

  return 0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define ul unsigned long long

int main() {
  ll A,b1,b2,B;
  char c;
  cin >> A >> b1 >> c >> b2;
  if(b1==10) B=10;
  else if(b2 > 9) B=b1*100+b2;
  else B = b1*10+b2;
  cout << (A*B)/100 << endl;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;

int main() {
    nl // youtu.be/2chfsFTNEXw
    char c;
    cin >> c;
    cout << (isupper(c) ? 'A':'a'); 
    return 0;  
}

Measured memory_bytes: 3632
#include<stdio.h>
#define MOD 1000000007
long int PROD(long int a,long int b){return a%MOD*(b%MOD)%MOD;}//a*b
int main(){
  char s[53],t[53];
  long int i,n,x=0,y=1;
  scanf("%ld%s%s",&n,s,t);
  for(i=0;i<n;i++){
    if(!i)y=3*(1+(s[i]!=t[i]));
    else{
      if(x){y=PROD(y,1+2*(s[i]!=t[i]));}
      else{y=PROD(y,2);}
    }
    x=s[i]!=t[i];
    i+=x;
  }
  printf("%ld",y);
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
#include<atcoder/all>
#define int long long
using namespace std;
using namespace atcoder;
signed main(){
  int Q;
  cin>>Q;
  while(Q--){
    int N,M,A,B;
    cin>>N>>M>>A>>B;
    cout<<floor_sum(N,M,A,B)<<endl;
  }
}

Measured memory_bytes: 3668
#include <cstdio>
#include <iostream>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
const int mod=1e9+7;
int n,m,K,ans,f[1<<20],A[401],B[401],C[401],t[21][21],g[1<<20][20],p[1<<20];
void inc(int&a,int b){a+=b;if(a>=mod)a-=mod;}
int main(){
	cin>>n>>m>>K;n--;
	ref(i,1,K){
		cin>>A[i]>>B[i]>>C[i],B[i]--;
		t[A[i]][++t[A[i]][0]]=i;
	}
	ref(i,0,(1<<n)-1){int I=i;
		ref(j,0,n-1)g[i][j]=I&-I,I=I^(I&-I);
		ref(j,0,n-1)if(i>>j&1)p[i]++;
	}
	f[0]=1;
	ref(i,1,m){
		ref(I,0,n-1){
			ref(j,0,(1<<n)-1)if((j>>n-1&1)&&p[j]==(I+1))
				inc(f[j],f[j^(1<<n-1)]);
			def(j,(1<<n)-1,0)if(g[j][I]){
				int G=g[j][I];
				if(G==(1<<n-1))continue;
				if(!(j&(G<<1)))inc(f[j],f[j^G^(G<<1)]);
			}
		}
		ref(j,0,(1<<n)-1)
			ref(I,1,t[i][0]){
				int id=t[i][I];
				if((j>>B[id]&1)!=C[id]){
					f[j]=0;break;
				}
			}
	}
	ref(i,0,(1<<n)-1)inc(ans,f[i]);
	cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int MX = 300 * 1000 + 7;

int h[MX];
int main() {
#ifdef BZ
    freopen("in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    swap(a, b);
    if (ll(a) * b < n || a + b - 1 > n) {
        cout << -1 << endl;
        return 0;
    } else {
        int more = n - b;
        for (int i = 1; i <= b; i++) {
            int cur = min(more, a - 1);
            h[i] = cur + 1;
            more -= cur;
        }
        assert(more == 0);
        int nxt = n;
        for (int i = n; i >= 1; i--) {
            int go = 1;
            while (go <= n && h[go] >= i) go++;
            int cnt = go - 1;
            for (int j = nxt - cnt + 1; j <= nxt; j++) {
                cout << j << " ";
            }
            nxt -= cnt;
        }
        cout << "\n";
    }
}

Measured memory_bytes: 3072
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main() {

    int n, m;
    for (;;) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        vector<int> players;
        players.reserve(n);
        for (int i = 1; i <= n; i++) players.push_back(i);
        int idx = m -1;
        while (players.size() > 1) {
            players.erase(players.begin()+idx);
            idx = (idx + m-1) % players.size();
        }
        printf("%d\n", players[0]);
    }
    return 0;
}


Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll N = 100007;
int n , m ;
int parent[N] , size[N];
int findParent(int i){
    if(parent[parent[i]]!=parent[i])
        parent[i]=findParent(parent[i]);
    return parent[i];
}
void merge(int a , int b){
    int parent_a=findParent(a),parent_b=findParent(b);
    if(parent_a==parent_b)
        return;
    if(size[parent_a]>=size[parent_b])//the larger connected component eats up the smaller one
    {
         size[parent_a]+=size[parent_b];
         parent[parent_b]=parent_a;
    }
    else
    {
         size[parent_b]+=size[parent_a];
         parent[parent_a]=parent_b;
    }
    return;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    cin >> n >> m;
    for(int i = 1 ;i <= n; i++){
        parent[i] = i;
        size[i] = 1;
    }
    int x , y , z;
    while(m--){
        cin >> x >> y >> z;
        merge(x , y);
    }
    int no = 0;
    for(int i = 1; i <= n; i++)
        if(findParent(i) == i)
            no++;
    cout << no << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		Integer count = 0;
		while (true) {

			count++;

			Integer a = sc.nextInt();

			if (a == 0) {
				return;
			}

			System.out.println("Case " + count + ": " + a);

		}

	}

}



Measured memory_bytes: 42472
#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

void printArray(int *A, int n) {
  rep(i, n) {
    std::cout << A[i];
    if (i == n - 1)
      std::cout << '\n';
    else
      std::cout << ' ';
  }
}

long long cnt = 0;

void merge(int *A, int n, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1 + 1], R[n2 + 1];
  rep(i, n1) L[i] = A[left + i];
  rep(i, n2) R[i] = A[mid + i];
  L[n1] = 1 << 30;
  R[n2] = 1 << 30;

  int l = 0, r = 0;
  for (int i = left; i < right; ++i) {
    if (L[l] < R[r]) {
      A[i] = L[l];
      l++;
    } else {
      cnt += n1 - l;
      A[i] = R[r];
      r++;
    }
  }
}

void mergeSort(int *A, int n, int left, int right) {
  if (right - left <= 1)
    return;
  int mid = (left + right) / 2;

  mergeSort(A, n, left, mid);
  mergeSort(A, n, mid, right);
  merge(A, n, left, mid, right);
}

int main() {
  int n;
  std::cin >> n;
  int *S = new int[n];
  rep(i, n) std::cin >> S[i];

  mergeSort(S, n, 0, n);
  // printArray(S, n);
  std::cout << cnt << '\n';
  return 0;
}



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

    typedef long long ll;
    const ll MOD = 1e9+7;
    const int N = 3005;

    int n;
    double p[N],dp[N][N];

    int main()
    {
        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
        cin>>n;
        for(int i=1;i<=n;i++)cin>>p[i];

        dp[0][0]=1.0;

        for(int i=1;i<=n;i++){
            for(int j=0;j<=i;j++){
                if(j)dp[i][j]=p[i]*dp[i-1][j-1]+(1.0-p[i])*(dp[i-1][j]);
                else dp[i][j]=(1-p[i])*dp[i-1][j];
            }
        }

        double ans=0.0;


        for(int i=1;i<=n;i++){
            if(i>n-i)ans+=dp[n][i];
        }

        cout<<fixed<<setprecision(12)<<ans;
        return 0;
    }


Measured memory_bytes: 69120
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int main()
{
    string s;
    cin>>s;
    s += 'R';
    vector<int> ve;
    int cnt = 1;
    for (int i = 1;i < s.size();i ++)
    {
        if (s[i] != s[i-1])
        {
            ve.push_back(cnt);
            if (s[i] == 'L') a[i-1] = a[i] = 1;
            //cout<<cnt<<endl;
            cnt = 0;
        }
        cnt ++;
    }
    for (int i = 0;i < ve.size();i += 2)
    {
        if ((ve[i]+ve[i+1]) & 1)//不同
        {
            int sum = ve[i] + ve[i+1];
            if (ve[i]&1) ve[i] = sum/2+1,ve[i+1] = sum/2;
            else ve[i] = sum/2,ve[i+1] = sum/2+1;
        }
        else ve[i] = (ve[i]+ve[i+1])/2,ve[i+1] = ve[i];
    }
    bool flag = 0;
    int pos = 0;
    for (int i = 0;i < s.size()-1;i++)
    {
        if (flag) cout<<' ';
            flag = 1;
        if (a[i])
        {

            cout<<ve[pos ++];
        }
        else cout<<0;
    }
    return 0;
}


Measured memory_bytes: 1528
#include <stdio.h>

int main(void){
	float w;
	while(scanf("%f" , &w)!=EOF){
		if(w <= 60){
			if(w <= 54){
				if(w <= 48) printf("light fly\n");
				else{
					if(w <= 51) printf("fly\n");
					else printf("bantam\n");
				}
			}else{
				if(w <= 57) printf("feather\n");
				else printf("light\n");
			}
		}else{
			if(w <= 75){
				if(w <= 64) printf("light welter\n");
				else{
					if(w <= 69) printf("welter\n");
					else printf("light middle\n");
				}
			}else{
				if(w <= 81) printf("middle\n");
				else if(w <= 91) printf("light heavy\n");
				else printf("heavy\n");
			}
		}
	}
	return 0;
}

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

using ll = long long int;

const int MAX_N = 300 + 5;

int n;
ll a[MAX_N][MAX_N];

ll path[MAX_N][MAX_N];
ll ans;

int main(void){
    // Here your code !
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
      scanf("%lld\n", &(a[i][j]));
    }

    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
      path[i][j] = a[i][j];
    }

    for (int i = 0; i < n; ++i) {path[i][i] = 0;}

    for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
      path[i][j] = min(path[i][j], path[i][k] + path[k][j]);
    }

    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
      if (a[i][j] != path[i][j]) {printf("%d\n", -1); return 0;}
    }

    for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) {
      bool exist = false;
      for (int k = 0; k < n; ++k) {
        if (k == i || k == j) continue;
        exist |= (path[i][j] == (path[i][k] + path[k][j]));
      }
      if (!exist) ans += a[i][j];
    }

    printf("%lld\n", ans);

    return 0;
}

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

int N, M;
vector<int> s, c;

bool ok(string str) {
    if (str.size() != N) return false;
    for (int i = 0; i < M; ++i) if (str[s[i]] != (char)(c[i] + '0')) return false;
    return true;
}

string solve() {
    for (int i = 0; i <= 999; ++i) {
        string str=to_string(i);
        if (ok(str)) return str;
    }
    return "-1";
}

int main() {
    cin >> N >> M;
    s.resize(M); c.resize(M);
    for (int i = 0; i < M; ++i) cin >> s[i] >> c[i], --s[i];
    cout << solve() << endl;
}

Measured memory_bytes: 256
// No.080639011920
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <deque>
#define N 200005
using namespace std;

int n;
char s[N];
deque<int> q;

void print() {
    for (int i = 1; i <= n; ++i)
        q.push_back(q.front()), cout << char('A' + (q.front())), q.pop_front();
    cout << endl;
}

int main() {
#ifdef LOCAL_JUDGE
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif

    int K;
    cin >> n >> K;
    scanf("%s", s + 1);


    for (int i = 1; i <= n; ++i)
        q.push_back((s[i] - 'A') ^ (i % 2 == 0));

    //print();

    K = min(K, n * 2 + K % 2);

    for (int i = 1; i <= K; ++i) {
        //print();
        int u = q.front(); q.pop_front();
        if (!u) q.push_front(1);
        else q.push_back((n % 2 == 0));
    }

    for (int i = 1; i <= n; ++i)
        putchar('A' + (q.front() ^ (i % 2 == 0))), q.pop_front();

    return 0;
}


Measured memory_bytes: 1536
A = int(input()) + 1
B = int(input()) + 1
C = int(input()) + 1
X = int(input())
ans = 0

for i in range(A):
    for j in range(B):
        for k in range(C):
            if 500*i + 100*j + 50*k == X:
                ans += 1

print(ans)



Measured memory_bytes: 3060
n, k = map(int, input().split())
h = list(map(int, input().split()))
#print(n,k,h)
h.sort(reverse=False)
#print(h)
ans = 0
if k >= n:
  ans = 0
else:
  for i in range(n-k):
    ans += h[i]
print(ans)

Measured memory_bytes: 26024
#include<stdio.h>

int main(){
	int a,b,c,jd1,jd2;
	
	scanf("%d %d %d", &a, &b, &c);

	if(a<1 || a>101 || b<1 || b>101 || c<1 || c>101) {
		exit(0);
	}

	jd1 = b - a; jd2 = c - b;

	if(jd1 == jd2){
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> A >> B >> C;
	if (A > B)swap(A, B);
	if (A <= C && C <= B)cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int K;
    string S;
    cin >> K >> S;
    if(S.size() <= K){
        cout << S << endl; return 0;
    }
    string ans;
    for(int i=0; i<K; i++) ans += S[i];
    ans += "...";
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
void solve(){
    char x;
    cin>>x;
    if(x>='A' && x<='Z')cout<<"A";
    else cout<<"a";
}
int main() {
    ios;
	int t=1;
	//cin>>t;
	while(t--)solve();
 
    
}


Measured memory_bytes: 3656
import java.util.Scanner;
class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] a = new int[n][4];
        for (int i=0; i<n; i++) {
        		for(int j=0; j<4; j++) {
        			a[i][j] = sc.nextInt();
        		}
        }
        for (int i=0; i<4; i++) {
        		int[][] b = new int[3][10];
        		for (int j=0; j<n; j++) {
        			if(a[j][0] == i+1
        					) {
        				b[a[j][1]-1][a[j][2]-1] += a[j][3];
        			}
        		}
        		for (int k=0; k<3; k++) {
        			for (int l=0; l<10; l++) {
        				if (l == 9) {
        					System.out.println(" " + b[k][l]);
        				} else {
        					System.out.print(" " + b[k][l]);
        				}
        			}
        		}
        		if (i != 3) System.out.println("####################");
        }
    }
}


Measured memory_bytes: 29576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> c(n - 1),s(n - 1), f(n - 1);
	rep(i,n - 1) cin >> c.at(i) >> s.at(i) >> f.at(i);
	rep(i,n - 1){
		ll k = 0;
		for(int j = i; j < n - 1; j++){
			if(k < s.at(j)){
				k = s.at(j) + c.at(j);
			}
			else{
				if((k - s.at(j)) % f.at(j) == 0){
					k += c.at(j);
				}
				else{
					k = k + (f.at(j) - (k - s.at(j)) % f.at(j)) + c.at(j);
				}
			}
		}
		cout << k << endl;
	}
	cout << 0 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main(){
   int k,banyak;
   scanf("%d %d", &k,&banyak);
   getchar();
   if(k*500>=banyak){
      cout<<"Yes"<<endl;
   }
   else {
      cout<<"No"<<endl;
   }
}

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

using namespace std;

int main(void) {
  vector <int> a(3);
  cin >> a[0] >> a[1] >> a[2];

  sort(a.begin(), a.end()); 
  int mx = a[2];
  int mn = a[0];
  int count = 0;
  while(mx - mn > 1) {
    int diff = mx - mn;
    count += diff / 2;
    // cout << "count: " << count << endl; 
    a[0] += diff / 2 * 2;
    // cout << "a[0]: " << a[0] << endl;
    sort(a.begin(), a.end());
    mx = a[2];
    mn = a[0];
  }
  if(a[2] - a[1] == 1) {
    count++;
  }
  else if(a[2] - a[1] == 0 && a[1] - a[0] == 1) {
    count += 2;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			String [] data = new String[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.next();
			}
			
			int count = 0;
			int pre = 0, suf = 0, med = 0;
			for(int i = 0; i < n; i++){
				for(int j = 1; j < data[i].length(); j++){
					if(data[i].charAt(j-1) == 'A' && data[i].charAt(j) == 'B'){
						count++;
					}
				}
				
				if(data[i].charAt(0) == 'B' && data[i].charAt(data[i].length()-1) == 'A') {
					med++;
				}
				else if(data[i].charAt(0) == 'B') {
					pre++;
				}
				else if(data[i].charAt(data[i].length()-1) == 'A'){
					suf++;
				}
			}
			int res = 0;
			res += Math.min(pre, suf);
			int rest = Math.max(pre, suf) - Math.min(suf, pre);
			if(rest < med){
				res += med;
				if(Math.max(pre, suf) == 0){
					res --;
				}
			}
			else {
				res += Math.min(rest, med);
			}
//			debug(count, pre, suf, med, res);
			System.out.println(count + res);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s;
	cin >> s;
	if (s.back() == 's') {
		cout << s << "es" << endl;
	}
	else {
		cout << s << "s" << endl;
	}
	return 0;
}



Measured memory_bytes: 3612
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()




int main() {

	string s, t;
	cin >> s >> t;
	ll ss = s.size(), ts = t.size();

	vector<string> cand;
	rep(i, ss - ts + 1) {
		bool flag = true;
		rep(j, ts) {
			if (s[i + j] != t[j] && s[i + j] != '?') {
				flag = false;
				break;
			}
		}
		if (flag) {
			string tmp = "";
			rep(j, ss) {
				if (i <= j && j < i + ts) tmp += t[j - i];
				else if (s[j] != '?') tmp += s[j];
				else tmp += 'a';
			}
			cand.push_back(tmp);
		}
	}
	if (cand.empty()) cout << "UNRESTORABLE" << endl;
	else cout << *min_element(all(cand)) << endl;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

count = 0

for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            bar = []
            bar.append(L[i])
            bar.append(L[j])
            bar.append(L[k])
            bar.sort()
            if bar[0] == bar[1] or bar[1] == bar[2]:
                continue
            if bar[2] >= bar[0] + bar[1]:
                continue
            count += 1
print(count)

Measured memory_bytes: 68408
using PanasonicProgrammingContest2020.Questions;
using PanasonicProgrammingContest2020.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace PanasonicProgrammingContest2020.Questions
{
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var a = new[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
            var k = inputStream.ReadInt();
            yield return a[k - 1];
        }
    }
}


namespace PanasonicProgrammingContest2020
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace PanasonicProgrammingContest2020.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace PanasonicProgrammingContest2020.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13268
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=2005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int f[MAXN],flag[MAXN][MAXN],dp[MAXN][MAXN],num[MAXN];
int find(int x) { return f[x]==x?f[x]:f[x]=find(f[x]); }
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int n=read(),m=read(),Flag=0;
	for (int i=1,u,v;i<=m;i++) u=read(),v=read(),flag[u][v]=flag[v][u]=1;
	for (int i=1;i<=n*2;i++) f[i]=i,num[i]=(i<=n);
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			if (!flag[i][j]) 
			{
				if (find(i)==find(j)||find(i+n)==find(j+n)) Flag=1;
				if (find(i)!=find(j+n)) num[find(j+n)]+=num[find(i)],f[find(i)]=find(j+n);
				if (find(i+n)!=find(j)) num[find(j)]+=num[find(i+n)],f[find(i+n)]=find(j);
//				cout<<i<<" "<<j+n<<endl;
//				cout<<i+n<<" "<<j<<endl;
			}
	if (Flag) { puts("-1"); return 0; }
	
	dp[0][0]=1;
	for (int i=1;i<=n;i++) dp[0][i]=0;
	for (int i=1;i<=n;i++)
	{
		if (f[i]==i||f[i+n]==i+n)
		{
			int x=num[i],y=num[find(i+n)];
//			cout<<i<<":"<<x<<" "<<y<<endl;
			for (int j=(n/2);j>=x;j--) dp[i][j]|=dp[i-1][j-x];
			for (int j=(n/2);j>=y;j--) dp[i][j]|=dp[i-1][j-y];
		}
		else 
		for (int j=0;j<=n/2;j++) dp[i][j]=dp[i-1][j];
	}
	int ans=INF;
	for (int i=0;i<=n/2;i++) 
		if (dp[n][i]) upmin(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	printf("%d\n",ans);
	return 0;
}
/*
2 4 1 1 1 1
*/

Measured memory_bytes: 12160
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int M =1000000007;
int counter[26];
int main() {
	long long n;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++)counter[s[i]-'a']++;
	long long ans = 1;
  for (int i = 0; i < 26; i++) {
    ans = (ans * (counter[i]+1)) % M;
  }
	cout<<ans-1;
	return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  long long N, K;
  cin >> N >> K;
  vector<pair<int,int>> array(N);
  for(int i = 0; i < N; i++){
    cin >> array[i].first >> array[i].second;
  }
  sort(array.begin(),array.end());

  for(int i = 0; i < N; i++){
    K -= array[i].second;
  //  cout << K << endl;
    if(K <= 0){
      cout << array[i].first << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
S = input()
counters = []
for i in range(0, 26):
	counters.append(0)
for i in range(0, N):
	counters[ord(S[i])-97] += 1
R = counters
L = []
for i in range(0, 26):
	L.append(0)
max = 0
for i in range(0, N):
	R[ord(S[i])-97] -= 1
	L[ord(S[i])-97] += 1
	cnt = 0
	for j in range(0, 26):
		if R[j] != 0 and L[j] != 0:
			cnt += 1
	if max < cnt:
		max = cnt
print(max)

Measured memory_bytes: 39952
n = int(input())
a = list(map(int, input().split()))
su = 1
flag = True
if 0 in a:
    print(0)
else:
    for i in range(n):
        su *= a[i]
        if su > 10**18:
            flag = False
            break
    if flag:
        print(su)
    else:
        print(-1) 

Measured memory_bytes: 21624
#include <stdio.h>
int main(){

  int a,b,x;

  x=1;

  while (x >= 0){

    scanf("%d %d",&a,&b);

    if (a == 0 && b == 0){

      break;

    } else {

      if (a >= b){

	x=a;
	a=b;
	b=x;

      }

      printf("%d %d\n",a,b);

    }

  }

  return 0;

}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100005];
struct Union_Find_Set {
	int fa[100005];
	void Init() {
		for (int i = 1; i <= n; i++) {
			fa[i] = i;
		}
	}
	int Find(int x) {
		if (fa[x] != x) fa[x] = Find(fa[x]);
		return fa[x];
	}
	void Union(int x, int y) {
		fa[Find(x)] = Find(y);
	}
}ufs;
vector<int>vec[100005], v;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	int rem = (n - 1 - m) * 2;
	if (n < rem) {
		printf("Impossible\n");
		return 0;
	}
	if (rem == 0) {
		printf("0\n");
		return 0;
	}
	ufs.Init();
	for (int x, y, i = 1; i <= m; i++) {
		scanf("%d%d", &x, &y);
		x++;
		y++;
		ufs.Union(x, y);
	}
	for (int i = 1; i <= n; i++) {
		vec[ufs.Find(i)].push_back(a[i]);
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (ufs.Find(i) == i) {
			sort(vec[i].begin(), vec[i].end());
			ans += vec[i][0];
			rem--;
			for (int j = 1; j < int(vec[i].size()); j++) {
				v.push_back(vec[i][j]);
			}
		}
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < rem; i++) {
		ans += v[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5632
s = input()

counter1 = 0
counter2 = 0
for i in range(len(s)):
    if i % 2 == 1 and s[i] != '0':
        counter1 += 1
    if i % 2 == 0 and s[i] != '1':
        counter1 += 1
    if i % 2 == 1 and s[i] != '1':
        counter2 += 1
    if i % 2 == 0 and s[i] != '0':
        counter2 += 1
print(min([counter1, counter2]))


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

int main(void){
  int n,k;
  vector<int> v;
  long long ans;
  
  cin >> n >> k;
  for (int i=0; i<n; i++){
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  ans = 0;
  for (int i=0; i<n-k; i++){
    ans += v[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1908
#include<iostream>
#include<algorithm>
#include<cstring>
#include<climits>
#include<cmath>
using namespace std;

#define ll long long

ll dp[100][100001];
ll knapsack1_TD(int n,int w,int arr[],int weight[]){

    if(n<0)
        return 0;
    // Look up
    if(dp[n][w]!=-1){
        return dp[n][w];
    }
    if(weight[n]>w){
        dp[n][w] = knapsack1_TD(n-1,w,arr,weight);
    }else{
        dp[n][w] = max(knapsack1_TD(n-1,w,arr,weight),arr[n]+knapsack1_TD(n-1,w-weight[n],arr,weight));
    }

    return dp[n][w];
}

ll knapsack1_BU(int arr[],int weight[],int n,int w){
    ll dp2[n+1][w+1];

    for(int i=0;i<=w;i++){
        dp2[0][i] = 0;
    }
    //dp2[1][weight[1]] = arr[1];


    for(int i=1;i<=n;i++){
        for(int j = 0;j<=w;j++){
            dp2[i][j] = dp2[i-1][j];
            if(weight[i]>j)
                continue;
            dp2[i][j] = max(dp2[i][j],arr[i]+dp2[i-1][j-weight[i]]);
        }
    }
    return *max_element(dp2[n],dp2[n]+w+1);
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<=w;j++){
    //         cout<<dp[i][j]<<" ";
    //     }   
    //     cout<<endl;
    // }
    // return dp2[n-1][w];

}


int main(){


    int n,w;
    cin>>n>>w;
    // memset(dp,-1,sizeof(dp));
    int arr[101],weight[101];
    for(int i=1;i<=n;i++){
        cin>>weight[i]>>arr[i];
    }

    // cout<<knapsack1_TD(n-1,w,arr,weight)<<endl;
    ll ans = knapsack1_BU(arr,weight,n,w);

    cout<<ans;

    return 0;
}







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

using namespace std;

int main() {
    int k, t;
    while(cin >> k >> t) {
        int sum = 0, mx = 0, a;
        for(int i = 0; i < t; ++i) {
            cin >> a;
            sum += a;
            mx = max(mx, a);
        }
        if(sum >= mx + mx - 1) {
            cout << 0 << endl;
        } else {
            cout << mx - (sum - mx + 1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int x,y,z,n;
	while(scanf("%d%d%d",&x,&y,&z) != EOF)
	{
	n = (x-z)/(y+z);
	printf("%d",n);
	return 0;
}
}


Measured memory_bytes: 128