akhauriyash/Code-Regression huggingface dataset:
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var s = Console.ReadLine().Trim();
        getAns(n, s);
    }
    static void getAns(int n, string s)
    {
        var s1 = n - s.Replace("1", "").Length;
        var r0 = new int[n];
        var r1 = new int[n];
        var r0mod = s1 - 1;
        var r1mod = s1 + 1;
        r1[0] = 1 % r1mod;
        if (r0mod != 0)
        {
            r0[0] = 1 % r0mod;
            for (int i = 1; i < n; i++)
            {
                r0[i] = (r0[i - 1] * 2) % r0mod;
                r1[i] = (r1[i - 1] * 2) % r1mod;
            }
        }
        else
        {
            for (int i = 1; i < n; i++)
                r1[i] = (r1[i - 1] * 2) % r1mod;
        }
        var smr0 = 0;
        var smr1 = 0;
        if (r0mod != 0)
        {
            for (int i = 0; i < n; i++)
            {
                if (s[n - 1 - i] == '1')
                {
                    smr0 += r0[i];
                    smr0 %= r0mod;
                    smr1 += r1[i];
                    smr1 %= r1mod;
                }
            }
        }
        else
        {
            for (int i = 0; i < n; i++)
            {
                if (s[n - 1 - i] == '1')
                {
                    smr1 += r1[i];
                    smr1 %= r1mod;
                }
            }
        }
        var res = 0;
        var resp = new int[n];
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '1')
            {
                if (r0mod != 0)
                {
                    var targ = smr0 - r0[n - 1 - i];
                    if (targ < 0) targ += r0mod;
                    targ %= r0mod;
                    res = f(targ) + 1;
                }
                else res = 0;
            }
            else
            {
                var targ = smr1 + r1[n - 1 - i];
                targ %= r1mod;
                res = f(targ) + 1;
            }
            resp[i] = res;
        }
        Console.WriteLine(string.Join("\n", resp));
    }
    static int f(long a)
    {
        var count = 0;
        var p = a;
        while (p > 0)
        {
            p %= bitCount((ulong)p);
            count++;
        }
        return count;
    }
    static int bitCount(ulong bits)
    {
        bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
        bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
        bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
        bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
        bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
        return (int)(bits & 0x00000000ffffffff) + (int)(bits >> 32);
    }
}


Measured memory_bytes: 32732
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, T;
ll A[3010], B[3010];
ll dp[3010][3010];
std::vector<P> ps;
ll right[3010];

int main()
{
  std::cin >> N >> T;
  
  rep( i, N ) {
    std::cin >> A[i] >> B[i];

    ps.emplace_back( A[i], B[i] );
  }

  std::sort(all(ps));

  rep( i, N )
    A[i] = ps[i].first, B[i] = ps[i].second;

  rep( i, N ) rep( j, T ) {
    chmax( dp[i+1][j], dp[i][j] );
    
    if( j-A[i] >= 0 )
      chmax( dp[i+1][j], dp[i][j-A[i]]+B[i] );
  }

  repd( i, N )
    right[i] = std::max( right[i+1], B[i] );

  ll ans = 0;

  rep( i, N+1 )
    chmax( ans, dp[i][T-1]+right[i] );

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 74332
N = int(input())
C = [0] * N
S = [0] * N
F = [0] * N

for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())

def arrive(st):
    time = C[st] + S[st]
    for i in range(st + 1, N-1):
        if time <= S[i]:
            time = C[i] + S[i]
        else:
            if time % F[i] != 0:
                time = time + C[i] + (F[i] - time % F[i])
            else:
                time = time + C[i]
    return time

for i in range(N-1):
    print(arrive(i))
print("0")

Measured memory_bytes: 9216
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <fstream>
#include <bitset>
#include <array>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)
#define ten(n) ((long long)(1e##n))

const int INF = 1e9+7;

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

int main() {
    ll w, h;
    cin >> w >> h;
    vector<ll> p(w), q(h);
    priority_queue<P, vector<P>, greater<P>> pq;
    for (ll i = 0; i < w; ++i) {
        cin >> p[i];
        pq.push(P(p[i], 1));
    }
    for (ll i = 0; i < h; ++i) {
        cin >> q[i];
        pq.push(P(q[i], -1));
    }
    ll ans = 0;
    while (pq.size()) {
        P now = pq.top();
        pq.pop();
        if (now.second == 1) {
            ans += (h + 1) * now.first;
            w--;
        }
        else {
            ans += (w + 1) * now.first;
            h--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int k;
string s;
int main()
{
	cin>>k;
	cin>>s;
	if (s.length()<=k) cout<<s<<endl;
	else
	{
		for (int i=0;i<k;i++) cout<<s[i];
		cout<<"..."<<endl;
	}
	return 0;
}


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


int main() {
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		sum += r - l + 1;
	}
	cout << sum << endl;
	return 0;
}


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

int main() {
    string s;
    std::cin >> s;
    string a = "keyence";
    
    for (int i = 0; i < 7; i++) {
        if(s[s.length()-7+i] == a[i]){
            if(i!=6){
                continue;
            }else{
                std::cout << "YES" << std::endl;
                return 0;
            }
            
        }else{
            break;
        }
    }
    
    for (int i = 0; i < 7; i++) {
        if(s[i] == a[i]){
            if(i!=6){
                continue;
            }else{
                std::cout << "YES" << std::endl;
                return 0;
            }
            
        }else{
            break;
        }
    }
    // どこできるか
    for (int j = 0; j <= 7; j++) {
        for (int i = 0; i < 7; i++) {
            bool flag = false;
            if(i<j){
                flag = s[i] == a[i];
            }else{
                flag  = s[s.length()-7+i] == a[i];
            }
            if(flag){
                if(i!=6){
                    continue;
                }else{
                    std::cout << "YES" << std::endl;
                    return 0;
                }
            }else{
                break;
            }
        }
    }
    std::cout << "NO" << std::endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define _rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define SF scanf
#define PF printf
int a[105],n,ans;
int  main(){
	SF("%d",&n);
	_rep(i,1,n){
		SF("%d",&a[i]);
		if((i&1) &&(a[i]&1))ans++;
	} 
	PF("%d",ans);
	return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

class CumulativeSum {
    vector<ll> numbers;
    vector<ll> sums;

public:
    CumulativeSum(int n) {
        numbers.resize(n);
        sums.resize(n);
    }

    void set(int i, ll value) {
        numbers[i] = value;
    }

    ll getSum(int i) {
        if (i == -1) return 0;
        if (i == sums.size()) return 0;
        return sums[i];
    }

    ll getSectionSum(int start, int end) {
        return getSum(end) - getSum(start - 1);
    }

    void calculate() {
        for (int i = 0; i < numbers.size(); i++) {
            sums[i] = getSum(i - 1) + numbers[i];
        }
    }

    ll upper_bound(ll query) {
        return distance(sums.begin(), std::upper_bound(sums.begin(), sums.end(), query));
    }

};


int main() {
    int n, q;

    cin >> n >> q;

    vector<ll> numbers(n);
    rep(i, n) cin >> numbers[i];

    CumulativeSum cs(n);

    rep(i, n) cs.set(i, numbers[i]);
    cs.calculate();
    rep(i, q) {
        ll ans = 0;
        ll query;
        cin >> query;

        {
            ll match = cs.upper_bound(query) - 1;
            ll now = match + 1;
            ans += now;
        }

        for (int l = 1; l < n; l++) {
            ll left = cs.getSum(l - 1);
            ll match = cs.upper_bound(query + left) - 1;
            ll now = match - l + 1;
            ans += now;
        }

        cout << ans << endl;
    }
}



Measured memory_bytes: 5220
n, a, b = map(int, input().split())
s = input()
s = [str(c) for c in s]
pas = 0
f = 0

for i, v in enumerate(s):
    if pas < a + b and v == "a":
        pas += 1
        print("Yes")
    elif pas < a + b and f < b and v == "b":
        pas += 1
        f += 1
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4692
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long long ll;
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("amusing.in", "r", stdin);
    //freopen("amusing.out", "w", stdout);
}

void solve() {
    int x;
    cin >> x;
    int y = 0;
    int ans = 0;
    while(true){
        ans++;
        y += x;
        if (y % 360 == 0){
            cout << ans << '\n';
            return;
        }
    }
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

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

#define INF 1E18



int main(){
    int n;
    cin>>n;
    int h[n];
    rep(i,n) cin>>h[i];

    int ans = 1;
    rep2(i,1,n){
        bool flag = true;
        rep(j,i){
            if(h[i] - h[j] >= 0) continue;
            else{
                flag = false;
                break;
            }
        }
        if(flag) ++ans;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	queue<long long>q;
	if(n<=9)
	{
		printf("%d",n);
		return 0;
	}
	for(int i=1;i<=9;i++)q.push(i);
	for(int i=10;;)
	{
		int L=q.front()%10;
		for(int j=max(0,L-1); j<=min(9,L+1); j++)
		{
			if(q.front()*10+j!=q.front())
			{
				q.push(q.front()*10+j);
//				printf("%d\n",q.back());
				if(i==n)
				{
					goto end;
				}
				i++;
			}
		}
		q.pop();
	}
end:
	;
	printf("%lld",q.back());
}

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

using namespace std;

using ll=long long;
void solve() {
    string s; cin >> s;
    reverse(s.begin(), s.end());
    int n = s.size();
    ll res = 0;
    for (int i = 0; i < n; i++) {
        ll x = s[i]-'0';
        for (int j = 0; j < i; j++) {
            res += x * pow(10, j) * (1<<(n-2-j));
        }
        res += x * pow(10, i) * (1<<(n-1-i));
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int N,i,j,a=0,b=0;
	scanf("%d",&N);
	int s[100];
	for(i=0;i<N;i++){
		scanf("%d",&s[i]);
		a+=s[i];
	}
	for(i=0;i<N;i++){
		for(j=i+1;j<N;j++){
			if(s[i]>s[j]){
				b=s[i];
				s[i]=s[j];
				s[j]=b;
			}
		}
	}
	if(a%10!=0){

	}else{
		for(i=0;i<N;i++){
			if((a-s[i])%10 !=0){
				a-=s[i];
				break;
			}
			if(i==N-1){
				a=0;
			}
		}
	}
	printf("%d",a);
	return 0;
}

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


int par[1000000];


void init( int n ){


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

          par[i] = i;

          }

     return;

     }


int root( int x ){

    
    if( par[x] == x ) return x;

    else return par[x] = root( par[x] );

    }


bool same( int x, int y ){


     return root(x) == root(y);

     }


void unite( int x, int y ){


     x = root(x);

     y = root(y);


     if( x == y ) return;


     par[x] = y;

     return;

     }
                                                                                   

int main(){


    int n, m, i, j, t;

    int k = 0;

    vector<int> a(51);

    vector<int> b(51);


    cin >> n >> m;


    for( i = 1 ; i <= m ; i = i + 1 ){

         cin >> a.at(i) >> b.at(i);

         }


    for( i = 1 ; i <= m ; i = i + 1 ){

         init(n);

         t = 0;

         for( j = 1 ; j <= m ; j = j + 1 ){

              if( j != i ) unite( a.at(j), b.at(j) );

              }

         for( j = 1 ; j <= n ; j = j + 1 ){

              if( j == par[j] ){

                  t += 1;

                  }

              }

         if( t > 1 ) k += 1;

         }


    cout << k << endl;


    return 0;

    }

Measured memory_bytes: 256
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

typedef long long ll;
/*
bool is_prime(int n){
    for (int i = 2; i*i<=n;i++){
        if(n%i==0) return false;
    }
    return n!=1;
}
*/
vector<int> divisor(int n){
    vector<int> res;
    for( int i=1;i*i<n;i++){
        if(n%i==0){
            res.push_back(i);
            if(i!=n/i)res.push_back(n/i);
        }
        
    }
    return res;
}
map<int,int> prime_factor(int n){
    map<int,int> res;
    for(int i=2;i*i;i++){
        if(n%i==0){
            res[i]++;
            n=n/i;
        }
    }
    if(n!=1)res[n]=1;
}


const ll MAX_N=1000000;
//ll prime[MAX_N];
bool is_prime[MAX_N];

int sieve(int n){
    
    ll p=0;
    for(ll i=0;i<=n;i++) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(ll i=2;i<=n;i++){
        if(is_prime[i]){
            //prime[p++]=i;
            p++;
            for(ll j=i*2;j<=n;j+=i){
                is_prime[j]=false;
            }
        }
    }
    return p;
}

int main(){
    ll a;
    while(scanf("%lld", &a)!=EOF){
        cout<<sieve(a)<<endl;
    }
    return 0;}

Measured memory_bytes: 4228
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int count = 1;
        for (int i = 0; i < 3; i++){
            if(s.charAt(i) == s.charAt(i+1)){
                count++;
            }
            else{
                count = 1;
            }
            if (count == 3){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

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

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

	return 0;
}


Measured memory_bytes: 3104
#include"bits/stdc++.h"
#include<cassert>
#define fr first
#define sc second
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 998244353;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P> PP;
signed main() {
	string s; cin >> s;
	int flg = 0;
	rep(i, s.size()) {
		if (i & 1) {
			if (s[i] == 'R')flg++;
		}
		else {
			if (s[i] == 'L')flg++;
		}
	}
	if (flg)cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	bool key=true;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		if(a%2==0&&(a%3!=0&&a%5!=0))key=false;
	}
	if(key)cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
#define int long long
signed main() {
	int q, h, s, d;
	cin >> q >> h >> s >> d;
	int n;
	cin >> n;
	if (q * 2 < h)h = 2 * q;
	if (h * 2 < s)s = 2 * h;
	if (s * 2 < d)d = 2 * s;
	cout << (n / 2)*d + (n & 1)*s << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);


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

  int n, m;
  cin >> n >> m;
  vector<vector<bool>> con(n, vector<bool>(m, false));  // n 番目のスイッチが m 番目の電球に繋がっているか？
  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      int s; cin >> s; s--;
      con[s][i] = true;
    }
  }
  vector<int> p(m);
  rep(i, m) cin >> p[i];

  auto f = [&](const vector<int>& n_on) {
    rep(i, m) {
      if (p[i] != (n_on[i] % 2)) return false;
    }
    return true;
  };

  ll ans = 0;

  for (int bit = 0; bit < (1 << n); bit++) {
    vector<int> n_on(m, 0);  // 各電球の on の数
    rep(i, n) {
      if ((bit >> i) & 1) {
        // i 番目のスイッチが on になっている
        rep(j, m) {
          if (con[i][j]) n_on[j]++;
        }
      }
    }
    if (f(n_on)) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;


int gcd(int a,int b)
{
    int r=a%b;
    if(r==0)return b;
    return gcd(b,r);
}


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

    int tmp; cin >> tmp;
    int maxA=tmp;

    for(int i=1;i<N;++i)
    {
        int A;
        cin >> A;
        maxA = max(maxA,A);
        tmp = gcd(tmp,A);
    }
    //cout << maxA << endl;
    if(maxA>=K&&K%tmp==0)
    {
        cout << "POSSIBLE" << endl;
    } else
    {
        cout << "IMPOSSIBLE" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
//	freopen("loan.in","r",stdin);
//	freopen("loan.out","w",stdout);
	int a,b;
	cin>>a>>b;
	if(a==b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <climits>
#include <cmath>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#include <bitset>
using namespace std;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define fi first
#define se second
#define ll long long
#define ii pair<int, int>

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("Test.inp", "r", stdin);
	//freopen("RATING.out", "w", stdout);
	ll n;
	cin >> n;
	ll t = 2, ans = 0;
	while (t <= n) {
		ans++;
		t <<= 1;
	}
	cout << t - 1;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		
		List<Integer> y = new ArrayList<Integer>();
		List<Integer> max_y_l = new ArrayList<Integer>();
		y.add(0);
		max_y_l.add(Integer.MIN_VALUE);
		String line = br.readLine();
		int n = line.length() + 1;
		for (int i = 0; i < line.length(); i++) {
			char c = line.charAt(i);
			int last_y = y.get(i);
			if (c == '\\')
				y.add(last_y - 1);
			else if (c == '/')
				y.add(last_y + 1);
			else
				y.add(last_y);
			max_y_l.add(Math.max(max_y_l.get(i), y.get(i)));
		}
		
		int A = 0;
		List<Integer> L = new ArrayList<Integer>();
		int x = n - 1;
		while (x > 0) {
			// x1????????????????????????????????¶???
			if (y.get(x) <= max_y_l.get(x) && y.get(x - 1) < y.get(x)) {
				int x1 = x;
				int h = y.get(x1);
				int area = 0;
				x--;
				while (x >= 0 && y.get(x) != h) {
					area += h - y.get(x);
					x--;
				}
				if (x < 0)
					break;
				// int x0 = x;
				L.add(area);
				A += area;
			} else {
				x--;
			}
		}
		
		StringBuilder sb = new StringBuilder();
		sb.append(A);
		sb.append('\n');
		sb.append(L.size());
		for (int i = L.size() - 1; i >= 0; i--) {
			sb.append(' ');
			sb.append(L.get(i));
		}
		sb.append('\n');
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 26228
from collections import deque

N, M, *L = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(L[:2 * M])] * 2):
    E[a].append(b)
    E[b].append(a)

colors = [0] * (N + 1)
visited = [-1] * (N + 1)

for v, d, c in reversed(tuple(zip(*[iter(L[2 * M + 1:])] * 3))):
    Q = deque([(d, v)])
    while Q:
        cnt, v = Q.popleft()
        if visited[v] >= cnt:
            continue
        if colors[v] == 0:
            colors[v] = c
        visited[v] = cnt
        if cnt > 0:
            Q.extend((cnt - 1, u) for u in E[v])

for c in colors[1:]:
    print(c)


Measured memory_bytes: 50256
#include<stdio.h>
#include<algorithm>
using namespace std;
int t[110][110];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<c;i++){
		int p,q,r;scanf("%d%d%d",&p,&q,&r);
		if(r==1){
			for(int j=0;j<p;j++)for(int k=0;k<b;k++)t[j][k]=1;
		}
		if(r==2){
			for(int j=p;j<a;j++)for(int k=0;k<b;k++)t[j][k]=1;
		}
		if(r==3){
			for(int j=0;j<a;j++)for(int k=0;k<q;k++)t[j][k]=1;
		}
		if(r==4){
			for(int j=0;j<a;j++)for(int k=q;k<b;k++)t[j][k]=1;
		}
	}
	
	int ret=0;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)if(t[i][j]==0)ret++;
	printf("%d\n",ret);
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String args[]) {

         Scanner sc=new Scanner(System.in);
		 String s=sc.next();
		String t=sc.next();
	//	System.out.println(t.substring(0,t.length()));
		if(s.equals(t.substring(0,t.length()-1)))System.out.println("Yes");
		else
System.out.println("No");




         
       // System.out.println("Hello World!");
    }
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dp[20000];

int main() {
  cout << setprecision(12) << fixed;
  int n, W;
  cin >> n >> W;
  REP(i,n) {
    int v, w;
    cin >> v >> w;
    REP(j,10000)
      chmax(dp[j + w], dp[j] + v);
  }
  cout << dp[W] << endl;
  return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int a,b;
  cin>>a>>b;

  int ans=0;
  for(int i=a;i<=b;i++){
    string s=to_string(i);
    if(s[0]==s[4]&&s[1]==s[3]) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3724
s = list(map(int,input()))
n_s = []
r_s = []

for i in range(len(s)):
    if i%2 == 0:
        n_s.append(0)
    else:
        n_s.append(1)

for i in range(len(s)):
    if i%2 == 0:
        r_s.append(1)
    else:
        r_s.append(0)

cnt = 0
cnt_n = 0
for i in range(len(s)):
    if s[i] != n_s[i]:
        cnt+=1
    if s[i] != r_s[i]:
        cnt_n+=1

print(min(cnt_n,cnt))
        


Measured memory_bytes: 50012
#line 2 "header.hpp"

//%snippet.set('header')%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF = 1e18;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, int> pii;
typedef tuple<int, int, int> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
void check_input(){
    assert(cin.eof() == 0);
    int tmp; cin >> tmp; 
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"

signed main() {
    //input
    int s,w;cin>>s>>w;
    check_input();

    //solve
    cout << (w>=s ? "unsafe" : "safe") << endl;

    return 0; 
}


Measured memory_bytes: 3616
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
# from copy import deepcopy, copy

import queue
from collections import deque




def main():
    node_num = int(input())
    data = [list(map(int, list(input()))) for i in range(node_num)]

    graph_data = defaultdict(set)
    dist_data = [[200 for i in range(node_num)] for j in range(node_num)]
    for i in range(node_num):
        dist_data[i][i] = 0
        for j in range(node_num):
            if data[i][j]:
                dist_data[i][j] = 1
                graph_data[i].add(j)

    which_graph = [-1 for i in range(node_num)]
    now_set = set()
    next_set = set()
    now_set.add(0)
    which_graph[0] = 0
    flg = 0
    while len(now_set) > 0:
        for now_ele in now_set:
            for next_ele in graph_data[now_ele]:
                if which_graph[next_ele] == -1:
                    which_graph[next_ele] = 1 ^ which_graph[now_ele]
                    next_set.add(next_ele)
                else:
                    if which_graph[now_ele] ^ which_graph[next_ele] == 0:
                        flg = 1
                        break
        now_set = next_set
        next_set = set()


    if flg:
        print(-1)
        sys.exit()



    for k in range(node_num):
        for i in range(node_num):
            for j in range(node_num):
                dist_data[i][j] = min(dist_data[i][j], dist_data[i][k] + dist_data[k][j])

    ans = 0
    for i in range(node_num):
        ans = max(ans, max(dist_data[i]))

    print(ans + 1)


if __name__ == '__main__':
    main()


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

int main() {
    string s;
    cin >> s;

    if(s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if(s == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }

    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
int A[100100];

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    sort(A, A+N);

    int res = 0;
    for(int i=0,j=0;i<N;i=j){
        while(j < N && A[j] == A[i]){++j;}

        res += (j - i) % 2;
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 640
#!/usr/bin/env python3

import queue

def main():
    N = int(input())
    UV = [[] for _ in range(N)]

    for i in range(N-1):
        u,v,w = map(int,input().split())
        UV[u-1].append([v-1,w])
        UV[v-1].append([u-1,w])

    ans = [-1 for i in range(N)]
    ans[0] = 0

    que = queue.Queue()
    que.put(0)
    while not(que.empty()):
        mm = que.get()
        for uv in UV[mm]:
            que.put(uv[0])
            if uv[1]%2==0:
                ans[uv[0]] = ans[mm]
            else:
                ans[uv[0]] = (ans[mm]+1)%2
        UV[mm] = []

    print(*ans,sep="\n")

if __name__ == '__main__':
    main()






Measured memory_bytes: 45368
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    K, S = LI()

    ans = 0
    for x, y in itertools.product(range(K + 1), repeat=2):
        if 0 <= S - (x + y) <= K:
            ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9944
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

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

pro = 0
for i in range(1,N+1):
    cnt = 0
    points = i
    while points < K:
        points *= 2
        cnt += 1
    # print(cnt)
    pro += (1/2)**cnt/N

print(pro)


Measured memory_bytes: 6860
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
int main()
{
  long n,c,x[100007],v[100007],a[100007],b[100007],d[100007],e[100007],f[100007],g[100007],al,ans;
  cin >> n >> c;
  ans=0;
  rep(i,n){cin >> x[i] >> v[i];
          }
  rep(i,n){al+=v[i];
          }
  a[0]=v[0]-2*x[0];
  b[0]=v[0]-x[0];
  rep(i,n){
    if(i!=0){a[i]=a[i-1]+v[i]+2*x[i-1];
             b[i]=a[i]-x[i];
             a[i]-=2*x[i];
            }
  }
  d[0]=al-2*c+2*x[0];
  e[0]=al-c+x[0];
  rep(i,n){
    if(i!=0){
      d[i]=d[i-1]-v[i-1]+2*c-2*x[i-1];
      e[i]=d[i];
      d[i]-=2*c;
      d[i]+=2*x[i];
      e[i]-=c;
      e[i]+=x[i];
    }
    }
    f[0]=a[0];
    FOR(i,1,n-1){
      if(f[i-1]<a[i])f[i]=a[i];
      else f[i]=f[i-1];
    }
    g[0]=b[0];
    FOR(i,1,n-1){
      if(g[i-1]<b[i])g[i]=b[i];
      else g[i]=g[i-1];
    }
  rep(i,n){
    if(f[i-1]+e[i]<g[i-1]+d[i]&&ans<g[i-1]+d[i])ans=g[i-1]+d[i];
    else if(ans<f[i-1]+e[i])ans=f[i-1]+e[i];
  }
  rep(i,n){
    if(ans<b[i])ans=b[i];
    if(ans<e[i])ans=e[i];
  }
  printf("%ld",ans);
}

Measured memory_bytes: 6528
# coding=utf-8


if __name__ == '__main__':
    counter = 0
    number_list = list(map(int, input().split()))
    number_list.sort()
    minimum, middle, maximum = number_list[0], number_list[1], number_list[2]
    if (middle - minimum) % 2 == 0:
        counter += (middle-minimum)//2
    else:
        counter += ((middle-minimum)//2 + 2)
    counter += (maximum-middle)
    print(counter)


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

int l, r, d, ans;

int main() {
  cin >> l >> r >> d;
  ans = 0;
  for (size_t i = l; i <= r; i++) {
    if (i%d == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

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

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e17 + 9;

const int M = 1000;
const int N = 100;

int n, m;

struct edge { int to, cost, id; };
vector<edge> G[M];
int d[M];

void dijkstra(int s, set<int> &use) {
	priority_queue<P, vector<P>, greater<P>> q;
	fill(d, d + n, INF);
	d[s] = 0;
	q.push(P(0, s));

	int tm[M];
	mclr(tm);

	while (q.size()) {
		auto p = q.top(); q.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				tm[e.to] = e.id;
				q.push(P(d[e.to], e.to));
			}
		}
	}

	rep(i, M) {
		if (tm[i] != -1) {
			use.insert(tm[i]);
		}
	}
}
signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);	

	cin >> n >> m;

	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;

		G[a].push_back(edge{ b, c, i});
		G[b].push_back(edge{ a, c, i });
	}

	set<int> use;
	rep(i, n) {
		dijkstra(i, use);
	}

	cout << m - use.size() << endl;

	return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  string s;
  while (cin >> s) {
    int x = count(s.begin(), s.end(), 'g') - count(s.begin(), s.end(), 'p');
    cout << x / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

ll max_num(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }


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

	}

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

	/*for (int i = 0; i < N; i++) cout << S[i] << endl;
	cout << "^-----------------------" << endl;
	*/

	//string tmp = S[0];
	int max_num = 1;
	int count = 1;
	for (int i = 1; i < N; i++) {
		if (S[i - 1] == S[i])count++;
		else count = 1;
		max_num = max(max_num, count);
	}

	vector<string> ans(N);
	count = 1;
	int num_ans = 0;
	if (max_num == 1) {
		ans[0] = S[num_ans];
		num_ans++;
	}
	for (int i = 1; i < N; i++) {
		if (S[i - 1] == S[i]) count++;
		else count = 1;

		if (count == max_num) {
			ans[num_ans] = S[i];
			num_ans++;
		}
	}

	/*cout << " max_num: " << max_num << endl;
	for (int i = 0; i < N; i++) cout << S[i] << endl;
	cout << "^-----------------------" << endl;
	for (int i = 0; i < N; i++) cout << ans[i] << endl;
	cout << "^---ans--------------------num_ans: "<< num_ans << endl;
	*/

	sort(ans.begin(), ans.end());
	/*for (int i = 0; i < num_ans; i++) {
		cout << ans[i] << endl;
	}*/
	for (int i = 0; i < N; i++) {
		if (ans[i] == "")continue;
		cout << ans[i] << endl;
	}

}


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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF 2000000000
#define int long long
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
int ll[500000],rr[500000];
long long cnt=0;	
  int a[500000];	

int merge(int l, int m,int r){
  int n1=m-l;
  int n2=r-m;
  lp(i,n1) ll[i]=a[l+i];
  lp(i,n2) rr[i]=a[m+i];
  int i=0,j=0;
  ll[n1]=INF;
  rr[n2]=INF;
  lps(k,l,r){
    if(ll[i]<rr[j]){
      a[k]=ll[i];
      i++;
    }
    else{
      a[k]=rr[j];
      j++;
    }
      cnt++;
  }
  return cnt;
}

int mergesort(int l,int r){
  if(l+1<r){
    int m=(l+r)/2;
    mergesort(l,m);
    mergesort(m,r);
    merge(l,m,r);
  }
  else return 0;
}

signed main(){
  int n;
  cin>>n;
  lp(i,n){
    cin>>a[i];
  }
  mergesort(0,n);
  lp(i,n){
  	if(i!=0) cout<<" ";
  	cout<<a[i];
  }
  cout<<endl;
  cout<<cnt<<endl;
  return 0;
}




Measured memory_bytes: 10900
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;

struct UnionFind {
  vector<int> rank, par;
  UnionFind(int n) {
    rank.assign(n, 0);
    par.assign(n, -1);
  }

  int root(int x) {
    if (par[x] == -1) return x;
    else return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x;
  }

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

  int size(int x) {
    return rank[root(x)];
  }
};

signed main() {
  int N, Q;
  cin >> N >> Q;
  UnionFind uf(N);
  for (int i = 0; i < Q; i++) {
    int com, x, y;
    cin>>com>>x>>y;
    if (com == 0) {
      uf.unite(x, y);
    } else {
      cout << uf.same(x, y) << endl;
    }
  }  
}



Measured memory_bytes: 3236
#include <algorithm>
#include<iostream>
#include<vector>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

#define MAX_SIZE 10

using namespace std;

bool matrix[MAX_SIZE+2][MAX_SIZE+2];

void ope(bool matrix[][MAX_SIZE+2],long r,long c){
  int ii,jj;
  for(ii=-1;ii<=1;ii++){
	for(jj=-1;jj<=1;jj++){
	  matrix[r+ii][c+jj] = !matrix[r+ii][c+jj];
	}
  }
}

long getNum(bool matrix[][MAX_SIZE+2],long n,long m){
  int ii,jj;
  long cnt = 0;
  for(ii=1;ii<=n;ii++){
	for(jj=1;jj<=m;jj++){
	  if(matrix[ii][jj]){
		cnt++;
	  }
	}
  }
  return cnt;
}


int main(){
  long n,m;
  long ii,jj;
  long cnt = 0;
  cin >> n >> m;

  memset(matrix,false,sizeof(bool)*(MAX_SIZE+2)*(MAX_SIZE+2));

  if(n<=10 && m <= 10){
	for(ii=1;ii<=n;ii++){
	  for(jj=1;jj<=m;jj++){
		ope(matrix,ii,jj);
	  }
	}
	cnt = getNum(matrix,n,m);
  }
  else if(n==1){
	cnt = m -2;
  }
  else if(m==1){
	cnt = n -2;
  }
  else{
	cnt = n * m;
	cnt = cnt - (2*n + 2*m -4);
  }
  //cout << getNum(matrix,n,m);


  //
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int k = stdIn.nextInt();
        //int b = stdIn.nextInt();
        //int num[] = new int[3];
        //String s = stdIn.next();
        //char c[] = s.toCharArray();
        //boolean flag = true;
        
        if(k % 2 == 0){
            System.out.println(k / 2 * k / 2);
        }else{
            System.out.println(k / 2 * (k + 1) / 2);
        }
        
        
        
        
        //System.out.println();
        //System.out.print();
    }
}


Measured memory_bytes: 21844