akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n;cin>>n;
    n=n%10;
    vs arr={"pon","pon","hon","bon","hon","hon","pon","hon","pon","hon"};
    cout<<arr[n]<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((x-r>=0 && W-r>=x) && (y-r>=0 && H-r>=y)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
int L[101];
int main()
{
	int n,x,sum=1;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	cin>>L[i];
	long long d=0;
	for(int i=1;i<=n;i++)
	{
		d+=L[i];
		if(x>=d)
		sum++;
	}
	cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;


int main(){
  string S, T;
  cin >> S;
  cin >> T;
  
  int N = S.size();
  int m = T.size();
 
  vector<int> start_point;
  
  if(m > N){
    cout << "UNRESTORABLE" << endl;
  }else{
    rep(i, N-m+1){
      bool temp_bool = true;
      rep(j, m){
        if(!(S.at(i+j) == '?' || S.at(i+j) == T.at(j))){
          temp_bool = false;
          break;
        }
      }
      if(temp_bool) start_point.push_back(i);
    }
    
    if(start_point.empty()) cout << "UNRESTORABLE" << endl;
    else{
      string res(N, 'z');
      rep(i, start_point.size()){
        string temp_string = S;
        rep(j, m){
          temp_string.at(start_point.at(i) + j) = T.at(j);
        }
        rep(j, N){
          if(temp_string.at(j) == '?') temp_string.at(j) = 'a';
        }
        if(res > temp_string) res = temp_string;
      }
      
      cout << res;
    }
  }
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>
#include<cmath>
#include<queue>

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

int main(void){
  ll n;cin >> n;
  vector<ll> h(n);
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  int max_cnt=0;
  for(int i=0;i<n-1;i++){
    int cnt=0;
    for(int j=i;j<n-1;j++){
      if(h[j]>=h[j+1]){
        cnt++;
      }
      else{
        break;
      }
    }
    if(cnt>max_cnt){
      max_cnt=cnt;
    }
    if(n-max_cnt<n/2)break;
  }
  cout << max_cnt << endl;
  return 0;

}


Measured memory_bytes: 1024
// low on constraints of W ~ 1e5

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
using namespace std;
 
const int p=1e9+7;
const int maxn=1e5+2;

void solve() {
    int N, W, w, v; cin>>N>>W;
    vpl pairs(N+1);  
    for(int i=1;i<=N;i++) {
        cin>>w>>v;
        pairs[i] = {w,v};
    }
    
    // sort(pairs.begin(), pairs.end()); // sorting of weights is necessary
    
    ll DP[N+1][W+1]; 
    for(int i=0; i<=N; i++) DP[i][0] = 0;
    for(int i=0; i<=W; i++) DP[0][i] = 0;
    for(int i=1; i<=N; i++) {
        for(int j=1; j<=W; j++) {
            if(pairs[i].first <= j) DP[i][j] = max(pairs[i].second + DP[i-1][j-pairs[i].first], DP[i-1][j]);
            else DP[i][j] = DP[i-1][j];
        }
    }
    cout<<DP[N][W]<<"\n";
}

int main() {
    fast 
    // input output
    int t=1; 
    // cin>>t; 
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 82352
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string str;
	cin>>str;
	ll n=str.size(),sum=0;
	vector<pair<char,ll>> v;
	for(int i=0;i<n;){
		int j=i+1;
		ll cnt=1;
		if(str[i]=='>'){
			while(str[j]=='>'){
				j++;
				cnt++;
			}
		}
		else{
			while(str[j]=='<'){
				j++;
				cnt++;
			}	
		}
		// cout<<cnt<<endl;
		sum+=(cnt*(cnt+1))/2;
		v.push_back({str[i],cnt});
		i=j;
	}
	// cout<<sum<<endl;
	for(int i=0;i<v.size()-1;i++){
		if(v[i].first=='<' && v[i+1].first=='>'){
			sum-=min(v[i].second,v[i+1].second);
		}
	}
	cout<<sum;
}

Measured memory_bytes: 7188
import java.util.Scanner


object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val k = sc.nextInt()
    var ans: Long = 0L
    
    for (i <- 1 to k) {
      for (j <- 1 to k) {
        for (n <- 1 to k) {
          ans += gcds(i, j, n)
        }
      }
    }
    
    println(ans)
  }
  
  def gcds(a: Int, b: Int, c: Int): Int = {
    val m = gcd(a, b)
    gcd(m, c)
  }
  
  def gcd(a: Int, b: Int): Int = {
    if (a % b == 0) {
      b
    } else {
      gcd(b, a % b)
    }
  }
  
  def printArray[T](arr: Array[T]): Unit = {
    for (i <- arr.indices) {
      print(s"${arr(i)} ")
    }
    println()
  }
}

Measured memory_bytes: 56712
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
set <int> q[26];
int n,op,x,l,r,t,len,cnt;
char s[500001]; 
char c;
int32_t main()
{
	int n;
	cin >> n;
	cin>>s;
	len=n;
	for (int i=0;i<len;i++) q[s[i]-97].insert(i);
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>op;
		if (op==1){
			cin>>x>>c;
			x--;
			q[s[x]-97].erase(x);
			s[x]=c;
			q[c-97].insert(x);
		}
		if (op==2){
			cin>>l>>r;
			l--;r--;
			cnt=0;
			for (int j=0;j<=25;j++) if (*q[j].lower_bound(l)<=r&&q[j].lower_bound(l)!=q[j].end()) cnt++;
			cout<<cnt<<endl;
		}
	}
}


Measured memory_bytes: 24192
coins :: Int -> Int-> [Int]
coins x n = map (* x) [0..n]

yens :: Int -> Int-> Int -> [Int]
yens a b c = [x + y + z | x <- coins 500 a, y <- coins 100 b, z <- coins 50 c]

main :: IO ()
main = do
    a <- readLn
    b <- readLn
    c <- readLn
    x <- readLn
    print $ length $ filter (== x) $ yens a b c

Measured memory_bytes: 508
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//約数列挙
//昇順
//#include <vector>
//#include <cmath>
std::vector<long long> div(long long n) {
	std::vector<long long> v(1, 1);
	for (long long i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) v.push_back(i);
	}
	if (sqrt(n) == (long long)sqrt(n)) {
		for (long long i = v.size() - 2; i >= 0; i--) v.push_back(n / v[i]);
	}
	else {
		for (long long i = v.size() - 1; i >= 0; i--) v.push_back(n / v[i]);
	}
	return v;
}

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

	ll n;
	cin >> n;
	ll ans = 0;
	ans += div(n - 1).size() - 1;
	vll v = div(n);
	for (ll i = 1; i < v.size(); i++) {
		ll x = n;
		while (x % v[i] == 0) x /= v[i];
		if (x == 1 || x % v[i] == 1) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
import java.math.BigDecimal;
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        sc.nextLine();
        String[] arr = sc.nextLine().split(" ");
        // 0
        if(Arrays.asList(arr).contains("0")){
            System.out.println(0);
            return;
        }

        BigDecimal ans = BigDecimal.ONE;
        BigDecimal max = new BigDecimal("1000000000000000000");
        boolean over = false;
        for(String str : arr){
            ans = ans.multiply(new BigDecimal(str));

            // 上限
            if(ans.compareTo(max) == 1){
                System.out.println(-1);
                over = true;
                break;
            }
        }

        if(!over){
            System.out.println(ans);
        }
    }
}

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

int main() {
    int N, M, a, b, s;
    cin >> N >> M;
    int R[N][N] = {0};
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        R[a-1][b-1] = 1;
        R[b-1][a-1] = 1;
    }

    deque<int> d, e;
    for (int i = 1; i < N; i++) {
        d.emplace_back(i);
    }

    int c = 0;
    do {
        s = 0;
        e = d;
        e.emplace_front(0);
        for (int i = 0; i < N-1; i++) {
            s += R[e[i]][e[i+1]];
        }
        if (s == N-1) {
            c++;
        }
    } while (next_permutation(d.begin(), d.end()));
    cout << c << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	string s;
	cin >> n >> s;
	map<char, int> mp;
	rep(i, n)mp[s[i]]++;

	ll ans = 1;
	for (auto x : mp){ans *= x.second + 1;ans %= MOD;}

	cout << ans - 1 << endl;

}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int X[]={1,0,-1,0};
  int Y[]={0,-1,0,1};
  int h,w,i,j,rr,r,t,dr[1000],y[1000],x[1000],gy[1000],gx[1000],mv[1000],f,ny,nx;
  char d[40][40]={0};
  while(scanf("%d %d",&w,&h),w||h){
    for(i=r=rr=0;i<h;i++){
      for(j=0;j<w;j++){
	scanf(" %c",&d[i][j]);
	if(d[i][j]=='E')dr[r++]=0;
	if(d[i][j]=='N')dr[r++]=1;
	if(d[i][j]=='W')dr[r++]=2;
	if(d[i][j]=='S')dr[r++]=3;
	if(d[i][j]-'#'&&d[i][j]-'.'&&d[i][j]-'X')d[y[r-1]=i][x[r-1]=j]='#';
	if(d[i][j]=='X'){
	  d[gy[rr]=i][gx[rr]=j]='.';
	  rr++;
	}
      }//printf("%s\n",d[i]);
    }
    for(t=0;t<181;t++){
      for(i=f=0;i<r;i++){//printf("%d:%d %d %d\n",i,y[i],x[i],dr[i]);
	mv[i]=0;
	if(y[i]==0&&x[i]==0)continue;
	f=1;
	for(j=3;j<7;j++){
	  ny=y[i]+Y[(j+dr[i])%4];
	  nx=x[i]+X[(j+dr[i])%4];
	  if(d[ny][nx]=='#')continue;
	  dr[i]=(j+dr[i])%4;//printf("%d:%d %d %d\n\n",i,y[i],x[i],dr[i]);
	  mv[i]=1;
	  break;
	}
      }
      if(f==0)break;
      for(j=2;j<6;j++){
	for(i=0;i<r;i++){
	  if(dr[i]-(j%4)||mv[i]==0)continue;
	  ny=y[i]+Y[j%4];
	  nx=x[i]+X[j%4];
	  if(d[ny][nx]=='.'){
	    d[y[i]   ][x[i]   ]='.';
	    d[y[i]=ny][x[i]=nx]='#';
	  }
	}
      }
      for(i=0;i<r;i++){
	if(mv[i]==0)continue;
	for(j=0;j<rr;j++){
	  if(y[i]==gy[j]&&x[i]==gx[j]){
	    y[i]=x[i]=0;
	    d[gy[j]][gx[j]]='.';
	  }
	}
      }
    }
    if(t-181)printf("%d\n",t);
    else     printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 636
#include <algorithm>
#include <climits>
#include <cstring>
#include <inttypes.h>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

const int cap = 1e5 + 1;
const int mod = 1e9 + 7;
int N, K;
int A[101];
int dp[101][cap];


int main() {
    scanf("%d %d", &N, &K);
    A[0] = 0;
    for (int i = 1; i <= N; ++i) {
        scanf(" %d", &A[i]);
        A[i] += A[i - 1];
    }

    fill(&dp[0][0], &dp[0][0] + 101 * cap + 1, 0);
    dp[0][0] = 1;
    for (int i = 1; i <= N; ++i) {
        int a = A[i] - A[i - 1];
        dp[i][0] = 1;
        for (int j = 1; j <= min(K, A[i]); ++j) {
            if (a > 0)
                dp[i][j] = (j - 1 < a) ? dp[i][j - 1] : (dp[i][j - 1] - dp[i - 1][j - 1 - a] + mod) % mod;
            if (j <= A[i - 1])
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
        }
    }

    printf("%d\n", dp[N][K]);
}











Measured memory_bytes: 39808
# -*- coding: utf-8 -*-

from scipy.sparse.csgraph import floyd_warshall

H, W = map(int, input().split())
C = [None] * 10
for i in range(10):
    C[i] = list(map(int, input().split()))
field = [None] * H
for i in range(H):
    field[i] = list(map(int, input().split()))

# ちょうどよく隣接行列なので、そのままscipyのワーシャルフロイド使う
dist = floyd_warshall(C)

ans = 0
for i in range(H):
    for j in range(W):
        if field[i][j] != -1:
            # 該当マスの数字から1への距離を足していくだけ
            ans += dist[field[i][j]][1]
print(int(ans))


Measured memory_bytes: 17452
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

signed main() {
    int N;
    cin >> N;
    int P[8],Q[8];
    int count = 0;
    int a = -1;
    int b = -1;
    vector<int> nums;
    vector<int> p,q;

    for(int i = 0; i < N; i ++){
        cin >> P[i];
        p.push_back(P[i]);
    }
    for(int i = 0; i < N; i ++){
        cin >> Q[i];
        q.push_back(Q[i]);
    }

    for(int i = 1; i <= N; i ++){
        nums.push_back(i);
    }


    if(p == q) cout << 0;
    else {
        do {
            count++;
            if (nums == p) {
                a = count;
            } else if (nums == q) {
                b = count;
            }
            if (a != -1 && b != -1) break;
        } while (next_permutation(nums.begin(), nums.end()));

        cout << abs(a - b);
    }
    return 0;
}

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

int main() {
  string s, t;
  cin>>s>>t;
  int s_len = s.length();
  int t_len = t.length();
  vector<int> idx[26];
  for (int i=0; i<s_len; i++) {
    int c = s[i] - 'a';
    idx[c].push_back(i);
  }

  int s_idx = -1;
  long long ans = 0;
  for (int i=0; i<t_len; i++) {
    int c = t[i] - 'a';
    if (idx[c].size() == 0) {
      cout<<-1<<endl;
      return 0;
    }
    auto it = upper_bound(idx[c].begin(), idx[c].end(), s_idx);
    if (it == idx[c].end()) {
      ans += s_len - s_idx - 1;
      s_idx = -1;
      it = upper_bound(idx[c].begin(), idx[c].end(), s_idx);
    }
    ans += (*it) - s_idx;
    s_idx = *it;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1216
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	abc := getIntSlice(3)

	m := make(map[int]bool)
	m[abc[0]] = true
	m[abc[1]] = true
	m[abc[2]] = true

	fmt.Println(len(m))
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

using namespace std;
            
int main () {
	long long a, b, c;
	cin >> a >> b >> c;
	if (a % 2 && b % 2 && c % 2) {
		cout << min (min (a * b, a * c), b * c);
	}
	else cout << 0;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt()
	P := readInt()
	haveOdd := false
	for i := 0; i < N; i++ {
		if readInt()%2 == 1 {
			haveOdd = true
		}
	}

	if haveOdd {
		println(pow2(N - 1))
	} else {
		if P == 0 {
			println(pow2(N))
		} else {
			println(0)
		}
	}
}

func pow2(n int) int64 {
	return int64(1) << uint(n)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int H,W,dp[109][109],INF=1<<30;
char c[109][109];
int main(){
	cin>>H>>W;
	for(int i=1;i<=H;i++)for(int j=1;j<=W;j++)cin>>c[i][j];
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			if(i==1&&j==1)dp[i][j]=0;
			else{
				dp[i][j]=INF;
				int score1=INF,score2=INF;
				if(i>=2){
					score1=dp[i-1][j];
					if(c[i-1][j]=='#'&&c[i][j]=='.')score1+=1;
				}
				if(j>=2){
					score2=dp[i][j-1];
					if(c[i][j-1]=='#'&&c[i][j]=='.')score2+=1;
				}
				dp[i][j]=min(score1,score2);
			}
		}
	}
	cout<<dp[H][W]+(c[H][W]=='#')<<endl;
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    double arr[n];
    
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    double **dp=new double*[n+1];
    for(int i=0;i<=n;i++){
        dp[i]=new double[n+1];
    }

    dp[0][0]=1;
    for(int i=1;i<=n;i++)    dp[0][i]=0;

    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(j==0)    dp[i][j]=(1-arr[i-1])*dp[i-1][j];
            else{
                dp[i][j]=(arr[i-1])*dp[i-1][j-1]+(1-arr[i-1])*dp[i-1][j];
            }
        }
    }
    double sum=0.0;
    for(int i=n/2+1;i<=n;i++)   sum+=dp[n][i];
    cout<<setprecision(10)<<sum;
    return 0;
}

Measured memory_bytes: 70656
N, K = map(int, input().split())

A = [[] for _ in range(N)]
B = [[] for _ in range(N)]

for i in range(N):
    A[i], B[i] = map(int, input().split())

import numpy as np
Ind = np.argsort(A)

mem = K
for ind in Ind:
    mem -= B[ind]
    if mem <= 0:
        print(A[ind])
        break

Measured memory_bytes: 21960
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    if a[i] == b[i] == c[i]:
        pass
    elif a[i] == b[i] or b[i] == c[i] or c[i] == a[i]:
        ans += 1
    else:
        ans += 2
print(ans)


Measured memory_bytes: 3060
N, W = map(int, input().split())
weights = []
values = []

for i in range(N):
    w, v = map(int, input().split())
    weights.append(w)
    values.append(v)

dp = {}
dp.setdefault(0, {})
dp[0][0] = 0

for i in range(N):
    weight_list = sorted(dp.keys(), reverse=True)
    for w in weight_list:
        dp.setdefault(w + weights[i], {})
        dp[w + weights[i]][i + 1] = max(
            max(dp[w].values()) + values[i],
            dp[w + weights[i]].get(i + 1, 0)
        )


res = 0
for w, prefix in dp.items():
    if w <= W:
        res = max(res, max(prefix.values()))

print(res)



Measured memory_bytes: 84176
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int n;  // 入力

// dp[i][j][k] := 皿に乗っている寿司の個数が (1,2,3) の皿の個数が (i,j,k) 枚のときに
// 全て食べきるまでの操作回数の期待値
vector<vector<vector<double>>> dp(305, vector<vector<double>>(305, vector<double>(305, -1)));

// メモ化再帰
double memo_rec(int i, int j, int k){
    if(dp[i][j][k] != -1)   return dp[i][j][k];
    if(i == 0 && j == 0 && k == 0)   return dp[0][0][0] = 0;
    
    double res = 0;
    res += n;
    if(i > 0)   res += memo_rec(i-1, j, k) * i;
    if(j > 0)   res += memo_rec(i+1, j-1, k) * j;
    if(k > 0)   res += memo_rec(i, j+1, k-1) * k;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;
}

int main(){
    cin >> n;
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        if(a == 1)  ++cnt1;
        else if(a == 2) ++cnt2;
        else    ++cnt3;
    }
    cout << fixed << setprecision(10);
    cout << memo_rec(cnt1, cnt2, cnt3) << endl;
}

Measured memory_bytes: 225664
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")


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

	string s;
	int ss;
	cin >> s;
	ss = 0;
	for (auto ch : s) ss = ss + ch - '0';
	if (ss % 9 == 0) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}



Measured memory_bytes: 3488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


const int N = 200005;
vector<int> seen(N);
vector<int> use(N); // 辺
vector<vector<pii> > G(N);
vector<int> x;

int dfs(int v) {
  seen[v] = 1;
  int c = x[v];
  for (pii p : G[v]) {
    int nv = p.F;
    if (seen[nv]) continue;
    // cout << nv << endl;
    int d = dfs(nv);
    c ^= d;
    // その下の頂点を 0 に
    use[p.S] = d;
  }
  // cout << "c " << v << " " << c << endl;
  return c;
}

// youtube editorial
void solve() {
  int n, m;
  cin >> n >> m;

  vector<pii> v(n);
  rep(i, n) cin >> v[i].F >> v[i].S;
  sort(all(v));

  // 差をとる
  // 差なら, 2 箇所を変えるだけ
  x.eb(v[0].S);
  rep(i, n - 1) x.eb(v[i].S ^ v[i + 1].S);
  x.eb(v[n - 1].S);
  // cout << x << endl;

  // 辺を作る
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    l = lb(v, pii(l, -1));
    r = ub(v, pii(r + 1, -1));
    r--;

    G[l].eb(r + 1, i);
    G[r + 1].eb(l, i);
  }

  rep(i, n + 1) {
    // どこから dfs してもいい
    if (seen[i]) continue;

    if (dfs(i)) {
      cout << -1 << endl;
      return;
    }
  }
  cout << accumulate(all(use), 0) << endl;
  rep(i, m) if (use[i]) cout << i + 1 << " "; cout << endl; // debuged, n to m
}


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

using namespace std;

int main()
{
    int n,k,x[101],i,dis=0;
    cin>>n>>k;
    for(i=1;i<=n;i++){
        cin>>x[i];
    }
    for(i=1;i<=n;i++){
        if(x[i]<=(k/2)) dis+=(2*x[i]);
        else{
            dis+=(2*(k-x[i]));
        }
    }cout<<dis;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;

template< typename T >
struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;

template< typename T >
T bellman_ford(Edges< T > &edges, int V, int s) {
    const auto INF = numeric_limits< T >::max();
    vector< T > dist(V, INF);
    vector< int > negative(V);
    dist[s] = 0;
    for(int i = 0; i < V - 1; i++) {
        for(auto &e : edges) {
            if(dist[e.src] == INF) continue;
            dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
        }
    }
    for(int i = 0; i < V; i++) {
        for(auto &e : edges) {
            if(dist[e.src] == INF) continue;
            if(dist[e.src] + e.cost < dist[e.to]) {
                negative[e.to] = 1;
                dist[e.to] = dist[e.src] + e.cost;
            }
            if(negative[e.src]) {
                negative[e.to] = 1;
            }
        }
    }
    if(negative[V-1]) {
        return 1;
    }
    return dist[V-1];
}


int main(void) {
    int N, M, P;
    cin >> N >> M >> P;
    Edges<int> g;
    while(M--) {
        int A, B, C;
        cin >> A >> B >> C;
        --A; --B;
        g.emplace_back(A, B, P-C);
    }

    int ans = bellman_ford(g, N, 0);
    if(ans == 1) {
        cout << -1 << endl;
    } else {
        cout << max(-ans, 0) << endl;
    }

    return 0;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict

n,m = map(int,input().split())
d = defaultdict(list)
for i in range(m):
    x,y = map(int,input().split())
    d[x-1].append(y-1)

dp = [-1]*n

def rec(v):
    if dp[v] != -1:
        return dp[v]
    res = 0
    for nv in d[v]:
        res = max(res,rec(nv)+1)
    dp[v] = res
    return res

res = 0
for v in range(n):
    res = max(res,rec(v))
print(res)

Measured memory_bytes: 201196
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int x = 0;
  for(int i=0; i<S.size(); i++){
    if(S.at(i) == 'x'){
      x++;
    }
  }
  if(x >= 8){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
n = int(input()) 
ai = input().split()
ai = list(map(int, ai))

sorted_ai = sorted(ai, reverse=True)

alice = 0
bob = 0

for index, x in enumerate(sorted_ai):
    if (index % 2 == 0):
        alice += x
    else:
        bob += x
        
print(alice - bob)

Measured memory_bytes: 3064
#include<cstdio>
using namespace std;
int main(){
    char cls[16]={0};
    while(scanf("%s",cls)!=EOF){
        int a,b;
        scanf("%d%d",&a,&b);
        int x;
        x = (a*200)+(b*300);
        printf("%s %d %d\n",cls,a+b,x);
    }
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

char s[MAXN];
char ans[MAXN];
int ans_len;

void solve(){
	scanf("%s", &s[0]);
	for(int i = 0; s[i]; i++){
		ans[ans_len++] = s[i];
		if (ans_len >= 2 && ans[ans_len - 2] == 'S' && ans[ans_len - 1] == 'T'){
			ans_len -= 2;
		}
	}
	printf("%d\n", ans_len);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
  int i, k, n, a[1000000];
  int max = 0;
  
  scanf("%d %d", &k, &n);
  
  for( i = 0; i < n; i++ ){
    scanf("%d", &a[i]);
  }
  
  for( i = 1; i < n; i++ ){
    if( a[i] - a[i-1] > max ){
      max = a[i] - a[i-1];
    }
  }

  if( k + a[0] - a[n-1] > max ){
    max =  k + a[0] - a[n-1];
  }
  
  printf("%d\n", k-max);
}

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

int main(void){
    int cnt[26];
    string w;
    cin>>w;
    bool flag=true;
    for(int i=0;i<26;i++)
        cnt[i]=0;

    for(int i=0;i<w.size();i++)
        cnt[w[i]-'a']++;

    for(int i=0;i<26;i++){
        if(cnt[i]%2!=0)
            flag=false;
    }
    cout<<(flag?"Yes":"No")<<endl;
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i+=2)cout<<s[i];cout<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

char s[110];

int main()
{
	scanf("%s",s);int l=strlen(s);
	int x=l,y=-1;
	for (int i=0;i<l;i++) if (s[i]=='C') {x=i;break;}
	for (int i=0;i<l;i++) if (s[i]=='F') y=i;
	if (x<y) puts("Yes"); else puts("No");
	return 0;
}


Measured memory_bytes: 128
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;


int main() {

	int n;
	cin >> n;
	vector<ll> b(100002, 0);
	for(int i = 0; i < n; i++) {
		int t;
		cin >> t;
		b[t]++;
	}
	b.push_back(0);
	b.push_back(0);
	ll ans = 0;
	for (int i = 0; i <= 100000; i++) {
		ans = max(ans, b[i] + b[i + 1] + b[i + 2]);
	}

	cout << ans NL;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
vvl G;
ll dfs(int v){
  ll res=1;
  for(auto nv:G[v]){
    res+=dfs(nv);
  }
  return res;
}
    
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  ll n;
  cin >> n;
  set<P>st;
  rep(i,n-1){
    exrep(j,i+1,n-1){
      st.insert(P(i+1,j+1));
    }
  }
  if(n&1){
    rep(i,n/2) st.erase(P(i+1,n-i-1));
  }
  else{
    rep(i,n/2) st.erase(P(i+1,n-i));
  }
  cout << st.size() << endl;
  for(auto s:st){
    cout << s.first << " " << s.second << endl;
  }
    
}


Measured memory_bytes: 12544
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
  char name[100];
  int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
 
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
 
int min(int a,int b) {
  return a < b ? a : b; 
}
 
int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  char str[64];
  
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}


Measured memory_bytes: 11908
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

class UnionFind {
public:
    vector<int> parent;  //親ノード
    vector<int> Siz;  //集合の大きさ

    // コンストラクタ
    UnionFind(int n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(int n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    int root(int x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {

        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }

        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }

        Siz[x] += Siz[y];
        parent[y] = x;
    }

    // xとyが同じ集合に属するかどうか
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    int size(int x) {
        return Siz[root(x)];
    }
};

int main() {
    int n, m;
    cin >> n >> m;

    UnionFind Uni(n);
    Uni.init(n);

    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;  y--;
        Uni.unite(x, y);
    }

    set<int> st;
    rep(v, n) {
        st.insert(Uni.root(v));
    }

    int renketuseibun = st.size();  // 連結成分の個数

    cout << renketuseibun << endl;
    return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a+b<10) {
			System.out.println(a+b);
		}
		else {
			System.out.println("error");
		}
	}
}

Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int k = scanner.nextInt();

        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = scanner.nextInt();
        }

        int[] dp = createArray(n, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            dp[i] = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            for (int j = 1; j <= k; j++) {
                if (i >= j) {
                    dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(h[i] - h[i - j]));
                }
            }
        }

        System.out.println(dp[n - 1]);
    }

    private static int[] createArray(int size, int defaultValue) {
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = defaultValue;
        }
        return array;
    }
}


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

using namespace std;

typedef long long lint;

lint rez;

int n, k;


int cautBin(int nr, int st)
{
    int a = (n - st) / nr;
    int i = st;
    int pas = 1 << 20;
    while(pas != 0)
    {
        if(i + pas < nr && (n - (i + pas)) / nr == a)
            i += pas;

        pas >>= 1;
    }

    return i;
}
/*
map <int, int> aps;

int apx[100001];*/

int main()
{
    cin >> n >> k;

    int i;
    int rez2 = 0;
    for(i = k + 1; i <= n; i ++)
    {
        ///b = i;
        int last = cautBin(i, k);
        rez += (last - k + 1) * ((n - k) / i + 1);

        if(last + 1 < i)
            rez += ((i - 1) - (last + 1) + 1) * ((n - (last + 1)) / i + 1);

       /* int  a =0 ;
        int b = 0;
        aps.clear();
        for(int j = k; j < i ; j ++)
        {
            int mx = (n - j) / i + 1;
            rez2 += mx;

            aps[mx] ++;
        }*/
       /* apx[(n - (last + 1)) / i + 1] = ((i - 1) - (last + 1) + 1);
        apx[(n - k ) / i + 1] = (last - k + 1);

        //cout << "ARE " << aps.size() << "\n";
        for(map <int, int> :: iterator it = aps.begin(); it != aps.end(); it ++)
        {
            //cout << it -> first << " " << it -> second << "\n";

            if(apx[it -> first] != it -> second)
            {
                cout << "eROAORORORO ";
                cout << k << " " << "++ " << last << "    +-+-+ "  << it -> first << " " << it -> second << " " << apx[it -> first] << "\n";

                return 0;
            }
        }*/
        //cout << "\n";

     //   cout << a << " " << b << "\n";


    }

    cout << rez - (k == 0) * n << "\n";
    //cout << rez2 << "\n";

    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++)

int main(){
	int N;
	cin >> N;
	int l, r;
	int total = 0;

	rep(i, N){
		cin >> l;
		cin >> r;
		total += (r - l) + 1;
	}
	printf("%d\n", total);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//g++ -std=c++11
using namespace std;
typedef long long int ll;
const int MAXN = 200000;
const ll MOD = 1000000007;
const int INF = 1000000000;

vector <ll> v(MAXN+1);

int main() {

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

    int n;
    cin >> n;

    bool hayCero = false;
    for (int i=0; i<n; i++) {
        cin >> v[i];
        if(v[i]==0)
            hayCero = true;
    }
    
    if(hayCero) {
        cout << 0 << endl;
        return 0;
    }

    long double ans = 0;
    for (int i=0; i<n; i++) {
        ans += log10(v[i]);
    }
    
    if(ans > 18.1) {
        cout << -1 << endl;
        return 0;
    }
    ll x = 1;
    for(int i=0; i<n; i++) x*=v[i];
    if(x > 1000000000000000000) {
        cout << -1 << endl;
        return 0;
    }
    cout << x << endl;  

    return 0;
}

Measured memory_bytes: 4684
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for(int i=0; i<n; i++) cin >> p[i];
    for(int i=0; i<n; i++) cin >> q[i];
    vector<int> a(n);
    for(int i=0; i<n; i++) a[i] = i+1;

    map<vector<int>, int> mp;
    do {
        mp[a] = mp.size();
    }while (next_permutation(a.begin(), a.end()));

    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

ll N, A, B;
vector<ll> X;
int main() {
  cin >> N >> A >> B;
  X.resize(N);

  rep(i, N) cin >> X[i];

  ll ans = 0;
  rep(i, N - 1) ans += min((X[i + 1] - X[i]) * A, B);

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


Measured memory_bytes: 1024
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

int calcRow(vi &v) {
  REP(i, 3) {
    if (v[i] == -1)
      continue;
    int cnt = 1;
    for (int j = 1; i + j < 5; j++) {
      if (v[i] == v[i + j]) {
        cnt++;
      } else {
        if (cnt >= 3) {
          int ret = cnt * v[i];
          REP(k, j) { v[i + k] = -1; }
          return ret;
        }
        cnt = 0;
        break;
      }
    }
    if (cnt != 0) {
      int ret = cnt * v[i];
      FOR(k, i, 5) v[k] = -1;
      return ret;
    }
  }
  return 0;
}

void calcCol(vector<vi> &cell, int h) {
  REP(j, 5) {
    for (int i = h - 1; i > 0; i--) {
      if (cell[i][j] == -1) {
        for (int above = i - 1; above >= 0; above--) {
          if (cell[above][j] != -1) {
            cell[i][j] = cell[above][j];
            cell[above][j] = -1;
            break;
          }
        }
      }
    }
  }
}

void print(vector<vi> &cell, int h) {
  cout << endl;
  REP(i, h) {
    REP(j, 5) { cout << cell[i][j] << (j == 4 ? "\n" : " "); }
  }
  cout << endl;
}

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

  while (true) {
    int h;
    cin >> h;
    if (h == 0)
      break;
    vector<vi> cell(h, vi(5, 0));
    int ans = 0;
    REP(i, h) {
      REP(j, 5) { cin >> cell[i][j]; }
    }

    bool changed = true;
    while (changed) {
      changed = false;
      REP(i, h) {
        int p = calcRow(cell[i]);
        if (p != 0)
          changed = true;
        ans += p;
      }
      calcCol(cell, h);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3128
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
mod = 1000000007

i = 0
sum = 0
each_sum = 0
asum = arr.sum
while i < n-1
  each_sum += arr[i]
  sum += arr[i] * (asum - each_sum)
  # a*b+ a*c + a*d + b*c + b*d + c*d  
  # a(b+c+d) + b(c+d) + 
  # 
  #
  i += 1
end
puts sum%mod

Measured memory_bytes: 36012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);

    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");
    int n = Integer.parseInt(sl[0]);
    int max = 1;
    int sum = 0;


    for(int i = 0; i < n; i++)
    {
      s = r.readLine();
      int v = Integer.parseInt(s);
      sum += v;
      max = Math.max(v, max);
    }

    System.out.println(sum - max / 2);

  }

}

Measured memory_bytes: 23124