akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
    int n, h, a, b, d = 0, max_a = 0, sol = 0;

    vector<pair<int, int>> v, rv;

    cin >> n >> h;

    for (int i = 0; i < n; ++i)
    {
        cin >> a >> b;

        if (a > max_a)
            max_a = a;

        v.push_back(make_pair(b, a));
    }

    for (int i = 0; i < n; ++i)
    {
        if (v[i].first >= max_a)
            rv.push_back(v[i]);
    }

    if (rv.empty())
    {
        cout << ceil(double(h * 1.0 / max_a)) << endl;
    }
    else
    {
        sort(rv.begin(), rv.end());


        for (int i = rv.size() - 1; i >= 0; --i)
        {
            d += rv[i].first;
            ++sol;

            if (d >= h)
            {
                cout << sol << endl;
                return 0;
            }
        }

        sol;

        int min_sol = 1000000000;

        for (int i = 0; i < rv.size(); ++i)
        {
            if (ceil((h * 1.0 - d) / rv[i].second) < min_sol)
                min_sol = ceil((h * 1.0 - d) / rv[i].second);
        }

        cout << sol + min_sol << endl;
    }
}

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

int main(){
  int n,i,m,s;
  cin >> n;
  vector<int> h(n);
  s=1;
  cin >> h.at(0);
  m=h.at(0);
  for(i=1;i<n;i++){
    cin >> h.at(i);
    if(m<=h.at(i)){
      s++;
      m=h.at(i);
    }
  }
  
  cout << s << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,m;
    cin>>n>>m;
    vector<set<int>> vi(n+1);
    for(int i=0; i<m; i++){
        int x,y;
        cin>>x>>y;
        vi[x].insert(y);
        vi[y].insert(x);
    }
    for(int j:vi[1]){
        if(vi[j].find(n)!=vi[j].end()){
            cout<<"POSSIBLE";
            return 0;
        }
    }
    
    cout<<"IMPOSSIBLE";
    
    return 0;
}

Measured memory_bytes: 28416
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		List<int[]> nxs = new ArrayList<>();

		while(true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

			if(n == 0) break;
			int[] nx = new int[] {n, x};
			nxs.add(nx);
		}
		sc.close();

		for (int[] nx : nxs) {
			int count = check(nx[0], nx[1]);
			System.out.println(count);
		}

	}

	private static int check(int n, int x) {

		if(n > x-3) n = x-3;

		int ans = 0;
		for (int i = 1; i <= n-2; i++) {
			for (int j = i+1; j <= n-1; j++) {
				for (int k = j+1; k <= n; k++) {
					if(i + j + k == x) ans++;
				}
			}
		}
		return ans;
	}
}

Measured memory_bytes: 26148
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map> 
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef __int128 _int ;
const int maxn=2e5+6;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n,k;
int a[maxn];
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}        
void write(int x){        
    if(x < 0) {        
        putchar('-');        
        x = -x;        
    }        
    if(x > 9)        
        write(x/10);        
    putchar(x % 10 + '0');        
    return;        
}   
signed main(){
	cin>>n>>k;
	int d;
	for(int i=1;i<=k;i++){
		cin>>d;
		for(int i=1;i<=d;i++){
			int x;
			cin>>x;
			a[x]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	  if(a[i]==0)  ans++;
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int n;
set<int> s;
int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	int sz = 0;
	for (int i = 0;i < n;++i)
	{
		int x;
		cin >> x;
		s.insert(x);
		if (sz == s.size())
		{
			puts("NO");
			return 0;
		}
		++sz;
	}
	puts("YES");
	return 0;
}



Measured memory_bytes: 9600
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#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>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int n, m;

int dijkstra(vector<vector<T>> &G){
    vector<int> dist(n, 1e9);
    priority_queue<T, vector<T>, greater<T>> que;
    que.emplace(0, 0, 0);

    int ans = 0;
    while(!que.empty()){
        int cdist, cv, ccost;
        tie(cdist, cv, ccost) = que.top();
        que.pop();
        
        if(dist[cv] <= cdist) continue;
        dist[cv] = cdist;
        ans += ccost;

        for(auto x : G[cv]){
            int nv, ndist, ncost;
            tie(nv, ndist, ncost) = x;
            if(dist[nv] != 1e9) continue;
            que.emplace(dist[cv] + ndist, nv, ncost);
        }
    }

    return ans;
}

int main(){
    while(1){
        cin>>n>>m;
        if(n == 0) return 0;
        vector<vector<T>> G(n);
        for(int i=0; i<m; i++){
            int u, v, d, c; cin>>u>>v>>d>>c;
            u--, v--;
            G[u].emplace_back(v, d, c);
            G[v].emplace_back(u, d, c);
        }

        cout << dijkstra(G) << endl;
    }
}


Measured memory_bytes: 4236
#include<iostream>
#include<queue>
#include<iostream>
#include<queue>
#include<vector>
#include<set>
#include<memory>
#include<algorithm>
#include<cmath>
using namespace std;
 
long long solve(long long n, long long p){
  if(n==1)    return p;
 
  long long ans = 1;
  double max_c = pow(p, 1.0/n) + 1;
  // cerr << max_c <<endl;
  long long c=2;
  while(c<=max_c){
    // cerr << (long long)(pow(c, n)) << endl;
    // cerr << p%(long long)(pow(c, n)) << endl;
    if(! (p % (long long)(pow(c, n)))){
      ans *= c;
      p /= pow(c, n);
      max_c = pow(p, 1.0/n)  + 1;
      // cerr << ans << ',' << p << ',' << max_c <<endl;
    }else{
      if(c==2)c++;
      else c+=2;
    }
  }
  return ans;
}
 
int main(){
  long long n, p;
  cin >> n >> p;
  cout << solve(n, p);
  return 0;
}

Measured memory_bytes: 384
def examA():
    S = SI()
    if S=="ARC":
        ans = "ABC"
    else:
        ans = "ARC"
    print(ans)
    return

def examB():
    N, K = LI()
    snuke = set(range(1,N+1))
    for _ in range(K):
        d = I()
        A = LI()
        for a in A:
            snuke.discard(a)
    ans = len(snuke)
    print(ans)
    return

def examC():
    N, M = LI()
    H = LI()
    good = set(range(1,N+1))
    for _ in range(M):
        a, b = LI()
        if H[a-1]>=H[b-1]:
            good.discard(b)
        if H[b-1]>=H[a-1]:
            good.discard(a)
    ans = len(good)
    print(ans)
    return

def examD():
    X = I()
    #print(1000**5-999**5)
    for a in range(-1000,1000):
        for b in range(-1000,1000):
            if a**5-b**5==X:
                print(a,b)
                return
    return

def examE():
    N = I()
    A = LI()
    B = [0]*N
    D = defaultdict(int)
    for i in range(N):
        B[i] = A[i]-i
        c = A[i]+i
        D[c] += 1
    #print(B)
    #print(D)
    ans = 0
    for b in B:
        ans += D[-b]
    print(ans)
    return

def examF():
    N, A, B, C = LI()
    S = [SI()for _ in range(N)]
    ans = [""]*N


    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 162284
#include <algorithm>
#include <cmath>
#include <deque>
#include <limits.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void NO() { cout << "NO" << endl; }
inline void Yes() { cout << "Yes" << endl; } inline void No() { cout << "No" << endl; }

const int MAX = 300;

void init();
double rec(int i, int j, int k);

double dp[301][301][301];
int n, c[4];

int main()
{
	init();

	cout << setprecision(15) << rec(c[1], c[2], c[3]) << endl;
}

void init()
{
	memset(dp, -1, sizeof dp);
	memset(c, 0, sizeof c);

	cin >> n;
	REP(_i, n)
	{
		int x; cin >> x;
		c[x]++;
	}
}

double rec(int i, int j, int k)
{
	if (dp[i][j][k] >= 0)
		return dp[i][j][k];

	int s = i + j + k;
	if (!s)
		return dp[i][j][k] = 0.0;

	double ret = 0.0;
	
	if (i > 0) ret += rec(i - 1, j, k) * ((dbl)i / s);
	if (j > 0) ret += rec(i + 1, j - 1, k) * ((dbl)j / s);
	if (k > 0) ret += rec(i, j + 1, k - 1) * ((dbl)k / s);

	ret += ((dbl)n / s);

	return dp[i][j][k] = ret;

}

Measured memory_bytes: 213376
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        double R1 = sc.nextDouble(), R2 = sc.nextDouble();
                        System.out.println(R1 * R2 / (R1 + R2));
                }
        }
}

Measured memory_bytes: 11344
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,W;
    char a[101][101];
    int flag[101]={};
    int flag2[101]={};
    
    cin>>H>>W;
    for(int i=0;i<H;i++)
        for(int j=0;j<W;j++) cin>>a[i][j];
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(a[i][j]=='#'){
                flag[i]=1;
                break;
            }
        }
    }
    
    for(int j=0;j<W;j++){
        for(int i=0;i<H;i++){
            if(a[i][j]=='#'){
                flag2[j]=1;
                break;
            }
        }
    }
    
    for(int i=0;i<H;i++){
        if(!flag[i]) continue;
        for(int j=0;j<W;j++){
            if(!flag2[j]) continue;
            cout<<a[i][j];
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())

from math import sqrt,log10
#1~sqrt(n)まで探索すれば良い
ret = 11
for i in range(1,int(sqrt(n)+1)):
    if n%i==0:
        ret = min([ret,log10(n//i)+1])
print(int(ret))


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define rnd(d) (ll)((double)d + (d >= 0 ? 0.5 : -0.5))
#define floorsqrt(x) ((ll)sqrt((double)x) + ((ll)sqrt((double)x) * (ll)sqrt((double)x) <= (ll)x ? 0 : -1))
#define ceilsqrt(x) ((ll)sqrt((double)x) + ((ll)x <= (ll)sqrt((double)x) * (ll)sqrt((double)x) ? 0 : 1))
#define ceildiv(a, b) ((ll)a / (ll)b + ((ll)a % (ll)b == 0 ? 0 : 1))
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)

/*******************************************************/

int main() {
	ll a, b, c, x, y; cin >> a >> b >> c >> x >> y;
	if (x > y) {
		swap(a, b);
		swap(x, y);
	}
	ll val1 = y * c * 2;
	ll val2 = x * c * 2 + (y - x) * b;
	ll val3 = x * a + y * b;
	cout << min(val1, min(val2, val3)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n , k;
cin>>n>>k;
int a[n];
for(int i = 0 ; i < n ;i++){
 cin>>a[i];
}
sort(a , a+n);
if(k >= n){
 cout<<0<<endl;
 return 0;
}
int cnt = 0;
int i ;
for( i = n-1 ; i >= 0 && cnt < k; i-- , cnt++){
     
}
int sum = 0;
for(; i >= 0 ; i--){
 sum += a[i];
}
cout<<sum<<endl;
}



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

using namespace std;

string res[10];

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

	res[2] = "hon";
	res[4] = "hon";
	res[5] = "hon";		
	res[7] = "hon";
	res[9] = "hon";
	res[0] = "pon";	
	res[1] = "pon";
	res[6] = "pon";
	res[8] = "pon";
	res[3] = "bon";

	int n;

	cin >> n;

	cout << res[n%10] << '\n';
	
	return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>

int main(){
  int N,x;
  int num_A[250000];
  scanf("%d",&N);
  for(int a=2;a<=N;a++){
    scanf("%d",&x);
    num_A[x]++;
  };
  for(int b=1;b<=N;b++)
    printf("%d\n",num_A[b]);
};
    
        


Measured memory_bytes: 2464
/**
 *   created: 01 June 2019  12:55:56
**/
#include<bits/stdc++.h>
using namespace std;

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

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================
vl par,sz;
int getpar(int node){
	if(par[node]==node)
		return node;
	return par[node] = getpar(par[node]);
}
ll merge(int n1,int n2){
	int p1=getpar(n1), p2=getpar(n2);
	if(p1==p2)
		return (ll)0;
	par[p1] = p2;
	ll t = sz[p1]*sz[p2];
	sz[p2] += sz[p1];
	sz[p1] = sz[p2];
	return t; 
}	
int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		// vector<double> v1();
		// vector<string> s;
		double res=0;
		while(n--){
			double d;
			string s;
			cin>>d>>s;
			if(s=="JPY")
				res += d;
			else
				res += (380000.0)*(d);
		}
		printf("%.9lf\n",res );
	}

	return 0;
}


Measured memory_bytes: 256
while True :
  m, f, r = map(int, input().split())
  if(m == -1 and f == -1 and r == -1) :
    break
  elif(m == -1 or f == -1) :
    print("F")
  elif(m + f >= 80) :
    print("A")
  elif(65 <= m + f and m + f < 80) :
    print("B")
  elif(50 <= m + f and m + f < 65) :
    print("C")
  elif(30 <= m + f and m + f < 50) :
    if(50 <= r) :
      print("C")
    else :
      print("D")
  else :
    print("F")



Measured memory_bytes: 5588
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

vector<int> g[100111];
int n,sg[100111];
void dfs(int x,int f=0)
{
	for(int i=0;i<(int)g[x].size();i++)
		if(g[x][i]!=f)
		{
			dfs(g[x][i],x);
			sg[x]^=sg[g[x][i]]+1;
		}
}
int main()
{
	get1(n);
	for(int i=1,u,v;i<n;i++)
	{
		get2(u,v);
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1);
	puts(sg[1]?"Alice":"Bob");
	return 0;
}

Measured memory_bytes: 13952
#include<iostream>
using namespace std;
  
#define mod 1000000007
  
/*long rec(int a[], int n, long **mem, int id, int k)
{
  if(k==0)
  	return 1;
  if(id==n&&k>0)
    return -1;
  if(id==n&&k==0)
    return 1;
  if(mem[id][k]!=-1)
    return mem[id][k];
  long ans=0;
  for(int i=0;i<=min(k,a[id]);i++)
  {
    long ans1=rec(a,n,mem,id+1,k-i);
    if(ans1==-1)
      continue;
    ans1%=mod;
    ans=(ans%mod+ans1%mod)%mod;
    
  }
  mem[id][k]=ans;
  return ans;
}*/
  
int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  /*long **mem=new long*[n+1];
  for(int i=0;i<=n;i++)
  {
    mem[i]=new long[k+1];
    for(int j=0;j<=k;j++)
      mem[i][j]=-1;
  }
  
  cout<<rec(a,n,mem,0,k);*/
  
  long dp[n+1][k+1];
  for(int j=0;j<=k;j++)
    dp[0][j]=0;
  for(int i=0;i<=n;i++)
    dp[i][0]=1;
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=k;j++)
    {
      dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
      if(j-a[i-1]-1>=0)
        dp[i][j]=(dp[i][j]-dp[i-1][j-a[i-1]-1]+mod)%mod;
    }
  }
  
  cout<<dp[n][k];
  

}

Measured memory_bytes: 79104
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


A, B, C, D = map(int, input().split())

CD_lcm = int((C * D) / gcd(C, D))
# B以下の数字に関する個数
BCcan = B//C
BDcan = B//D
BCDcan = B//CD_lcm

A1Ccan = (A-1)//C
A1Dcan = (A-1)//D
A1CDcan = (A-1)//CD_lcm

count = (BCcan+BDcan - BCDcan) - (A1Ccan+A1Dcan - A1CDcan)

print(int(B-(A-1) - count))


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

int main()
{
    int N, A;
    cin >> N;
    cin >> A;
    cout << (N % 500 <= A ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define standardVar ll n,m,i,j,k,num,num1,num2,flag=0
#define nn <<"\n"
#define __ <<" "<<
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define ittr(x,v) for(auto x=v.begin();x!=v.end();x++)
#define itr(x,n) for(x=0;x<n;x++)
#define itrab(x,a,b) for(x=a;x<b;x++)
#define itpr(v) ittr(x,v)cout<<*x<<" "; cout nn
#define itppr(v) ittr(x,v)cout<<(*x).ff<<" "<<(*x).ss<<"  "; cout nn
#define pi 3.14159265359
#define dTor(x) ((x)*pi)/180.0

typedef long long int ll;       //TYPEDEFS
typedef long double ld;
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef set<ll> sl;
typedef string str;
typedef pair<ll, ll> pl;
typedef vector< pl > vpl;
typedef map<pl,ll> mpl;
typedef set< pl > spl;
typedef vector<str> vst;
typedef vector<vl> vvl;

const ll M=1000000007;          //COMMON MODULO
const ll N=998244353;

ll power(ll x, ll y, ll p){     //MODULAR EXPONENTIATION
    ll res=1;
    x=x%p;
    if(x==0)
        return 0;
    while(y>0){
        if(y&1)
            res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}
ll inv(ll x, ll m){             //FERMAT INVERSE
    return power(x,m-2,m);
}
struct comp{                    //COMPARISON ON PAIRS
    template<typename T>        
    bool operator()(const T &a, const T &b){
        if (a.ff==b.ff)
            return (a.ss<b.ss);
        else
            return (a.ff<b.ff);
    }
};
bool mod(const pair<ll,ll> &a, const pair<ll,ll> &b){   //COMPARATOR FOR PAIRS (SORTING)
    if(a.ff!=b.ff)
        return (a.ff<b.ff);
    else
        return (a.ss<b.ss);
}
void sieve(vl &prime){          //SIEVE OF ERATOSTHENES
    ll maxN=1e6;
    vector<bool> pr(maxN+1,1);
    for(int i=2;i*i<=maxN;i++)
        if(pr[i]==1)
            for(int j=i*i;j<=maxN;j+=i)
                pr[j]=0;
    for(ll i=2;i<=maxN;i++)
        if(pr[i]==1)
            prime.pb(i);
}
bool isValid(ll i, ll j, ll n, ll m){   //CHECKS FOR OVERFLOW
    if(i>=0&&i<n&&j>=0&&j<m){
        return true;
    }
    return false;
}

//MAIN FUNCTION STARTS HERE

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    standardVar;
    cin>>n;
    vl v;
    itr(i,n){
        cin>>num;
        v.pb(num);
    }
    sort(all(v),greater<>());
    k=1;
    ll sum=v[0];
    for(i=1;i<n;i++){
        sum+=v[i];
        k+=1;
        if(k>n-1){
            sum-=v[i];
            break;
        }
        else{
            sum+=v[i];
            k+=1;
        }
        if(k>n-1){
            sum-=v[i];
            break;
        }
    }
    cout<<sum nn;
    return 0;
}

Measured memory_bytes: 5312
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N ;
    cin >> N ;
    
    N--;
    
    cout << (N+1) * N / 2 << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

int main(){
	const int max=20*2000;
	int n;
	cin >> n;
	int checkList[max]={};
	int i,j,x;
	int lim=0;
	
	checkList[0]=1;
	for (i=0;i<n;i++){
		cin >> x;
		for (j=lim;j>=0;j--){
			if (checkList[j]==1){
				checkList[j+x]=1;
			}
		}
		lim+=x;
	}
	
	int q;
	cin >> q;
	for (i=0;i<q;i++){
		cin >>x;
		if (checkList[x]==1){
			cout <<"yes" <<endl;
		}else{
			cout << "no" << endl; 
		}
	}
	
	return 0;
}

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

int main(void){
    ll x, y;
    cin >> x >> y;

    ll ans = x;
    ll count = 1;
    while(ans * 2 <= y){
        ans *= 2;
        count++;
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  string s1,s2;
  cin>>s1;
  cin>>s2;
  ll ans=1;
  rep(i,n)
    if(s1[i]==s2[i]){
      if(i==0)ans*=3;
      else if(s1[i-1]==s2[i-1])ans=(ans*2)%MOD;
    }else{
      if(i==0)ans*=6;
      else if(s1[i-1]==s2[i-1])ans=(ans*2)%MOD;
      else ans=(ans*3)%MOD;
      i++;
    }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
from math import ceil
import re
S = input()
N = len(S)

X = re.findall('R+L+', S)
ans = [0] * N

i = 0
for x in X:
    x_len = len(x)
    start = x.find('RL')

    ans[i + start] += (x_len - start - 1) // 2 + ceil((start + 1) / 2)
    ans[i + start + 1] += (start + 1) // 2 + ceil((x_len - start - 1) / 2)

    i += x_len

print(*ans, sep=' ')


Measured memory_bytes: 9712
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  string s; cin >> s;
  int q; cin >> q;
  vector<int> k(q);
  REP(i,q){
      cin >>k[i];
  }
  vector<LP> pa;
  REP(i,n){
      if(s[i]=='D'){
          pa.pb(mp(0,i));
      }else if(s[i]=='M'){
          pa.pb(mp(1,i));
      }else if(s[i]=='C'){
          pa.pb(mp(2,i));
      }
  }
  vector<ll> whd;
  REP(i,pa.size()){
      if(pa[i].first==0){
          whd.push_back(i);
      }
  }
  REP(i,q){
      ll m=0;
      ll c=0;
      ll mc = 0;
      ll range = k[i];
      ll now = whd[0];
      ll pos = whd[0]+1;
      bool isd = true;
      ll ans = 0;
      while(now<pa.size()){
          if(pa[pos].second-pa[now].second<range && isd && pos< pa.size()){
              if(pa[pos].first==1){
                  m++;
              }else if(pa[pos].first==2){
                  c++;
                  mc+=m;
              }
              pos++;
          }else{
              if(isd){
                  ans += mc;
                  isd = false;
              }
              now++;
              if(pa[now].first==1){
                  m--;
                  mc -= c;
              }else if(pa[now].first==2){
                  c--;
              }
              if(pa[now].first==0){
                  isd = true;
              }
          }
      }
          cout << ans << endl;
  }
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n,m;cin >> n >> m;
    vector<ll> a(n);rep(i,m)cin >> a[i];
    ll sum = accumulate(ALL(a),0LL);
    if(sum > n)cout << -1 << endl;
    else cout << n - sum << endl;
    return 0;
}

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

#define int long long

vector<int> sieve_of_eratosthenes(int n)
{
    vector<int> primes(n);
    for (int i=2; i<n; ++i)
        primes[i] = i;
    for (int i=2; i*i<n; ++i)
        if (primes[i])
            for (int j=i*i; j<n; j+=i)
                primes[j] = 0;

    primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());
    return primes;
}

signed main()
{
    int a, d, n;
    vector<int> primes = sieve_of_eratosthenes(1000001);
    while(cin>>a>>d>>n, a) {
        int cnt = 0;
        int ans = 0;
        for(int i=a;; i+=d) {
            if(*lower_bound(primes.begin(), primes.end(), i)==i) cnt++;
            if(cnt==n) {
                ans = i;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 10568
#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define mp make_pair
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int isprime(int n){
    int count =0;
    for(int i=2;i<=sqrt(n);i++)
    if(n%i==0)count++;
    if(count)return 0;
    return 1;
}
int gcd(int a, int b) 
{ 
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
    if (a == b) 
        return a; 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
int main(){
    int x;
    cin>>x;
    int p = x*360/(gcd(x,360));
    cout<<p/x;
    
    return 0;
}





Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
int main(){
  ll dp[100020];
  ll x;
  cin>>x;
  dp[0]=1;
  for(ll i=100;i<=x;i++){
    if(dp[i]==0 && dp[max((ll)0,i-100)]==1)dp[i]=dp[max((ll)0,i-100)];
    if(dp[i]==0 && dp[max((ll)0,i-101)]==1)dp[i]=dp[max((ll)0,i-101)];
    if(dp[i]==0 && dp[max((ll)0,i-102)]==1)dp[i]=dp[max((ll)0,i-102)];
    if(dp[i]==0 && dp[max((ll)0,i-103)]==1)dp[i]=dp[max((ll)0,i-103)];
    if(dp[i]==0 && dp[max((ll)0,i-104)]==1)dp[i]=dp[max((ll)0,i-104)];
    if(dp[i]==0 && dp[max((ll)0,i-105)]==1)dp[i]=dp[max((ll)0,i-105)];
  }
  cout<<dp[x]<<endl;
} 

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    int r = n;
    int l = -1;
    int m;
    int male_idx;
    cout << 0 << endl;
    string tmp_s;
    cin >> tmp_s;
    if (tmp_s == "Vacant") return 0;
    else if (tmp_s == "Male") {
        male_idx = 0;
    }
    else {
        male_idx = 1;
    }
    while(r-l>0) {
        m = (r + l) / 2;
        cout << m << endl;
        string s;
        cin >> s;
        if (s == "Vacant") break;
        else if (s == "Male") {
            if (m % 2 == male_idx) {
                l = m;
            }
            else {
                r = m;
            }
        }
        else if (s == "Female") {
            if (m % 2 == male_idx) {
                r = m;
            }
            else {
                l = m;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3852
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
char r[600][600],b[600][600],a[600][600];
int main(){
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i+=2)  for(int j=1;j<=m;j++)  r[i][j]='#';
  for(int i=2;i<=n;i+=2)  for(int j=1;j<=m;j++)  r[i][j]='.';
  for(int i=2;i<=n;i+=2)  for(int j=1;j<=m;j++)  b[i][j]='#';
  for(int i=1;i<=n;i+=2)  for(int j=1;j<=m;j++)  b[i][j]='.';
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    {
      char cur;cin>>cur;
      if(cur=='#')
      {
        r[i][j]='#';
        b[i][j]='#';
      }
    }
  for(int i=1;i<=n;i++)  r[i][1]='#',b[i][1]='.';
  for(int i=1;i<=n;i++)  r[i][m]='.',b[i][m]='#';
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=m;j++)  cout<<r[i][j];
    cout<<endl;
  }
  cout<<endl;
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=m;j++)
      cout<<b[i][j];
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	string s;
  	cin >> s;
  	for(char c: s) {
    	if ( c == '7') {
        	cout << "Yes" << endl;
          	return 0;
        }
    }
  	cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3604
N=int(raw_input())

W_list = []
flag=True
before = ""
for i in range(N):
    W = raw_input()
    if W in W_list:
        flag=False
    if i!=0 and W[0]!=before:
        flag=False
    W_list.append(W)
    before = W[-1]

if flag:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 2568
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<vector>
using namespace std;
long long  mod = 1000000007;

long long d[200010] = { 0 };
vector<int> G[200010];
int co[200010] = { 0 };

void dfs(int v, int parent) {
	for (int i = 0; i < G[v].size(); i++) {

		if (G[v][i] == parent) {
			d[v] += (d[parent] + co[v]);
			continue;
		}
		dfs(G[v][i], v);
	}
}

int a, b;
int p, x;
int main()
{

	int N, Q;
	cin >> N >> Q;
	for (int i = 0; i < N - 1; i++) {
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for (int i = 0; i < Q; i++) {
		cin >> p >> x;
		co[p] += x;
	}
	for (int i = 1; i <= N; i++) {
		sort(G[i].begin(), G[i].end());
	}
	d[1] = co[1];
	dfs(1, 0);
	for (int i = 1; i <= N; i++) {
		cout << d[i] << " ";
	}
}


Measured memory_bytes: 31104
class UnionFind:
    def __init__(self, n):
        self.v = [-1 for _ in range(n)]  # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)

    def find(self, x):  # xを含む木における根の頂点番号を返す
        if self.v[x] < 0:  # (負)は根
            return x
        else:  # 根の頂点番号
            self.v[x] = self.find(self.v[x])  # uniteでは, 旧根に属する頂点の根が旧根のままなので更新
            return self.v[x]

    def unite(self, x, y):  # 違う根に属していたらrankが低くなるように連結
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:  # size比較, 　(-1) * (連結頂点数 * (-1)), (正)同士の大小比較
            x, y = y, x  # 連結頂点数が少ない方をyにすると, findでの更新回数が減る？
        self.v[x] += self.v[y]  # 連結頂点数の和を取る, 連結頂点数 * (-1)
        self.v[y] = x  # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする

    def root(self, x):
        return self.v[x] < 0  # (負)は根

    def same(self, x, y):
        return self.find(x) == self.find(y)  # 同じ根に属するか

    def size(self, x):
        return -self.v[self.find(x)]  # 連結頂点数を返す


N, M = map(int, input().split())

uf = UnionFind(N)
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    uf.unite(x, y)

ans = sum(1 for i in range(N) if uf.root(i))
print(ans)


Measured memory_bytes: 69152
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll h,w;
  cin >> h >> w;
  char a[h][w];
  REP(i,h)REP(j,w) cin >> a[i][j];
  bool blank_row[h];
  bool blank_col[w];
  fill(blank_col,blank_col+w,true);
  fill(blank_row,blank_row+h,true);
  REP(i,h){
    REP(j,w){
      if(a[i][j]=='#') blank_row[i] = false;
    }
  }
  REP(j,w){
    REP(i,h){
      if(a[i][j]=='#') blank_col[j] = false;
    }
  }
  REP(i,h){
    REP(j,w){
      if(!blank_row[i]&&!blank_col[j]) cout << a[i][j];
    }
    if(!blank_row[i]) cout << endl;
  }
  return 0;
}


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

int main(){
  int n, i, j, ch=0;
  cin >> n;
  vector<int> A(n);
  for(i=0; i<n; i++) cin >> A[i];
  sort(A.begin(), A.end());
  
  for(i=0; i<n-1; i++){
    if(A[i] == A[i+1]) {
      ch++;
      break;
    }
  }
  if(ch == 1) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}

template<typename T>
vector<T> make_unique(vector<T> v) {
    sort(all(v));
    return v.resize(unique(all(v)) - v.begin());
}

int nxt() {
    int x;
    cin >> x;
    return x;
}


int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

//#############################
const int MAXN = 1000005;

int main() {
    fastIO();

    int k = nxt(), a = nxt(), b = nxt();
    for(int i = 1; i < 1001; i++) {
        if (k*i >= a && k*i <= b){
            cout << "OK\n";
            return 0;
        }
    }

    cout << "NG\n";
    return 0;
}

Measured memory_bytes: 3104
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		int N = GetInt();
		int[] p = Enumerable.Range(0, N).Select(_ => GetInt() - 1).ToArray();
		int diff = Enumerable.Range(0, N).Where(x => x != p[x]).Count();
		Console.WriteLine((diff <= 2) ? "YES" : "NO");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    int n, m;
    ll z = (ll)mod * mod * 8, x[52] = {}, y[52] = {};
    cin >> n >> m;
    fr(n) cin >> x[i] >> y[i];
    fr(n) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) for (int l = 0; l < n; l++) {
        if (x[i] > x[j] || y[k] > y[l]) continue;
        int c = 0;
        for (int a = 0; a < n; a++) {
            if (x[a] < x[i]) continue;
            if (x[a] > x[j]) continue;
            if (y[a] < y[k]) continue;
            if (y[a] > y[l]) continue;
            c++;
        }
        if (c >= m) {
            z = min(z, (x[j] - x[i]) * (y[l] - y[k]));
        }
    }
    cout << z;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  int M=2;
  string ans;
  for(int i=0;N!=0;i++){
    if(N%M!=0){
      ans+='1';
      if(i%2==0)
        N-=M/2;
      else
        N+=M/2;
    }
    else
      ans+='0';
    M*=2;
  }
  if(ans.size()==0)
    ans='0';
  reverse(ALL(ans));
  cout<<ans<<endl;
  }


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

using namespace std;

int main()
{
    while (true) {
        int n, m, p;
        cin >> n >> m >> p;
        if (n == 0 and m == 0 and p == 0) {
            break;
        }
        m--;
        vector<int> x(n);
        int sum = 0;
        for (int i = 0; i < n; i++) {
            cin >> x[i];
            sum += x[i];
        }
        sum *= (100 - p);
        if (x[m] == 0) {
            cout << 0 << endl;
        } else {
            cout << sum / x[m] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3060
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <time.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000001
#define mod 1000000009
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)

int main()
{
    int k,t;
    int a[200];
    int flag = -1;
    int doub = 1;
    int ans = 0;
    int num;
    cin >> k >> t;
    for(int i = 0;i < t; i++){
        cin >> a[i];
    }
    for(int i = 0;i < k;i++){
        sort(a,a + t);
        if(flag != -1){
            for(int j = 0;j < t;j++){
                if(num == a[j]){
                    flag = j;
                    break;
                }
            }
            doub = 1;
            for(int j = t - 1;j >= 0;j--){
                if(j != flag){
                    if(a[j] != 0){
                        flag = j;
                        a[flag]--;
                        num = a[flag];
                        doub = 0;
                        break;
                    }
                }
            }
            if(doub == 1){
                ans++;
                a[flag]--;
            }
        }else{
            flag = t - 1;
            a[flag]--;
            num = a[flag];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n,a[100005];
int main()
{
    n=read();reg int sum=0,ans=0;
    for(reg int i=1;i<=n;++i)a[i]=read();
    for(reg int i=1;i<n;++i)
    {
        if(a[i+1]<=a[i]){sum++;}
        else {ans=max(ans,sum);sum=0;}
    }
    ans=max(ans,sum);
    cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 640