akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100000+19;
const int M=200000+19;

struct Edge{
	int y,nxt;
} E[M*2];
int las[N],vis[N];
int n,m,x,y,cnt,ji,ou,yi;
ll ans;

void Link(int x,int y){
	E[cnt]=(Edge){y,las[x]};las[x]=cnt++;
	E[cnt]=(Edge){x,las[y]};las[y]=cnt++;
}
bool dfs(int x,int col){
	if (~vis[x]) return vis[x]!=col;
	vis[x]=col;
	bool res=0;
	for (int i=las[x];~i;i=E[i].nxt){
		res|=dfs(E[i].y,col^1);
	}
	return res;
}

int main(){
	memset(las,-1,sizeof(las));
	memset(vis,-1,sizeof(vis));
	n=IN(),m=IN();
	For(i,0,m) Link(IN(),IN());
	For(i,1,n+1) if (vis[i]==-1){
		if (las[i]==-1) yi++;lf (dfs(i,0)) ji++;else ou++;
	}
	ans+=2ll*ji*ou;
	ans+=1ll*ji*ji;
	ans+=2ll*ou*ou;
	ans+=2ll*yi*(n-yi);
	ans+=1ll*yi*yi;
	cout<<ans<<endl;
}

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

int main(){
  queue<pair<string, int> > q;
  int N, Q;
  cin >> N >> Q;
  rep(i, N){
    string s;
    int in;
    cin >> s >> in;
    pair<string, int> p(s, in);
    q.push(p);
  }
  int nowtime = 0;
  while(!q.empty()){
    pair<string, int> p = q.front();
    q.pop();
    if(p.second <= Q){
      nowtime += p.second;
      cout << p.first << " " << nowtime << endl;
    }else{
      nowtime += Q;
      p.second -= Q;
      q.push(p);
    }
  }
  
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

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

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

vi c(200000,0);
vii G(200000,vi());

void dfs(int f,int bf){
    for(auto x:G[f]){
        if(x==bf)continue;
        c[x]+=c[f];
        dfs(x,f);
    }
}

int main(){
    int N,Q;
    cin>>N>>Q;
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    rep(i,Q){
        int p,x;
        cin>>p>>x;
        p--;
        c[p]+=x;
    }
    dfs(0,-1);
    rep(i,N)cout<<c[i]<<" ";
    cout<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 23424
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll a,b,x; cin>>a>>b>>x;
    ll ans=b/x-a/x+1;
    if(a%x!=0)ans--;
    cout<<ans<<endl;
}




Measured memory_bytes: 256
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        // long N = sc.nextLong();
        // long K = sc.nextLong();
        int B = sc.nextInt();
        int A = sc.nextInt();

        System.out.println((A - 1) % (B - 1) != 0 ? (A - 1) / (B - 1) + 1 : (A - 1) / (B - 1));

    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>

#define M 1000001/* your task*/
#define L 14
#define FALSE -1

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
   long sum = 0, p = 1, i;
   for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return /* your task */key % M; }
int h2(int key){ return /* your task */1 + (key % (M-1)); }

int find(char str[]){

  /* your task */
  long long i,j,k;
  k = getKey(str);
  for(i=0; ;i++){
    j = (h1(k)+i*h2(k))%M;
    if(strcmp(H[j],str) == 0)return 1;
    else if(strlen(H[j]) == 0)return 0;
  }
  return 0;
}

int insert(char str[]){

  /* your task */
  long long i,j,k;
  k = getKey(str);
  for(i=0; ;i++){
    j = (h1(k)+i*h2(k))%M;
    if(strcmp(H[j],str) ==0)return 1;
    else if(strlen(H[j]) ==0){
      strcpy(H[j],str);
      return 0;
    }
  }
  
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if ( find(str) ==1 ){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



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

int main(){
  string a;
  cin >> a;
  
  int c=0;
  string b;
  
  for(int i=0; i<3; i++){
    b=a[i];
    if(b=="1"){
      c++;
    }
  }
  
  cout << c << endl;
}
  
  
  


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
  int a,b;
  char op;
  while(cin >> a >> op >> b) {
    if(op == '+')
      cout << a + b << endl;
    else if(op == '-')
      cout << a - b << endl;
    else if(op == '*')
      cout << a * b << endl;
    else if(op == '/')
      cout << a / b << endl;
    else if(op == '?')
      break;
  }
  return 0;
}

Measured memory_bytes: 3084
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int dp[100100];

int main()
{
    int n; cin >> n;
    int h[n];
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i = 0; i < n-2; i++){
        dp[i+2] = min(dp[i]+abs(h[i+2] - h[i]),dp[i+1]+abs(h[i+2]-h[i+1]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n;
  scanf("%d", &n);
  if (n/1000 == 0) printf("ABC\n");
  else printf("ABD\n");
  return 0;
}


Measured memory_bytes: 128
table = []
for i in range(3):
    table.append(list(map(int, input().split())))
parts = int(input())
p_list = []
for i in range(parts):
    p_list.append(int(input()))

result = [[False, False, False], [False, False, False], [False, False, False]]
chk = 0
for r_idx, row in enumerate(table):
    for c_idx, col in enumerate(row):
        result[r_idx][c_idx] = col in p_list


for i in range(3):
    if result[i][0] and result[i][1] and result[i][2]:
        chk += 1
    if result[0][i] and result[1][i] and result[2][i]:
        chk += 1

if result[0][0] and result[1][1] and result[2][2]:
    chk += 1

if result[0][2] and result[1][1] and result[2][0]:
    chk += 1

print('Yes' if chk > 0 else 'No')


Measured memory_bytes: 3064
#include"bits/stdc++.h"
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
int64_t i,j,k,l;//preparation for
int main(){
    string s;
    bool t;
    int u,u2;
    cin>>s;

    t=true;
    u=s.size();
    u2=(u-1)/2;
    for(i=0;i<u2;i++){
        if(s[i]!=s[u-i-1]){
            t=false;
            break;
        }
    }

    for(i=0;i<=u2/2;i++){
        if(s[i]!=s[u2-i-1]){
            t=false;
            break;
        }
    }

    if(t){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>		
using namespace std;
int main (void){
	int N;
	cin >> N;
	int TOTAL=0;
	for(int i=0;i<N;i++){
		int l,r;
		cin >> l >> r;

		
		TOTAL+=r-l+1;
	}
	cout << TOTAL <<endl;
	return 0;
}

Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

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

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


vector<ll> A, B;

auto lis() {
    vector<ll> LIS;
    rep (i, A.size()) {
        if (LIS.size() == 0 || A[i] >= LIS[LIS.size() - 1]) {
            LIS.pb(A[i]);
        } else {
            auto it = upper_bound(all(LIS), A[i]);
            if (it != LIS.end()) {
                *it = A[i];
            }
        }
    }
    return LIS;
}

int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    rep (i, N) {
        ll a;
        cin >> a;
        B.pb(a);
    }
    rep (i, N) {
        A.pb(B[N - i - 1]);
    }
    cout << lis().size() << endl;
}


Measured memory_bytes: 3316
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,w=map(int,input().split())
    a-=1;b-=1
    G[a].append((b,w))
    G[b].append((a,w))
C=[-1]*n 
C[0]=0
def dfs(x):
    for v,w in G[x]:
        if C[v]==-1:
            C[v]=1-C[x] if w%2==1 else C[x]
            dfs(v)

dfs(0)
# print(G)
for i in range(n):
    print(C[i])


Measured memory_bytes: 172128
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define MOD 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(var) (var).begin(), (var).end()
#define sz(x) (int)x.size()
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> > 
#define vvpi vector<vector<pair<int,int> > >

vvi adj(200005);
int v[200005],cn=0;

void dfs(int x)
{
	v[x] = 1;
	cn++;
	for(auto it : adj[x])
	{
		if(!v[it])
		{
			dfs(it);
		}
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int n,m,x,y,i;
	cin >> n >> m;
	while(m--)
	{
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	int ans = 0;
	for(i=1;i<=n;i++)
	{
		if(!v[i])
		{
			cn = 0;
			dfs(i);
			ans = max(ans, cn);
		}
	}

	cout << ans;
	
	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

const ll MOD = TEN(9)+7;
int x,y;

template <long long MOD>
long long mod_pow(long long a, long long b)
{
  if (b == 0) return 1;
  long long ret = mod_pow<MOD>(a, b/2);
  ret = ret * ret % MOD;
  if (b % 2 == 1) ret = a * ret % MOD;
  return ret;
}


template<long long mod> struct Comb {
  int n;
  vector<long long> fact, inv;

  Comb(int n) : n(n), fact(n+1,0), inv(n+1,0) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i-1] * i % mod;
    inv[n] = mod_pow<mod>(fact[n], mod-2);
    for (int i = n; i >= 1; i--) inv[i-1] = inv[i] * i % mod;
  }

  long long operator()(int m, int k) {
    if (m > n || m < k || k < 0) return 0;
    else return fact[m] * inv[m-k] % mod * inv[k] % mod;
  }
};


int main()
{
  fastio();

  cin >> x >> y;

  Comb<MOD> comb(x+y);

  ll ans = 0;
  for (int c1 = 0; c1 <= x; c1++) {
    if ((x - c1) % 2) continue;
    int c2 = (x - c1) / 2;
    if (2 * c1 + c2 != y) continue;

    ans += comb(c1+c2, c1);
  }

  cout << ans << endl;


  return 0;
}


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

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

	int n, k;
	string str;

	cin >> n >> k >> str;

	k--;

	str[k] = str[k] + 32;

	cout << str << endl;

	return 0;
}

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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>

typedef long long ll;

int main() {
  int N, ans = 0;
  cin >> N;
  for (int i = 1; i <= N; i += 2) {
    int cnt = 0;
    for (int j = 1; j <= N; j++) {
      if (i % j == 0) {
        cnt++;
      }
    }
    if (cnt == 8) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1e9+7;

int main() {
	int n;string a,b,c;
	cin >> n >> a >> b >> c;
	int ans = 0;
	for (int i = 0;i < n;i++) {
		if (a[i] != b[i] && b[i] != c[i] && a[i] != c[i]) {ans += 2;}
		if (a[i] != b[i] && b[i] != c[i] && a[i] == c[i]) {ans += 1;}
		if (a[i] != b[i] && b[i] == c[i] && a[i] != c[i]) {ans += 1;}
		if (a[i] == b[i] && b[i] != c[i] && a[i] != c[i]) {ans += 1;}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vl a(3 * n); REP(i, 3 * n) cin >> a[i];
	sort(ALL(a));
	ll sum = 0;
	REP(i, n) sum += a[n + i * 2];
	cout << sum << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
const int N=200010;
vector<long long> r,w;

int main(){ 
    int len;
    cin>>len;
    char a[N];
    cin>>a;
    int cntr=0,cntw=0;
    w.push_back(0);
    r.push_back(0);
    for(int i=0;i<len;i++){
        if(i+1!=len&&a[i]=='W'&&a[i+1]!='R') cntw++;
        else if(a[i]=='W'&& i+1 !=len){
            cntw++;
            w.push_back(cntw);
            cntw=0;
        }
    }
    for(int i=len-1;i>=0;i--){
        if(i!=0&&a[i]=='R'&&a[i-1]!='W') cntr++;
        else if(a[i]=='R'&&i!=0){
            cntr++;
            r.push_back(cntr);
            cntr=0;
        }
    }
    
    for(int i=1;i<w.size();i++){

        w[i]=w[i-1]+w[i];
        r[i]=r[i-1]+r[i];;
    }
    int ans=200010;
    for(int i=0;i<w.size();i++){
        int temp=max(w[i],r[w.size()-i-1]);
        ans=min(ans,temp);
    }

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



Measured memory_bytes: 4452
#include <stdio.h>

#define INF 999999999
#define REP(i,n,m) for(i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

void printTable(int h,int w,int t[102][102],int *sales,int *totals){
	int i,j;
	rep(i,h){
		rep(j,w) printf("%10d",t[i][j]);
		printf("%10d\n",totals[i]);
	}
	rep(i,w+1) printf("%10d",sales[i]);
	printf("\n\n");
}

int main(void){
	int i,j;
	int h,w,tmp,startFlg,contFlg,count;
	int flg[102][102],t[102][102],totals[102],sales[102],ct[102],cs[102];

	startFlg = 1;
	while(scanf("%d",&h) && h){
		if(startFlg) startFlg = 0;
		else printf("\n");
		scanf("%d",&w);

		rep(i,h+1) totals[i] = ct[i] = 0;
		rep(i,w+1) sales[i] = cs[i] = 0;

		rep(i,h){
			rep(j,w){
				tmp = scanf("%d",&t[i][j]);
				if(tmp == 0){
					ct[i]++;
					cs[j]++;
					flg[i][j] = 1;
					t[i][j] = INF;
					getchar();
				}
				else{
					flg[i][j] = 0;
					totals[i] -= t[i][j];
					sales[j] -= t[i][j];
				}
			}
			scanf("%d",&tmp);
			totals[i] += tmp;
		}
		rep(i,w+1){
			scanf("%d",&tmp);
			sales[i] += tmp;
		}

		contFlg = 1;
		while(contFlg){
			contFlg = count = 0;
			rep(i,h){
				rep(j,w){
					if(t[i][j] == INF){
						if(ct[i] == 1){
							t[i][j] = totals[i];
							sales[j] -= totals[i];
							totals[i] = 0;
							ct[i] = 0;
							cs[j]--;

							contFlg = 1;
						}
						else if(cs[j] == 1){
							t[i][j] = sales[j];
							totals[i] -= sales[j];
							sales[j] = 0;
							ct[i]--;
							cs[j] = 0;

							contFlg = 1;
						}
						else{
							count++;
						}
					}
				}
			}
		}

		if(count == 0){
			rep(i,h) rep(j,w) if(flg[i][j] && t[i][j] != INF) {
				printf("%d\n",t[i][j]);
			}
		}
		else{
			printf("NO\n");
		}
	}

	return 0;
}

Measured memory_bytes: 0
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
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);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
signed main()
{
	fastio;
	int n;
	cin>>n;
	if(n==2)
	{
		cout<<1<<endl;
		return 0;
	}
	vi div;
	vi sub;
	for(int i=2;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			if(n/i==i)
				div.pb(i);
			else
			{
				div.pb(i);
				div.pb(n/i);
			}
		}
		if((n-1)%i==0)
		{
			if((n-1)/i==i)
				sub.pb(i);
			else
			{
				sub.pb(i);
				sub.pb((n-1)/i);
			}
		}
	}
	div.pb(n);
	div.pb(n-1);
	int cnt=0;
	for(int i=0;i<div.size();i++)
	{
		int temp=n;
		int x=div[i];
		while(temp%x==0)
		{
			temp/=x;
		}
		if(temp%x==1)
			cnt++;
	}
	for(int i=0;i<sub.size();i++)
	{
		int temp=n;
		int x=sub[i];
		while(temp%x==0)
		{
			temp/=x;
		}
		if(temp%x==1)
			cnt++;
	}
	cout<<cnt<<endl;	
}

Measured memory_bytes: 3708
using AtCoderBeginnerContest136.Questions;
using AtCoderBeginnerContest136.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest136.Questions
{
    public class QuestionC : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var h = inputStream.ReadIntArray();

            for (int i = 0; i < h.Length - 1; i++)
            {
                if (h[i + 1] > h[i])
                {
                    h[i + 1] -= 1;
                }
                else if (h[i + 1] < h[i])
                {
                    yield return "No";
                    yield break;
                }
            }
            yield return "Yes";
        }
    }
}


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

#region Base Classes

namespace AtCoderBeginnerContest136.Questions
{

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

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

            return Solve(reader);
        }

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

}

#endregion

#region Extensions

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

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

#endregion

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

#define int long long



signed main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int ma = b- (b / c + b / d - b / ( c / __gcd(c, d) * d ));
    a--;
    int mi = a- (a / c + a / d - a / ( c / __gcd(c, d) * d ));

    cout << ma-mi << endl;

    return 0;
}


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

int h, w;
char a[10][10];

int main(){
  cin >> h >> w;
  int cnt = 0;
  rep(i, h){
    rep(j, w){
      cin >> a[i][j];
      if(a[i][j] == '#'){
        cnt++;
      }
    }
  }
  if(cnt == h + w - 1){
    cout << "Possible"<< endl;
  }else{
    cout << "Impossible" << endl;
  }
}


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

int main() {
  int x;
  cin >> x;

  int a, b, ans;
  a = (x-x%500) / 500;
  x -= 500 * a;
  b = (x-x%5) / 5;
  ans = 1000 * a + 5 * b;

  cout << ans << endl;
}


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

 int main (){

	 int n;
	 std::vector<long long> vec;
	 std::cin >> n;

	 vec = { 2,1 };

	 for (int i = 1; i < n; ++i) {
		 vec.push_back(vec[i] + vec[i - 1]);
	 }

	 std::cout << vec[n] << std::endl;

	 return 0;
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    S = input()

    S = list(S)
    if S[K-1] == 'A':
        S[K-1] = 'a'
    elif S[K-1] == 'B':
        S[K-1] = 'b'
    elif S[K-1] == 'C':
        S[K-1] = 'c'

    print(''.join(S))

main()


Measured memory_bytes: 3060
def check(w):
	count=0
	flag=0
	mx=0
	for i in range(len(w)):
		if w[i][0]==w[i][1]:
			count+=1
			flag=0
		else:
			mx=max(mx,count)
			count=0
			flag=1
	if flag==0:
		mx=max(mx,count)
		
	if mx>=3:
		return 1
	else:
		return 0
			
n=int(input())
w=[]
for i in range(n):
	a,b=map(int,input().split())
	w.append([a,b])
if check(w):
	print("Yes")
else:
	print("No")
	
	
	


Measured memory_bytes: 62436
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	int from, to;
	ll w;
};
typedef vector<vector<Edge>> Graph;

signed main(void) {
	int n, k;
	cin >> n >> k;
	vector<int> h(n  +103);
	REP(i, n) {
		cin >> h[i];
	}

	int dp[100103] = {};
	Fill(dp, INT_MAX);
	dp[0] = 0;
	REP(i, n) {
		rep(j,1, k + 1)
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
	}


	cout << dp[n - 1] << endl;
	return 0;
}



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

vector<int> memo;
int n;
int f(int h, const vector<int> a, const vector<int> b){
  if(h <= 0) return 0;
  int mmin = 100000000;
  int karimin;
  rep(i,n){
    if(h-a[i]-1 >=0 && memo[h-a[i]-1]!=0){
      karimin = b[i] + memo[h-a[i]-1];
    }else{
      karimin = b[i] + f(h-a[i],a,b);
    }
    mmin = min(karimin, mmin);
  }
  memo[h-1] = mmin;
  return mmin;
}

int main(){
  int h;
  cin >> h >> n;  
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];
  
  memo.assign(h,0);
  cout << f(h,a,b) << endl;   
}

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

int main()
{
	int H;
	int W;
	int cnt = 0;
	char c[55][55];

	cin >> H >> W;
		

	// 縦
	for (int i = 1; i <= H; i++) {
		// 横
		for (int j = 1; j <= W; j++) {		
			cin >> c[i][j];		
		}
	}

	// 縦
	for (int i = 1; i <= H; i++) {
	
		// 横
		for (int j = 1; j <= W; j++) {
		
			if (c[i][j] == '#' && c[i - 1][j] != '#' && c[i + 1][j] != '#' && c[i][j - 1] != '#' && c[i][j + 1] != '#')
				cnt++;			
		}
	}

	string answer = "No";
	
	if (cnt==0) { answer = "Yes"; }
		
	cout << answer << endl;
	
	return 0;

}

Measured memory_bytes: 256
program taskH;
var k,s,sum,x,y,z:longint;
begin
readln(k,s);
for x:=0 to k do
begin
for y:=0 to k do
begin
z:=s-x-y;
if (z<=k) and (z>=0) then
sum:=sum+1;
end;
end;
writeln(sum);
end.

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val as = Array.fill(3*n)(sc.nextLong())

  val h1 = new BinaryHeap[Long](n+1, _ < _)
  val sums1 = Array.fill(n+1)(0L)
  var sum1 = 0L
  for (a <- as.take(n)) {
    sum1 += a
    h1.add(a)
  }
  sums1(0) = sum1

  for ((a, i) <- as.slice(n, 2*n).zipWithIndex) {
    sum1 += a
    h1.add(a)
    sum1 -= h1.pop()
    sums1(i+1) = sum1
  }

  val h2 = new BinaryHeap[Long](n+1, _ > _)
  val sums2 = Array.fill(n+1)(0L)
  var sum2 = 0L
  for (a <- as.takeRight(n)) {
    sum2 += a
    h2.add(a)
  }
  sums2(0) = sum2

  for ((a, i) <- as.slice(n, 2*n).reverse.zipWithIndex) {
    sum2 += a
    h2.add(a)
    sum2 -= h2.pop()
    sums2(i+1) = sum2
  }

  val ans = sums1.zip(sums2.reverse).map{case (s1, s2) => s1 - s2}.max

  println(ans)
}

class BinaryHeap[A: scala.reflect.ClassTag](maxSize: Int, comparator: (A, A) => Boolean) {
  private val heap = Array.ofDim[A](maxSize)

  var size = 0
  def isEmpty: Boolean = size == 0
  def nonEmpty: Boolean = !isEmpty

  private def par(idx: Int): Int = (idx - 1) / 2
  private def left(idx: Int): Int = 2 * idx + 1
  private def right(idx: Int): Int = 2 * idx + 2

  private def isRoot(idx: Int): Boolean = idx == 0
  private def hasLeft(idx: Int): Boolean = left(idx) < size
  private def hasRight(idx: Int): Boolean = right(idx) < size

  private def swap(i: Int, j: Int): Unit = {
    val t = heap(i)
    heap(i) = heap(j)
    heap(j) = t
  }

  private def upHeap(idx: Int): Unit = {
    if (!isRoot(idx) && comparator(heap(idx), heap(par(idx)))) {
      swap(idx, par(idx))
      upHeap(par(idx))
    }
  }

  private def downHeap(idx: Int): Unit = {
    if (hasLeft(idx)) {
      val t = if (hasRight(idx) && comparator(heap(right(idx)), heap(left(idx)))) {
        right(idx)
      } else {
        left(idx)
      }
      if (comparator(heap(t), heap(idx))) {
        swap(idx, t)
        downHeap(t)
      }
    }
  }

  def add(a: A): Unit = {
    size += 1
    heap(size - 1) = a
    upHeap(size - 1)
  }

  def pop(): A = {
    val head = heap(0)
    heap(0) = heap(size - 1)
    size -= 1
    downHeap(0)
    head
  }
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

int gcd(int a, int b) {
    if (a < b) { swap(a, b); }
    return b == 0 ? a : gcd(b, a % b);
}

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

    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;

    return 0;
}


Measured memory_bytes: 3152
#include <iostream>

using namespace std;

int main(void){
        int x,a,b,la,lb;
        cin >> x >> a >> b;
        la=x-a;
        if(la<0)la*=(-1);
        lb=x-b;
        if(lb<0)lb*=(-1);
        if(la>lb){
                cout << 'B' << endl;
        }else{
                cout << 'A' << endl;
        }
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#define M 1000003
using namespace std;
char a[M][13];
void init()
{
    for(int i=0;i<M;i++)
        a[i][0] = '\0';
}
int getkey(char s[])
{
    int i = 0,key = 0,mul = 1,j;
    for(i=0;s[i]!='\0';i++)
    {
        switch(s[i]){
            case 'A':j = 1;break;
            case 'G':j = 2;break;
            case 'C':j = 3;break;
            case 'T':j = 4;
        }
        key += mul*j;
        mul *= 5;
    }
    return key;
}
int h1(int key)
{
    return key%M;
}
int h2(int i)
{
    return i;
}
bool insert(char s[])
{
    int key = getkey(s);
    int i,index;
    for(i=0;i<M;i++)
    {
        index = (h1(key)+h2(i))%M;
        if(a[index][0]=='\0')
        {
            strcpy(a[index],s);
            return true;
        }
        else if(strcmp(a[index],s)==0)
            return true;
        else
            continue;
    }
    return false;

}
bool find(char s[])
{
    int key,i,index;
    key = getkey(s);
    for(i=0;i<M;i++)
    {
        index = (h1(key)+h2(i))%M;
        if(a[index][0]=='\0')
            return false;
        else if(strcmp(a[index],s)==0)
            return true;
        else
            continue;
    }
    return false;
}
int main()
{
    int n;
    char s1[7],s2[13];
    cin>>n;
    init();
    while(n--)
    {
        cin>>s1>>s2;
        if(s1[0]=='i')
        {
            insert(s2);
        }
        else
        {
            if(find(s2))
                cout<<"yes"<<endl;
            else
                cout<<"no"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 15784
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int a,b,c,d;
   a=s[0]-'0';
   b=s[1]-'0';
   c=s[2]-'0';
   d=s[3]-'0';
   if(a*10+b>12||a*10+b<1){
       if(c*10+d>12||c*10+d<1){
     cout<<"NA"<<endl;
     return 0;
       }
   }
   if(a*10+b>12||a*10+b<1){
     cout<<"YYMM"<<endl; 
     return 0;
   }
   if(c*10+d>12||c*10+d<1){
       
      cout<<"MMYY"<<endl;
      return 0;
   }
     cout<<"AMBIGUOUS"<<endl;  
}

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

c_t_list = [tuple(map(int,input().split())) for i in range(N)]

c_t_filtered = list(filter(lambda x:x[1] <= T ,c_t_list))
if len(c_t_filtered) > 0:
    print(min(c_t_filtered,key=lambda x:x[0])[0])
else:
    print("TLE")

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    Int H, W, d;

    void solve() {
        cin >> H >> W >> d;
        vector<vector<char>> col(H + W, vector<char>(H + W));
        for (int i = 0; i < H + W; ++i) {
            for (int j = 0; j < H + W; ++j) {
                string cnv[2] = {"RG", "BY"};

                Int r = (i / d) % 2;
                Int c = (j / d) % 2;
                col[i][j] = cnv[r][c];
            }
        }

        vector<vector<char>> ans(H, vector<char>(W));
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                ans[i][j] = col[i + j][i - j + W];
                cout << ans[i][j];
            }
            cout << endl;
        }


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1792
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

int64_t Get(const int64_t n) {
  if (n == 0) {
    return 0;
  }
  int64_t result = Get(n / 5LL);
  result += n / 5;
  return result;
}

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

  int64_t N;
  cin >> N;
  if (N % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  int64_t result = 0;
  result = Get(N / 2LL);
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	lint A,B,C,K;
	
	cin >> A >> B >> C >> K;
	
	if(K%2==0)
		cout << A-B;
	else 
		cout << B-A;
	cout << endl;
	
	return 0;
}



Measured memory_bytes: 256
N, M = map(int,input().split())
par = [i for i in range(N+1)]
size = [1 for _ in range(N+1)]

def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y
    size[y] = size[x] + size[y]
    size[x] = 0
    
for i in range(M):
    x, y,  z= map(int,input().split())
    unite(x,y)
    
Ans =0
for j in size[1:]:
    if j != 0:
        Ans +=1
print(Ans)

Measured memory_bytes: 14408
def func(a_n):
    if a_n % 2 == 0:
        return a_n // 2
    else:
        return 3*a_n + 1

a_0 = int(input())
A_n = [a_0]
m = 0
while True:
    A_n.append(func(A_n[m]))
    m += 1
    if A_n.count(A_n[m]) == 2:
        print(m+1)
        break


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;
char N[505050];
char M[505050];

int ok(int k) {
	int i;
	if(k<=0) return 0;
	memmove(M,N,sizeof(N));
	int tot=0;
	int carry = 9*k;
	FOR(i,505000) {
		int v = M[i] + carry;
		carry = v/10;
		M[i] = v%10;
		tot += M[i];
	}
	return 9*k >= tot;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	reverse(ALL(S));
	FOR(i,S.size()) N[i]=S[i]-'0';
	FOR(i,505000) N[i]*=9;
	FOR(i,505000) {
		N[i+1] += N[i]/10;
		N[i] %= 10;
	}
	
	int ret=(1<<20);
	for(i=20;i>=0;i--) if(ok(ret-(1<<i))) ret-=1<<i;
	cout<<ret<<endl;
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 1820
use std::cmp::Reverse;
use std::collections::BinaryHeap;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: Vec<usize> = sc.vec(n);
    let mut b: Vec<usize> = sc.vec(n);
    b.sort_by_key(|&b| Reverse(b));

    let mut dup = None;
    for i in 0..n {
        if a[i] == b[i] {
            dup = Some(a[i]);
        }
    }

    if let Some(dup) = dup {
        let mut from = vec![];
        let mut to = vec![];
        for i in 0..n {
            if b[i] == a[i] {
                from.push(i);
            } else if b[i] != dup && a[i] != dup {
                to.push(i);
            }
        }

        if from.len() > to.len() {
            println!("No");
        } else {
            println!("Yes");
            for i in 0..from.len() {
                b.swap(from[i], to[i]);
            }

            for i in 0..n {
                if i > 0 {
                    print!(" ");
                }
                print!("{}", b[i]);
            }
            println!();
        }
    } else {
        println!("Yes");
        for i in 0..n {
            if i > 0 {
                print!(" ");
            }
            print!("{}", b[i]);
        }
        println!();
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main(){
  string N;
  cin >> N;
  bool ans=false;
  if(N.at(0)=='7'){
    ans = true;
  }
  if(N.at(1)=='7'){
    ans = true;
  }
  if(N.at(2)=='7'){
    ans = true;
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 3624
def main():
    N = int(input())
    X = list(map(int, input().split(" ")))
    calc = [0]*max(X)
    for i in range(max(X)):
        for j in range(N):
            calc[i] += (X[j] - (i+1))**2

        #print(calc)
    print(min(calc))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<int> A(4);
	for(int i=0;i<4;i++) cin>>A[i];
	sort(A.begin(),A.end());
	do{
		if(A[0]==1 && A[1]==9 && A[2]==7 &&A[3]==4){
			cout<<"YES\n";
			return 0;
		}
	}while(next_permutation(A.begin(),A.end()));
	cout<<"NO\n";
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std; 
int main(){
    string x;
    int y = 0;
    string z = "CODEFESTIVAL2016";
    for (int i = 0; i <= 15; i++)
    	{
    		cin >> x[i];
			if	(x[i] != z[i])
				{
					y++;
				}
		}
	cout << y << endl;
    return 0;
}

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

using ll = long long;
const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main()
{
    int a,b,c,d;
    while(cin>>a>>b>>c>>d)
    {
        if(b<=c){cout<<0<<endl;continue;}
        if(a<=c&&b>c&&d>=b){cout<<b-c<<endl;continue;}
        if(a<=c&&d<=b){cout<<d-c<<endl;continue;}
        if(c<=a&&a<=d&&d<=b){cout<<d-a<<endl;continue;}
        if(d<=a){cout<<0<<endl;continue;}
        if(a>=c&&b<=d){cout<<b-a<<endl;continue;}
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct edge{ int to,cost; };
const int N = 2e5+10;
vector<vector<edge>> G(N);
vector<double> dp(N),dp2(N);

void dfs1(int u,int pre){
  double res = 0;
  int child = 0;
  for(auto e : G[u]){
    if(e.to == pre) continue;
    dfs1(e.to,u);
    res += dp[e.to] + 1.0;
    child++;
  }
  if(child > 0) dp[u] = res / child;
  else dp[u] = 0;
}

void dfs2(int u,int pre,double d_par){
  double res = 0;
  for(auto e : G[u]){
    if(e.to == pre) res += d_par + 1;
    else res += dp[e.to] + 1;
  }
  dp2[u] = res / G[u].size();

  for(auto e : G[u]){
    if(e.to == pre) continue;
    dfs2(e.to,u,(res - dp[e.to] - 1) / (G[u].size() - 1.0));
  }
}

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n-1; i++){
    int s,t; cin >> s >> t;
    s--,t--;
    G[s].push_back({t,1});
    G[t].push_back({s,1});
  }
  if(n <= 2){
    cout << 1 << endl << 1 << endl;
    return 0;
  }

  int root = 0;
  for(int i = 0; i < n; i++){
    if(G[i].size() >= 2) root = i;
  }

  dfs1(root,-1);
  dfs2(root,-1,0);
  for(int i = 0; i < n; i++){
    printf("%.6f\n",dp2[i]);
  }

  return 0;
}


Measured memory_bytes: 23424
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#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)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n;
  cin>>n;
  vll a(5);
  rep(i,5) cin>>a[i];
  vll ans(5);
  ll mi=a[0];
  ll k=(n+a[0]-1)/a[0];
  ans[0]=k;
  for(int i=1;i<5;i++){
    if(mi>a[i]){
      mi=a[i];
      k=(n+a[i]-1)/a[i];
      ans[i]=k;
    }
    else{
      ans[i]=k;
    }
  }
  ll cu=0;
  rep(i,5){
    cu+=ans[i];
    if(i!=4){
      cu-=ans[i]-1;
    }
  }
  COUT(cu);
}

Measured memory_bytes: 256