akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  pair<ll,ll>p[114514];
  ll n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>p[i].first>>p[i].second;
  sort(p,p+n);
  ll ans=0,cnt=0;
  for(int i=0;i<n;i++){
    if(m-cnt>p[i].second){
      ans+=p[i].first*p[i].second;
      cnt+=p[i].second;
      if(cnt==m){
        cout<<ans<<endl;
        return 0;
      }
    }else{
      ans+=(m-cnt)*p[i].first;
      cout<<ans<<endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define stop exit(0)
int main(){
    vector <long long> v;
    long long a,b,c=0,d=0,e=0,f=0,g=0,i,j,k=1,l=0,r=1,n,m,z[200001],h[600001],p[600001];
    string s,t,x,y;
    double q,u,w;
    cin>>a>>b;
    for(i=1;i<=a;i++){
        cin>>p[i];
    }
    c=p[1];
    d=1;
    h[1]=c;
    z[c]=1;
    while(c>1){
        d++;
        c=p[c];
        h[d]=c;
        if(z[c]==1){
            e=d-1;
            while(h[e]!=c){
                e--;
            }
            break;
        }
        z[c]=1;
    }
    h[0]=h[d];
    if(c==1){
        b%=d;
        cout<<h[b];
        stop;
    }
    if(b<=e){
        for(i=1;i<=b;i++){
            k=p[k];
        }
        cout<<k;
    }
    else{
        b=(b-e)%(d-e);
        for(i=1;i<=b;i++){
            c=p[c];
        }
        cout<<c;
    }
}

Measured memory_bytes: 8156
N = int(input()) 

s = [input() for i in range(N)] 

AC = 0
WA = 0
TLE = 0
RE = 0

for str in s :
  if str == "AC" :
    AC += 1
  elif str == "WA" :
    WA += 1
  elif str == "TLE" :
    TLE += 1
  elif str == "RE" :
    RE += 1

print('AC x ',AC)
print("WA x ",WA)
print("TLE x ",TLE)
print("RE x ",RE)

Measured memory_bytes: 16284
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int N,ANS=0,max=0;
	cin >> N;

	for(int i=0;i<N;i++)
	{
		int A; cin >> A;
		ANS = ANS+A;
		if(max<A){max=A;}
	}

	cout << ANS - (max/2) << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r,d,x;
    cin >> r;
    cin >> d;
    cin >> x;
    
    for(int i = 0;i < 10; i++){
        x = r * x - d;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
import sys
import math
import itertools

def gcd(x,y):
  if x < y:
    tmp = x
    x = y
    y = tmp

  rem = x % y
  if rem == 0:
    return y
  else:
    return gcd(y, rem)

def main():
  x,y = map(int, input().split())

  print(gcd(x,y))


if __name__ == '__main__':
  main()


Measured memory_bytes: 5688
#include <iostream>
#include <vector>

using namespace std;

const int kInf = 1e9+10;

void solve() {
	int n;
	cin >> n;

	vector<int> cnt(26, kInf);

	for (int i = 1; i <= n; ++i) {
		string s;
		cin >> s;

		vector<int> cnt1(26, 0);

		for (int j = 0; j < s.length(); ++j) {
			cnt1[s[j]-'a']++;
		}

		for (int j = 0; j < 26; ++j) {
			cnt[j] = min(cnt[j], cnt1[j]);
		}
	}

	for (int i = 0; i < 26; ++i) {
		while (cnt[i]) {
			cout << (char)(i + 'a');
			--cnt[i];
		}
	}
	cout << "\n";
}

int main() {
	int tests = 1;

	for (;tests; --tests) {
		solve();
	}
}

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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	int p;
	int sum = 0;
	int maxp = 0;
	for(int i = 0; i < n; i++){
		cin >> p;
		sum += p;
		maxp = max(maxp,p);
	}
	cout << sum-(int)maxp/2 << endl;
    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		long[] a=new long[n];
		int count=0,flag=0;
		for(int i=0;i<n;i++) {
			a[i]=sc.nextLong();
		}
		Arrays.sort(a);
		for(int i=0;i<n-1;i++) {
			if(a[i]==a[i+1]) {
				flag=1;
				break;
			}
		}
		if(flag==0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 83416
import numpy as np
n,m,c=map(int,input().split())
#print(n)

ms=list(map(int,input().split()))
ms=np.array(ms)


codes=[]
for i in range(n):
        codes.append(list(map(int,input().split())))

#print(ms)
#print(codes)

cnt=0
for j in range(len(codes)):
        x=ms*np.array(codes[j])
        if sum(x)+c>0:
                cnt+=1

print(cnt)


Measured memory_bytes: 18864
#include <stdio.h>
#include <iostream>
using namespace std ;

double calc( int cnt , double N ){
	if( cnt == 11 ) return 0;
	else return N + calc( cnt+1 , N / ( (cnt%2)?0.5:3.0 ) ) ;
}

int main(){
	
	double D;
	
	while( cin >> D ){
		if( cin.eof() ) break ;
		printf("%.8lf\n",calc(1,D));
	}
	
	return 0;
}

Measured memory_bytes: 1232
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int p;
		double t;
		double[] r = new double[8];
		int[] c = new int[8];
		
		for(int i = 0; i < 8; i++){
			r[i] = 100;
		}
		
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 8; j++){
				p = scan.nextInt();
				t = scan.nextDouble();
				
				if(t < r[2 * i]){
					if(r[2 * i + 1] < r[6]){
						c[7] = c[6];
						r[7] = r[6];
						c[6] = c[2 * i + 1];
						r[6] = r[2 * i + 1];
					}else if(r[2 * i + 1] < r[7]){
						c[7] = c[2 * i + 1];
						r[7] = r[2 * i + 1];
					}
					c[2 * i + 1] = c[2 * i];
					r[2 * i + 1] = r[2 * i];
					c[2 * i] = p;
					r[2 * i] = t;
				}else if(t < r[2 * i + 1]){
					if(r[2 * i + 1] < r[6]){
						c[7] = c[6];
						r[7] = r[6];
						c[6] = c[2 * i + 1];
						r[6] = r[2 * i + 1];
					}else if(r[2 * i + 1] < r[7]){
						c[7] = c[2 * i + 1];
						r[7] = r[2 * i + 1];
					}
					c[2 * i + 1] = p;
					r[2 * i + 1] = t;
				}else if(t < r[6]){
					c[7] = c[6];
					r[7] = r[6];
					c[6] = p;
					r[6] = t;
				}else if(t < r[7]){
					c[7] = p;
					r[7] = t;
				}
			}
		}
		for(int k = 0; k < 8; k++){
			System.out.println(c[k] + " " + r[k]);
		}
	}
}

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

int main() {
    char a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((a == b && c == d && a != c) || (a == d && b == c && a != b) || (a == c && b == d && a != b)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    string S,T;
//    cin >> S[0] >> S[1] >> S[2];
//    cin >> T[0] >> T[1] >> T[2];

    cin >> S >> T;

    int cnt = 0;

    for(int i=0; i<3; i++){
        if(S.at(i) == T.at(i)) cnt++;
    }

//    if(S[0] == T[0]) cnt++;
//    if(S[1] == T[1]) cnt++;
//    if(S[2] == T[2]) cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
typedef long long ll;

template<typename T>
void read(T &x) {
	int flag = 1; x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
}

const int _ = 4e5 + 10;
int n, q, d[_], cnt, fa[_];
struct Edge { int u, v, w; } e[_];
inline bool operator < (const Edge &a, const Edge &b) { return a.w < b.w; }
inline void ChkMin(int &a, int b) { if(a > b) a = b; }
inline void addEdge(int u, int v, int w) { e[++cnt] = (Edge){u, v, w}; }
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
bool unionn(int x, int y) {
	int fx = find(x), fy = find(y);
	if(fx == fy) return 0;
	fa[fx] = fy; return 1;
}

int main () {
#ifdef OFFLINE_JUDGE
	freopen("233.in", "r", stdin);
	freopen("233.out", "w", stdout);
#endif
	read(n), read(q);
	memset(d, 127, sizeof d);
	for(int i = 1, a, b, c; i <= q; ++i) {
		read(a), read(b), read(c), addEdge(a, b, c);
		ChkMin(d[a], c + 1), ChkMin(d[b], c + 2);
	}
	for(int i = 0; i < n; ++i) ChkMin(d[i], d[(i - 1 + n) % n] + 2);
	for(int i = 0; i < n; ++i) ChkMin(d[i], d[(i - 1 + n) % n] + 2);
	for(int i = 0; i <= n; ++i) addEdge(i, (i + 1) % n, d[i]);
	sort(e + 1, e + cnt + 1);
	for(int i = 1; i < n; ++i) fa[i] = i;
	int blo = n; ll ans = 0;
	for(int i = 1; i <= cnt && blo > 1; ++i)
		if(unionn(e[i].u, e[i].v)) ans += e[i].w, --blo;
	printf("%lld\n", ans);
	return 0;
} 


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

using namespace std;

const long long INF = 1e12;

int main() {
  int n;
  cin >> n;
  vector<vector<long long>> dp(n, vector<long long> (n));
  vector<int> v(n);
  for (int &x : v)
    cin >> x;
  for (int i=0; i<n; ++i)
    dp[i][i] = v[i];
  for (int l=n-1; l>=0; --l)
    for (int r=l+1; r<n; ++r)
      dp[l][r] = max(v[l]-dp[l+1][r], v[r]-dp[l][r-1]);
  cout << dp[0][n-1] << '\n';
  return 0;
}


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

int main () {
  int A;
  cin >> A;
  int a = A/1000, B = A%1000/100, C = A%100/10, D = A%10;
  if (a+B+C+D == 7) {
    cout << a << '+' << B << '+' << C << '+' << D << '=' << 7 << endl;
    return 0;
  }
  else if (a+B+C-D == 7) {
    cout << a << '+' << B << '+' << C << '-' << D << '=' << 7 << endl;
    return 0;
  }
  else if (a+B-C+D == 7) {
    cout << a << '+' << B << '-' << C << '+' << D << '=' << 7 << endl;
    return 0;
  }
  else if (a+B-C-D == 7) {
    cout << a << '+' << B << '-' << C << '-' << D << '=' << 7 << endl;
    return 0;
  }
  else if (a-B+C+D == 7) {
    cout << a << '-' << B << '+' << C << '+' << D << '=' << 7 << endl;
    return 0;
  }
  else if (a-B-C+D == 7) {
    cout << a << '-' << B << '-' << C << '+' << D << '=' << 7 << endl;
    return 0;
  }
  else if (a-B+C-D == 7) {
    cout << a << '-' << B << '+' << C << '-' << D << '=' << 7 << endl;
    return 0;
  }
  else {
    cout << a << '-' << B << '-' << C << '-' << D << '=' << 7 << endl;
    return 0;
  }
}

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

int main() {
  int N;
  cin >> N;
  int count = 1;
  int ans = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == count) {
      count++;
    }
    else {
      ans++;
    }
  }
  if (ans == N) {
    cout << "-1" << endl;
  }
  else {
    cout << ans<< endl;
  }
}

    
  

Measured memory_bytes: 1024
import sys

H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(map(str, input().rstrip())))

# 外枠を「.」で囲う準備
li = []
for i in range(H+2):
    li.append(["."]*(W+2))

# 外枠付きSの生成
for i in range(1, H+1):
    li[i][1:-1] = S[i-1]

# 上下左右に「#」が隣接していれば必ず塗れる
for h in range(1, H+1):
    for w in range(1, W+1):
        tmp = 0
        if li[h][w]=='#':
            if li[h - 1][w]=="#":
                tmp += 1
            if li[h + 1][w]=="#":
                tmp += 1
            if li[h][w - 1]=="#":
                tmp += 1
            if li[h][w + 1]=="#":
                tmp += 1
            if tmp==0:
                print("No")
                sys.exit()

print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(int argc, char *argv[]) {
  int n, i;
  ll sum, a, max;

  cin >> n;

  sum = 0;
  max = 0;
  for(i=0;i<n;i++){
    cin >> a;
    if(a<max){
      sum += (max-a);
    }
    else{
      max = a;
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<stack>
#include<map>
using namespace std;

int gcd(int A, int B) {
  int a = A, b = B, r;
  while (b) {
    r = a % b; a = b; b = r;
  }
  return a;
}

int lcm(int N, int A[], int mod_m) {
  map<int, int> max_p;
  for (int i = 0; i < N; i++) {
    int a = A[i];
    for (int d = 2; d < a; d++) {
      if (d * d > a) break;
      int power = 0;
      while (a % d == 0) {
        power++; a /= d;
      }
      if (max_p.find(d) == max_p.end() || power > max_p[d])
        max_p[d] = power;
    }
    if (a > 1 && (max_p.find(a) == max_p.end() || max_p[a] < 1))
      max_p[a] = 1;
  }
  int res = 1;
  for (map<int, int>::iterator it = max_p.begin();
       it != max_p.end(); it++) {
    pair<int, int> item = *it;
    for (int i = 0; i < item.second; i++) {
      res = (long)res * (long)item.first % mod_m;
    }
  }
  return res;
}

int div(int A, int B, int mod_p) {
  stack<int> q_stack;
  int a = B, b = mod_p, r;
  while (b) {
    q_stack.push(a / b);
    r = a % b; a = b; b = r;
  }
  long u = 1, v = 0;
  while (!q_stack.empty()) {
    int q = q_stack.top(); q_stack.pop();
    long u1 = v, v1 = u-q*v; u = u1 % mod_p; v = v1 % mod_p;
  }
  return (long)A * (u + mod_p) % mod_p;
}

int main() {
  int DIV = 1e+9 + 7;
  int N; cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  int m = lcm(N, A, DIV);
  int inv_sum = 0;
  for (int i = 0; i < N; i++)
    inv_sum = (inv_sum + div(1, A[i], DIV)) % DIV;
  int res = (long)m * (long)inv_sum % DIV;
  cout << res << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

int main()
{
  mp::cpp_int a, b, c;
  cin >> a >> b >> c;
  if (c - a - b < 0)
  {
    cout << "No" << endl;
    return 0;
  }
  cout << (((4 * a * b) < (c - a - b) * (c - a - b)) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define retrun return
#define cpnst const
int n,m;
#include<vector>
std::vector<int>v[1111111];
int lnk[1111][1111];
bool vis[1111111];
bool isp[1111][1111],isq[1111][1111];
#include<queue>
#include<algorithm>
std::queue<int>q;
void flood(int x,bool*vs)
{
	q.push(x),vs[x]=1;
	for(;!q.empty();)
	{
		int p=q.front();q.pop();
		for(auto t:v[p])
			if(!vs[t])q.push(t),vs[t]=1;
	}
}
void bfs(int x)
{
	register int i;
	for(i=1;i<=n;i++)vis[i]=0;vis[x]=1;
	for(auto t:v[x])
	{
		isp[x][t]|=vis[t];
		if(!vis[t])flood(t,vis);
	}for(i=1;i<=n;i++)vis[i]=0;vis[x]=1;
	std::reverse(v[x].begin(),v[x].end());
	for(auto t:v[x])
	{
		isp[x][t]|=vis[t];
		if(!vis[t])flood(t,vis);
	}flood(x,isq[x]);
}
int x[1111111],y[1111111];
int main()
{
	scanf("%d%d",&n,&m);
	register int i;
	for(i=1;i<=m;i++)scanf("%d%d",x+i,y+i),lnk[x[i]][y[i]]=lnk[y[i]][x[i]]=i,
	v[x[i]].push_back(y[i]);
	for(i=1;i<=n;i++)bfs(i);
	for(i=1;i<=m;i++)puts((isp[x[i]][y[i]]^isq[y[i]][x[i]])?"diff":"same");
}
/*
Just go for it.
*/

Measured memory_bytes: 38860
#include<stdio.h>
int main()
{
   int A1,A2,A3;
   
   scanf("%d%d%d",&A1,&A2,&A3);
   if(A1+A2+A3>=22)
   {
       printf("bust");
   }
   else
   {
       printf("win");
   }

    return 0;
}




Measured memory_bytes: 128
import sys
input = sys.stdin.readline
class UnionFindNode:
    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1
        self.member_num_ = 1

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                n_root, child = root, unite_root
            else:
                n_root, child = unite_root, root
            child.parent_ = n_root
            n_root.rank_ = max(n_root.rank_, child.rank_ + 1)
            n_root.member_num_ = n_root.member_num_ + child.member_num_
N, K, L = map(int, input().split())
node_list1 = [UnionFindNode(i) for i in range(N)]
d3 = [0] * N
for _ in range(K):
    a, b = map(int, input().split())
    node_list1[a-1].unite(node_list1[b-1])
    d3[a-1] += 1
    d3[b-1] += 1
    
for _ in range(L):
    a, b = map(int, input().split())
    if node_list1[a-1].root().group_id_ == node_list1[b-1].root().group_id_:
        d3[a-1] += 1
        d3[b-1] += 1


rr = []
for i in range(N):
    x = node_list1[i].root().member_num_
    rr.append(x-d3[i]-1)
print(*rr)


Measured memory_bytes: 77344
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={0,31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
string s,t,str;
int n,m;
int ans=100010;
inline int change(){
	int num=0;
	for(int i=0;i<m;i++)if(t[i]!=str[i])num++;
	return num;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s>>t;
	n=s.size(),m=t.size();
	for(int i=0;i+m<=n;i++){
		str=s.substr(i,m);
		ans=min(ans,change());
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 3652
#include <stdio.h>
int main(void){
    
    int a, b;
    
    scanf("%d %d", &a, &b);
    
    if(a == b){
        printf("a == b\n");
    }
    else if(a > b){
        printf("a > b\n");
    }
    else{
        printf("a < b\n");
    }
    
    
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int count1=0,count2=0,count3=0,count4=0,n;
    string a;
    cin>>n;
    while(n--)
    {
        cin>>a;
        if(a=="AC")
            count1++;
        else if(a=="WA")
            count2++;
        else if(a=="TLE")
            count3++;
        else if(a=="RE")
            count4++;
    }
    cout<<"AC x "<<count1<<endl;
    cout<<"WA x "<<count2<<endl;
    cout<<"TLE x "<<count3<<endl;
    cout<<"RE x "<<count4<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n, -1) {}
    int find(int x) {
        if (d[x]<0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x==y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return -d[find(x)];
    }
};


int main(){
    int n, m;
    cin >> n >> m;
    UnionFind u(n);
    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        u.unite(x, y);
    }
    int ans = 0;
    map<int, int> mp;
    rep(i, n) {
        mp[u.find(i)]++;
    }
    ans = mp.size();
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<memory.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  ll a[n]={};
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  int left=-1;
  int right=n;
  int cnt=0;
  while(right-left>1){
    cnt++;
    if(cnt>=100000)break;
    int mid=(right+left)/2;
    bool flag=false;
    ll sum=0;
    ll pos=0;
    while(pos<n && (2*sum>=a[pos] || pos<=mid) ){
      sum+=a[pos];
      pos++;
    }
    if(pos>=n){
      right=mid;
    }else left=mid;
  }
  ll ans=0;
  rep(i,n)if(i>=right)ans++;
  cout << ans << endl;
return 0;}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  }

  int n;
  char s[];
  int ans;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      n = sc.nextInt();
      s = sc.next().toCharArray();
    } finally {
      sc.close();
    }
  }
  
  void solve() {
    char cur = s[0];
    ans++;
    for (int i = 1; i < n; i++) {
      if (cur != s[i]) {
        ans++;
        cur = s[i];
      }
    }
  }

  void show() {
    System.out.println(ans);
  }
}


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

int main () {
	int N;
	int first, last;
	int count = 0;
	
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> first >> last;
		count += (last - first) + 1;
	}
	cout << count << endl;
}


Measured memory_bytes: 3644
fun main(args: Array<String>) {
    val (n, x0) = readLine()!!.split(" ").map(String::toInt)
    val x = (readLine()!!.split(" ").map(String::toInt) + listOf(x0)).sorted()

    val delta = (0 until x.size-1).mapIndexed{i, n ->
        x[i+1] - x[i]
    }
    print(delta.reduce{a, b -> gcd(a,b)})
}

tailrec fun gcd(a: Int, b: Int): Int{
    if(b == 0) return a
    return gcd(b, a%b)
}

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

int main(int argc, char const *argv[])
{
	int n[3];
	int tmp= 10000;
	int i,j;

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

	for(i=2;i>-1;i--){
		
		for(j=0;j<i;j++){
			if(n[j] > n[j+1]){
				tmp = n[j+1];
				n[j+1] = n[j];
				n[j] = tmp;
			}
		}
	}


	for(i=0;i<2;i++){
		cout << n[i] << ' ';
	}
	cout << n[2] << endl;

	return 0;
}


Measured memory_bytes: 3096
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
LL n, m, x, flag = 0;
string st[2];
int main(){
	cin >> st[0] >> st[1];
	for (int i = 0; i < st[0].size(); i++)if (st[0][i] != st[1][st[0].size() - 1 - i])flag = 1;
	cout << (!flag?"YES":"NO")<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    std::cin >> s;
    bool a[26];
    for (int i = 0; i < 26; i++) {
        a[i]=false;
    }
    for (int i = 0; s[i] !='\0'; i++) {
        a[s[i]-'a']=true;
    }
    for (int i = 0; i < 26; i++) {
        if(!a[i]){
            std::cout << (char)(i+'a') << std::endl;
            return 0;
        }
    }
    std::cout << "None" << std::endl;
    return 0;
 

}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    if(n%10 == 7 || n%100 - n%10 == 70 || n - n%100 == 700) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int k,x;
	cin>>k>>x;
	if(k*500>=x)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

int MP(std::string &S, std::vector<long long int> &A);
int KMP(std::string &S, std::string &word, std::vector<long long int> &match_table);

int main(){

  long long int N, tmp1, tmp2;
  std::vector<long long int> a, b;

  scanf("%lld", &N);
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp1);
    a.push_back(tmp1);
  }
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp1);
    b.push_back(tmp1);
  }

  std::string Sa, Sb;

  // make Sa
  for(long long int i = 0; i < N; i++){
    tmp1 = a[i]^a[(i+1)%N];
    //std::cerr << "i: " << i << " tmp1: " << tmp1 << std::endl;
    for(long long int j = 0; j < 30; j++){
      if((tmp1>>j)&1){
        Sa += '1';
      }
      else{
        Sa += '0';
      }
    }
  }

  // make Sb
  for(long long int i = 0; i < 2*N-1; i++){
    tmp1 = b[(i+N)%N]^b[(i+1)%N];
    for(long long int j = 0; j < 30; j++){
      if((tmp1>>j)&1){
        Sb += '1';
      }
      else{
        Sb += '0';
      }
    }
  }

  //std::cerr << "Sa: " << Sa << std::endl;
  //std::cerr << "Sb: " << Sb << std::endl;

  // solve problem
  std::vector<long long int> match_table;
  KMP(Sb, Sa, match_table);
  long long int k;

  std::cerr << "Answer: " << std::endl;

  if(match_table.size() > 0 && match_table[0] == 0){
    std::cout << 0 << " " << (a[0]^b[0]) << std::endl;
  }
  for(long long int i = match_table.size()-1; i >= 0; i--){
    if(match_table[i] == 0){
      continue;
    }
    if((match_table[i]+30)%30 == 0){
      k = match_table[i]/30;
      std::cout << (N-k)%N << " " << (a[0]^b[k]) << std::endl;
    }
  }

  return 0;
}



int MP(std::string &S, std::vector<long long int> &A){
  
  A[0] = -1;
  long long int L = S.length();
  long long int j = -1;
  
  for(long long int i = 0; i < L; i++){
    while(j >= 0 && S[i]!=S[j]) j=A[j];
    j++;
    A[i+1] = j;
  }
  
  return 0;
}

int KMP(std::string &S, std::string &word, std::vector<long long int> &match_table){
  
  // preparation: MP calculation
  std::vector<long long int> MP_table(word.length()+1);
  MP(word, MP_table);
  match_table.clear();
  
  // make match_table
  long long int m  = 0, i = 0, ls = S.length(), lword = word.length();
  
  while(m+i < ls){
    if(word[i] == S[m+i]){
      i++;
      if(i == lword){
        match_table.push_back(m);
        m = m+i - MP_table[i];
        i = MP_table[i];
      }
    }
    else{
      m = m+i - MP_table[i];
      if(i > 0){
        i = MP_table[i];
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 143472
#include <stdio.h>

int main(){
  char c[300];
  int m,h,i,j,k,num=0,temp;
  while(1){
    scanf("%s",&c);
    if(c[0]=='-')break;
    for(num=0; num<300; num++)if(c[num]=='\0')break;
    scanf("%d",&m);
    for(i=0; i<m; i++){
      scanf("%d",&h);
      for(j=0; j<h; j++){
	temp=c[0];
	for(k=0; k<num; k++){
          c[k]=c[k+1];
	}
        c[num-1]=temp;
      }
    }
    printf("%s\n",&c);
  }
  return 0;
}

Measured memory_bytes: 584
# 総当たり：
# A, Bは30以下。30より大きいと重量の制約を満たせないから。
# 砂糖が溶け残らずに入る最大量は、E = 100, F = 3000 のときで、1500g. なので
# Dを総当たり（1500/2 = 750以下）してCを最大値決め打ち
# 30 * 30 * 750 = 750000 でいけるだろ。

a, b, c, d, e, f = list(map(int, input().split()))
ans_water = 1
ans_sugar = 0

for i_a in range(30+1):
    for i_b in range(15+1):
        water = 100 * a * i_a + 100 * b * i_b
        if water == 0:
            continue
        if water > f:
            continue
        for i_d in range(750+1):
            sugar = d * i_d
            if water + sugar > f:
                continue
            if sugar > water // 100 * e:
                continue
            sugar_max = water // 100 * e
            sugar_max = min(sugar_max, f - water)
            i_c = (sugar_max - sugar) // c

            # print(water, sugar, i_a, i_b, i_d, sugar_max, i_c)
            # if sugar + c * i_c == sugar_max:
            #     sugar += c * i_c
            #     print("{} {}".format(water + sugar, sugar))
            #     print("###")
            #     exit()
            
            sugar += i_c * c

            if sugar / water >= ans_sugar / ans_water:
                ans_sugar = sugar
                ans_water = water
                # print("koushin: ")
                # print(water, sugar, i_a, i_b, i_d, sugar_max, i_c)

print("{} {}".format(ans_water + ans_sugar, ans_sugar))


Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
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 anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGrandGarden solver = new CGrandGarden();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGrandGarden {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }
            int max = Integer.MIN_VALUE;
            for (int x : h)
                max = Math.max(max, x);

            int answer = 0;
            for (int i = max; i > 0; i--) {
                int tot = 0, pairs = 0;
                for (int j = 0; j < n; j++) {
                    if (h[j] >= i)
                        tot++;
                    if (h[j] >= i && j + 1 < n && h[j + 1] >= i)
                        pairs++;
                }
                answer += (tot - pairs);
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define rep(i,b) for(int i=0; i<int(b);i++)
#define eb emplace_back

using Weight = int;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src_, int dst_, Weight weight_) :
        src(src_), dst(dst_), weight(weight_) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

vector<int> stronglyConnectedComponents(const Graph &g){
    int n = g.size(); Graph rg(n);
    int cnt = n;
    for(const Edges &es : g){
        cnt += es.size();
        for(const Edge &e : es) rg[e.dst].eb(e.dst, e.src, e.weight);
    }
    vector<int> S(cnt);
    vector<int> cmp(n, -1), added(n), visited(n), ord(n);
    int sz = 0;
    for(int i = 0; i < n; i++) if(!visited[i]){
        int s = 0; S[s++] = i;
        while(s){
            int v = S[s-1]; visited[v] = true;
            bool pushed = false;
            for(auto & e : g[v]){
                int dst = e.dst;
                if(!visited[dst]){ S[s++] = dst; pushed = true; }
            }
            if(pushed) continue;
            int t = S[s-1];
            if(!added[t]){ added[t] = true; ord[sz++] = t; }
            --s;
        }
    }
    int k = 0;
    for(int i = 0; i < n; i++){
        int u = ord[n-i-1];
        if(cmp[u] != -1) continue;
        int s = 0; S[s++] = u;
        while(s){
            int v = S[--s]; cmp[v] = k;
            for(auto & e : rg[v]){
                int d = e.dst;
                if(cmp[d] == -1) S[s++] = d;
            }
        }
        ++k;
    }
    return cmp;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n,m;
    cin >> n >> m;
    Graph g(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        g[a].eb(a,b,0);
    }
    vector<int> c = stronglyConnectedComponents(g);
    int q; cin >> q;
    rep(i,q){
        int a,b;
        cin >> a >> b;
        cout << (c[a]==c[b]) << '\n';
    }
}

Measured memory_bytes: 4188
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    A, B, C = map(int, readline().split())
    if A<=C<=B:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


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

void bfs(ll s,Graph graph, vector<ll> &cnt,vector<bool> &visit)
{
	visit[s]=true;
	queue<int> que;
	que.push(s);
	while (!que.empty())
	{
		int v=que.front();
		que.pop();
		for (ll i=0;i<graph[v].size();i++)
		{
			if (!visit[graph[v][i]])
			{
				cnt[graph[v][i]]+=cnt[v];
				que.push(graph[v][i]);
				visit[graph[v][i]]=true;
			}
		}
	}
}

int main()
{
	ll N,Q;cin >> N >> Q;
	Graph graph(N,vector<ll>());
	ll a,b;
	for (ll i=0;i<N-1;i++)
	{
		cin >> a >>b;
		a--;b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	vector<bool> visit(N,false);
	vector<ll> cnt(N,0);
	for (ll i=0;i<Q;i++)
	{
		cin >> a >>b;
		a--;
		cnt[a]+=b;
	}
	bfs(0,graph,cnt,visit);
	for (ll i=0;i<N;i++) cout << cnt[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 28120
#include<bits/stdc++.h>
using namespace std;
int n, W;
int w[105], v[105];

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

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

    cin >> n >> W;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }

    vector<long long> dp(W + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = W; j >= w[i]; j--) {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    cout << dp[W] << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
  int main()
  {
    std::string S;
    std::cin >> S;
    int min = 1000;
    for(int i = 0; i < S.size(); i++){min = std::min(min, std::abs(753-std::stoi(S.substr(i,3))));}
    std::cout << min << std::endl;
    return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 998244353
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}

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

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

    int minP = 1000000;
    int ans = 0;
    for (int i=0; i<N; i++) {
        if (P[i] < minP) ans++;
        minP = min(minP, P[i]);
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
	string s;
	cin >> s;
	if(s=="SUN"){
		cout << 7 << endl;
	}
	else{
		if(s=="SAT"){
			cout << 1 << endl;
		}
		else{
			if(s=="FRI"){
				cout << 2 << endl;
			}
			else{
				if(s=="THU"){
					cout << 3 << endl;
				}
				else{
					if(s=="WED"){
						cout << 4 << endl;
					}
					else{
						if(s=="TUE"){
							cout << 5 << endl;
						}
						else{
							if(s=="MON"){
								cout << 6 << endl;
							}
						}
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long dp[2300];
char str[110][210];
typedef unsigned long long wolf;
wolf hash[110][210];
int len[110];
long long INF=1100000000000000000LL;
char ret[2300];
long long dp2[2300];
long long mod=1000000007;
wolf th[2300];
int main(){
	int a,b;
	long long c;
	scanf("%d%d%lld",&a,&b,&c);
	c--;
	for(int i=0;i<a;i++)scanf("%s",str[i]);
	for(int i=0;i<a;i++){
		hash[i][0]=str[i][0];
		for(int j=1;str[i][j];j++)hash[i][j]=hash[i][j-1]*mod+str[i][j];
	}
	for(int i=0;i<a;i++)len[i]=strlen(str[i]);
	dp[0]=1;
	for(int i=0;i<b;i++){
		for(int j=0;j<a;j++){
			dp[i+len[j]]=min(INF,dp[i+len[j]]+dp[i]);
		}
	}
	dp2[0]=1;
	if(dp[b]<=c){
		printf("-\n");return 0;
	}
	for(int i=0;i<b;i++){
		for(int j=0;j<26;j++){
			long long val=0;
			wolf ks=1;
			wolf now=j+'a';
			for(int k=0;k<min(210,i+1);k++){
				if(k){
					ks*=mod;
					now+=ks*ret[i-k];
				}
				th[k]=now;
			}
			for(int k=0;k<a;k++){
				for(int l=max(0,i-len[k]+1);l<=i;l++){
					if(!dp2[l])continue;
					int n=i-l;
					if(th[n]==hash[k][n]){
						if((INF-val)/dp2[l]<dp[b-len[k]-l])val=INF;
						else val+=dp2[l]*dp[b-len[k]-l];
					}
				}
			}
			//if(val){
		//		for(int k=0;k<20;k++)printf("%llu ",th[k]);
		//		printf("\n");
		//		printf("%d %d: %lld %lld\n",i,j,val,c);
		//	}
			if(c<val){
				for(int k=0;k<a;k++){
					if(th[len[k]-1]==hash[k][len[k]-1]){
						dp2[i+1]=min(INF,dp2[i+1]+dp2[i+1-len[k]]);
					}
				}
				ret[i]='a'+j;
				break;
			}else c-=val;
		}
	}
	printf("%s\n",ret);
}

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

const ll INF = 1LL << 60;

vector<int> G[(int)1e5 + 5];

int color[(int)1e5 + 5];
ll N, M;

bool dfs(int v, int c) {
    color[v] = c;
    for (int i = 0; i < G[v].size(); i++) {
        // 隣接している頂点が同じ色
        if (color[G[v][i]] == c) return false;

        // 隣接している頂点がまだ塗られていない
        if (color[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false;
    }

    return true;
}
int main() {
    // ll tmp = 1e5 - 1; 
    // ll black = tmp / 2; 
    // ll white = tmp / 2;
    // if (tmp % 2 == 1) {
    //     black++;
    // }
    // cout << black << " " << white << endl;
    // return 0;
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    bool nibu = true;
    for (int i = 0; i < N; i++) {
        if (color[i] == 0) {
            if (!dfs(i, 1)) {
                nibu = false;
                break;
            }
        }
    }

    if (nibu) {
        // ll black = N / 2;
        // if (N % 2 == 1) {
        //     black++;
        // }
        // ll white = N / 2;

        ll b2 = 0, w2 = 0;
        rep(i, N) {
            if (color[i] == 1) {
                b2++;
            } else {
                w2++;
            }
        }
        w2 = N - b2;

        ll ans = b2 * w2 - M;
        cout << ans << endl;
    } else {
        // 全部の辺 - M
        ll ans = N * (N - 1) / 2;
        ans -= M;

        cout << ans << endl;
    }
}

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

int main()
{
	int n,a,b,sum=0,total=0;
	
	cin>>n>>a>>b;
	
	for(int i=1; i<=n; i++){
		int p=i;
		sum=0;
		while(p!=0){
			sum+=p%10;
			p/=10;
		}
		
		if(sum>=a && sum<=b) total+=i;
	}
	
	cout<<total<<endl;
	return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
s = [input() for i in range(H)]
precount = 0
for i in range(H):
    precount += s[i].count("#")
if precount == 0:
    print("Yes")
else:
    ans = "Yes"
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
               count = 0
               for k in range(4):
                   nx = j+dx[k]
                   ny = i+dy[k]
                   if 0 <= nx < W and 0 <= ny < H:
                      if s[ny][nx] == "#":
                         count += 1
               if count == 0:
                  ans = "No"

    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

int main() {
	optimizar_io

	int n;
	string s;
	map<string,int> cnt;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		cnt[s]++;
	}
	int votos = 0;
	for (auto a : cnt) {
		votos = max(votos, a.second);
	}
	vector<string> v;
	for (auto a : cnt) {
		if (a.second == votos)
			v.push_back(a.first);
	}
	sort(v.begin(), v.end());
	for (auto a : v)
		cout << a << "\n";
	return 0;
}

Measured memory_bytes: 25584
N = int(input())
s = list(map(int, input().split(" ")))

ans = 0
for q in range(1, N - 1):
    k = 0
    a1 = 0
    seen = set()

    p = N - 1 - k * q
    while p > q:
        if k * q in seen:
            break
        seen.add(k * q)
        if p in seen:
            break
        seen.add(p)

        a1 = a1 + s[p] + s[k * q]
        # print(p, p - q,  a1)
        ans = max(ans, a1)

        k += 1
        p = N - 1 - k * q

print(ans)


Measured memory_bytes: 88464
#include<bits/stdc++.h>
#include<stdio.h>
#define mod 1000000007;
using namespace std;
using ll = long long;
using ld = long double;
long double pi = 2 * acos(0.0);

void solve() {
    ll a, b;
    cin >> a >> b;
    cout << a * b;
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

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

void fnInput(vector<int>& rvnMonstr, vector<int>& rvnBrave)
{
  int nMonstrSiz;
  cin >> nMonstrSiz;
  rvnMonstr.resize(nMonstrSiz + 1);
  rvnBrave.resize(nMonstrSiz);

  for (int& rnMonstr : rvnMonstr)
    cin >> rnMonstr;

  for (int& rnBrave : rvnBrave)
    cin >> rnBrave;
}
  
llong fnStrikMonstr(vector<int>& rvnMonstr, vector<int>& rvnBrave)
{
  llong nSumStrikMon = 0;

  for (int nBgn = 0; nBgn < rvnBrave.size(); ++nBgn)
    for (int nFwd = nBgn; nFwd < nBgn + 2; ++nFwd)
    {
      int nStrikMonstr = min(rvnBrave[nBgn], rvnMonstr[nFwd]);
      rvnMonstr[nFwd] -= nStrikMonstr;
      rvnBrave[nBgn]  -= nStrikMonstr;
      nSumStrikMon += nStrikMonstr;
    }

  return nSumStrikMon;
}
  
int main()
{
  vector<int> vnMonstr, vnBrave;

  fnInput(vnMonstr, vnBrave);
  cout << fnStrikMonstr(vnMonstr, vnBrave) << endl;

  return 0;
}

Measured memory_bytes: 4036
n = int(input())

hl = list(map(int,input().split()))

ans = 0
while True:
    if sum(hl) == 0:
        break
    ans += 1
    flag = False
    for idx, h in enumerate(hl):
        if h > 0:
            hl[idx] -= 1
            flag = True
        elif flag:
            break
        else:
            continue

print(ans)
            
        
    

Measured memory_bytes: 41068
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int, int> pii;
typedef std::pair<int, double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1e9+7;



void solve(){

    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int ans = 0;
    
    rep(i,n){
        FOR(j,i+1,n){
            FOR(k,j+1,n){
                set<int> ss;
                ss.insert(l[i]);
                ss.insert(l[j]);
                ss.insert(l[k]);
                if (ss.size() != 3) continue;
                vector<int> s = {l[i],l[j],l[k]};
                SORT(s);
                
                if (s[0] + s[1] > s[2]){
                    ans++;
                }
            }
        }
    }
    cout << ans;
}


int main() {
    int T;
    //cin >> T;
    T = 1;
    while (T--) {
        solve();
        cout << endl;
    }
}














Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string s;
	cin >> s;
	vector<int> tr(4);
	rep(i, 4){
		tr.at(i) = s[i] - '0';
	}
	rep(i, 1 << 3){
		int temp = tr.at(0);
		rep(j, 3){
			if((i & (1 << j)) == 0) temp += tr.at(j+1);
			else temp -= tr.at(j+1);
		}
		if(temp == 7){
			rep(j, 4){
				cout << tr.at(j);
				if(j != 3){
					if((i & (1 << j)) == 0) cout << '+';
					else cout << '-';
				}
			}
			cout << "=7";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import heapq
input = sys.stdin.readline
n,m = map(int, input().split())
job_list = {}
for i in range(n):
    a,b = map(int, input().split())
    if a in job_list:
        job_list[a].append((-b,a))
    else:
        job_list[a] = [(-b,a)]
# job_list.sort(key=lambda x:x[0])
# print(job_list)

hq = []
max_income = 0
# j = 0
for i in range(1,m+1):
    if i in job_list:
        for j in job_list[i]:
            heapq.heappush(hq, j)
    # while j < n and job_list[j][0] <= i:
        # heapq.heappush(hq, (-job_list[j][1],job_list[j][0]))
        # j += 1
    if len(hq) < 1:
        continue
    b_i, a_i = heapq.heappop(hq)
    max_income += -b_i

print(max_income)

Measured memory_bytes: 31652