akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t = "AKIHABARA";
    cin >> s;
    bool f = true;
    int now = 0;
    rep(i, 0, t.size()){
        if(t[i] == s[now]) now++;
        else{
            if(t[i] == 'A');
            else f = false;
        }
    }
    if(f && now == s.size()) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
 
int m[11][11024];
int n,s;
 
void dfs(int b,int d,int s){
    m[d][s]++;
    for(int i=0;i<10;i++)
        if((b>>i)&1)
            dfs(b-(1<<i),d+1,s+(1+d)*i);
}
int main(){
    memset(m,0,sizeof(m));
    dfs(1023,0,0);
    while(cin>>n>>s)
        cout<<m[n][s]<<endl;
}

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

const int N = 105;

int n, cnt = 0, red[2 * N];
string s;
vector<int> ve;

int ask() {
    cout << "? ";
    for (int &v : ve) {
        cout << v << " ";
    }
    cout << endl;
    cin >> s;
    return s == "Red";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        ve.push_back(i);
    }
    int beg = ask();
    int le = 1, ri = n;
    while (le <= ri) {
        int mi = (le + ri) / 2;
        ve.clear();
        for (int i = 1; i <= n; i++) {
            ve.push_back(mi + i);
        }
        if (ask() != beg) {
            ri = mi - 1;
        } else {
            le = mi + 1;
        }
    }
    ve.clear();
    red[le] = beg; red[le + n] = 1 - beg;
    for (int i = 1; i < n; i++) {
        ve.push_back(le + i);
    }
    for (int i = 1; i <= 2 * n; i++) {
        if (i < le || i > le + n) {
            ve.push_back(i);
            red[i] = ask();
            ve.pop_back();
        }
    }
    ve.clear();
    for (int i = 1; i <= 2 * n; i++) {
        if (i < le || i > le + n) {
            ve.push_back(i);
        }
    }
    for (int i = le + 1; i <= le + n - 1; i++) {
        ve.push_back(i);
        red[i] = ask();
        ve.pop_back();
    }
    cout << "! ";
    for (int i = 1; i <= 2 * n; i++) {
        cout << (red[i] ? 'R' : 'B');
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 724
# -*- coding: utf-8 -*-
N = int(input())
p = [0 for _ in range(N+1)]

p[0], p[1] = map(int, input().split())
for n in range(2, N+1):
    p[n] = list(map(int, input().split()))[1]

M = [[0]*(N+1) for _ in range(N+1)]

for n in range(N+1):
    M[n][n] = 0

for l in range(2, N+1):
    for i in range(1, N-l+2):
        j = i + l - 1
        M[i][j] = float("inf")
        for k in range(i, j):
            M[i][j] = min(M[i][j], M[i][k] + M[k+1][j] + p[i-1]*p[k]*p[j])

print(M[1][N])

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

struct Card {
  char suit, value;
};

void bubble(struct Card A[], int N) {
  for (int i = 0; i < N; ++i) {
    for (int j = N - 1; j >= i; --j) {
      if (A[j].value < A[j - 1].value) {
        Card t = A[j];
        A[j] = A[j - 1];
        A[j - 1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N) {
  for (int i = 0; i < N; ++i) {
    int minj = i;
    for (int j = i; j < N; ++j) {
      if (A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[], int N) {
  for (int i = 0; i < N; ++i) {
    if (i > 0) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
  for (int i = 0; i < N; ++i)
    if (C1[i].suit != C2[i].suit) return false;
  return true;
}

int main() {
  Card C1[100], C2[100];
  int N;
  
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> C1[i].suit >> C1[i].value;
  for (int i = 0; i < N; ++i) C2[i] = C1[i];
  
  bubble(C1, N);
  selection(C2, N);
  
  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if (isStable(C1, C2, N))
    cout << "Stable" << endl;
  else
    cout << "Not stable" << endl;
}

Measured memory_bytes: 3040
#include<iostream>
#include<algorithm>
using namespace std;
const int BUF = 100005;
const int MOD = 1000000007;


int add(long long a, long long b) {
    return (a + b) % MOD;
}

int sub(long long a, long long b) {
    return (a + MOD - b) % MOD;
}

int mul(long long a, long long b) {
    return a * b % MOD;
}

int modPow(int p, int n) {
    if (n == 0) return 1;
    int t = modPow(p, n / 2);
    return n % 2 == 0 ? mul(t, t) : mul(p, mul(t, t));
}

int inv(int p) {
    return modPow(p, MOD - 2);
}


int nVal, nPick;
int val[BUF];

void read() {
    cin >> nVal >> nPick;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}


long long getSum(int a, int b, long long sum[BUF]) {
    return sum[b] - (a == 0 ? 0 : sum[a - 1]);
}


void work() {
    if (nPick == 1) {
        cout << 0 << endl;
        return;
    }

    sort(val, val + nVal);

    long long sum[BUF] = {};
    sum[0] = val[0];
    for (int i = 1; i < nVal; ++i) {
        sum[i] = sum[i - 1] + val[i];
    }
    
    int ans = 0;

    // len-2 C nPick-2
    int nCk = 1;

    for (int len = nPick; len <= nVal; ++len) {
        //   val[len - 1] - val[0]
        // + val[len    ] - val[1]
        // + val[len + 1] - val[2]
        // + val[len + 2] - val[3]
        // + ...
        // + val[nVal - 1] - val[nVal - len]
        //
        // -> sum of val[len-1 ... nVal-1] - sum of val[nVal-len ... 0]
        ans = add(ans, mul(nCk, sub(getSum(len - 1, nVal - 1, sum), getSum(0, nVal - len, sum))));
        nCk = mul(nCk, mul(len - 1, inv(len + 1 - nPick)));
    }

    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
#include<fstream>
using namespace std;
typedef long long LL;

int main(void)
{
	LL x,k;
	cin >>k>>x;
	for (LL i = (x - k) + 1; i < (x + k)-1 ; i++) {
		cout <<i<<" ";
	}
	cout <<x+k-1<<endl;
	return 0;
}

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

int main(){
  int A,B;
  cin>>A>>B;
  
  int answer;
  if (A==B) answer=2*A;
  else answer = 2*max(A,B)-1;
  
  cout<<answer<<endl;
}


Measured memory_bytes: 256
let n = read_int ()
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let s, x, ans = Array.fold_left (+) 0 a_s, ref 0, ref max_int
let _ = Array.iteri (fun i a -> if i < n - 1 then x := !x + a; ans := min !ans @@ abs @@ 2 * !x - s) a_s; Printf.printf "%d\n" !ans

Measured memory_bytes: 5888
#include<stdio.h>
int main()
{

    int n;
    scanf("%d",&n);

    int ary[n];
    double sum=0;

    for(int i=0;i<n;i++)
    {
        scanf("%d",&ary[i]);

    }
    for(int i=0;i<n;i++)
    {

        sum+=1/(ary[i]*1.000);
    }

    printf("%lf",1/sum);
}


Measured memory_bytes: 128
h,n=map(int,input().split())
a,b=[],[]
for i in range(n):
  aa,bb=map(int,input().split())
  a.append(aa)
  b.append(bb)
inf=float("inf")
dp=[[inf]*(h+1) for i in range(n+1)]
dp[0][0]=0
for i in range(n):
  for j in range(h+1):
    dp[i+1][j]=min(dp[i+1][j],dp[i][j])
    dp[i+1][min(h,j+a[i])]=min(dp[i+1][j]+b[i],dp[i+1][min(h,j+a[i])])
    
print(dp[n][h])

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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	int n = s.size();
	int m = 2019;
	vector<vector<ll>> v(2, vector<ll>(m, 0));
	ll ans = 0;
	rep(i, n){
		rep(j, m) v[(i+1) % 2][j] = 0;

		int x = s[i] - '0';
		v[(i+1) % 2][x % m]++;
		rep(j, m){
			v[(i+1) % 2][(10 * j + x) % m] += v[i%2][j];
		}

		ans += v[(i+1) % 2][0];
	}

	cout << ans << endl;
}


Measured memory_bytes: 3772
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!long);
    auto N = s[0];
    auto A = s[1];
    auto B = s[2];
    auto C = s[3];
    auto D = s[4];

    long lb = A - (N - 1) * D;
    long ub = A - (N - 1) * C;

    foreach (i; 0..N) {
        if (lb <= B && B <= ub) {
            "YES".writeln;
            return;
        }
        lb += C + D;
        ub += C + D;
        //writeln(i, " " , lb, " ", ub);
    }

    "NO".writeln;
}


Measured memory_bytes: 256
use std::io::{stdin, Stdin, BufRead};

fn main() {
    let stdin = stdin();
    let a_num = read(&stdin);
    let b_num = read(&stdin);
    let c_num = read(&stdin);
    let x_num = read(&stdin);
    assert_eq!(x_num % 50, 0);

    let mut pairs: Vec<(i32, i32, i32)> = Vec::new();

    // 500円硬貨から
    for a in 0..a_num + 1 {
        if a * 500 > x_num {
            continue;
        }

        for b in 0..b_num + 1 {
            if a * 500 + b * 100 > x_num {
                continue;
            }

            for c in 0..c_num + 1 {
                if a * 500 + b * 100 + c * 50 == x_num {
                    pairs.push((a, b, c));
                }
            }
        }
    }

    println!("{}", pairs.len());
}

fn read(stdin: &Stdin) -> i32 {
    let mut buf = String::new();
    stdin.lock().read_line(&mut buf).unwrap();
    buf.pop();
    buf.parse().unwrap()
}


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

using namespace std;

int A[500900];
int sum = 0;

void merge(int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1 + 1], R[n2 + 1];
    for(int i = 0; i < n1; i++){
        L[i] = A[left + i];
    }
    for(int i = 0; i < n2; i++){
        R[i] = A[mid + i];
    }
    L[n1] = 1010009000;
    R[n2] = 1100009000;
    int i = 0;
    int j = 0;
    for(int k = left; k < right; k++){
        sum ++;
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
}

int main(void){
    int n; cin >> n;
    for(int i = 0; i < n; i++) cin >> A[i];
    mergeSort(0, n);
    for(int i = 0; i < n-1; i++){
        cout << A[i] << " ";
    }
    cout << A[n-1] << endl <<  sum << endl;
    return 0;
}


Measured memory_bytes: 6988
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,x,v[nmax],tot,tot1,nr[nmax],i;
string y;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>m;
	while(m--)
	{
		cin>>x>>y;
		if(!v[x] && y=="WA")nr[x]++;
		else if(!v[x] && y=="AC")v[x]=1,tot++;
	}    
	for(i=1;i<=n;i++)if(v[i])tot1+=nr[i];
	cout<<tot<<" "<<tot1<<endl;                                                         
	return 0;
}


Measured memory_bytes: 1024
use strict;
use warnings;

my %n = (
    A => 10,
    B => 11,
    C => 12,
    D => 13,
    E => 14,
    F => 15,
);

my $s = <STDIN>;
chomp $s;
my ($a, $b) = split / /, $s;

if ($n{$a} < $n{$b}) {
    print '<';
} elsif ($n{$a} > $n{$b}) {
    print '>';
} else {
    print '=';
}


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

int main()
{
    int n(0);
    std::cin >> n;
    
    std::vector<long long> mons(n+1, 0);
    for(auto& v : mons){
        std::cin >> v;
    }
    
    std::vector<long long> human(n, 0);
    for(auto& v : human){
        std::cin >> v;
    }
    
    long long c(0);
    for(int i=0; i < n; ++i){
        auto n_hit = human[i];
        auto n_mons = mons[i];
        
        if(n_hit <= n_mons){
            c += n_hit;
            continue;
        }else{
            c += n_mons;
            n_hit -= n_mons;
        }
        
        n_mons = mons[i+1];
        if(n_hit <= n_mons){
            c += n_hit;
            mons[i+1] -= n_hit;
        }else{
            c += n_mons;
            mons[i+1] = 0;
        }
    }
    
    std::cout << c << std::endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
 
using namespace std;
 
int main(void)
{
    long long int n, k;
    cin >> n >> k;

    long long int new_n1, new_n2, best = n;
    while(true)
    {
        if (best == 0)
            break;

        new_n1 = abs(best - (best / k) * k);
        new_n2 = abs(best - (k / best) * k);
        if (best > min(new_n1, new_n2))
            best = min(new_n1, new_n2);
        else
            break;
    }

    cout << best << endl;

    return 0;
}

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

int main(void){
    int n,m;
    cin >> n;
    string s[n];
    map<string,int>mp;
    for(int i = 0;i < n;i++){
        cin >> s[i];
        mp[s[i]] += 1;
    }
    cin >> m;
    string t[m];
    for(int i = 0;i < m;i++){
        cin >> t[i];
        mp[t[i]] -= 1;
    }
    int max = 0;
    for(int i = 0;i < n;i++){
        if(max < mp[s[i]])max = mp[s[i]];
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    for i in range(3):
        if s[i] == s[i + 1]:
            print("Bad")
            return
    print("Good")
    return

#B
def B():
    n, l = LI()
    lis = [l + i for i in range(n)]
    s = sum(lis)
    a = inf
    for i in lis:
        if abs(a) > abs(i):
            a = i
    print(s-a)
    return

#C
def C():
    def gcd(a, b):
        a, b = max(a, b), min(a, b)
        while b:
            a, b = b, a % b
        return a
    def lcm(a, b):
        return a * b // gcd(a, b)
    a, b, c, d = LI()
    x = b // c - (a-1) // c
    y = b // d - (a-1) // d
    z = b // lcm(c , d) - (a-1) // lcm(c , d)
    print(b-a+1-(x+y-z))
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()


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

using namespace std;
typedef vector<int> vi;

vector< vector<vi> > dp(41, vector<vi>(401, vi(401, 10000)));
int a[40], b[40], c[40];

int main(void) {
  int n, ma, mb;
  cin >> n >> ma >> mb;

  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }

  for (int i = 0; i < n; i++) {
    dp[i][0][0] = 0;
    for (int j = 0; j <= 400; j++) {
      for (int k = 0; k <= 400; k++) {
        if (j >= a[i] && k >= b[i]) {
          dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
        } else {
          dp[i + 1][j][k] = dp[i][j][k];
        }
      }
    }
  }

  int ans = 10000;
  for (int i = 1; i * ma <= 400 && i * mb <= 400; i++) {
    ans = min(ans, dp[n][i * ma][i * mb]);
  }
  cout << (ans == 10000 ? -1 : ans) << endl;

  return 0;
}

Measured memory_bytes: 27264
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;


// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a + b >= 10) cout << "error" << endl;
  else cout << a + b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(void)
{
    int A,B,N;
    scanf("%d%d%d",&N,&A,&B);
    if(N==1)
    {
        if(A==B)
            printf("1\n");
        else
            printf("0\n");
    }
    else 
    {
        if(A>B)
            printf("0\n");
        else
            printf("%lld\n",(long long )(B-A)*(N-2)+1);
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int k = sc.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) {a[i] = sc.nextInt();}
		boolean res = false;

		int ansCount = n-k;
		long ans[] = new long[ansCount+1];

		//1つ目を計算
		ans[0] = a[0];
		for(int i=1; i<k; i++) {
			ans[0] *= a[i];
		}
		for(int i=1; i<=n-k; i++) {
/*			ans[i] = ans[i-1] / a[i-1] * a[i-1+k];*/
			if(a[i-1] < a[i-1+k]) {
				System.out.printf("Yes\n");
			} else {
				System.out.printf("No\n");
			}
		}


/*
		for(int i=0; i<n; i++) {
			if(i<=n-k) {
				ans[i] = a[i];
			}
			for(int back = 1; back < k; back++) {
				if((0 <= i-back) && (i-back <= n-k)) {
					ans[i-back] *= a[i];			}
				}
		}
*/
/*
		//n-k>=1
		for(int i=1; i<ansCount+1; i++) {
			if(ans[i] > ans[i-1]) {
				System.out.printf("Yes\n");
			} else {
				System.out.printf("No\n");
			}
		}
*/
	}
}


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

using namespace std;
using ll = long long;

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

	int n;
	cin >> n;
	vector<vector<pair<int, int>>> g(n);
	for (int i = 1; i < n; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		g[v].emplace_back(u, i - 1);
		g[u].emplace_back(v, i - 1);
	}

	int mx = 0;
	for (int i = 0; i < n; i++) {
		mx = max(mx, (int)g[i].size());
	}

	vector<int> ans(n - 1, -1);
	for (int i = 0; i < n; i++) {
		set<int> used;
		for (auto [j, num] : g[i]) {
			used.insert(ans[num]);
		}

		int free = 1;
		for (auto [j, num] : g[i]) {
			if (ans[num] != -1) {
				continue;
			}
			while (used.count(free)) {
				free++;
			}
			ans[num] = free++;
		}
	}

	cout << mx << '\n';
	for (auto el : ans) {
		cout << el << '\n';
	}
}

Measured memory_bytes: 9664
#include<stdio.h>
#define MAX 100

int n,t=0,math[MAX][MAX],ans1[MAX],ans2[MAX],tmp[MAX];
//DFS
void calc(int u){
  int i;
  tmp[u]=1;
  ans1[u]= ++t;
  for(i=0;i<n;i++) if(math[u][i]==1 &&tmp[i]==0)calc(i);
  tmp[u]=2;
  ans2[u]= ++t;
}

void set(int num){
    int i,j;
    for(i=0;i<num;i++){
        tmp[i]=0;
        for(j=0;j<num;j++)math[i][j]=0;
    } 
}

void input(int num){
    int i,j,v,k,w;
    for(i=0;i<num;i++){
        scanf("%d%d",&v,&k);
        for(j=0;j<k;j++){
          scanf("%d",&w);
          math[v-1][w-1]=1;
        }
    }
}

int main(){
  int i;
  
  scanf("%d",&n);
  
  set(n);
 
  input(n);
  //calc
  for(i=0;i<n;i++) if(tmp[i]==0) calc(i);
  //output
  for(i=0;i<n;i++) printf("%d %d %d\n",i+1,ans1[i],ans2[i]);
  
  return 0;
}


Measured memory_bytes: 2108
#include <stdio.h>
int a[105];
int main(){
	int n,i,flag=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
		if(a[i]%2==0){
			if(a[i]%3==0||a[i]%5==0)continue;
			else{
				flag=1;
				break;
			}
		}
	if(flag)printf("DENIED\n");
	else printf("APPROVED\n");
	return 0;
}

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

void Main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> frig(n); // friend group tree
    vector<int> numf(n); // number of friend
    vector<int> numb(n); // number of ban
    vector<int> numc(n); // size of group
    for (int i = 0; i < n; i++)
    {
        frig[i] = i;
    }
    
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        numf[a]++;
        numf[b]++;
        int p1 = a, p2 = b;
        while(frig[p1] != p1) p1 = frig[p1];
        while(frig[p2] != p2) p2 = frig[p2];
        frig[p1] = p2;
        frig[a] = p2;
        frig[b] = p2;
    }
    for (int i = 0; i < n; i++)
    {
        int p = i;
        while(frig[p] != p) p = frig[p];
        frig[i] = p;
        numc[p]++;
    }
  
    for (int i = 0; i < k; i++)
    {
        int c, d;
        cin >> c >> d;
        c--; d--;
        if(frig[c] == frig[d]){
            numb[c]++;
            numb[d]++;
        }
    }
    
    for (int i = 0; i < n; i++)
    {
        if(i != 0) cout << " ";
        cout << numc[frig[i]] - numf[i] - numb[i] - 1;
    }
    cout << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 4772
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
ans=B[A[0]-1]
for i in range(1,n):
  ans+=B[A[i]-1]
  if A[i]==A[i-1]+1:
    ans+=C[A[i-1]-1]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main()
{
    stack<int> si;
    string in;
    while (cin >> in) {
        if (in == "+") {
            int a = si.top(); si.pop();
            int b = si.top(); si.pop();
            si.push(a + b);
        } else if (in == "-") {
            int b = si.top(); si.pop();
            int a = si.top(); si.pop();
            si.push(a - b);
        } else if (in == "*") {
            int a = si.top(); si.pop();
            int b = si.top(); si.pop();
            si.push(a * b);
        } else {
            si.push(atoi(in.c_str()));
        }
    }
    cout << si.top() << endl;
    si.pop();

    return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100,mod=1e9+7;
ll seg[N*4];
void upd(ll nod,ll l,ll r,ll id,ll val){
    if (r-l==1){
        seg[nod]+=val;
        seg[nod]%=mod;
        return ;
    }
    ll mid=(r+l)/2;
    if (mid>id) upd(nod*2,l,mid,id,val);
    else upd(nod*2+1,mid,r,id,val);
    seg[nod]=seg[nod*2]+seg[nod*2+1];
    seg[nod]%=mod;
}
ll get(ll nod,ll l,ll r,ll L,ll R){
    if (l>=R || L>=r) return 0;
    if (l>=L && r<=R) return seg[nod];
    ll mid=(r+l)/2;
    return (get(nod*2,l,mid,L,R)+get(nod*2+1,mid,r,L,R))%mod;
}
ll a[N],b[N];
map <int,int> mp;
int32_t main(){
    ll n,m;
    cin >> n >> m;
    for (int i=1;i<=n;i++) cin >> a[i];
    for (int i=1;i<=m;i++) cin >> b[i];
    vector <pii> c;
    vector <int> w;
    for (int i=1;i<=n;i++){
        ll k=upper_bound(b+1,b+m+1,a[i])-b;
        if (k>m || k==1) continue;
        c.pb({a[i]-b[k-1],b[k]-a[i]});
        w.pb(b[k]-a[i]);
    }
    sort(w.begin(),w.end());
    for (int i=0;i<w.size();i++){
        mp[w[i]]=i+1;
    }
    for (int i=0;i<c.size();i++){
        c[i].S=mp[c[i].S];
    }
    sort(c.begin(),c.end());
    for (int i=0;i<c.size();i++){
        if (i>0 && c[i-1]==c[i]) continue;
       // cout << c[i].F << " " << c[i].S << endl;
        ll x=c[i].F,y=c[i].S;
        ll z=get(1,1,n+1,1,y);
        if (i>0 && c[i].F==c[i-1].F){
            z--;
            ll u=get(1,1,n+1,1,c[i-1].S);
            z-=u;
            z+=mod;
            z%=mod;
        }
        z++;
        upd(1,1,n+1,y,z);
    }
    cout << (seg[1]+1)%mod << endl;
}


Measured memory_bytes: 14604
#include<bits/stdc++.h>
using namespace std;
int arr[1200];
int main()
{
    int n,m;
    cin>>n>>m;
    int sum=0;
    for(int i=0;i<n;++i)
        cin>>arr[i],sum+=arr[i];
    int cnt=0;
    for(int i=0;i<n;++i)
    {
        if(arr[i]>=ceil(sum*1.0/4/m))
            ++cnt;
    }
    if(cnt>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

// 約数列挙
vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            ll j = N / i;
            if (j != i)  {
                res.push_back(j);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}

void Main() {
    ll N; cin >> N;
    ll ans = 0;
    rep(i, N){
        if ((i + 1) % 2 == 0){continue;}
        vector<ll> tmp = divisor(i + 1);
        if (tmp.size() == 8){ans++;}
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3652
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

# N = I()
N,X,T = LI()

ans = math.ceil(N/X) * T

print(ans)

Measured memory_bytes: 27164
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
 
typedef long long ll;
const int N=1e5+5;
const ll p=1000000007;
 
char s[1000000];
int l=3*N,r,op;
int main()
{
    scanf("%s",s+l);
    r=strlen(s+l)+l-1;
    int q;
    cin>>q;
    while(q--)
    {
        int t;
        scanf("%d",&t);
        if(t==1)
        {
            op^=1;
        }
        else
        {
            int f;
            scanf("%d",&f);
            char now[2];
            scanf("%s",now);
            if((f==1&&op==0)||(f==2&&op==1))
                s[--l]=now[0];
            else
                s[++r]=now[0];
        }
    }
    if(op)
        for(int i=r; i>=l; i--)
            printf("%c",s[i]);
    else
        printf("%s",s+l);
 
}

Measured memory_bytes: 896
import bisect
n,k=map(int,input().split())
x=list(map(int,input().split()))
idx = bisect.bisect_left(x,0)
now = max(0,idx-k)
mini =1e10
for i in range(now,n-k+1):
    if(x[i]*x[i+k-1]>=0):
        mini=min(max(abs(x[i]),abs(x[i+k-1])),mini)
        continue
    mini = min(mini,abs(x[i])+x[i+k-1]+min(abs(x[i]),x[i+k-1]))
print(mini)


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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


int main()
{
	fastio;
	ll a,b;
	cin>>a>>b;
	ll g = __gcd(a,b);
	cout<<(a*b)/g<<endl;
    return 0;
}





Measured memory_bytes: 3592
W,N = map(int,input().split())
 
table = [10000000]*(W+1)
 
table[0] = 0
 
coin_list = list(map(int,input().split()))
 
for coin in coin_list:
    for i in range(coin,W+1):
        table[i] = min(table[i],table[i-coin]+1)
 
 
print("%d"%(table[W]))


Measured memory_bytes: 7512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;


int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
	ll a, b, c, d;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	if (d % 2 == 0)printf("%lld\n", a - b);
	else printf("%lld\n", b - a);
}


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

constexpr int64_t dir[] = {2, 3, 5};
map<int64_t, int64_t> dp;
int main() {
	int t; cin >> t;
	while(t--) {
		dp.clear();
		int64_t n, a[3], d;
		cin >> n;
		for(int i = 0; i < 3; ++i) cin >> a[i];
		cin >> d;
		dp[n] = 0;
		priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>, greater<pair<int64_t, int64_t>>> pq;
		pq.emplace(0, n);
		while(not pq.empty()) {
			auto [cost, num] = pq.top();
			pq.pop();
			if(dp.count(num) and cost > dp[num]) continue;
			for(int64_t i = -5; i <= 5; ++i) {
				int64_t nxt = num + i;
				int64_t nc = cost + abs(i) * d;
				for(int j = 0; j < 3; ++j) {
					if(nxt % dir[j] != 0) continue;
					int64_t _nxt = nxt / dir[j];
					int64_t _nc = nc + a[j];
					if(not dp.count(_nxt) or _nc < dp[_nxt]) {
						dp[_nxt] = _nc;
						pq.emplace(_nc, _nxt);
					}
				}
			}
			constexpr int64_t INF = 1e18;
			if(num < INF / d) {
				int64_t _nxt = 0;
				int64_t _nc = cost + num * d;
				if(not dp.count(_nxt) or _nc < dp[_nxt]) {
					dp[_nxt] = _nc;
					pq.emplace(_nc, _nxt);
				}
			}
		}
		cout << dp[0] << '\n';
	}
	return 0;
}

Measured memory_bytes: 7284
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  rep(i,n)a[i]*=2;
  vector<ll> odds(n);
  vector<ll> evens(n);
  odds[1]=a[1];
  evens[0]=a[0];
  evens[1]=a[0];
  repeat(i,2,n) {
    if(i%2==0) {
      evens[i]=a[i]+evens[i-1];
      odds[i]=odds[i-1];
    } else {
      odds[i]=a[i]+odds[i-1];
      evens[i]=evens[i-1];
    }
  }
  ll s = accumulate(a.begin(),a.end(),0LL)/2;
  rep(i,n) {
    //cout << "i=" << i << endl;
    if(i%2==0) {
      ll ans=s;
      if(i-1>=0) {
	ans-=evens[i-1];
	//cout << "left evens=" << evens[i-1] << endl;
      }
      //cout << "right odds=" << (odds[n-1]-odds[i]) << endl;
      ans-=(odds[n-1]-odds[i]);
      cout << ans << " ";
      //      cout << endl;
    } else {
      ll ans=s;
      if(i-1>=0) {
	//	cout << "left odds=" << odds[i-1] << endl;
	ans-=odds[i-1];
      }
      //      cout << "right evens=" << (evens[n-1]-evens[i]) << endl;
      ans-=(evens[n-1]-evens[i]);
      cout << ans << " ";
      //      cout << endl;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3712
import sys
input = sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))
IJK = [0,0,0]
for i in range(N):
    IJK[a[i]-1]+=1

dp = [[[0.0]*(N+3) for _ in range(N+3)] for _ in range(N+3)]

for k in range(N+1):
    for j in range(N+1):
        for i in range(N+1):
            if i+j+k > N: continue
            if i+j+k == 0: continue
            tmp = 1.0*N
            if i>0: tmp += i*dp[i-1][j][k]*1.0
            if j>0: tmp += j*dp[i+1][j-1][k]*1.0
            if k>0: tmp += k*dp[i][j+1][k-1]*1.0
            dp[i][j][k] = tmp/(i+j+k)
print(dp[IJK[0]][IJK[1]][IJK[2]])




Measured memory_bytes: 260232
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<=n;i++)
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

class UnionFind{
    public:
    vector<int> Parent;

    UnionFind(int N){
        Parent = vector<int>(N,-1);
    }
    int root(int A){
        if(Parent[A]<0)return A;
        return Parent[A] = root(Parent[A]);
    }
    int size(int A){
        return -Parent[root(A)];
    }
    bool connect(int A, int B){
        A = root(A);
        B = root(B);
        if(A == B){
            return false;
        }
        if(size(A)<size(B)) swap(A,B);

        Parent[A] += Parent[B];
        Parent[B] = A;
        return true;
    }
};

int main(){
int N,M;
cin >> N >> M;
vector<int> A(M),B(M);
for(int i=0;i<M;i++){
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
}
vector<long long> ans(M);
ans[M-1] = (long long)N*(N-1)/2;
UnionFind Uni(N);

for(int i = M-1; i >= 1; i--){
    ans[i-1] = ans[i];
    if(Uni.root(A[i]) != Uni.root(B[i])){
        ans[i-1]  -= (long long)Uni.size(A[i])*Uni.size(B[i]);
        Uni.connect(A[i],B[i]); 
    }
}

for(int i = 0;i<M;i++){
    cout << ans[i] << endl;
}
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int N;
int A,B;
string s,t;
int ans;
int main(){
	cin >> s >> t;
	t.pop_back();
	if(s==t)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>

// data structure
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <vector>

#include <algorithm>
#include <cmath>

using namespace std;

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

  long long int sum = 0;

  for (long long int i = 1; i <= n; i++) {
    if (i % 3 == 0)
      continue;
    if (i % 5 == 0)
      continue;
    sum += i;
  }

  std::cout << sum << std::endl;

  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
long long d[60]={1};
long long p[60]={1};
long long f(long long n,long long m){
  long long s=0;
  if(m==0)return s;
  m--;
  if(m>=d[n-1]){
    s+=p[n-1];
    m-=d[n-1];
  }
  else return s+f(n-1,m);
  if(m==0)return s;
  m--;
  s++;
  if(m>=d[n-1]){
    s+=p[n-1];
    m-=d[n-1];
  }
  else return s+f(n-1,m);
  m--;
  return s;
}

int main(){
  long long n,m,i;
  scanf("%lld %lld",&n,&m);
  for(i=0;i<50;i++)d[i+1]=d[i]+d[i]+3;
  for(i=0;i<50;i++)p[i+1]=p[i]+p[i]+1;
  printf("%lld\n",f(n,m));
  return 0;
}


Measured memory_bytes: 128
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn reads<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().split(' ').map(|x| x.parse().unwrap()).collect()
}

use std::collections::VecDeque;

fn main() {
    let nm = reads();
    let mut xs = vec![vec![]; nm[0]];

    for _ in 0..nm[1] {
        let lrd: Vec<usize> = reads();

        let l = lrd[0] - 1;
        let r = lrd[1] - 1;
        let d = lrd[2] as i64;

        xs[l].push((r, d));
        xs[r].push((l, -d));
    }

    let mut res = true;
    let mut bs = vec![true; nm[0]];
    let mut vs = vec![0i64; nm[0]];
    let mut q = VecDeque::new();

    'outer:
    for idx in 0..nm[0] {
        if bs[idx] {
            bs[idx] = false;
            q.push_back(idx);

            while let Some(i) = q.pop_front() {
                for &(j, d) in &xs[i] {
                    if bs[j] {
                        vs[j] = vs[i] + d;
                        bs[j] = false;
                        q.push_back(j); 
                    }
                    else {
                        res = vs[j] == vs[i] + d;
                        if !res {
                            break 'outer;
                        }
                    }
                }
            }
        }
    }

    println!("{}",
    if res {
        "Yes"
    }
    else {
        "No"
    });
}

Measured memory_bytes: 18684
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <algorithm>
#include <vector>
using namespace std;
using llong = long long;

//===
template<class OperatorMonoid,
         class Merge = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)> >
struct DualSegmentTree {
    int sz, height;
    const OperatorMonoid e;
    const Merge merge_operator;
    vector<OperatorMonoid> lazy;
 
    DualSegmentTree(OperatorMonoid e, const Merge &h):
        e(e), merge_operator(h) {};
    void init(int nmemb) {
        sz = nmemb;
        lazy.assign(sz << 1, e);

        height = -1;
        while (nmemb) nmemb >>= 1, height++;
    };
 
    inline void propagate(int k) {
        if (k >= sz || lazy[k] == e) return;
        lazy[(k << 1) | 0] = merge_operator(lazy[(k << 1) | 0], lazy[k]);
        lazy[(k << 1) | 1] = merge_operator(lazy[(k << 1) | 1], lazy[k]);
        lazy[k] = e;
    };
    void push_down(int k) {
        for (int i = height; i > 0; i--) {
            propagate(k >> i);
        }
    };
 
    // [l, r)
    void update(int l, int r, OperatorMonoid op) {
        l += sz; r += sz;
        push_down(l);
        push_down(r - 1);
         
        while (l < r) {
            if (l & 1) lazy[l] = merge_operator(lazy[l], op), l++;
            if (r & 1) --r, lazy[r] = merge_operator(lazy[r], op);
 
            l >>= 1;
            r >>= 1;
        }
    };
 
    OperatorMonoid operator [] (int k) {
        k += sz;
        push_down(k);
        return lazy[k];
    };
};
//===

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

    auto f = [](auto l, auto r){return l + r;};
    //DualSegmentTree<llong> dst(0, [](auto l, auto r){ return l + r; });
    DualSegmentTree<llong, decltype(f)> dst(0, f);
    llong n, q;
    llong com, s, t, x;

    cin >> n >> q;
    dst.init(n);

    while (q--) {
        cin >> com;

        if (com == 0) {
            cin >> s >> t >> x;

            s--;
            dst.update(s, t, x);
        }
        else if (com == 1) {
            cin >> x;

            x--;
            cout << dst[x] << '\n';
        }
    }

    return 0;
}

int main() {
    return AOJ_DSL_2_E();
}



Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    string s;
    cin >> s;
    string s2 = s + s;
    string tmp = s;
    ll k;cin >> k;
    ll cnt = 0;
    rep(i,s.size()-1) if(s[i]==s[i+1]){cnt++; s[i+1] = '#';}
    ll cnt2 = 0;
    rep(i,s2.size()-1) if(s2[i]==s2[i+1]){cnt2++;s2[i+1] = '#';}
    ll sa = cnt2 - 2*cnt;
    ll ans = cnt * k + sa * (k-1);
    string t = string(tmp.size(),tmp[0]);
    if(tmp == t){
        ans = s.size() * k /2;
    }
    if(s.size()==1){
        ans = k/2;
    }
    cout << ans << endl;
}

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

int main(){
        int n,q,i,idx,a,b;
        cin >> n >> q;
        vector<int> p(n);
        vector<int> par(n);
        vector<bool> done(n);
        vector<vector<int>> node(n);
        queue<int> qu;
        for(i=0;i<n-1;++i){
                cin >> a >> b;
                --a; --b;
                node.at(a).push_back(b);
                node.at(b).push_back(a);
        }
        for(i=0;i<q;++i){
                cin >> a >> b;
                --a;
                p.at(a) += b;
        }
        qu.push(0);
        while(!qu.empty()){
                idx = qu.front(); qu.pop();
                done.at(idx) = true;
                if(idx!=0) p.at(idx) += p.at(par.at(idx));
                for(auto e : node.at(idx)){
                        if(!done.at(e)){
                                par.at(e) = idx;
                                qu.push(e);
                        }
                }
        }
        for(i=0;i<n;++i) cout << p.at(i) << " ";
        cout << endl;
        return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int H, W,h,w;
	cin >> H >> W;
	cin >> h >> w;
	int res = H * W;
	res -= W * h;
	res -= H * w;
	res += w * h;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
class Player:

    def __init__(self, id, score):
        self.id = id
        self.score = score

    def __lt__(self, other):
        return float(self.score) < float(other.score)

    def print(self):
        print(self.id, self.score)

g1 = []
for l in range(8):
    p,t = input().split()
    g1.append(Player(p, t))

g2 = []
for l in range(8):
    p,t = input().split()
    g2.append(Player(p,t))

g3 = []
for l in range(8):
    p,t = input().split()
    g3.append(Player(p,t))

g1.sort()
g2.sort()
g3.sort()

g4 = []
g4.append(g1[2])
g4.append(g2[2])
g4.append(g3[2])
g4.sort()

g1[0].print()
g1[1].print()
g2[0].print()
g2[1].print()
g3[0].print()
g3[1].print()
g4[0].print()
g4[1].print()



Measured memory_bytes: 5580
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int L;
int64 dp[MAXN][6],A[MAXN];
void Solve() {
	read(L);
	for(int i = 1 ; i <= L ; ++i) {read(A[i]);}
	for(int i = 1 ; i <= 4 ; ++i) dp[0][i] = 1e16;
	dp[0][0] = 0;
	for(int i = 1 ; i <= L ; ++i) {
		dp[i][0] = dp[i - 1][0] + A[i];
		int t = A[i] & 1;
		dp[i][1] = min(dp[i - 1][1],dp[i - 1][0]);

		dp[i][2] = min(min(dp[i - 1][1],dp[i - 1][0]),dp[i - 1][2]);
		if(A[i] % 2 == 0) dp[i][2]++;
		dp[i][3] = min(dp[i - 1][2],dp[i - 1][3]);
		if(A[i] & 1) {dp[i][1]++;dp[i][3]++;}
		if(A[i] == 0) {dp[i][1] += 2;dp[i][3] += 2;}
		dp[i][4] = min(min(dp[i - 1][3],dp[i - 1][2]),min(dp[i - 1][1],dp[i - 1][4]));
		dp[i][4] += A[i];
	}
	int64 res = dp[L][0];
	for(int i = 1 ; i <= 4 ; ++i) res = min(res,dp[L][i]);
	out(res);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


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

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

  string A[36];
  for(int i=0;i<n;i++) cin>>A[i];
  string C[36];
  for(int i=0;i<n;i++) C[i]=A[i];
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(C[j][1]<C[j-1][1]){
	swap(C[j],C[j-1]);
      }
    }
  }

  string x[10],y[10];
  for(int i=0;i<n;i++){
    x[A[i][1]-'0']+=A[i][0];
    y[C[i][1]-'0']+=C[i][0];
  }
  ans=1;
  for(int i=0;i<10;i++) ans&=x[i]==y[i]; 
  for(int i=0;i<n;i++) cout<<C[i]<<" \n"[i==n-1];
  cout<<(ans?"Stable":"Not stable")<<endl;
  
  for(int i=0;i<n;i++) C[i]=A[i];
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(C[j][1]<C[minj][1]){
	minj=j;
      }
    }
    if(i!=minj) swap(C[i],C[minj]);
  }
  
  for(int i=0;i<10;i++) x[i]=y[i]="";
  for(int i=0;i<n;i++){
    x[A[i][1]-'0']+=A[i][0];
    y[C[i][1]-'0']+=C[i][0];
  }
  ans=1;
  for(int i=0;i<10;i++) ans&=x[i]==y[i]; 
  for(int i=0;i<n;i++) cout<<C[i]<<" \n"[i==n-1];
  cout<<(ans?"Stable":"Not stable")<<endl;
  
  return 0;
}



Measured memory_bytes: 3184
import itertools

N, K = map(int, input().split())
d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

A = list(itertools.chain.from_iterable(A))
ans = 0
for i in range(1, N + 1):
    if i in A:
        continue
    else:
        ans += 1

print(ans)

Measured memory_bytes: 9180
#include <cstdio>

int main(void) {
    int ind[3];
    for(int i=0 ; i<3 ; i++) {
        scanf("%d", &ind[i]);
    }
    if(ind[0]!=ind[1] && ind[1]!=ind[2] && ind[0]!=ind[2])
        printf("3");
    else if(ind[0]==ind[1] && ind[1]==ind[2])
        printf("1");
    else
        printf("2");
    printf("\n");
    return 0;
}


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

int main()
{
    long long X;
    cin >> X;
    int t = 0;
    while (1)
    {
        t++;
        if (X <= t * (t + 1) / 2)
            break;
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256