akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::io::prelude::*;
use std::u32;

/// トラックk台のそれぞれの最大積載量がpの時、それが実現可能か判定する
fn check(vec: &Vec<u64>, k: u32, p: usize) -> bool {
    // k台のトラックでそれぞれ、荷物をpを超えるまで合計していく。
    // すべてのトラックについて合計が終わったとき、荷物が余っていればfalse, 荷物を載せきれていればtrueを返す

    let n = vec.len();
    let mut i = 0;
    for _ in 0..k {
        // トラック1台ごとに,iから荷物を載せていき、pを超えないところまで載せる
        let mut cur_w = 0;
        while i < n && (cur_w + vec[i]) as usize <= p {
            cur_w += vec[i];
            i += 1;
        }
    }

    // 添え字がnに達するなら末尾まで到達したので載せきることが出来た
    i >= n
}

/// k台のトラックにvecの荷物(n個)を割り当てる。この時トラックの最大積載量Pが最小になる値を求める
/// なお、割り当てにおいては、12|3456|のように、連続する荷物でないと同時に載せられない。
/// 場合の数だと、n-1 C k 通りの組合せが存在するはず。
fn calc_p(k: u32, vec: &Vec<u64>) -> u32 {
    // 二分法を用いるのがいいらしい

    let mut st: usize = 0;
    let mut end: usize = 100000 * 10000 + 1; // 荷物の最大個数*最大重量でpの取りうる最大値
    let mut p: usize = 0;
    while st < end {
        let mid = (st + end) / 2;   // 判定対象のpの計算
        if check(vec, k, mid) {
            p = mid;
            end = mid;
        } else {
            st = mid + 1;
        }
    }

    p as u32
}

fn main() {
    let sin = io::stdin();
    let mut l_iter = sin.lock().lines();

    let line = l_iter.next().unwrap().unwrap();
    let mut ws = line.split_whitespace();
    let n: usize = ws.next().unwrap().parse().unwrap();
    let k: u32 = ws.next().unwrap().parse().unwrap();

    let mut vec: Vec<u64> = vec![0; n];
    for i in 0..n {
        let line = l_iter.next().unwrap().unwrap();
        vec[i] = line.trim().parse().unwrap();
    }

    let res = calc_p(k, &vec);

    println!("{}", res);
}



Measured memory_bytes: 5056
package main

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

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	stdInScanner.Scan()
	i, _ := strconv.Atoi(stdInScanner.Text())
	return i
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	N := nextInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		if A[i] == 0 {
			fmt.Println(0)
			return
		}
	}

	answer := 1
	for i := 0; i < N; i++ {
		if A[i] <= int(1e18)/answer {
			answer *= A[i]
		} else {
			answer = -1
			break
		}
	}
	fmt.Println(answer)
}


Measured memory_bytes: 5836
class BellmanFord:
    """Bellman-Ford algorithm : find the shortest path from a vertex
       Complexity: O(VE)
       used in GRL1A(AOJ)
    """

    def __init__(self, V, E, start, INF=10**9):
        """ V: the number of vertexes
            E: adjacency list (all edge in E must be 0 or positive)
            start: start vertex
            INF: Infinity distance
        """
        self.V = V
        self.E = E
        self.bellman_ford(start, INF)

    def bellman_ford(self, start, INF):
        self.distance = [INF] * self.V # distance from start
        self.prev = [-1] * self.V # prev vertex of shortest path
        self.distance[start] = 0
        self.negativeCycle = False
        
        for i in range(V):
            update = False
            for v in range(V):
                for to, cost in self.E[v]:
                    if self.distance[v] != INF and self.distance[v] + cost < self.distance[to]:
                        self.distance[to] = self.distance[v] + cost
                        self.prev[to] = v
                        update = True
                        if i == V - 1:
                            self.negativeCycle = True
            if update == False:
                break

    def getPath(self, end):
        assert self.hasNegativeCycle() == False
        path = [end]
        while self.prev[end] != -1:
            end = self.prev[end]
        return path[::-1]

    def hasNegativeCycle(self):
        return self.negativeCycle

V, E, r = map(int, input().split())
INF = 10**9
edge = [[] for _ in range(V)]
for _ in range(E):
    s, t, d = map(int, input().split())
    edge[s].append((t, d))

sp = BellmanFord(V, edge, r, INF)
if sp.hasNegativeCycle():
    print('NEGATIVE CYCLE')
else:
    print(*[dist if dist != INF else 'INF' for dist in sp.distance], sep='\n')

Measured memory_bytes: 7084
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  int i,n;
  cin >> s;
  n = s.size();
  for(i=0;i<n;i++){
    if(i%2==0 && s[i]=='L'){
      cout << "No" << endl;
      return 0;
    }else if(i%2==1 && s[i]=='R'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=1000000007;
bool isPrime(long long x){
  if(x == 1)return 0;
  for(long long i = 2; i*i <= x; i++) if(x%i == 0) return 0;
  return 1;
}

int main(){
int n;cin>>n;
double a[n];
rep(i,n)cin>>a[i];
double b[n];
rep(i,n)b[i]=(double)1/a[i];
double sum=0;
rep(i,n)sum+=b[i];
double ans=0;
ans=(double)1/sum;
cout << setprecision(12) <<ans<< endl;
}

Measured memory_bytes: 256
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int main(void) {

	char s[12], y[5], m[3], d[3];
    scanf("%s", s);

    REP(i, 0, 4) y[i] = s[i];

    REP(i, 5, 7) m[i - 5] = s[i];

    REP(i, 8, 10) d[i - 8] = s[i];

    int year = atoi(y);
    int month = atoi(m);
    int day = atoi(d);

    if ( year > 2019 || year < 2019 ) puts("TBD");
    else if ( month > 4 ) puts("TBD");
    else if ( month <= 4 ) puts("Heisei");

	return 0;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0) {
        a -= d;
        c -= b;
    }
    if (a <= 0 && c <= 0 || c <= 0) puts("Yes");
    else puts("No");
    return 0;
}

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

#define int long long
#define mod 1000000007
#define maxn 200005
#define endl '\n'

int dp[maxn];

void solve(){
    int n , k;
    cin>>n>>k;
    double x[n];
    for(int i = 0 ; i < n ; i++){
        cin>>x[i];
    }
    for(int j = 0 ; j < n ; j++){
        x[j] = (x[j] + 1) / 2.0;
    }
    double maxi = 0 , win = 0;
    for(int i = 0 ; i < k ; i++){
        win += x[i];
    }
    maxi = win;
    for(int i = 1 ; i <= n - k ; i++){
        win += x[i + k -1];
        win -= x[i-1];
        maxi = max(maxi , win);
    }
    printf("%0.8lf\n" , maxi);

}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr) , cout.tie(nullptr);
    int t = 1;
//    cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 5344
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<random>
#include<fstream>
#include<iterator>
#include <numeric>

using namespace std;

int main() {

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

	string s;

	int a = 0, b = 0, c = 0;

	cin >> s;


	for (int i = 0; i < 3; i++) {
		if (s[i] == 'a')a++;
		else if (s[i] == 'b')b++;
		else if (s[i] == 'c')c++;
	}

	if (a == b && b == c &&a == c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 764
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

template<typename T>
void p(T elem) {cout << elem << endl;}
template<typename T>
void ps(vector<T>& arr) { for(T e: arr) p(e); }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

#define DIVISOR 1000000007
pii gcdext(int a, int b) {
    if(a==0) { return make_pair(0,1); }
    pii p = gcdext(b%a, a);
    return make_pair(p.second - (b/a)*p.first, p.first);
}

static vector<int64_t> factorial;
static vector<int64_t> inv_factorial;

void init_factorial(int size) {
    factorial.resize(size+1);
    inv_factorial.resize(size+1);
    factorial[0] = factorial[1] = 1;
    inv_factorial[0] = inv_factorial[1] = 1;

    for(int i = 2; i <= size; i++) {
        factorial[i] = (factorial[i-1] * i)%DIVISOR;
        pii p = gcdext(i, DIVISOR);
        int inv = (p.first + DIVISOR)%DIVISOR;
        inv_factorial[i] = (inv_factorial[i-1] * inv)%DIVISOR;
    }
    return;
}

int64_t calc_npk(int n, int k) {
    if(k > n) return 0;
    int64_t ans = 1;
    ans = (ans * factorial[n])%DIVISOR;
    ans = (ans * inv_factorial[n-k])%DIVISOR;
    // ans = (ans * inv_factorial[k])%DIVISOR;
    debug("%d, %d -> %lld\n", n, k, ans);
    return ans;
}


int64_t dfs(vector<vector<int>>& graph, int k, int node, int parent) {
    int64_t ans = (parent==-1) ? k : 1;
    int cnt = 0;
    for(int elem: graph[node]) {
        if(elem==parent) continue;
        //excluding parent
        ans = (ans * dfs(graph, k, elem, node))%DIVISOR;
        cnt++;
    }
    int is_parent = (parent!=-1); // exclude parent node
    ans = (ans * calc_npk(k-1-is_parent, cnt))%DIVISOR;
    return ans;
}

int main(void) {
    int vs, k;
    cin >> vs >> k;
    int es = vs-1;
    vector<vector<int>> graph(vs);
    init_factorial(max(vs, k));
    for(int i = 0; i < es; i++) {
        int v1, v2;
        cin >> v1 >> v2;
        // 1-indexed -> 0-indexed
        v1--; v2--;
        graph[v1].push_back(v2);
        graph[v2].push_back(v1);
    }

    int64_t ans = dfs(graph, k, 0, -1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13184
from collections import deque


def solve(a):
    ans = deque()

    for i, aa in enumerate(a):
        if i % 2 == 0:
            ans.append(str(aa))
        else:
            ans.appendleft(str(aa))

    if len(a) % 2 == 1:
        ans.reverse()

    return list(ans)


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    print(' '.join(solve(a)))


Measured memory_bytes: 36000
#include <bits/stdc++.h>
using namespace std; 
const int dx[]={1,0,-1,0,1,-1,-1,1}; 
const int dy[]={0,1,0,-1,1,1,-1,-1}; 
const int INF = 1e9; 
const long long LINF = 1e18; 
const double EPS = 1e-8; 
#define pb push_back
#define mk make_pair 
#define fr first 
#define sc second 
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); ++i) 
#define rep(i,j) reps(i,0,j) 
#define all(a) (a).begin(),(a).end() 
#define MOD 1000000007 
typedef pair<int,int> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;

int main(){

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

	printf("%.8f\n",(double)(a*b)/(double)(a+b));

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e2+2;

int main(){
    IOS;
    int n,k,cnt=0;
    cin>>n>>k;
    int a[n];
    deque<int>v;
    lp(i,0,n){
        cin>>a[i];
        v.pb(a[i]);
        if(i>=k){
            if(v.back()>v.front())
                cout<<"Yes\n";
            else
                cout<<"No\n";
            v.pop_front();
        }
    }

}
/*

*/


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	cout<<fixed<<setprecision(15);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	double pi = acos(-1);
	double l = abs(30*c-6*d+0.5*d)*(2*pi)/360;
	//cout << l*180/pi << "\n";
	cout << sqrt(a*a+b*b-2*a*b*cos(l)) << "\n";
	return 0;
}

Measured memory_bytes: 4196
right = [chr(ord('a') + i) for i in range(7,16)]
right += ['u','y']

def check(a):
        if a in right:
                return "ri"
        else:
                return "le"

while True:
        a = input()
        if a == '#':
                break
        word = [c  for c in a]
        n = ""
        ans = 0
        for i,w in enumerate(word):
                if i == 0:
                        n = check(w)
                else:
                        if n != check(w):
                                ans += 1
                                n = check(w)
        print(ans)
        




Measured memory_bytes: 5568
n = int(input())
cnt = 0
ans = []
if n == 3:
    print('2 5 63')
else:
    for i in range(2, 30001):
        if cnt == n - 2:
            break
        if i % 2 == 0 or i % 3 == 0 or i % 5 == 0:
            ans.append(i)
            cnt += 1

    sm = sum(ans)
    for j in range(i+1, 30001):
        for k in range(j+1, 30001):
            if (sm + j + k) % (2*3*5) == 0 and\
               (j % 2 == 0 or j % 3 == 0 or j % 5 == 0) and\
               (k % 2 == 0 or k % 3 == 0 or k % 5 == 0):
                ans.append(j)
                ans.append(k)
                break
        else:
            continue
        break
    print(' '.join(map(str, ans)))


Measured memory_bytes: 5180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int H,W;
    cin >> H >> W;
    vector<vector<char>> data(H+1, vector<char>(W+1));
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin >> data[i][j];
        }
    }
    for(int i=1;i<=2*H;i++){
        for(int j=1;j<=W;j++){
            if(j==W){
                cout << data[(i+1)/2][j] << endl;
            }
            else{
                cout << data[(i+1)/2][j];
            }
        }
    }
}

Measured memory_bytes: 3616
#include <cstdio>

typedef long long LL;
const int N=131100;
int l[N],r[N],lef[N],rig[N],v[N],cnt,tot;
LL Mid;

struct P{
	LL x,y;
	P(const LL xx=0,const LL yy=0):x(xx),y(yy){}
}a[N],b[N];

void solve(int l1,int r1,int l2,int r2,LL val,int v1,int v2){
	for (int i=l1,j=l2;i<=r1;i++){
		for (;j<=r2 && a[i].y+a[j].x<=val;j++);
		if (j>l2) b[++tot]=P(a[i].x+v1,a[j-1].y+v2);
	}
}

int merge(int mid,int r,int l){
	int t=l-1;
	for (int i=1,j=mid+1;i<=mid || j<=r;){
		P po;
		if (i<=mid && (j>r || b[i].x<b[j].x)) po=b[i++];
			else po=b[j++];
		if (t<l) a[++t]=po;
		else if (a[t].x<po.x && a[t].y>po.y) a[++t]=po;
		else if (a[t].x==po.x && a[t].y>po.y) a[t].y=po.y;
	}
	return t;
}

bool dfs(int x){
	int s1=l[x],s2=r[x];
	if (!s1){
		lef[x]=rig[x]=++cnt;
		a[cnt].x=a[cnt].y=0;
		return 1;
	}
	if (!dfs(s1) || !dfs(s2)) return 0;
	LL val=Mid-v[s1]-v[s2];
	tot=0;lef[x]=lef[s1];
	solve(lef[s1],rig[s1],lef[s2],rig[s2],val,v[s1],v[s2]);
	int m=tot;
	solve(lef[s2],rig[s2],lef[s1],rig[s1],val,v[s2],v[s1]);
	rig[x]=merge(m,tot,lef[x]);
	return lef[x]<=rig[x];
}

int main(){
	int n;
	scanf("%d\n",&n);
	LL L=0,R=0,ans=0;
	for (int i=2;i<=n;i++){
		int fa;
		scanf("%d%d",&fa,&v[i]);
		if (!l[fa]) l[fa]=i;
			else r[fa]=i;
		R+=v[i];
	}
	for (;L<=R;){
		Mid=(L+R)>>1;
		cnt=0;
		if (dfs(1)) ans=Mid,R=Mid-1;
			else L=Mid+1;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define po          pop_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define ms          map<string,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define pqb         priority_queue<int>
#define pqs         priority_queue<int,vi,greater<int> >
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define debug(x,y)  cout<<x<<" "<<y<<"\n";
#define w(x)        ll x

using namespace std;
bool isPrime(int n) 
{
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}
void solve()
{
     int n;
     cin>>n;
     int a[n+1];
     rep(i,1,n+1){
         cin>>a[i];
     }
     int dp[n+1];
     dp[1]=0;
     dp[2]=abs(a[2]-a[1]);
     rep(i,3,n+1){
         dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
     }
     cout<<dp[n];
     
}
int main()
{
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 1024
s = input()
ans = 0
for i in range(1 << (len(s)) - 1):
    t = ''
    for j in range(len(s) - 1):
        t += s[j]
        if (1 & i >> j) == 1:
            t += '+'
    t += s[-1]
    ans += eval(t)
print(ans)

Measured memory_bytes: 3060
from collections import defaultdict
n = int(input())
S = [input() for i in range(n)]
d = defaultdict(int)
num=0
for s in S:
  d[s] += 1
  if d[s] > num: num=d[s]
  
max_strs = []
for s in S:
  if d[s]==num: max_strs.append(s)

max_strs = list(set(max_strs))
max_strs.sort()
for i in range(len(max_strs)): print(max_strs[i])
    

Measured memory_bytes: 45936
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	fmt.Println(A(sc))
}

func A(sc *bufio.Scanner) (cnt int) {
	sc.Scan()
	s := sc.Text()
	for _, t := range strings.Split(s, "") {
		if t == "1" {
			cnt++
		}
	}
	return
}


Measured memory_bytes: 640
// 参考: http://genkisugimoto.com/jp/blog/procon/2015/04/15/print-debug-technique-in-cpp.html
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> a(H);
    map<char, int> counter;
    for (int i = 0; i < H; i++) {
        cin >> a[i];
        for (char ch : a[i]) {
            counter[ch]++;
        }
    }
    if ((H & 1) and (W & 1)) {   // 両方奇数
        int life2 = H / 2 + W / 2,
            life1 = 1;
        for (auto& mp : counter) {
            if (mp.second % 4 == 0) continue;

            if (mp.second % 2 == 1) {
                life1--;
            }
            if (mp.second % 4 == 0) continue;

            if (mp.second % 2 == 0) {
                life2--;
            }
        }
        if (life1 != 0 or life2 < 0) cout << "No" << endl;
        else cout << "Yes" << endl;

    } else if ((H & 1) or (W & 1)) {
        int life = (H & 1) ? W / 2 : H / 2;
        for (auto& mp : counter) {
            if (mp.second % 4 == 0) continue;

            if (mp.second % 2 == 0) {
                life--;
            } else {
                cout << "No" << endl;
                return 0;
            }
        }
        if (life >= 0) cout << "Yes" << endl;
        else cout << "No" << endl;

    } else {
        for (auto& mp : counter) {
            if (mp.second % 4 != 0) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }

    return 0;
}

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

int main() {
  int N, K, x[100], ans = 0;
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    cin >> x[i];
    ans += x[i] < (K - x[i]) ?
      (x[i] * 2) : ((K - x[i]) * 2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N, H, W;
  cin >> N >> H >> W;
  vector<int> A(N);
  vector<int> B(N);
  for(int i = 0; i < N; i++){
    cin >> A[i] >> B[i];
  }
  int count = 0;
  for(int i = 0; i < N; i++){
    if(A[i] >= H && B[i] >= W){
      count = count + 1;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <string>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    if(a<=0 && b>=0) cout<<"Zero\n";
    else if(b<0 && (b-a)%2==0) cout<<"Negative\n";
    else cout<<"Positive\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define FOR(i,n) for(int i = 0; i < (n); i++) 
#define sz(c) ((int)c.size())

const int C = (int)1e4;

vector<int> mul(vector<int> l, vector<int> r) {
	vector<int> ret(sz(l) + sz(r) - 1);
	FOR(i, sz(l)) FOR(j, sz(r)) {
		ret[i + j] += l[i] * r[j];
	}
	FOR(i, sz(ret)) {
		if (ret[i] >= C) {
			if (sz(ret) == i + 1) ret.push_back(0);
			ret[i + 1] += ret[i] / C;
			ret[i] %= C;
		}
	}
	return ret;
}

string tbl[] = {
	"","Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts" 
};

int main() {
	int n, m; 
	while (cin >> m >> n, m&&n) {
		vector<int> cur;
		cur.push_back(1);

		vector<int> input(1, m);
		FOR(i, n) {
			cur = mul(cur, input);
		}

		int up = sz(cur);
		for (int i = up - 1; i >= 0; i--) {
			if (cur[i]) printf("%d%s", cur[i], tbl[i].c_str());
		}
		puts("");
	}
}

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

using namespace std;

int main(){
    long n,k;
    cin>>n>>k;
    double d;
    long a;
    if(k==0){a=0;}
    else{a=n/k;}
    long ans=min(abs(n-a*k),abs(n-((a+1)*k)));
    //d=(double)n/k;
    //if(d>((int)(n/k))+0.5){a=(int)d+1;}
    //else{a=(int)d;}
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

N, W = MAP()
w, v = ZIP(N)

dp = [0]*(W+1)

for i in range(N):
	for j in range(W, -1, -1):
		if j-w[i] >= 0:
			dp[j] = max(dp[j], dp[j-w[i]]+v[i])
print(dp[W])


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

int
main ()
{
  string s; cin >> s;
  if(s.find("YAKI") == 0) cout << "Yes" <<endl;
  else cout << "No" << endl;
  return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl






// same question on cf: https://codeforces.com/contest/559/problem/C



using ll = long long;

const ll mod = 1e9+7;
const int maxn = 2e5;



ll fac[maxn], ifac[maxn], inv[maxn];

ll nck(ll n, ll k) {
    if (n<k) return 0;
    assert(n>=0);
    assert(k>=0);
    return fac[n]*ifac[k]%mod*ifac[n-k]%mod;
}

void gen_inv() {
    fac[0]=inv[0]=ifac[0]=1;
    fac[1]=inv[1]=ifac[1]=1;

    for (int i=2; i<maxn; i++) {
	fac[i]=fac[i-1]*i%mod;
	inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	ifac[i]=ifac[i-1]*inv[i]%mod;
    }

    assert(nck(4,2)==6);
}

int n, m, k;
int r[maxn], c[maxn];


ll dp[maxn];//# paths that reach ith obstacle w/o hitting previous obstacles

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

    gen_inv();

    cin>>n>>m>>k;
    vector<pair<int,int>> sq;
    for (int i=0; i<k; i++) {
	int x, y; cin>>x>>y;
	sq.emplace_back(x,y);
    }

    sort(sq.begin(), sq.end());
    for (int i=0; i<k; i++) {
	r[i] = sq[i].first;
	c[i] = sq[i].second;
    }


    for (int i=0; i<k; i++) {
	int R = r[i];
	int C = c[i];
	ll &res = dp[i] = nck(R-1+C-1,R-1);

	for (int j=0; j<i; j++) {
	    int dr = R - r[j];
	    int dc = C - c[j];
	    if (dr<0 || dc<0) continue;
	    res += (mod - nck(dr+dc, dc)*dp[j]%mod);
	    res %= mod;
	}	
    }



    ll res = nck(n-1+m-1, n-1);

    for (int i=0; i<k; i++) {
	ll cur = dp[i]*nck(n-r[i]+m-c[i], n-r[i])%mod;
	res += (mod-cur);
	res %= mod;
    }


    res %= mod;
    res += mod;
    res %= mod;
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
void solve()
{
	ll n;
	cin>>n;
	if(n%10==n/100)
		cout<<"Yes";
	else
		cout<<"No";
	return;
}


int main()
{
	fast;
	ll q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3616
let split str delim =
  let rec doit s acc =
    match 
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let nth_root x n =
  let fn = float_of_int n in
  if x < 0. && n mod 2 = 1 then (-. exp (log (-. x) /. fn))
  else exp (log x /. fn)

let rec power m = function
  | 0 -> 1.
  | n when n mod 2 = 0 -> power (m *. m) (n / 2)
  | n -> m *. power m (n - 1)

let minkowski_distance x y n p =
  let rec doit i acc =
    if i >= n then acc
    else doit (i + 1) (acc +. (power (abs_float (x.(i) -. y.(i))) p))
  in
  nth_root (doit 0 0.) p

let manhattan_distance x y n = minkowski_distance x y n 1
let euclidean_distance x y n = minkowski_distance x y n 2
let three_norm_distance x y n = minkowski_distance x y n 3

let chebyshev_distance x y n =
  let rec doit i ret =
    if i >= n then ret
    else doit (i + 1) (max ret (abs_float (x.(i) -. y.(i))))
  in
  doit 0 (-1.)

let () =
  let ary_of_str l = Array.of_list (List.map float_of_string (split l ' ')) in
  let n = read_int () in
  let x = ary_of_str (read_line ()) in
  let y = ary_of_str (read_line ()) in
  Printf.printf "%f\n" (manhattan_distance x y n);
  Printf.printf "%f\n" (euclidean_distance x y n);
  Printf.printf "%f\n" (three_norm_distance x y n);
  Printf.printf "%f\n" (chebyshev_distance x y n);

Measured memory_bytes: 2632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LLINF = 1LL << 60;
int main()
{
    ll N, M, K;
    ll dp[20005];
    ll A[20005];
    fill_n(dp, 20005, LLINF);
    cin >> N >> M >> K;
    dp[0] = 0;
    for(ll i = 0; i < N; i++) cin >> A[i];
    for(ll i = 0; i < N; i++) {
        ll maxv = -1, minv = LLINF;
        for(ll j = 0; j < M; j++) {
            if(i + j >= N) continue;
            maxv = max(A[i + j], maxv);
            minv = min(A[i + j], minv);
            dp[i + j + 1] = min(dp[i + j + 1], dp[i] + K + (j + 1) * (maxv - minv));
        }
    }
    cout << dp[N] << endl;
    return (0);
}


Measured memory_bytes: 3420
#include <bits/stdc++.h>
#include <string.h>
#define ll long long int
#define pb push_back
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<n;i++)

using namespace std;

void solve(){
    //Miles To Go
    string s;
    cin>>s;
    f(i,s.size()){
        if(s[i]=='7'){
            cout<<"Yes";
            return;}
    }
    cout<<"No";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
	int t;
	//cin>>t;
	//while(t--)
	    solve();
	return 0;
}

Measured memory_bytes: 3608
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N = S()


if N[-1] =='2' or N[-1] == '4'  or N[-1] =='5' or N[-1] =='7' or N[-1] == '9':
    print('hon')
elif N[-1] =='1' or N[-1] == '0'or N[-1] == '6'or N[-1] == '8':
    print('pon')
elif N[-1] =='3':
    print('bon')



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

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

int main() {
	string s;
	cin >> s;
	rep(i, s.size()) {
		cout << 'x';
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
a = int(input())

import math
def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

while True:
    if is_prime(a):
        print(a)
        break
    else:
        a+=1

Measured memory_bytes: 9112
#include <stdio.h>
int main(void) {
	int i,a[3];
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	int j,tmp;
	for(j=2;j>0;j--){
		for(i=0;i<j;i++){
			if(a[i]>a[i+1]){
				tmp=a[i];
				a[i]=a[i+1];
				a[i+1]=tmp;
			}
		}
	}
	int b[2];
	for(i=0;i<2;i++){
		scanf("%d",&b[i]);
	}
	for(j=1;j>0;j--){
		for(i=0;i<j;i++){
			if(b[i]>b[i+1]){
				tmp=b[i];
				b[i]=b[i+1];
				b[i+1]=tmp;
			}
		}
	}
	printf("%d\n",a[0]+b[0]-50);
	return 0;
}


Measured memory_bytes: 2064
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N; cin >> N;
	string S; cin >> S;
	string T = S;
	SORT(T);
	int cnt = 0;
	REP(i, N) {
		if (S[i] != T[i])cnt++;
	}
	
	cout << cnt / 2 << endl;

	return 0;
}



Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline int msbp(int x) {return 31-__builtin_clz(x);}
inline int msb(int x) {return 1 << msbp(x);}
typedef long long ll;
typedef pair<int, int> pii;
// const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x3f3f3f3f;
// const int INF = INT_MAX;
// const int nINF = INT_MIN;
// const ll INF = LLONG_MAX;
// const ll nINF = LLONG_MIN;

/////////////////////////////////////////////////////////////////////

const int M = 1e9+7;

ll mod(ll x) {return ((x % M) + M) % M;}
int add(ll a, ll b) {return mod(mod(a)+mod(b));}
int mult(ll a, ll b) {return mod(mod(a)*mod(b));}

int n, m, k, x, ans = 1;
vector<int> pos, neg;

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n >> k;
    REP(i, n) {
    	cin >> x;
    	if(x > 0) pos.push_back(x);
    	else neg.push_back(x);
    }
    n = pos.size(), m = neg.size();
    if(n) {
		// we have a choice on number of positive numbers.
		if(k & 1) {
			// choose the biggest positive number first
			sort(pos.begin(), pos.end());
			ans = pos.back();
			pos.pop_back();
			--k;
			--n;
		}
		vector<ll> all;
		sort(pos.begin(), pos.end(), greater<int>());
		sort(neg.begin(), neg.end());
		for(int i = 0; i+1 < n; i += 2) all.push_back((ll)pos[i]*pos[i+1]);
		for(int i = 0; i+1 < m; i += 2) all.push_back((ll)neg[i]*neg[i+1]);
		if(n & m & 1) all.push_back((ll)pos.back()*neg.back());
		sort(all.begin(), all.end(), greater<ll>());
		REP(i, k/2) ans = mult(ans, all[i]);
    } else {
    	sort(neg.begin(), neg.end());
    	if(k & 1) reverse(neg.begin(), neg.end());
    	REP(i, k) ans = mult(ans, neg[i]);
    }
    cout << ans << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE) CHECK IF IT SHOULD BE 2*N!!!!
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - negative arithmetic, ceiling division, modulo (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)
// - forgetting to rename recursive call when copy/pasting recursive function (WA)
// - not clearing DS between test cases EVEN FOR INPUT (WA, RTE, TLE, MLE)


Measured memory_bytes: 5620
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


template <class Monoid>
class SegmentTree
{
public:
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid M1;
  int sz;
  vector<Monoid> seg;

  SegmentTree(int n,const Func fu, const Monoid &m1): F(fu) , M1(m1) {init(n);}
  void init(int n)
  {
      sz= 1;
      while (sz < n) sz *= 2;
      seg.assign(sz * 2, M1);
  }
  void update(int k,const Monoid &x)
  {
    k+=sz;
    seg[k]=x;
    while(k>>=1)
    {
      seg[k]=F(seg[k*2],seg[k*2+1]);
    }
  }
  void add(int k,const Monoid &x)
  {
    k+=sz;
    seg[k]+=x;
    while(k>>=1)
    {
      seg[k]=F(seg[k*2],seg[k*2+1]);
    }
  }
  Monoid query(int l,int r)
  {
    Monoid L=M1,R=M1;
    l+=sz;r+=sz;
    for(;l<r;l>>=1,r>>=1)
    {
      if(l&1)L=F(L,seg[l++]);
      if(r&1)R=F(seg[--r],R);
    }
    return F(L,R);
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  vector<ll>a(n),s(n+1);
  rep(i,n)cin>>a[i];
  rep(i,n)s[i+1]+=s[i]+a[i];
  rep(i,n+1){
    s[i]=(s[i]-i)%k;
    if(s[i]<0)s[i]+=k;
    //cout<<s[i]<<" ";
  }
  vector<ll>syu;
  syu=s;
  sort(all(syu));
  syu.erase(unique(all(syu)),syu.end());
  ll res=0;
  ll sz=syu.size();

  vector<vector<ll>>id(sz);
  rep(i,n+1){
    ll ti=lower_bound(all(syu),s[i])-syu.begin();
    id[ti].push_back(i);
  }
  SegmentTree<ll> st(n+1,[](ll a,ll b){return a+b;},0LL);
  rep(j,sz){
    ll num=syu[j];
    //cout<<num<<endl;
    for(auto i:id[j]){
      st.add(i,1);
      res+=st.query(max(0LL,i-k+1),i);
    }
    for(auto i:id[j]){
      if(s[i]!=num)continue;
      st.update(i,0);
    }
  }
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 19968
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil, sqrt
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N = int(input())
    ans = [0] * 20000

    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 100):
                v = x * x + y * y + z * z + x * y + y * z + z * x
                if v <= 10001:
                    ans[v] += 1
    for k in range(1, N + 1):
        print(ans[k])


if __name__ == '__main__':
    main()

Measured memory_bytes: 69220
n, a, b = list(map(int, input().split()))
x = list(map(int, input().split()))
ans = 0

for i in range(n - 1):
    if (x[i + 1] - x[i]) * a >= b:
        ans += b
    else:
        ans += (x[i + 1] - x[i]) * a
        
print(ans)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string a, b;
    cin >> a >> b;
    if (a == b) cout << "EQUAL" << endl;
    else if (a.size() > b.size()) cout << "GREATER" << endl;
    else if (a.size() < b.size()) cout << "LESS" << endl;
    else {
        vector<string> vec{a, b};
        sort(ALL(vec));
        if (vec.at(0) == a) {
            cout << "LESS" << endl;
        } else {
            cout << "GREATER" << endl;
        }
    }
    return 0;

}

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

int N, M, a, b, c, p[100100], num[100100], ans=0;

int top(int a) {
    return p[a]==a?a:top(p[a]);
}

bool same(int a, int b) {
    return top(a)==top(b);
}

void join(int a, int b) {
    if (num[top(a)] > num[top(b)]) {
        p[top(b)] = top(a);
    } else if (num[top(a)] < num[top(b)]) {
        p[top(a)] = top(b);
    } else {
        p[top(b)] = top(a);
        num[top(a)]++;
    }
}

int main () {
    cin >> N >> M;
    for(int i=1; i<=N; i++) {
        p[i] = i;
        num[i] = 1;
    }
    for(int i=0; i<M; i++) {
       cin >> a >> b >> c;
       join(a, b);
    }
    for(int i=1; i<=N; i++)
        if (p[i] == i)
            ans++;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    map<pair<ll, ll>, ll> mp;
    rep(i, n) {
        ll a;
        cin >> a;
        a--;
        ll x = i;
        if(x > a) {
            swap(x, a);
        }
        mp[make_pair(x, a)]++;
    }

    ll ans = 0;
    for(auto p : mp) {
        if(p.second >= 2) {
            ans++;
        }
    }

    out(ans);
    re0;
}

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

using namespace std;

int a;

int main()
{
    int n,h,sum=0;  cin >> h >> n;
    for(int i =0 ;i<n;i++)  cin >> a , sum+=a;
    if(sum >= h)  cout << "Yes";
    else  cout << "No";
    return 0;
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7


def mod_pow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        half_p = p // 2
        half = mod_pow(a, half_p)
        return half * half % mod
    else:
        return a * mod_pow(a, p - 1) % mod


def calc_comb(a, b):
    if b > a - b:
        return calc_comb(a, a - b)

    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= (a - i)
        ans_div *= (i + 1)
        ans_mul %= mod
        ans_div %= mod

    ans = ans_mul * mod_pow(ans_div, mod - 2) % mod
    return ans


N, M = map(int, input().split())
ans = 1
rest = M
for i in range(2, int(M ** 0.5) + 1):
    if rest % i == 0:
        cnt = 0
        while rest % i == 0:
            cnt += 1
            rest = rest // i
        ans *= calc_comb(N + cnt - 1, N - 1)
        ans %= mod
if rest != 1:
    ans *= calc_comb(N + 1 - 1, N - 1)
    ans %= mod
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
vector<pll> LR;
vector<ll> minleft;
vector<ll> minright;

ll calc(ll n) {
	if (n == 1) {
		ll ans = LR[1].second - LR[1].first + 1;
		if (LR[N].first <= minright[2])ans += minright[2] - LR[N].first + 1;
		return ans;
	}
	//一番小さいものを残す
	ll temp1 = min(LR[n].second, minleft[n - 1]);
	ll ans1 = max(minleft[n - 1] - LR[n].first + 1, (ll)0) + max(minright[n + 1] - LR[N].first + 1, (ll)0);
	//一番小さいものを移す
	ll temp2 = min(minright[n + 1], minleft[n - 1]);
	ll ans2 = max(LR[n].second - LR[n].first + 1, (ll)0) + max(temp2 - LR[N].first + 1, (ll)0);
	return max(ans1, ans2);
}

int main() {
	cin >> N;
	LR.resize(N + 1);
	for (ll n = 1; n <= N; n++) {
		cin >> LR[n].first >> LR[n].second;
	}
	sort(LR.begin(), LR.end(), [](pll a, pll b) {
		return a.first < b.first;
	});
	minleft.resize(N + 2);
	minleft[0] = LLONG_MAX;
	for (ll n = 1; n <= N; n++) {
		minleft[n] = min(minleft[n - 1], LR[n].second);
	}
	minleft[N + 1] = 0;
	minright.resize(N + 2);
	minright[N + 1] = LLONG_MAX;
	for (ll n = N; n >= 1; n--) {
		minright[n] = min(minright[n + 1], LR[n].second);
	}
	minright[0] = 0;
	ll ans = 0;
	for (ll n = 1; n <= N - 1; n++) {
		ll temp = calc(n);
		ans = max(ans, temp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N, K;
	cin >> N >> K;
	vector<int> T(N);
	for (int i = 0; i < N; i++)
		cin >> T[i];
	sort(all(T));
	int mn = 1e9;
	K--;
	for (int i = 0; i+K < N; i++)
		mn = min(mn, T[i+K] - T[i]);
	cout << mn << endl;
}



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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    
    vector<int> wa(n, 0);
    wa[0] = p[0];
    for (int i = 1; i < k; i++) wa[i] = p[i]+wa[i-1];
    int max_wa = wa[k-1];
    for (int i = k; i < n; i++) {
        wa[i] = wa[i-1] - p[i-k] + p[i];
        if (wa[i] > max_wa)
            max_wa = wa[i];
    }
    
    cout << fixed << setprecision(10) << (max_wa+k) / 2.0 << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
struct edge { int to, cost; };
int H, W;
vector<string> table;
vector<edge> G[30];
bool isOut(int y, int x)
{
    if(y < 0 || x < 0 || y >= H || x >= W) return true;
    return false;
}
void makeGragh(int y, int x)
{
    bool used[H][W] = {};
    used[y][x] = true;
    queue<P> que;
    que.push(P(y, x));
    while(que.size())
    {
        P p = que.front(); que.pop();
        for(int i = 0; i < 4; i++)
        {
            int ny = p.first;
            int nx = p.second;
            while(not isOut(ny + dy[i], nx + dx[i]))
            {
                ny += dy[i];
                nx += dx[i];
                if(table[ny][nx] == '.' || used[ny][nx]) break; 
                if(dy[i] == 0 && table[ny][nx] == '|') break;
                if(dx[i] == 0 && table[ny][nx] == '-') break;
                if(table[ny][nx] >= 'A' && table[ny][nx] <= 'Z')
                {
                    int a = table[p.first][p.second] - 'A';
                    int b = table[ny][nx] - 'A';
                    G[a].push_back({b, 1});
                    G[b].push_back({a, 1});
                    que.push(P(ny, nx));
                    break;
                }
                used[ny][nx] = true;
            }
        }
    }
}
int solve(int s, int t)
{
    // for(int i = 0; i < 26; i++)
    // {
    //     cout << char(i + 'A') << " : ";
    //     for(int j = 0; j < G[i].size(); j++) cout << char(G[i][j].to + 'A') << " "; cout << endl;
    // }
    vector<int> dist(30, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    dist[s] = 0;
    while(que.size())
    {
        P p = que.top(); que.pop();
        int v = p.second;
        for(int u = 0; u < G[v].size(); u++)
        {
            edge e = G[v][u];
            if(dist[v] + e.cost < dist[e.to])
            {
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
    return dist[t];
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char s, t;
    cin >> H >> W >> s >> t;
    table.resize(H);
    vector<char> v;
    int sy, sx;
    for(int i = 0; i < H; i++)
    {
        string s; cin >> s;
        for(int j = 0; j < s.size(); j++) if(s[j] >= 'A' && s[j] <= 'Z') sy = i, sx = j;
        table[i] = s;
    }
    makeGragh(sy, sx);
    cout << solve(s - 'A', t - 'A') << endl;
    return 0;
}




Measured memory_bytes: 3236