akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int b[1000001]{};

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    set<int> st;

    REP(i, n) {
        cin >> a[i];
        b[a[i]]++;
        st.insert(a[i]);
    }

    bool flag[1000001]{};

    for (auto i : st) {
        for(int j = 2; j < 1000001; j++) {
            if (i * j >= 1000001) break;
            flag[i*j] = true;
        }
    }

    int res = 0;
    for(int i = 0; i < n; i++) {
        if (b[a[i]] == 1 && !flag[a[i]]) res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 17340
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
using Int = long long;
int main()
{
    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C+1);
    for (int i = 1; i <= C; i++) {
        D[i].resize(C+1);
        for (int j = 1; j <= C; j++) cin >> D[i][j];
    }
    vector<vector<int>> map(N+1);
    for (int i = 1; i <= N; i++) {
        map[i].resize(N+1);
        for (int j = 1; j <= N; j++) cin >> map[i][j];
    }
    int W[3][31];
    int s[3][3] = {{3,2,1},{1,3,2},{2,1,3}};
    for (int i = 0; i < 3; i++) {
        for (int c = 1; c <= C; c++) {
            int sum = 0;
            for (int y = 1; y <= N; y++) {
                for (int x = s[i][(y-1)%3]; x <= N; x+=3) {
                    sum += D[map[y][x]][c];
                }
            }
            W[i][c] = sum;
        }
    }
    int result = INT_MAX;
    for (int c0 = 1; c0 <= C; c0++) {
        for (int c1 = 1; c1 <= C; c1++) {
            for (int c2 = 1; c2 <= C; c2++) {
                if (c0 == c1 || c1 == c2 || c2 == c0) continue;
                result = min(result, W[0][c0] + W[1][c1] + W[2][c2]);
            }
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>//..1..2..3:Correct:Solved by F2tekkz:)
#define ll long long
#define str string
#define sonic ios_base::sync_with_stdio(0)
using namespace std;
int main(){
	sonic;
	ll n , m , cnt = 0;
	cin >> n >> m;
	cnt = n * 500;
	if(m <= cnt){
		cout << "Yes";
	}	
	else{
		cout << "No";
	}
}
//     *    *  *  ****    *    *   *
//    *	*   * *   *      * *   *   *
//   *****  **    ****  *****  *****
//   *   *  * *      *  *   *      *
//   *   *  *  *  ****  *   *  *****

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;
 
int main()
{
    ll x;
    cin >> x;
    ll d = sqrt(sqrt(x));
    for(int i=0;i<=d;i++){
        ll a = pow(i,5);
        ll b = -1*(x - a);
        for(int j=0;j<=d;j++){
            ll c = pow(j,5);
            if(c==b){
                cout << i << " " << j<<endl;
                return 0;
            }
            if(-c==b){
                cout << i << " " << -j<<endl;
                return 0;
            }
        }
 
 
    }
   
 
    return 0;
}

Measured memory_bytes: 4044
#include <stdio.h>
int main(void){
    long long int c = 1, i, n, a[200005] = {0}, b[200005] = {0}, d[200005], e = 0, k, num, count = 0;
    
    scanf("%lld %lld", &n, &k);
    
    for( i = 1; i <= n; i++ ){
        scanf("%lld", &a[i]);
    }
    
    b[1] = 1;
    
    for( i = 1; i != 0; i++ ){
        c = a[c];
        b[c] += 1;
        k--;
        
        if( b[c] == 2 ){
            d[e] = c;
            e++;
            count++;
        }
        
        if( b[c] == 3 ){
            break;
        }
        
        if( k <= 0 ){
            printf("%lld", c);
            return 0;
        }
        
        
 
    }
    
    num = k % count;
    
    printf("%lld\n", d[num]);
        
    return 0;
}

Measured memory_bytes: 5772
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 201;
ll i,j,n,c,ans;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    for(i = 1;i <= n;i+=2){
        c = 0;
        for(j = 1;j <= i;j++) if(i % j == 0)
            c += 1;
        if(c == 8)
            ans += 1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;
public class Input
{
    string[] stock = new string[0];
    int index = 0;
    void CheckStock()
    {
        if (index == stock.Length)
        {
            stock = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            index = 0;
        }
    }
    public string Next()
    {
        CheckStock();
        return stock[index++];
    }
    public char NextChar()
    {
        CheckStock();
        char val = stock[index][0];
        if (stock[index].Length == 1)
        {
            ++index;
        }
        else
        {
            stock[index] = stock[index].Remove(0, 1);
        }
        return val;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
}
class MainClass
{
    static int[,] mv = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

    void Calc()
    {
        Input inp = new Input();
        int n, k;
        decimal ans = 0;
        n = inp.NextInt();
        k = inp.NextInt();
        for(int i = 1, j; i <= n; ++i)
        {
            j = 1;
            for (; i * j < k; j *= 2) {}
            ans += 1m / (decimal)(n * j);
        }
        Console.WriteLine(ans);
    }
    static void Main()
    {
        new MainClass().Calc();
    }
}

Measured memory_bytes: 11220
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,k=mii()

a=n%k
b=abs(a-k)
print(min(a,b))

Measured memory_bytes: 65388
/*
 * src.cpp
 *
 *  Created on: 2016/07/27
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

const int MAX_N=30;

struct dice{
	char c[7];
	void move(int f){
		if (f==1){
			swap(c[1],c[3]);
			swap(c[3],c[4]);
			swap(c[3],c[6]);
		}else if (f==2){
			swap(c[1],c[2]);
			swap(c[2],c[5]);
			swap(c[2],c[6]);
		}else{
			swap(c[2],c[3]);
			swap(c[3],c[4]);
			swap(c[3],c[5]);
		}
	}
	bool operator == (dice &a){
		if (c[1]!=a.c[1]){
			REP(i,4){
				a.move(1);
				if (c[1]==a.c[1]) break;
			}
			if (c[1]!=a.c[1]){
				REP(i,4){
					a.move(2);
					if (c[1]==a.c[1]) break;
				}
			}
		}
		if (c[6]!=a.c[6]) return false;
		REP(i,4){
			a.move(3);
			if (c[2]==a.c[2]) break;
		}
		FOR(i,1,7){
			if (c[i]!=a.c[i]){
				return false;
			}
		}
		return true;
	}
};

int N;
dice d[MAX_N];

int main(){
	do{
		cin>>N;
		if (N){
			cin.ignore();
			string s;
			REP(i,N){
				REP(j,6){
					cin>>s;
					d[i].c[j+1]=s[0];
				}
			}
			int ans=0;
			REP(i,N){
				REP(j,i){
					if (d[i]==d[j]){
						ans++;
						break;
					}
				}
			}
			cout<<ans<<endl;
		}
	}while (N);
	return 0;
}

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

const int INF = 1e9;

int main() {
  int n, t;
  cin>>n>>t;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];

  int max_a[n];
  max_a[0] = 0;
  max_a[n-1] = a[n-1];

  for (int i=n-2; i>0; i--) {
    if (a[i] > max_a[i+1]) {
      max_a[i] = a[i];
    } else {
      max_a[i] = max_a[i+1];
    }
  }

  int tmp_profit = 0;
  int cnt = 0;
  for (int i=0; i<n-1; i++) {
    int tmp = max_a[i+1] - a[i];
    if (tmp > tmp_profit) {
      tmp_profit = tmp;
      cnt = 1;
    } else if (tmp == tmp_profit) {
      ++cnt;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
       
        public static long gcd(long x,long y)
        {
            if (x < y) gcd(y, x);
            
            while (y > 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }

        public static long lcm(long x,long y)
        {
            return x * y / gcd(x, y);
        }



        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);


            var xn = Reads();
            var x = xn[0];
            var n = xn[1];
            long[] p = new long[n];
            if (n != 0)
                p = Reads();
            long ans = -100;
            for (int i = -100; i <=200; i++)
            {
                if (!p.Contains(i) && Math.Abs(ans - x) > Math.Abs(i - x)) ans = i;
            }
            WriteLine(ans);
           
          
            Out.Flush();
        }
    }
}




Measured memory_bytes: 19704
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		num = num % 10;


		if(num==2 || num==4 || num==5 || num==7 || num==9) {
			System.out.println("hon");
		}else if(num == 3) {
			System.out.println("bon");
		}else if(num==0 || num==1 || num==6 || num==8){
			System.out.println("pon");
		}

	}

}


Measured memory_bytes: 35620
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>

using namespace std;
using ll = long long;

template<typename T> void print(T t) { cout << t << endl; }

int main() {
	int X, ans;
	cin >> X;
	if (X < 600) ans = 8;
	else if (X < 800) ans = 7;
	else if (X < 1000) ans = 6;
	else if (X < 1200) ans = 5;
	else if (X < 1400) ans = 4;
	else if (X < 1600) ans = 3;
	else if (X < 1800) ans = 2;
	else  ans = 1;
	print(ans);
}


Measured memory_bytes: 3640
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
      	boolean b = false;
        for(int i=0;i<=9;i++){
          for(int j=i;j<=9;j++){
            if(A==i*j){b=true;}
          }
        }
      	System.out.println((b)?"Yes":"No");
    }
}

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

int main(){
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  int a[n+1],b[m+1];
  a[n]=x,b[m]=y;
  rep(i,n)cin>>a[i];
  rep(i,m)cin>>b[i];
  sort(a,a+n+1);
  sort(b,b+m+1);
  if(a[n]<b[0])cout<<"No ";
  cout<<"War"<<endl;

   
   return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<ll, ll> mp;
    int ma = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
        ma = max(ma, a[i]);
    }
    map<ll, int> mp1;
    for (int i = 0; i < n; i++) {
        for (int j = 2; a[i] * j <= ma; j++) {
            mp1[a[i] * j] = 1;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (mp[a[i]] == 1 && mp1[a[i]] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 75788
#include<stdio.h>
#define NUM 100

int main(void)
{
    int num[NUM];
    int N,i;
    double sum = 0.0;
    
    scanf("%d",&N);
    
    for(i = 0; i < N; i++){
        scanf("%d",&num[i]);
        sum += 1.0 / num[i];
    }
    
    printf("%f",1.0 / sum);
  
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

typedef long long LL;
typedef vector<int> VI;

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  int64_t cnt = 0;
  for (int i = 0; i < N-2; i++) {
    for (int j = i+1; j < N-1; j++) {
      for (int k = j+1; k < N; k++) {
        if (L[i] + L[j] > L[k] &&
            L[j] + L[k] > L[i] &&
            L[i] + L[k] > L[j] &&
            L[i] != L[j] && L[j] != L[k] && L[i] != L[k]) {
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int N, M, X;
    cin >> N >> M >> X;

    vector<int> C(N), P(N);
    vector<vector<int>> vec(N, vector<int>(M));
    int ans = 1001001001;
    rep(i, N)
    {
        cin >> C[i];
        rep(j, M) cin >> vec[i][j];
    }
    rep(i, N) P[i] = i;

    for (int bit = 0; bit < (1 << N); bit++)
    {
        int tmp = 0;
        vector<int> check(M, 0);
        rep(i, N)
        {
            if (bit & (1 << i))
            {
                rep(j, M)
                {
                    check[j] += vec[i][j];
                }
                tmp += C[i];
            }
        }
        bool ok = true;
        rep(i, M)
        {
            if (check[i] < X)
            {
                ok = false;
            }
        }
        if (ok)
        {
            ans = min(ans, tmp);
        }
    }

    if (ans == 1001001001)
    {
        ans = -1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)

def max_happiness(n, data, dp, a, b, c):
  string = str(n) + str(a) + str(b) + str(c)

  if dp[string] is not None:
    return dp[string]

  if n == 0:
    if a and b:
      dp[string] = max(data[n][0], data[n][1])
      return dp[string]
    elif b and c:
      dp[string] = max(data[n][1], data[n][2])
      return dp[string]
    elif c and a:
      dp[string] = max(data[n][2], data[n][0])
      return dp[string]

  max_a = -1
  max_b = -1
  max_c = -1

  if a:
    max_a = data[n][0] + max_happiness(n-1, data, dp, a=0, b=1, c=1)
  if b:
    max_b = data[n][1] + max_happiness(n-1, data, dp, a=1, b=0, c=1)
  if c:
    max_c = data[n][2] + max_happiness(n-1, data, dp, a=1, b=1, c=0)

  dp[string] = max(max_a, max_b, max_c)
  return dp[string]

N = int(input())
data = []
dp = defaultdict(lambda: None)

for _ in range(N):
  data.append([int(num) for num in input().split()])

print(max_happiness(N-1, data, dp, a=1, b=1, c=1))

Measured memory_bytes: 162256
#067_C
n=int(input())
a=list(map(int,input().split()))
cs=[a[0] for _ in range(n)]
for i in range(n-1):
    cs[i+1]=cs[i]+a[i+1]
abs_cs=[abs(2*cs[i]-cs[-1]) for i in range(n-1)]
print(min(abs_cs))

Measured memory_bytes: 28168
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1<<30;
const ll MOD = 1000000007;

int main() {
  string s,t,u;
  int k;
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> k;
  for(int i=0; i<32; i++){
    if(i+1==k){
        cout << a[i] << endl;
    }
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;

  ll four = 0;

  while(four <= N){
    if((N - four) % 7 == 0){
      cout << "Yes" << endl;
      return 0;
    }
    four += 4;
  }

  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
 
const int N = 2e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

inline int mul(int a, int b){
    return ((ll)a * b) % mod;
}

inline int add(int a, int b){
    int ans = a + b;
    if(ans >= mod) ans -= mod;
    return ans; 
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
 
    string s;
    cin >> s;
    int n = s.length();
    int d;
    cin >> d;
    vector< vector<int> > dp(2, vector<int>(d, 0));
    dp[1][0] = 1;

    for(int j = 0; j < n; j++){
        vector< vector<int> > new_dp(2, vector<int>(d, 0));
        for(int i = 0; i < d; i++){
            for(int cur = 0; cur <= 9; cur++){
                if((s[j] - '0') > cur){
                    new_dp[0][(i+cur)%d] = (new_dp[0][(i+cur)%d] + dp[0][i] + dp[1][i]) % mod;
                } 
                else if((s[j] - '0') == cur){
                    new_dp[1][(i+cur)%d] = (new_dp[1][(i+cur)%d] + dp[1][i]) % mod;
                    new_dp[0][(i+cur)%d] = (new_dp[0][(i+cur)%d] + dp[0][i]) % mod;
                }
                else{
                    new_dp[0][(i+cur)%d] = (new_dp[0][(i+cur)%d] + dp[0][i]) % mod;
                }
            }
        }
        dp = new_dp;
    }
    cout << (dp[0][0] + dp[1][0] - 1 + mod) % mod;
    return 0;
}


Measured memory_bytes: 256
a = list(map(int, input().split()))
if a[1] == 0:
    print(a[0])
else:
    b = list(map(int, input().split()))
    c = []
    out = 0
    res = 10000001
    for i in range(102):
        if i not in b:
            c.append(i)
    for j in c:
        if (abs(j - a[0]) < res):
            res = abs(j - a[0])
            out = j
    print(out)

Measured memory_bytes: 9240
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n,y; cin>>n>>y;
  rep(i,n+1){
    rep(j,n+1-i){
      int k=n-(i+j);
      int sum=i*10000+j*5000+k*1000;
      if(sum==y){
        cout<<i<<" "<<j<<" "<<k<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;

  return 0;
}


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

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<long long>; using vvll = vector<vll>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}
// Preprocessing & "Global" variables {{{
struct Solver {
	Solver() {}
	int solve();
};
// }}}

int Solver::solve() {
	int n, k; cin >> n >> k;
	vi p(n); cin >> p;
	sort(p.begin(), p.end());
	cout << accumulate(p.begin(), p.begin() + k, 0) << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	Solver solver;
	#ifdef JUDGE_MULTI_CASE
		int t; cin >> t; for (int i = 1; i <= t; i++)
	#endif
	solver.solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int ctoi(const char c) {
    switch(c) {
        case '0': return 0;
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
        case '4': return 4;
        case '5': return 5;
        case '6': return 6;
        case '7': return 7;
        case '8': return 8;
        case '9': return 9;
        default : return -1;
    }
}

int main() {
    char a, b;
    cin >> a >> b;
    int na = ctoi(a);
    int nb = ctoi(b);
    string sa;
    string sb;
    for (int i = 0; i < nb; ++i) {
        sa.push_back(a);
    }
    for (int i = 0; i < na; ++i) {
        sb.push_back(b);
    }
    if (sa < sb) cout << sa << endl;
    else cout << sb << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007 
#define MOD1 998244353
#define ll long long int
#define db double
#define endl "\n"
#define INF 1000000000000000000
#define INF1 1000000000
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define debx cout<<" X "<<endl;
#define deby cout<<" Y "<<endl;
#define debz cout<<" Z "<<endl;
#define deb(x) cout << '>' << #x << ':' << x << endl;
using namespace std;
 
ll mpow(ll a, ll b){
    if(!b)
        return 1;
    ll temp=mpow(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2)
        return (a*temp)%MOD;
    return temp;
}
ll mod_in(ll n){
    return mpow(n,MOD-2);
}
ll cl(ll a, ll b){
    if(a%b)
        return 1+a/b;
    return a/b;
}
ll dig(ll n){
    if(!n)
        return 0;
    return 1 + dig(n/10);
}
ll calc(ll n ){
    if(n<1)
        return 1;
    return n* calc(n-2);
}
int main(){
    // fastio
    ll n,ans=0;
    cin>>n;
    if(n<5){
        cout<<0;
        exit(0);
    }
    if(n%2==0){
        n /= 2;
        ll curr = 5;
        while(curr<=n){
            ans += n/curr;
            curr *= 5;
        }
    }
    else{
        ans = 0 ;
    }
    cout<<ans<<endl;
}

// 1000000000000000000
// 124999999999999995
// 249999999999999990

Measured memory_bytes: 256
import pprint as pp

class Main():
    def exchange(self, n1, n2):
        tmp = self.A[n1]
        self.A[n1] = self.A[n2]
        self.A[n2] = tmp

    def left(self, i):
        return i * 2

    def right(self, i):
        return i * 2 + 1

    def maxHeapify(self, i):
        l = self.left(i)
        r = self.right(i)
        if l <= self.H and self.A[l] > self.A[i]:
            largest = l
        else :
            largest = i
        if r <= self.H and self.A[r] > self.A[largest]:
            largest = r
        if largest != i:
            self.exchange(i, largest)
            self.maxHeapify(largest) # 再帰的に呼び出し

    def buildMaxHeap(self):
        for i in reversed( range(1, self.H//2 + 1) ):
            self.maxHeapify(i)

    def main(self):
        self.H = int( input() )
        self.A = [0]
        inputData = [int(x) for x in input().split()]
        self.A.extend(inputData)
        self.buildMaxHeap()
        for i in range(1, self.H+1):
            print(" " + str(self.A[i]), end = "" )
        print()

if __name__ == '__main__':
    M = Main()
    M.main()



Measured memory_bytes: 62628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, l, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
#define sort(v) sort(v.begin(), v.end())
#define sortr(v) sort(v.rbegin(), v.rend())
void chmin(int &a, int b) {if(a > b) a = b;}
void chmax(int &a, int b) {if(a < b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
  cin >> n;
    map<string, int> mp;
    rep(i,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << mp.size();
}

Measured memory_bytes: 19176
n, m, q = map(int, input().split())
li = [1]
ans = 0
a_li = []
b_li = []
c_li = []
d_li = []

for i in range(q):
    a, b, c, d = map(int, input().split())
    a_li.append(a)
    b_li.append(b)
    c_li.append(c)
    d_li.append(d)


def dfs(li):
    score = 0

    for i in range(li[-1], m+1):
        if len(li) == n+1:
            for j in range(q):
                if li[b_li[j]] - li[a_li[j]] == c_li[j]:
                    score += d_li[j]
                    global ans

                    if score > ans:
                        ans = score
            return 0

        li.append(i)
        dfs(li)
        li.pop()


dfs(li)
print(ans)


Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pie (3.141592653589)
using namespace std;

const int N = 2e5 + 10;
const long long INF = 1e18 + 10;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);
	
	int n;
	cin >> n;
	vector<long long> dp(n + 1);
	dp[0] = 1;
	for(int i = 0; i < n; i++)
	{
		for(int j = 3; j <= n; j++)
		{
			if(i + j > n)
				break;
			dp[i + j] = (dp[i + j] + dp[i]) % mod;
		}
	}
	cout << dp[n];
	
	return 0;
}


Measured memory_bytes: 3580
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int m = sc.nextInt();
			if (m == 0) {
				break;
			}
			int value[] = new int[m];
			int num[] = new int[m];
			for (int i = 0; i < m; i++) {
				value[i] = sc.nextInt();
				num[i] = sc.nextInt();
			}
			int dp[] = new int[8000];
			dp[0] = 1;
			for (int i = 0; i < m; i++) {
				for (int k = 7999; k >= value[i]; k--) {
					for (int j = 1; j <= num[i]; j++) {
						if (k - value[i] * j >= 0) {
							dp[k] += dp[k - value[i] * j];
						}
					}
				}
			}

			int g = sc.nextInt();
			for (int i = 0; i < g; i++) {
				int n = sc.nextInt();
				System.out.println(dp[n]);
			}

		}

	}

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

Measured memory_bytes: 12000
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(char[]x,y;(x=s.next().toCharArray())[0]!='0';){Deque<char[]>q=new ArrayDeque<char[]>();Deque<Long>c=new ArrayDeque<Long>();Set<String>e=new HashSet<String>();for(q.add(x),c.add(0L);q.size()>0;c.poll()){if(new HashSet<String>(Arrays.asList(new String(x=q.poll()).split(""))).size()<3)break;if(e.add(new String(x)))for(int i=0,t;i<x.length-1;++i)if(x[i]!=x[i+1]){(y=x.clone())[i]=y[i+1]=(t=x[i]+x[i+1])==201?'r':t==212?'g':'b';q.add(y.clone());c.add(c.peek()+1);}}System.out.println(c.size()<1?"NA":c.poll());}}}

Measured memory_bytes: 17000
#include<stdio.h>
int main(void)
{
	int a[200],n,i,cnt,flg;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	cnt=0;	flg=0;
	while(1){
		for(i=0;i<n;i++){
			if(a[i]%2==0){
				a[i]=a[i]/2;
				flg++;
			}
		}
		if(flg==n){
			cnt++;
			flg=0;
		}
		else	break;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b;
	long long i;
	cin>>a>>b;
	long long w = a*b;
	for(i = min(a,b);i>0;i--)
	{
		if(a%i == 0&&b%i == 0)
			break;
	}
//	cout<<"("<<w<<","<<i<<")"<<endl;
	cout<<w/i<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int par[100001];
bool v[100001];
int root(int x){
	if(par[x]==x) return x;
	return par[x]=root(par[x]);
}
int main(){
	int N,M,x,y,X,Y,rx,ry;
	long long c=0;
	scanf("%d%d",&N,&M);
	int n=2*(N-M-1);
	multiset<int> b;
	if(M==N-1)
		printf("0");
	else if(n>N)
		printf("Impossible");
	else{
		long long fre[N];
		long long a[N];
		for(int i=0;i<N;i++){
			scanf("%lld",&a[i]);
			par[i]=i;
			fre[i]=a[i];
		}

		for(int i=0;i<M;i++){
			scanf("%d%d",&x,&y);
			rx=root(x);
			ry=root(y);
			if(fre[ry]<fre[rx]){
			fre[rx]=fre[ry];
			par[rx]=ry;
			}else{
			fre[ry]=fre[rx];
			par[ry]=rx;
			}
		}
		for(int i=0;i<N;i++){
			rx=root(i);
			if(!v[rx]){
				c+=a[rx];
				n--;
				v[rx]=1;
			}
			if (!v[i]){
				b.insert(a[i]);
			}
		}
		while(n--){
			c+=*b.begin();
			b.erase(b.begin());
		}
		printf("%lld",c);
	}
}


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

int main() {
  int n;
  scanf("%d", &n);
  unordered_map<string, int> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    m[s]++;
  }

  printf("AC x %d\n", m["AC"]);
  printf("WA x %d\n", m["WA"]);
  printf("TLE x %d\n", m["TLE"]);
  printf("RE x %d\n", m["RE"]);

  return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,x;
    cin >> N >> x;
    vector<int>a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if(x < a[i]) {
            break;
        }
        else {
            cnt++;
            x-=a[i];
        }
    }
    if(cnt == N && x > 0) {
        cnt--;
    }
    cout << cnt << endl;
}


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

#define INF 1 << 28

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

int dfs(vector<int> cards) {
//    cout << cards.size() << ' ';
//    for (int i = 0; i < cards.size(); i++) {
//        cout << cards[i] << ' ';
//    } cout << endl;
    int min_penalty = cards.size();
    for (int i = 0; i < cards.size(); i++) {
        if (min_penalty == 0) break;
        for (int j = 0; j < 8; j++) {
            if (i % 4 == 0 && dx[j] < 0) continue;
            if (i % 4 == 3 && dx[j] > 0) continue;
            if (0 <= i+dx[j]+dy[j] && i+dx[j]+dy[j] <= cards.size()
                    && cards[i+dx[j]+dy[j]] == cards[i]) {
                vector<int> next_cards = cards;
                if (i < i+dx[j]+dy[j]) {
                    next_cards.erase(next_cards.begin()+i);
                    next_cards.erase(next_cards.begin()+i+dx[j]+dy[j]-1);
                } else {
                    next_cards.erase(next_cards.begin()+i+dx[j]+dy[j]);
                    next_cards.erase(next_cards.begin()+i-1);
                }
                int penalty = dfs(next_cards);
                if (min_penalty > penalty) min_penalty = penalty;
            }
        }
    }
    return min_penalty;
}

int main() {
    int n; cin >> n;
    while (n--) {
        vector<int> cards;
        for (int i = 0; i < 20; i++) {
            int c; cin >> c;
            cards.push_back(c);
        }
        cout << dfs(cards) << endl;
    }
    return 0;
}
        

Measured memory_bytes: 0
package main

import "fmt"

func main() {
	// Code for B - Acrostic
	var S string
	fmt.Scanf("%s", &S)
	var w int
	fmt.Scanf("%d", &w)

	for i := 0; i < len(S); i = i + w {
		fmt.Printf("%c", S[i])
	}

	fmt.Println()
}


Measured memory_bytes: 1848
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    solve();
	}
    }

    public static void solve(){
	int n = kbd.nextInt();
	int i, j, k;
	int cnt=0;
	for(i=0; i<10; i++){
	    for(j=i; j<10; j++){
		for(k=j; k<10; k++){
		    int x = n-i-j-k;
		    if(x<=i && x>=0) {
			// 4つ等しい
			if(i==j && j==k && k==x){
			    cnt += fac(4)/fac(4);
			}
			// 3つ等しい
			else if((x==i && i==j)||(i==j && j==k)){
			    cnt += fac(4)/(fac(3)*fac(1));
			}
			// 2つずつ等しい
			else if(x==i && j==k){
			    cnt += fac(4)/(fac(2)*fac(2));
			}
			// 2つ等しい
			else if(x==i || i==j || j==k){
			    cnt += fac(4)/(fac(2)*fac(1)*fac(1));
			}
			// 全て違う
			else cnt += fac(4);			
		    }
		}
	    }
	}
	System.out.println(cnt);
    }

    public static int fac(int n){
	if(n==1) return 1;
	return n*fac(n-1);
    }
}

Measured memory_bytes: 18060
# https://atcoder.jp/contests/abc074/tasks/arc083_a

import itertools
from collections import Counter
import bisect

def main():
    A, B, C, D, E, F = map(int, input().split())

    ans_nod = -1
    ans_sugar = 0
    ans_water = 0
    for a in range(31):
        for b in range(31):
            water = a * A * 100 + b * B * 100
            if water == 0:
                continue
            if water > F:
                continue
            max_sugar = E * (a * A + b * B)
            for i in range(3000):
                for j in range(3000):
                    sugar = i * C + j * D
                    if sugar > max_sugar:  # 解けないならダメ
                        break
                    if sugar + water > F:  # F超えるならダメ
                        break
                    nod = 100 * sugar / (water + sugar)
                    if nod > ans_nod:
                        ans_nod = nod
                        ans_sugar = sugar
                        ans_water = water
    print("{} {}".format(ans_water + ans_sugar, ans_sugar))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
h, w, K = map(int, input().split())
c = [list(input()) for _ in range(h)]

black = 0
for i in range(h):
    for j in range(w):
        if c[i][j] == '#':
            black += 1

ans = 0

for i in range(1 << h):
    for j in range(1 << w):
        count = black
        visited = [[False for _ in range(w)] for __ in range(h)]
        for p in range(h):
            if i >> p & 1:
                for k in range(w):
                    if not visited[p][k] and c[p][k] == '#':
                        count -= 1
                        visited[p][k] = True
        for p in range(w):
            if j >> p & 1:
                for k in range(h):
                    if not visited[k][p] and c[k][p] == '#':
                        count -= 1
                        visited[k][p] = True
        if count == K:
            ans += 1

print(ans)


Measured memory_bytes: 69288
#include <iostream>
#include <string>
#include <vector>

int main() {
	int data[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int K;
	std::cin >> K;
	std::cout << data[K-1];
	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)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string s; cin >> s;

    string ns = "";
    rep(i, s.size()) {
        if (i+1 < (int)s.size() && (s[i] == 'B' && s[i+1] == 'C')) {
            ns += "X";
            i++;
        } else {
            ns += s[i];
        }
    }

    ll ans = 0, cnt = 0;
    for (int i = ns.size() - 1; i >= 0; --i) {
        if (ns[i] == 'A') ans += cnt;
        else if (ns[i] == 'X') cnt++;
        else cnt = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 776
#coding:utf-8
import bisect
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True



def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n = II()
    a = LMIIS()

    s = sum(a)

    m = s
    x = 0
    for i in range(n):
        x += a[i]
        m = min(m, abs(s/2 - x))
    ans = int(m * 2)


    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25788
N, M = map(int, input().split(' '))
wa_count = [0] * N
ac = [False] * N
ac_count = 0

WA = 'WA'
AC = 'AC'
for i in range(M):
    #print()
    #print('wa_count', wa_count)
    #print('ac', ac)
    #print('ac_count', ac_count)
    #print()

    _p, S = input().split(' ')
    p = int(_p) - 1

    if ac[p]:
        continue

    if S == WA:
        wa_count[p] += 1
    elif S == AC:
        ac[p] = True
        ac_count += 1

    #if ac_count == N:
    #    break

wa_total = 0
for i, c in enumerate(wa_count):
    if ac[i]:
        wa_total += c

print(ac_count, wa_total)


Measured memory_bytes: 4596
//union find
//DSU Disjoint Set Union
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;

class DSU {
public:
	vector<int> parent;

	DSU(int _size) : size(_size) {
		rank = vector<int>(size, 1);
		parent = vector<int>(size, 0);
		for(int i = 0; i < size; i++)
		{
			parent[i] = i;
		}
	}

	int find(int i) {
		if(parent[i] != i)
		{
			parent[i] = find(parent[i]);
		}
		return parent[i];
	}

	bool Union(int i, int j) {
		int ri = find(i), rj = find(j);
		if(ri == rj) return false;
		if(rank[ri] > rank[rj])
		{
			parent[rj] = ri;
		}
		else if (rank[ri] < rank[rj])
		{
			parent[ri] = rj;
		}
		else
		{
			parent[rj] = ri;
			rank[ri] += 1;
		}
		return true;
	}

private:
	int size;
	vector<int> rank;
};

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> X(M), Y(M), Z(M);
	for(int i = 0; i < M; i++)
	{
		cin >> X[i] >> Y[i] >> Z[i];
	}

	DSU dsu(N);
	int ans = N;
	for(int i = 0; i < M; i++)
	{
		ans -= dsu.Union(X[i] - 1, Y[i] - 1);
	}

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


Measured memory_bytes: 2176
{-# LANGUAGE BangPatterns #-}
import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import qualified Data.ByteString.Char8 as BS
import           Data.List

getAsCharArray1DWithLength :: IO (Int, UArray Int Char)
getAsCharArray1DWithLength = BS.getLine >>= \cs ->
  let !n = BS.length cs
      !ary = (U.listArray (1,n) $ unfoldr BS.uncons cs) :: UArray Int Char
  in return (n, ary)

main :: IO ()
main = do
  (!n,!sa) <- getAsCharArray1DWithLength
  (!m,!ta) <- getAsCharArray1DWithLength
  let !result = solve (n,sa) (m,ta)
  putStrLn $ restore sa result n m

solve :: (Int, UArray Int Char) -> (Int, UArray Int Char) -> UArray (Int,Int) Int
solve (!n',!sa) (!m',!ta) = runSTUArray $ do
  !dp <- newArray ((0,0),(n',m')) 0
  forM_ [(n_,m_) | !n_ <- [1..n'], !m_ <- [1..m']] $ \(!n,!m) -> do
    !a <- readArray dp (n-1,m-1)
    !b <- readArray dp (n,m-1)
    !c <- readArray dp (n-1,m)
    if sa U.! n == ta U.! m
      then writeArray dp (n,m) $ maximum [a+1,b,c]
      else writeArray dp (n,m) $ maximum [b,c]
  return dp

restore :: UArray Int Char -> UArray (Int,Int) Int -> Int -> Int -> String
restore !st !ary !n !m = go n m ""
  where go 0 _ !ss = ss
        go _ 0 !ss = ss
        go !i !j !ss
          | ary U.! (i,j) == ary U.! (i-1,j) = go (i-1) j ss
          | ary U.! (i,j) == ary U.! (i,j-1) = go i (j-1) ss
          | otherwise                        = go (i-1) (j-1) ((st U.! i):ss)


Measured memory_bytes: 71804
#include <stdio.h>

int N;
int lights[100008];
int list_size=0;
int list[100002];
int main() {
	int i;
	int total=0;
	int max=0;
	int sequence=0;
	scanf("%d",&N);
	for(i=0;i<N;i++) scanf("%d",&lights[i]);
	for(i=0;i<N;i++) {
		if(sequence>0) {
			if(lights[i]==lights[i-1]) {
				list[list_size++]=sequence;
				sequence=0;
			}
		}
		sequence++;
	}
	if(sequence>0) list[list_size++]=sequence;

	for(i=0;i<list_size;i++) {
		total+=list[i];
		if(i>2) total-=list[i-3];
		if(max<total) max=total;
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    rep(i, n + 1)
    {
        int sum = 0;
        string s = to_string(i);
        rep(j, s.size())
        {
            sum += (int)(s[j] - '0');
        }
        if (a <= sum && sum <= b)
            ans += i;
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
bool check(ll total,int a,int b,vector<ll> & h){
    int n = (int)h.size();
    auto v = h;
    for(auto & vi : v)vi -= total*b;
    ll ret = 0ll;
    for(int i=0;i<n;++i){
        if(v[i] >0ll){
            ret += (v[i]+a-b-1ll)/(a - b);
        }
    }
    if(ret <= total) return true;
    return false;
}
int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    vector<ll> h(n);
    ll r = (1ll<<30)-1;
    for(auto &hi : h){ cin>>hi;}
    sort(h.rbegin(),h.rend());
    for(int i=29;i>=0;i--)if(check(r-(1ll<<i),a,b,h))r -= (1ll<<i);
    cout << r << endl;
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s;
	cin>>s;
	int sum=0;
	REP(i,s.size())
	{
		sum=(sum+(s[i]-'0'))%9;
	}
	if(sum==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long 
typedef pair<int,int>pii;
const int mxN=2e5,M=1e9+7;
int n,x;
int v[mxN],a[1005];
// LONG LONG CASE
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v,v+n);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            auto it=lower_bound(v,v+n,v[i]+v[j]);
            //cout<<it-v<<"\n";
            ans+=(it-v)-j-1;
            //cout<<v[i]<<" "<<v[j]<<" "<<j<<"\n";
        }
    }
    cout<<ans;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll      	long long int
#define PI      	acos(-1)
#define read    	freopen("in.txt","r",stdin)
#define uu      	first
#define vv      	second
#define write   	freopen("out.txt","w",stdout)
#define pii     	pair<int,int>
#define pll         pair<ll,ll>
#define INF     	1e9
#define EPS     	1e-8
#define MAX     	1000006
#define MOD     	1000000007
#define fastRead 	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
int n ,k;
ll ara[MAX] ,dp[MAX];

ll solve(int id) {
    if( id ==n-1 ) return 0;
    ll &ret = dp[id];
    if( ret != -1) return ret;

    ret = INF;

    for(int i = 1 ; i <=k && id + i < n ; i++ ) {
//        cout<<id<<" "<<i<<endl;
        ret = min(ret , abs(ara[id+i] - ara[id]) + solve(id+i) );
    }
    return ret;
}

int main()
{
    fastRead;
    cin>>n>>k;
    for(int i = 0 ; i < n ; i++ ) cin>>ara[i];
    memset(dp , - 1, sizeof dp);
    cout<<solve(0)<<endl;
    return 0;
}


Measured memory_bytes: 15232
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    Subs = [0 for _ in range(N)]
    for i, a in enumerate(A):
        Subs[a-1] += 1
    [print(n) for n in Subs]

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 107104