akhauriyash/Code-Regression huggingface dataset:
import Data.List

solve :: Int -> String -> String
solve _ s = foldr1 f $ map solveB (mkBlocks s)
  where
    f s1 s2 | cmpless s1 s2 = s2
            | otherwise     = s1 ++ s2

cmpless (x : s) (y : t) | x == y = cmpless s t
                        | otherwise = x < y
cmpless _ _ = False

mkBlocks = unfoldr f
  where
    f "" = Nothing
    f s@(c:_) = let cnts = (takeWhile (> 0) (tail (scanl' g 0 s))) ++ [0]
                    (s1, s2) = splitAt (length cnts) s
                in Just $ ((s1, cnts), s2)
      where g n c' | c' == c   = n + 1
                   | otherwise = n - 1

solveB (s@('a':_), _) = take (2*count) $ cycle "ab"
  where
    count = sub 0 0 0 s

    sub ia ib cnt [] = cnt
    sub ia ib cnt ('a':s) = sub2 ia (ia+1) ib cnt s
    sub ia ib cnt ('b':s) = sub ia (ib+1) cnt s

    sub2 ga ia ib cnt ('a':s) = sub2 ga (ia+1) ib cnt s
    sub2 ga ia ib cnt ('b':s) | ga == ib = sub ia (ib+1) (cnt+1) s
                              | otherwise = sub2 ga ia (ib+1) cnt s

solveB (s@('b':_), cnts) =
  maximum [take cmax (repeat 'b') ++ drop i s
          | (i, cnt) <- zip [1..] cnts, cnt == cmax]
  where
    cmax = maximum cnts

main = do
  cont <- getContents
  let [sn, s] = words cont
  putStrLn $ solve (read sn) s


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    if(n%2==1)
    {
        cout<<"No";
        return 0;
    }
    string t=s.substr(n/2);
    string tt=t+t;
    if(tt==s) cout<<"Yes";
    else cout<<"No";
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n){
    cin >> s[i];
  }
  int ac,wa,tle,re=tle=wa=ac=0;
  rep(i,n){
    if(s[i] == "AC"){
      ac++;
    }
    if(s[i] == "WA"){
      wa++;
    }
    if(s[i] == "TLE"){
      tle++;
    }
    if(s[i] == "RE"){
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    rep(i, s.size() - 8) cout << s[i];
    cout << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args ) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[100];
        for (int i = 0; i < N; i++)
            A[i] = scanner.nextInt();

        int count = 0;
        for (int i = 0; i < N; i++){
            int minj = i;
            for (int j = i; j < N; j++){
                if(A[j] < A[minj])
                    minj = j;
            }
            if(i != minj){
                int tmp = A[i];
                A[i] = A[minj];
                A[minj] = tmp;
                count++;
            }
        }
        for(int i = 0; i < N; i++){
            System.out.print(A[i]);
            if(i != N-1) System.out.print(" ");
        }
        System.out.println("\n" + count);
    }
}



Measured memory_bytes: 26408
#include<stdio.h>
#include<math.h>

int main() {
	int a,b,c;
	int f = 0;
	scanf("%d%d%d", &a, &b, &c);
	if (a == b) {
		if (c != a)
			f = 1;
	}
	else if (b == c) {
		if (a != b)
			f = 1;
	}
	else if (a == c) {
		if (b != a)
			f = 1;
	}
	if (f == 0)
		printf("No");
	else if (f == 1)
		printf("Yes");
}

Measured memory_bytes: 128
function main(input) {
  input = input.split("\n");
  var n = input[0];
  var A = input[1];
  var B = input[2];
  var C = input[3];
  var count = 0;
  for (var i = 0; i < n; i++) {
    if (!(A[i] === B[i] && B[i] === C[i]))
      if (A[i] === B[i] || B[i] === C[i] || C[i] === A[i])
        count++;
      else
        count += 2;
  }
  console.log(count);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int x, n; cin >> x >> n;
  vector<int> p(n);
  for (auto& e : p) cin >> e;

  int ans, min_diff = 10e3;
  for (int i = 0; i < 120; i++) {
    if (find(p.begin(), p.end(), x + i) == p.end()) {
      if (i <= min_diff) {
        min_diff = i;
        ans = x + i;
      }
    }

    if (find(p.begin(), p.end(), x - i) == p.end()) {
      if (i <= min_diff) {
        min_diff = i;
        ans = x - i;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
# get initial input parameter
n, k, q = map(int, input().split())
 
# init point
point_list = [ (k - q) for _ in range(n) ]
 
for round in range(q):
    # get correct answer persion
    person_index = int(input()) - 1
    
    # point decrement
    point_list[person_index] += 1
 
for item in point_list:
    if (0 < item):
        print('Yes')
    else:
        print('No')

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

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


AB.sort()

dp = [[0 for _ in range(T)] for _ in range(N+1)]




for i in range(N):
    for j in range(T):
        if AB[i][0] > j:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j - AB[i][0]] + AB[i][1] )


ans = 0
for i, d in enumerate(dp):
    # dp[i][:]にはi-1番目までで最大の満足度が入れられてるから、ABのi以降（使ってないから）で一番大きいのを足す
    mb = 0
    for a,b in AB[i:]:
        mb = max(mb, b)
    ans = max(ans, d[-1] + mb)

print(ans)

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

int main(){
  int a,b;
  cin>>a>>b;
  if(a+b==15){
    cout<<"+"<<endl;
  }
 else if(a*b==15){
    cout<<"*"<<endl;
 }
  else{
    cout<<"x"<<endl;
  }
}


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

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(322179);
#ifdef LOCAL
    freopen("/root/alg/clion_main/input.txt", "rt", stdin);
    freopen("/root/alg/clion_main/output.txt", "wt", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector
#define $ make_pair

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define int long long

// ----------------------------- CODE NOW ------------------------


int power[200];

int get_pref(vi &arr, int i) {
    int n = arr.size();
    int p = power[n - 1];

    int res = 0;
    for (int j = 0; j < i; ++j) {
        res += arr[j] * p;
        p /= 2;
    }
    return res;
}

int len(int x) {
    int res = 0;
    while (x > 0) {
        ++res;
        x /= 2;
    }
    return res;
}

signed main() {
    doRoutine();

    power[0] = 1;
    for (int i = 1; i < 200; ++i) {
        power[i] = power[i - 1] * 2;
    }

    int l;
    cin >> l;

    int n = len(l);
    vi arr(n);
    for (int i = 0; i < n; ++i) {
        arr[i] = l % 2;
        l /= 2;
    }
    reverse(all(arr));

    vc<pair<pii, int> > edges;
    for (int i = 1; i < n; ++i) {
        if (arr[i]) {
            edges.pb({{0, i}, get_pref(arr, i)});
        }
    }

    for (int i = 0; i < n - 1; ++i) {
        edges.pb({{i, i + 1}, power[n - i - 2]});
        edges.pb({{i, i + 1}, 0});
    }

    cout << n << " " << edges.size() << endl;
    for (int i = 0; i < edges.size(); ++i) {
        cout << edges[i].fi.fi + 1 << " " << edges[i].fi.se + 1 << " " << edges[i].se << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from bisect import bisect_left

n = int(input())
l = sorted(list(map(int, input().split(' '))))

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        t = l[i]+l[j]
        idx = bisect_left(l, t)
        ans += max(0, idx-j-1)

print(ans)

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

import sys

s=int(input())

if s==1 or s==2:
    print(4)
else:
    cnt=1
    tmp=s
    while True:
        if tmp==4:
            print(cnt+3)
            break
        cnt+=1
        if tmp%2==0:
            tmp=tmp/2
        else:
            tmp=tmp*3+1


Measured memory_bytes: 2940
a,b,k = map(int,input().split())

cnt = 0

for i in range(k):
    if cnt%2 == 0:
        if a%2 == 0:
            a = a//2
            b += a
            cnt += 1
        else:
            a -= 1
            a = a//2
            b += a
            cnt += 1
    else:
        if b%2 == 0:
            b = b//2
            a += b
            cnt += 1
        else:
            b -= 1
            b = b//2
            a += b
            cnt += 1

print(a,b) 

Measured memory_bytes: 9204
import itertools


def f(A):
    A = A[::-1]
    ret = 0
    for c, a in enumerate(A):
        ret += int(a) * 10 ** int(c)

    return ret


S = input()
ans = f(S)

# +の数
for n in range(1, len(S)):
    for k in itertools.combinations(range(1, len(S)), r=n):
        st = 0
        q = 0
        for i in k:
            q += f(S[st:i])
            st = i
        q += f(S[st:])
        ans += q

print(ans)


Measured memory_bytes: 9196
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  string X;
  cin >> X;
  int ret = 0;

  vector< pair<char,int> > v;
  rep(i,X.size()){
    int cnt = 1;
    int j = i+1;
    while(j<X.size() && X[j]==X[i]){ j++; cnt++; }
    v.push_back(make_pair(X[i],cnt));
    i = j-1;
  }

  rep(i,v.size()-1){
    if(v[i].first == 'S' && v[i+1].first == 'T'){
      int mn = min(v[i].second, v[i+1].second);
      v[i].second -= mn;
      v[i+1].second -= mn;

      if(v[i].second>0){
        if(i+2<v.size() && v[i+2].first == 'S'){
          v[i+2].second += v[i].second;
          v[i].second = 0;
        }
      }
    }
  }

  rep(i,v.size()){
    ret += v[i].second;
  }

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 1552
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    n=length(s)
    ans="Yes"
    for i in 1:n
        if s[i]!=s[n-i+1]
            ans="No"
        end
    end
    for i in 1:(n-1)÷2
        if s[i]!=s[(n-1)÷2-i+1]
            ans="No"
        end
    end
    for i in (n+3)÷2:n
        if s[i]!=s[n-i+(n+3)÷2]
            ans="No"
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 109160
#include <cstdio>
#include <string>
using namespace std;

int n;
char tmp[101];
string s,t;


int main(){
	scanf("%d", &n);
	scanf("%s", tmp);
	s = tmp;
	scanf("%s", tmp);
	t = tmp;
	int a = n * 2;
	for(int i=0; i<n; i++){
		bool f = true;
		for(int j=0; i+j<n; j++){
			if(s[i+j] != t[j]){
				f = false;
				break;
			}
		}
		if(f){
			a = n+i;
			break;
		}
	}

	printf("%d\n", a);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 123;
int n, m, d[N], used[N], c[N], good[N], ex[N], sz[N], par[N], ind[N];
array <int, 3> e[N];
vector <int> g[N], tg[N];

void dfs(int v, int p) {
	for (int to : tg[v]) {
		if (to == p) continue;
		c[to] = c[v] ^ 1;
		dfs(to, v);
	}
}

bool cmp(const int & x, const int & y) {
	return d[x] < d[y];
}

void make_set(int x) {
	par[x] = x;
	sz[x] = 1;
}

int find_set(int x) {
	if (x == par[x]) return x;
	return par[x] = find_set(par[x]);
}

bool union_set(int x, int y) {
	x = find_set(x), y = find_set(y);
	if (x == y) return false;
	if (sz[x] < sz[y]) swap(x, y);
	sz[x] += sz[y];
	par[y] = x;
	return true;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> d[i];
		ind[i] = i;
		make_set(i);
	}
	sort(ind + 1, ind + n + 1, cmp);
	for (int i = 1; i <= m; i++) {
		cin >> e[i][0] >> e[i][1];
		g[e[i][0]].pb(i);
		g[e[i][1]].pb(i);
	}
	for (int i = 1; i <= n; i++) {
		int ok = 0;
		for (int j : g[i]) {
			int to = e[j][0] ^ e[j][1] ^ i;
			if (d[to] <= d[i]) ok = 1;
		}
		if (!ok) return cout << -1, 0;
	}
	for (int i = 1; i <= n; i++) {
		int v = ind[i];
		ex[v] = 1;
		for (int j : g[v]) {
			int to = e[j][0] ^ e[j][1] ^ v;
			if (ex[to] && union_set(v, to)) {
				good[j] = 1;
				tg[v].pb(to);
				tg[to].pb(v);
			}
		}
	}
	dfs(1, 1);
	for (int i = 1; i <= n; i++) {
		if (c[i] == 0) cout << 'B';
		else cout << 'W';
	}
	cout << '\n';
	for (int i = 1; i <= m; i++) {
		if (good[i])
			cout << max(d[e[i][0]], d[e[i][1]]) << '\n';
		else cout << (int)1e9 << '\n';
	}
}


Measured memory_bytes: 28028
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = 0;
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			if (count != 0) {
				System.out.println();
			}
			Map<String, Integer> map = new LinkedHashMap<String, Integer>();
			List<Integer> list = new ArrayList<Integer>();
			while (n-- > 0) {
				String str = scanner.next();
				int a = scanner.nextInt();
				scanner.next();
				int b = scanner.nextInt();
				int c = a * 3 + b;
				map.put(str, c);
				list.add(c);
			}
			Collections.sort(list);
			for (int i = list.size() - 1; i >= 0; i--) {
				for (Entry<String, Integer> entry : map.entrySet()) {
					if (entry.getValue() == list.get(i)) {
						System.out.println(entry.getKey() + ","
								+ entry.getValue());
						entry.setValue(-1);
						break;
					}
				}

			}
			count++;
		}
	}
}

Measured memory_bytes: 20736
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
int N;
int A[MAX_N];
int D;
int X;
int main () {
  scanf("%d", &N);
  scanf("%d%d", &D, &X);
  for(int i = 0; i < N; ++i){
    scanf("%d", A + i);
  }
  int ans = X;
  for(int i = 0; i < N; ++i){
    int tmp = (D - 1) / A[i] + 1;
  ans += tmp;
  }
  printf("%d\n", ans);
  return 0;
}


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

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

	int n;
	cin >> n;
	vector<vector<int>> a(3, vector<int>(n));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			cin >> a[j][i];
		}
	}
	vector<vector<int>> dp(3, vector<int>(n));
	for(int i = 0; i < 3; i++) {
		dp[i][0] = a[i][0];
	}
	for(int i = 1; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			dp[j][i] = a[j][i] + max(dp[(j + 1) % 3][i - 1], dp[(j + 2) % 3][i - 1]);
		}
	}
	int ans = 0;
	for(int i = 0; i < 3; i++) {
		ans = max(dp[i][n - 1], ans);
	}
	cout << ans << endl;
	return 0;	
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{

	string a,b,c;
	cin>>a>>b;
	for(int i=0;i<a.size();i++){
		c=a.substr(1,a.size()-1)+a[0];
		if(c==b){
			cout<<"Yes"<<endl;
			return 0;
		}
		a=c;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
# 7_D
n,m,l=map(int,input().split())
A=[[0 for j in range(m)]for k in range(n)]
B=[[0 for j in range(l)]for k in range(m)]
C=[[0 for j in range(l)]for k in range(n)]
for j in range(n):
    var=list(map(int,input().split()))
    A[j]=var
for j in range(m):
    var=list(map(int,input().split()))
    B[j]=var

for j in range(n):
    for k in range(l):
        for t in range(m):
            C[j][k]+=A[j][t]*B[t][k]

for line in C:
    length=len(line)
    for col in line:
        length-=1
        if length ==0 :
            print(str(col))
        else:
            print(str(col)+" ",end='')


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

public class Main {
    public static long ans(long N, long M){
    	if(N==1) return Math.abs(M-2);
    	else if(M==1) return Math.abs(N-2);
    	else return (N-2)*(M-2);
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();
        System.out.println(ans(N,M));
        
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define itn int
int N;
string S;
bool dbg = false;
int dp[3030][3030];
int c[3030];
void solve() {
    FOR(i, 0, N - 1) {
        if (S[i] == '<') {
            c[i + 1] = 1;
        }
    }
    dp[1][1] = 1;
    FORR(i, 2, N) {
        if (c[i - 1]) {
            int t = 0;
            for (int k = 2; k <= i; k++) {
                t += dp[i - 1][k - 1];
                dp[i][k] = t;
                dp[i][k] %= MOD;
            }
        } else {
            int t = 0;
            for (int k = i; k >= 1; k--) {
                t += dp[i - 1][k];
                dp[i][k] = t;
                dp[i][k] %= MOD;
            }
        }
    }
    int ans = 0;
    FORR(i, 1, N) {
        ans += dp[N][i];
        ans %= MOD;
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> S;
    solve();
    return 0;
}


Measured memory_bytes: 70272
#include <bits/stdc++.h>
using namespace std;
int N, M;
int main() {
    cin >> N;
    vector<string> blue(N);
    for(int i = 0; i < N; ++i) {
        cin >> blue.at(i);
    }

    cin >> M;
    vector<string> red(M);
    for(int j = 0; j < M; ++j) {
        cin >> red.at(j);
    }

    int l = 0;

    for(int i = 0; i < N; ++i) {
        int k = 0;
        for(int j = 0; j < N; ++j) {
            if(blue.at(i) == blue.at(j)) k++;
        }
        for(int m = 0; m < M; ++m) {
            if(blue.at(i) == red.at(m)) k--;
        }
        if(k > l) l = k;
    }

    cout << l << endl;
}

Measured memory_bytes: 384
K,T=map(int,input().split())
A=list(map(int,input().split()))
if K%2==0:
  a=K//2
  b=max(A)
  if a>=b:
    print(0)
  else:
    print((b-a)*2-1)
else:
  a=K//2+1
  b=max(A)
  if a>=b:
    print(0)
  else:
    print((b-a)*2)

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

int main(){
	for(;;){
		int H,W;
		cin>>H>>W;
		if(H==0&&W==0) break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i==0||i==H-1||j==0||j==W-1)
					cout<<"#";
				else
					cout<<".";
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)

int main() {

  string s;
  cin>>s;
  int cnt=0;
  r(i,s.size())
    if(s.at(i)=='p')cnt++;

  cout<< s.size()/2 -cnt <<endl;


return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

int binary_search(ll x, vel a){
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin() ;
    } else {
        return -1;
    }

}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}

int main() {
    ll H, W, M, h, w, count = 0, h_max, w_max, c_h = 0, c_w = 0, ans;
    cin >> H >> W >> M;
    vel max_h(H, 0), max_w(W), ar_h(M), ar_w(M);
    

    REP(i, M){
        cin >> h >> w;
        ar_h[i] = h;
        ar_w[i] = w;
        max_h[h-1] ++;
        max_w[w-1] ++;
    }
    h_max = MAX(max_h);
    w_max = MAX(max_w);
    ans = h_max + w_max - 1;

    REP(i, M){
        h = ar_h[i];
        w = ar_w[i];
        if(ans == max_h[h-1] + max_w[w-1] - 1) count++;
    }

    SORT(max_h);
    SORT(max_w);

    REV(max_h);
    REV(max_w);

    REP(i, H){
        if(max_h[i] != h_max) break;
        c_h ++;
    }

    REP(i, W){
        if(max_w[i] != w_max) break;
        c_w ++;
    }
    
    if(count == c_h * c_w){
        cout << ans << endl;
    } else {
        cout << ans + 1 << endl;
    }


    return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> X(N);
  rep(i,N) cin>>X[i];
  vector<int> Y=X;//いったんYにコピー
  sort(Y.begin(),Y.end());
  rep(i,N){
    if(X[i]<=Y[N/2-1]) cout<<Y[N/2]<<endl;
    else cout<<Y[N/2-1]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>

int main()
{
    short w,h,x,y,r;
    scanf("%d%d%d%d%d%d",&w,&h,&x,&y,&r);
    if((x + r) <= w && (x - r) >= 0 && (y + r) <= h && (y - r) >= 0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2108
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class AKyuInAtCoder {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int x;
        cin >> x;
        if (x < 600) {
            cout << 8 << endl;
        } else if (x < 800) {
            cout << 7 << endl;
        } else if (x < 1000) {
            cout << 6 << endl;
        } else if (x < 1200) {
            cout << 5 << endl;
        } else if (x < 1400) {
            cout << 4 << endl;
        } else if (x < 1600) {
            cout << 3 << endl;
        } else if (x < 1800) {
            cout << 2 << endl;
        } else {
            cout << 1 << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    AKyuInAtCoder solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3644
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCandyDistribution solver = new DCandyDistribution();
        solver.solve(1, in, out);
        out.close();
    }

    static class DCandyDistribution {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            HashMap<Integer, Integer> count = new HashMap<>();
            count.put(0, 1);

            int sum = 0;
            long answer = 0;
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                sum += a;
                sum %= m;
                answer += count.getOrDefault(sum, 0);
                count.put(sum, count.getOrDefault(sum, 0) + 1);
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 46532
#include <stdio.h>
#include <stdlib.h>

int top, s[300];

void push(int n)
{
  s[++top] = n;               //上に積む
}

int pop()
{
  top--;
  return s[top + 1];        //積んだものを返す
}

int main(void)
{
  int i, j, n;
  char s[100];
  top = 0;

  while(scanf("%s", s) != EOF){
    if(s[0] == '+'){
      i = pop();
      j = pop();
      n = i + j;
      push(n);
    }
    else if(s[0] == '-'){
      j = pop();
      i = pop();
      n = i - j;
      push(n);
    }
    else if(s[0] == '*'){
      i = pop();
      j = pop();
      n = i * j;
      push(n);
    }
    else{
      push(atoi(s));
    }
  }

  printf("%d\n", pop());

  return 0;
}



Measured memory_bytes: 2092
#include <iostream>
#include <set>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    cin >> N;
    set<string> s;
    REP(i, N) {
        string tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    if (s.size() == 4) cout << "Four" << '\n';
    else cout << "Three" << '\n';
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  vector<int> edit;
  
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '0') {
      edit.push_back(0);
    } else if (S[i] == '1') {
      edit.push_back(1);
    } else {
      if (edit.size()) edit.pop_back();
    }
  }
  
  for (int i = 0; i < edit.size(); i++) {
    cout << edit[i];
  }
  cout << endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

vll G[100100];

ll ans=0;
ll dfs(ll v, ll p){
  vll child;
  ll cnt=0;
  for(auto nv: G[v]){
    if(nv==p) continue;
    cnt+=dfs(nv,v);
    child.push_back(nv);
  }
  ll sz=child.size();
  ll req=sz-1;
  if(req-cnt>0){
    // cout<<v<<' '<<req<<' '<<cnt<<endl;
    ans+=req-cnt;
  }
  
  return (req-cnt)>0 || cnt>0;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  rep(i,n-1){
    ll a,b; cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  rep(i,n){
    if(G[i].size()>=3){
      dfs(i,-1);
      // cout<<i<<endl;
      cout<<ans<<endl;
      return 0;
    }
  }
  
  cout<<1<<endl;
  
}

Measured memory_bytes: 15284
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, X;
        public long MOD = 1000000007;

        public void Run()
        {
            var line = Input.ReadIntArray();
            N = line[0];
            X = line[1];
            int[] L = Input.ReadIntArray();

            int x = 0;
            int ret = 0;
            for (int i = 0; i <= N; i++)
            {
                x += i == 0 ? 0 : L[i-1];
                if (x <= X) ret++;
            }

            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

int main() {
  ll N, Z, W; cin >> N >> Z >> W;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  vector<vector<ll>> dp(N+1, vector<ll>(2));
  for (int i = N-1; i >= 0; i--) {
    dp.at(i).at(0) = -1;
    if (i == 0) dp.at(i).at(0) = abs(a.at(N-1) - W);
    else dp.at(i).at(0) = abs(a.at(N-1) - a.at(i-1));
    for (int j = i+1; j < N; j++) {
      dp.at(i).at(0) = max(dp.at(i).at(0), dp.at(j).at(1));
    }
    dp.at(i).at(1) = 1000000001;
    if (i == 0) dp.at(i).at(1) = abs(a.at(N-1) - Z);
    else dp.at(i).at(1) = abs(a.at(N-1) - a.at(i-1));
    for (int j = i+1; j < N; j++) {
      dp.at(i).at(1) = min(dp.at(i).at(1), dp.at(j).at(0));
    }
  }
  cout << dp.at(0).at(0) << endl;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
slist = []
plist = []

for i in range(N):
  a, b = map(int, input().split())
  slist.append([a,b])  
  
for i in range(M):
  c, d = map(int, input().split())
  plist.append([c,d])

for i in range(N):
  list = []
  for j in range(M):
    list.append(abs(slist[i][0] - plist[j][0]) + abs(slist[i][1] - plist[j][1]))
  print(list.index(min(list)) + 1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n, a, b, sum = 0, tmp;
    cin >> n >> a >> b;
    string s;
    for (int i = 1; i <= n; i++) {
        s.clear();
        tmp = 0;
        s = to_string(i);
        for (int j = 0; j < s.length(); j++) {
            tmp += s[j] - '0';
        }
        if (tmp >= a && tmp <= b) {
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
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[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,m,r;
  cin >> n >> m >> r;
  ll dist[n][n];
  rep(i,n)rep(j,n)dist[i][j]=1e9;
  
  vector<int>city(r);
  rep(i,r){
    cin >> city[i];
    city[i]--;
  }
  sort(city.begin(),city.end());
  rep(i,m){
    int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    dist[a][b]=c;
    dist[b][a]=c;
  }
  rep(k,n){
    rep(i,n){
      rep(j,n){
        chmin(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  ll ans = INF;
  do{
    ll res = 0;
    rep(i,r-1){
      res+=dist[city[i]][city[i+1]];
    }
    chmin(ans,res);
  }while(next_permutation(city.begin(),city.end()));
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 200010
typedef long long lnt;
int n, s;
char buf[MAXN];
lnt ans = 0;
int main() {
	scanf("%s", buf + 1);
	n = strlen(buf + 1);
	for (int i = 1; i <= n; i++) {
		if (buf[i] == 'W') {
			ans += s;
		} else {
			s++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
// Problem : C - management
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vector <int> ele(n-1);
	for(int j = 0 ; j < n-1; j++)
	{
		cin>>ele[j];
	}
	map <int,int> pairs;
	for(int j = 1; j <= n; j++)
	{
		pairs.insert(make_pair(j,0));
	}
	for(int j = 0 ; j < n-1; j++)
	{
		auto it = pairs.find(ele[j]);
		it->second += 1;
	}
	for(auto it = pairs.begin() ; it != pairs.end(); it++)
	{
		cout<<it->second<<"\n";
	}
	return 0;
}

Measured memory_bytes: 13504
#include<stdio.h>
int main(void)
{
    char S[5];
    int days=0;
    scanf("%s",S);
    switch(S[0])
    {
        case'M':
            days=6;
            break;
        case'W':
            days=4;
            break;
        case'F':
            days=2;
            break;
        case'S':
            if(S[1]=='A')
                days=1;
            else
                days=7;
            break;
        case'T':
            if(S[1]=='U')
                days=5;
            else
                days=3;
    }
    printf("%d\n",days);
    return 0;
}

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

int main(){
    size_t N, M;
    cin >> N >> M;
    vector<vector<size_t>> edge(N);
    for(size_t _ = 0, a, b; _ < M; ++_){
        cin >> a >> b;
        edge[--a].push_back(--b);
        edge[b].push_back(a);
    }
    vector<size_t> ord(N, numeric_limits<size_t>::max()), low(N, numeric_limits<size_t>::max());
    size_t time{0};
    [dfs = [&ord, &low, &edge, &time](auto f, auto now, auto prev) -> void{
        low[now] = ord[now] = ++time;
        for(const auto& i : edge[now])if(i != prev){
            if(ord[i] > time)f(f, i, now);
            low[now] = min(low[now], low[i]);
        }
    }](auto now, auto prev){dfs(dfs, now, prev);}(0, 0);
    size_t ans{0};
    for(size_t i = 0; i < N; ++i)for(const auto& j : edge[i])ans += ord[i] < low[j];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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; }
const long long INF = 1LL << 60;

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

    int64_t ans = 0;

    reps(i,n){
        if(i % 3 != 0 && i % 5 != 0){
            ans+=i;
        }
    }

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

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

int main()
{
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	vector<long long> A(x), B(y), C(z);
	for(auto&& i : A)
	{
		cin >> i;
	}
	for(auto&& i : B)
	{
		cin >> i;
	}
	for(auto&& i : C)
	{
		cin >> i;
	}
	sort(rbegin(A), rend(A));
	sort(rbegin(B), rend(B));
	sort(rbegin(C), rend(C));
	set<tuple<int, int, int>> s;
	priority_queue<pair<long long, tuple<int, int, int>>> pq;
	pq.push(make_pair(A[0] + B[0] + C[0], make_tuple(0, 0, 0)));
	for(int i = 0; i < k; i++)
	{
		int a = get<0>(pq.top().second), b = get<1>(pq.top().second), c = get<2>(pq.top().second);
		long long score = pq.top().first;
		pq.pop();
		if (s.count(make_tuple(a, b, c))) {
			i--;
			continue;
		}
		s.insert(make_tuple(a, b, c));
		cout << score << "\n";
		
		if(a + 1 < x)
		{
			pq.push(make_pair(A[a + 1] + B[b] + C[c], make_tuple(a + 1, b, c)));
		}
		if (b + 1 < y)
		{
			pq.push(make_pair(A[a] + B[b + 1] + C[c], make_tuple(a, b + 1, c)));
		}
		if (c + 1 < z)
		{
			pq.push(make_pair(A[a] + B[b] + C[c + 1], make_tuple(a, b, c + 1)));
		}
	}
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
queue<int> q;
const ll inf=1ll<<60;
const int N=400010,mod=(int)1e9+7;
int eg[N][3];
int e[N],nex[N],head[N],c[N],ed=0;
ll d1[N],d2[N];
int ind[N],oud[N],inq[N],fl[N],ys[N],f[N],f2[N];
int n;
void upd(int &x,int y){x=(x+y)%mod;}
void adde(int x,int y,int z){e[++ed]=y;nex[ed]=head[x];head[x]=ed;c[ed]=z;}
void spfa(int S,int T,ll *d){
    int i,t;
    for(i=1;i<=n;i++) d[i]=inf;
    d[S]=0;q.push(S);inq[S]=1;
    while(!q.empty()){
        t=q.front();q.pop();inq[t]=0;
        for(i=head[t];i;i=nex[i]){
            if(d[e[i]]>d[t]+c[i]){
                d[e[i]]=d[t]+c[i];
                if(!inq[e[i]]) inq[e[i]]=1,q.push(e[i]);
            }
        }
    }
}
int main(){
    int i,x,y,z,m,S,T,t,ans;
    ll ss=1ll<<60;
    scanf("%d %d%d %d",&n,&m,&S,&T);
    for(i=1;i<=m;i++){
        scanf("%d %d %d",&x,&y,&z);
        eg[i][0]=x,eg[i][1]=y,eg[i][2]=z;
        eg[i+m][0]=y,eg[i+m][1]=x,eg[i+m][2]=z;
        adde(x,y,z);adde(y,x,z);
    }
    m*=2;
    spfa(S,T,d1);
    spfa(T,S,d2);
    //for(i=1;i<=n;i++) printf("%lld %lld\n",d1[i],d2[i]);
    for(i=1;i<=n;i++)
        if(d1[i]+d2[i]<ss) ss=d1[i]+d2[i];
    for(i=1;i<=n;i++)
        if(d1[i]+d2[i]==ss) fl[i]=1;
    for(i=1;i<=m;i++){
        x=eg[i][0];y=eg[i][1];z=eg[i][2];
        if(fl[x]&&fl[y]&&d1[x]+z==d1[y]) ys[i]=1,ind[y]++,oud[x]++;
    }
    q.push(S);f[S]=1;
    while(!q.empty()){
        t=q.front();q.pop();
        for(i=head[t];i;i=nex[i])
            if(fl[e[i]]&&d1[e[i]]==d1[t]+c[i]){
                upd(f[e[i]],f[t]);
                if(--ind[e[i]]==0) q.push(e[i]);
            }
    }
    //for(i=1;i<=n;i++) printf("%d\n",f[i]);
    q.push(T);f2[T]=1;
    while(!q.empty()){
        t=q.front();q.pop();
        for(i=head[t];i;i=nex[i])
            if(fl[e[i]]&&d2[e[i]]==d2[t]+c[i]){
                upd(f2[e[i]],f2[t]);
                if(--oud[e[i]]==0) q.push(e[i]);
            }
    }
    //printf("-------\n");
    //for(i=1;i<=n;i++) printf("%d\n",f2[i]);
    ans=(ll)f[T]*f[T]%mod;
    for(i=1;i<=m;i++){
        x=eg[i][0];y=eg[i][1];z=eg[i][2];
        if(ys[i]&&d1[x]*2<d1[T]&&d1[y]*2>d1[T]){
            ans=((ans-(ll)f[x]*f[x]%mod*f2[y]%mod*f2[y]%mod)%mod+mod)%mod;
        }
    }
    for(i=1;i<=n;i++)
        if(fl[i]&&d1[i]*2==d1[T]) ans=((ans-(ll)f[i]*f[i]%mod*f2[i]%mod*f2[i]%mod)%mod+mod)%mod;
    printf("%d",ans);
    return 0;
}


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

int main(int argc, const char * argv[]) {
    int N, K;
    cin >> N;
    cin >> K;
    bool *sunuke = new bool[N];
    memset(sunuke, false, sizeof(bool) * N);
    
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int A;
            cin >> A;
            sunuke[A - 1] = true;
        }
    }
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (!sunuke[i]) {
            ans++;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#define int long long
using namespace std;

int32_t main() {
	
	int n;	cin >> n;
	int sum =0;
	int num = n;
	while(num > 0){
		sum += num % 10;
		num /= 10;
	}
	
	cout << (n % sum == 0 ? "Yes" : "No") << endl;
	
	return 0;
}

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

int main(){
    int x; cin >> x;
    vector<bool>ans(x+1);

    ans[1]=1;
    for(int b=2; b<=x; b++){
        int v = b*b;
        while(v<=x){
            ans[v] = 1;
            v *= b;
        }
    }

    for(int i=x; i>=1; i--) if(ans[i]){
        cout << i << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    int tmp;
    vector<int> cnt(200010, 0);
    cnt[1] = 0;
    for (int i = 2; i <= N; i++)
    {
        cin >> tmp;
        cnt[tmp] += 1;
    }

    for (int i = 1; i <= N; i++)
    {
        cout << cnt[i] << endl;
    }
    
    
    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>>a(n, vector<int>(m));
  vector<int>b(m);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++)cin >> a[i][j];
  }
  for(int i = 0; i < m; i++)cin >> b[i];
  for(int i = 0; i < n; i++){
    int sum = 0;
    for(int j = 0; j < m; j++)sum += a[i][j] * b[j];
    cout << sum << endl;
  }
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  
  vector<int>l(N);
  
  vector<int>r(N);
  
  for(int i=0;i<N;i++){
cin>>l.at(i)>>r.at(i);
  }
  
  int sum=0;
  
  for(int i=0;i<N;i++){
sum+=(r.at(i)-l.at(i)+1);
  }
  
  
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    long even=N/K, odd=0;

    if(K % 2==0) {
        odd = (N + K / 2) / K;
    }

    cout << even*even*even + odd*odd*odd << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <ctime>
#include <cassert>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])  
#define md 1000000007
#define MAXN 200005

long long gcd(long long c, long long d)
{
  long long a,b;
  a = c<d?c:d;
  b = c+d-a;
  if(a==0) return b;
  return gcd(a,b%a);
}


int main()
{   
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    string s1,s2;
    cin>>s1>>s2;
    int g = gcd(n,m);
    int d1 = n/g, d2 = m/g;
    string ns1, ns2;
    rep(i,g)
    {
    	ns1 += s1[i*d1];
    	ns2 += s2[i*d2];
    }
    if (ns1 != ns2) {
    	cout<<-1;
    }
    else {
    	cout<<1LL*d1*d2*g;
    }
    return 0;
}


Measured memory_bytes: 640
N, M = map(int, input().split())
mod = int(1e+9 + 7)
a = mod - 2
ax = []
while a != 0:
  ax = [a%2] + ax[:]
  a //= 2
def inved(x):
  y = 1
  for i in range(len(ax)):
    if ax[i] == 1:
      y *= x
      y %= mod
    if i != len(ax) - 1:
      y *= y
      y %= mod
  return y

p, n = 2, M
L = []
dig = 1
while n != 1:
  i = 0
  while n % p == 0:
    n //= p
    dig *= p
    i += 1
  if i != 0:
    L.append([p, i])
  p += 1
  if p > int(M**(1/2)) and dig != M:
    if L != []:
      L.append([M//dig, 1])
    else:
      L.append([M, 1])
    break

if M == 1:
  print(1)
else:
  prod = 1
  mm = max(x[1] for x in L)
  fact = [1]
  for i in range(N + mm - 1):
    fact.append((fact[i] * (i + 1)) % mod)
  invf = inved(fact[N - 1])
  for i in L:
    pad = (fact[N - 1 + i[1]] * inved(fact[i[1]]) * invf) % mod
    prod *= pad
    prod %= mod
  print(prod)

Measured memory_bytes: 7212