akhauriyash/Code-Regression huggingface dataset:
"""
20個しかないので包除原理？
使う、使わないで 2**20通り

答え = 2**N - 1満たさない + 2つ満たさない - 3つ満たさない…
で表される

各場合はいずれかのパスに属す点以外は自由に塗れる
各パス上の点をbitで管理
黒に塗ってはいけない点のかずをあぶりだす

計算量は 2**20

"""
from collections import deque

N = int(input())

dic = {}

for i in range(N-1):

    a,b = map(int,input().split())
    a -= 1
    b -= 1
    c = N+i

    if a not in dic:
        dic[a] = []
    if b not in dic:
        dic[b] = []
    dic[c] = []

    dic[a].append(c)
    dic[b].append(c)
    dic[c].append(a)
    dic[c].append(b)

M = int(input())
bitlis = []

for loop in range(M):

    u,v = map(int,input().split())
    u -= 1
    v -= 1
    
    bits = [0] * N + [2**i for i in range(N-1)]
    dis = [float("inf")] * (2*N-1)
    dis[u] = 0

    q = deque([u])

    while len(q) > 0:

        now = q.popleft()

        for nex in dic[now]:
            if dis[nex] > dis[now] + 1:
                dis[nex] = dis[now] + 1
                bits[nex] += bits[now]
                q.append(nex)

    bitlis.append(bits[v])

#print (bitlis)
uselis = [0] * (M+1)

for use in range(2**M):

    white = 0
    usenum = 0
    for i in range(M):
        if use & (2**i) > 0:
            white |= bitlis[i]
            usenum += 1

    able = N-1
    ws = format(white,"b")
    for i in ws:
        if i == "1":
            able -= 1

    uselis[usenum] += 2 ** able

#print (uselis)
ans = 2 ** (N-1)

for i in range(M):

    i += 1

    if i % 2 == 1:
        ans -= uselis[i]
    else:
        ans += uselis[i]

print (ans)
    


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

using namespace std;

int main(){
	int n;
	string name;
	string board;
	int count = 0;
	cin >> n >> name;

	for (int i = 0; i < n; i++){
		cin >> board;
		bool x = 0;
		for (int j = 0; j < board.size() && !x ; j++){
			if (name[0] == board[j]){
				for (int k = j + 1; k < board.size() && !x; k++){
					if (board[k] == name[1]){
						for (int l = 0, m = j; !x && m < board.size(); l++, m += k - j){
							if (name[l] != board[m]) break;
							if (l == name.size() - 1) x = 1;
						}
					}
				}
				if (x) count++;
			}
		}
	}
	
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n, i, j;
	cin >> n;
	int h[n];
	roop(i, n) {
		cin >> h[i];
	}
	if (n == 1) {
		cout << "Yes" << endl;
		return 0;
	} else if (n == 2) {
		if (h[0] < h[1] || h[0] == h[1]) {
			cout << "Yes" << endl;
		} else if ((h[0] - h[1]) == 1) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	for (i = n - 2; i > -1; i--) {
		if (h[i] < h[i + 1] || h[i] == h[i + 1]) {

		} else if ((h[i] - h[i + 1]) == 1) {
			h[i]--;
		} else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 640
package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
)

type Pizza struct {
	price int
	n     int
}

func main() {
	defer writer.Flush()
	var a, b, c, x, y, ans int
	fmt.Fscanf(reader, "%d %d %d %d %d\n", &a, &b, &c, &x, &y)
	pizzaA := Pizza{price: a, n: x}
	pizzaB := Pizza{price: b, n: y}
	pizzaC := Pizza{price: c, n: 0}
	if (pizzaA.price+pizzaB.price)/2 < pizzaC.price {
		ans += pizzaA.n*pizzaA.price + pizzaB.n*pizzaB.price
	} else {
		if pizzaA.n < pizzaB.n {
			ans += pizzaA.n * 2 * pizzaC.price
			pizzaB.n -= pizzaA.n
			if pizzaB.n*pizzaB.price < pizzaB.n*2*pizzaC.price {
				ans += pizzaB.n * pizzaB.price
			} else {
				ans += pizzaB.n * 2 * pizzaC.price
			}
		} else {
			ans += pizzaB.n * 2 * pizzaC.price
			pizzaA.n -= pizzaB.n
			if pizzaA.n*pizzaA.price < pizzaA.n*2*pizzaC.price {
				ans += pizzaA.n * pizzaA.price
			} else {
				ans += pizzaA.n * 2 * pizzaC.price
			}
		}
	}
	fmt.Fprintln(writer, ans)
}


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

using namespace std;

int main(){
	int n, m;
	bool infect[20001];
	pair< int,pair<int,int> > packet[20000];
	while(cin >> n >> m, n){
		memset(infect, false, sizeof(infect));
		infect[1] = true;
		for(int i=0;i<m;i++){
			int t, s, d;
			scanf("%d %d %d", &t, &s, &d);
			packet[i] = make_pair(t,make_pair(s,d));
		}
		sort(packet,packet+m);
		for(int i=0;i<m;i++){
			int s = packet[i].second.first;
			int d = packet[i].second.second;
			if(infect[s]) infect[d] = true;
		}
		int ans = 0;
		for(int i=1;i<=n;i++) ans += infect[i];
		cout << ans << endl;
	}
}

Measured memory_bytes: 1164
#include<iostream>

using namespace std;

int main(){
  int N;
  int x[55],y[55];
  cin >> N;
  int i,j,k,m;
  for(i=0;i<=N-1;i++)
    cin >> x[i] >> y[i];
  int X[55][55];
  int Y[55][55];
  int count[55][55] = {0};
  if(N==1) cout << 1 << endl;
  else{
  for(i=0;i<=N-1;i++)
    for(j=0;j<=N-1;j++){
      X[i][j] = x[i]- x[j];
      Y[i][j] = y[i]- y[j];
      }
  for(i=0;i<=N-1;i++)
    for(j=0;j<=N-1;j++)
      for(k=0;k<=N-1;k++)
        for(m=0;m<=N-1;m++)
          if(X[i][j]==X[k][m] && Y[i][j]==Y[k][m])
            count[i][j]++;
  for(i=0;i<=N-1;i++)
    count[i][i] = 0;
  for(i=0;i<=N-1;i++)
    for(j=0;j<=N-1;j++){
      count[i][j]--;
    }
  int max = 0;
  for(i=0;i<=N-1;i++)
    for(j=0;j<=N-1;j++)
      if(max < count[i][j]) max = count[i][j];
  max++;
  cout << N - max << endl;
  }
}

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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  ll p, q;
  cin >> p >> q;
  vector<int> factor;
  q = q / __gcd(p, q);
  for(int x = 2; x*x <= q; x++) {
    if(q % x == 0) {
      factor.push_back(x);
      while(q % x == 0) q /= x;
    }
  }
  if(q != 1) factor.push_back(q);
  ll ans = 1;
  rep(i, factor.size()) ans *= factor[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int q;
    cin >> q;
    bool prime[100001] = {false};
    int sum[100002] = {0};
    repi(i, 100000 + 1, 2)
    {
        if (!prime[i])
        {
            for (int j = i + i; j <= 100000; j += i)
            {
                prime[j] = true;
            }
        }
    }
    for (int i = 3; i <= 100000; i += 2)
    {
        if (!prime[i] && !prime[(i + 1) / 2])
            sum[i]++;
    }
    repi(i, 100000 + 1, 3)
    {
        sum[i + 1] += sum[i];
    }
    repi(ri, q, 0)
    {
        int r,l;
        cin >> l >> r;
        cout << sum[r] - sum[l - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1152
package main

import ( "fmt" )

func main() {
  var a int
  var b int
  var c int

  fmt.Scanf("%d %d %d", &a, &b, &c)

  if (a < b) && (b < c) {
    fmt.Printf("Yes\n")
  } else {
    fmt.Printf("No\n")
  }

}


Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
//typedef __int64 LL;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;

LL INF=100000000000000;
int main(){
	LL n;cin>>n;
	LL ans=INF;
	for(LL i=1;i*i<=n;i++)
	{
		if(n%i==0)ans=min(ans,i+n/i);
	}	
	cout<<ans-2<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;
	if ((a % 3 == 0) || (b % 3 == 0) || (a + b) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader

fun main() {
    val br = System.`in`.bufferedReader()
    val s = br.readLine()
    val t = br.readLine()
    var ct = 0
    for (i in s.indices) {
        if (s[i] != t[i]) {
            ct++
        }
    }
    print(ct)
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val NL_INT = '\n'.toInt()

private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }

    while (read <= SPACE_INT && read != -1 && read != NL_INT) {
        mark(1)
        read = read()
    }
    if (read > SPACE_INT) {
        reset()
    }
    return if (neg) -ret else ret
}

Measured memory_bytes: 38156
import sys
n,m,X,Y = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z=[]
for i in range(-100,101):
    if X < i <= Y:
        z.append(i)
for i in range(len(z)):
    if max(x) < z[i] <= min(y):
        print("No War")
        sys.exit()
print("War")

Measured memory_bytes: 3064
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
B = [[0 for _ in range(3)] for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                B[i][j] = 1
flag = 0
for i in range(3):
    if sum(B[i])==3:
        flag = 1
        break
for j in range(3):
    cnt = 0
    for i in range(3):
        cnt += B[i][j]
    if cnt==3:
        flag = 1
        break
if B[0][0]+B[1][1]+B[2][2]==3:
    flag = 1
if B[2][0]+B[1][1]+B[0][2]==3:
    flag = 1
if flag==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62172
#include<stdio.h>
#define MAX 500000
#define SENTINEL 2000000000
int L[MAX/2+2],R[MAX/2+2];
int cnt;
void merge(int A[],int n,int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      A[k]=L[i++];
    }
    else{
      A[k]=R[j++];
    }
  }
}
void mergeSort(int A[],int n, int left,int right){
  if(left+1 < right){
    int mid;
    mid=(left + right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}
int main(){
  int A[MAX],n,i;
  cnt=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,n,0,n);
  for(i=0;i<n;i++){
    if(i){
      printf(" ");
    }
    printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}

Measured memory_bytes: 4508
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  map<int,int> pos;
  rep(i,N){
    cin >> A[i];
    pos[A[i]] = i;
  }
  sort(A.begin(),A.end());
  int ans = 0;
  rep(i,N){
    if(i%2 != pos[A[i]]%2){
      ans++;
    }
  }
  cout << ans/2 << endl;
  return 0;
}

Measured memory_bytes: 5376
QQ = <<-EOS
1x1=1
1x2=2
1x3=3
1x4=4
1x5=5
1x6=6
1x7=7
1x8=8
1x9=9
2x1=2
2x2=4
2x3=6
2x4=8
2x5=10
2x6=12
2x7=14
2x8=16
2x9=18
3x1=3
3x2=6
3x3=9
3x4=12
3x5=15
3x6=18
3x7=21
3x8=24
3x9=27
4x1=4
4x2=8
4x3=12
4x4=16
4x5=20
4x6=24
4x7=28
4x8=32
4x9=36
5x1=5
5x2=10
5x3=15
5x4=20
5x5=25
5x6=30
5x7=35
5x8=40
5x9=45
6x1=6
6x2=12
6x3=18
6x4=24
6x5=30
6x6=36
6x7=42
6x8=48
6x9=54
7x1=7
7x2=14
7x3=21
7x4=28
7x5=35
7x6=42
7x7=49
7x8=56
7x9=63
8x1=8
8x2=16
8x3=24
8x4=32
8x5=40
8x6=48
8x7=56
8x8=64
8x9=72
9x1=9
9x2=18
9x3=27
9x4=36
9x5=45
9x6=54
9x7=63
9x8=72
9x9=81
EOS

puts QQ

Measured memory_bytes: 8616
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <fstream>
#include <cstring>

using namespace std;

int arr[21];
vector <int> v;
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, t;

	arr[0] = 0;
	
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> t;
		arr[i + 1] = max(arr[i], t);
		v.push_back(t);
	}

	int res = 0;
	for (int i = 0; i < n; i++)
	{
		if (arr[i] <= v[i])
		{
			res++;
		}
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool mp[10005][4];

int main(){
  ios_base::sync_with_stdio(false);
  int h,n,x,y;
  for(int i=0;i<10005;i++){
    for(int j=0;j<4;j++){
      mp[i][j] = true;
    }
  }
  cin >> h >> n;
  
  for(int i=0;i<n;i++){
    cin >> x >> y;
    mp[y][x] = false;
  }

  int ans = 0;
  for(int i=0;i<h-1;i++){
    if(mp[i][0] && mp[i][1] && mp[i+1][0] && mp[i+1][1]){ //左に正方形が作れるとき
      mp[i][0] = mp[i][1] = mp[i+1][0] = mp[i+1][1] = false;
      ans++;
    }
    if(mp[i][2] && mp[i][3] && mp[i+1][2] && mp[i+1][3]){ //右に正方形が作れるとき
      mp[i][2] = mp[i][3] = mp[i+1][2] = mp[i+1][3] = false;
      ans++;
    }
    if(mp[i][1] && mp[i][2] && mp[i+1][1] && mp[i+1][2]){ //真ん中に正方形が作れるとき
      int j=0;
      while(i+1+j < h && mp[i+1+j][0] && mp[i+1+j][1] && mp[i+1+j][2] && mp[i+1+j][3]) j++;
      if(j == 0 || j%2 == 1){
	mp[i][1] = mp[i][2] = mp[i+1][1] = mp[i+1][2] = false;
	ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3228
main = do
  [n, m] <- map read . words <$> getLine
  as <- map read . words <$> getLine
  if solve n m as
    then putStrLn "Yes"
    else putStrLn "No"

solve n m as = let sa = sum as in sum [ 1 | a <- as, 4 * m * a >= sa ] >= m


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


int N;

int main(){
	cin >> N;
	int M[100][100]={0};
	int t,a,k;
	for(int i=0;i<N;i++){
		cin >> t >> k;
		t--;
		for(int j=0;j<k;j++){
			cin >> a;
			a--;
			M[t][a] = 1;
		}
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if (j) cout << " ";
			cout << M[i][j];
		}
		cout << endl;
	}
}



Measured memory_bytes: 3144
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(n):
  s = input().rstrip()
  if s == "AC":
    ac += 1
  elif s == "WA":
    wa += 1
  elif s == "TLE":
    tle += 1
  elif s == "RE":
    re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))


Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll k, n; cin >> k >> n;
    vll a(n); rep(i, n) cin >> a[i];
    a.insert(a.begin(), a[n - 1] - k);
    ll mn = 0;
    rep(i, n) {
        mn = max(mn, a[i + 1] - a[i]);
    }
    cout << k - mn << endl;
    return 0;
}

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

using namespace std;

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

	string S;

	cin >> S;

	int y, m, d;

	y = stoi(S.substr(0, 4));
	m = stoi(S.substr(5, 2));
	d = stoi(S.substr(8, 2));

	int result = y * 10000 + m * 100 + d;

	if (result <= 20190430)
		cout << "Heisei";
	else
		cout << "TBD";
}

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

using namespace std;

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

	long long sum = 0;
	long long streak = 0;
	for (int i = 0; i < n; i++) {
		if (a[i]) {
			streak += a[i];
		} else {
			sum += streak / 2;
			streak = 0;
		}
	}
	sum += streak / 2;
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 640
<?php
function inputData(){
	return explode(" ", trim(fgets(STDIN)));
}
$input = inputData();
$W = $input[0];
$H = $input[1];
$N = $input[2];
$H0 = 0;
$W0 = 0;
for($i = 0; $i < $N; $i++){
	$input = inputData();
	switch($input[2]){
		case 1:
			if($W0 < $input[0]) $W0 = $input[0];
			break;
		case 2:
			if($input[0] < $W) $W = $input[0];
			break;
		case 3:
			if($H0 < $input[1]) $H0 = $input[1];
			break;
		case 4:
			if($input[1] < $H) $H = $input[1];
			break;
		default:
	}
}
if(($H - $H0) < 0 or ($W - $W0) < 0) echo 0;
else echo ($H - $H0) * ($W - $W0);
?>

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int X,Y,Z;
    cin>>X>>Y>>Z;
    int ans = 0;
    for (int i=0;i<=X;i++) {
        if (i*Y+(i+1)*Z <= X) ans = i;
        else break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int a, b;
  std::cin >> a >> b;
  if (a < b) {
    std::cout << "a < b" << "\n";
  } else if (a > b) {
    std::cout << "a > b" << "\n";
  } else {
    std::cout << "a == b" << "\n";
  }
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
int main(){
  long n,a,b,x,y,r=0;
  cin>>n>>a>>b>>y;
  for(int i=1;i<n;++i){
    x=y;
    cin>>y;
    r+=min(a*(y-x),b);
  }
  cout<<r;
  return 0;
}

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

using namespace std;

int main()
{
  vector<int> n(3);

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

  sort(n.begin(), n.end());
  n.erase(unique(n.begin(), n.end()), n.end());

  printf("%d", n.size());
}

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

using namespace std;

int main(void){
    int N = 0;
    cin >> N ;
    char S[N] = {0};
    for(int i =0;i < N;i++)cin >> S[i];
    int cnt = 0,cnt2 = 0;
    for(int i = 0;i < (N - 2); i++){
        if(S[cnt] == 'A' && S[cnt + 1] == 'B' && S[cnt + 2] == 'C') cnt2++;
        cnt ++;
    }
    cout << cnt2;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <unordered_set>

using namespace std;

int main() {
	int x, n;
	cin >> x >> n;
	map<int, int> diff;
	unordered_set<int> vals;
	vector<int> arr(n);
	for (auto& ele : arr) {
		cin >> ele;
		vals.insert(ele);
		diff.emplace(abs(ele - x), ele);
	}
	int smallest = -1;
	int i = 0;

	for (auto& dif : diff) {
		if (vals.count(x - i) == 0 || vals.count(x + i) == 0)
			break;
		i++;
	}
	// cout << " i : " << i << endl;
	if (vals.count(x - i) == 0)
		cout << x - i << endl;
	else
		cout << x + i << endl;
	return 0;
}

Measured memory_bytes: 3272
#include <iostream>
#include <vector>
#include <algorithm>

int main(int argc, char **argv)
{
    int N, M;
    std::cin >> N >> M;

    int b = 1;
    int e = N;
    bool flag = false;
    for(int i = 0; i < M; i++){
        std::cout << b << " " << e << std::endl;
        b += 1;
        e -= 1;
        if((N % 2 == 0) && ((e - b) <= (N / 2)) && !flag){
            e -= 1;
            flag = true;
        }
    }

    /*
    std::vector<std::pair<int,int>> ans;
    if(N%2){
        for(int l = 1, r = N-1; l < r; l++, r--){
            ans.emplace_back(l, r);
        }
    }else{
        bool flag = false;
        for(int l = 1, r = N-1; l < r; l++, r--){
            if(!flag && r-l <= N/2){
                --r;
                flag = true;
            }
            ans.emplace_back(l, r);
        }
    }
    for(int i = 0; i < M; i++){
        std::cout << ans.at(i).first << " " << ans.at(i).second << std::endl;
    }
    return 0;
    */
}


Measured memory_bytes: 3604
import sys
from collections import defaultdict as dd
from bisect import bisect_left as bl
input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
res = 0
cs = [0] * (N + 1)
d = dd(list)
d[0].append(0)
for i in range(N):
  cs[i + 1] = cs[i] + A[i] - 1
  cs[i + 1] %= K
  d[cs[i + 1]].append(i + 1)
for i in range(N):
  x = bl(d[cs[i]], i) + 1
  y = bl(d[cs[i]], i + K)
  res += y - x
  #print(x, y, i)
  #print(res)
print(res)

Measured memory_bytes: 118736
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)					// repeat
#define repr(i, begin, end) for (ll i = begin - 1; end <= i; i--)		// repeat reverse

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif


int main(void)
{
	ll n; cin >> n;
	vector<ll> w(n);
	rep(i, 0, n)
		cin >> w[i];

	ll l = w[0];
	ll r = 0;
	rep(i, 1, n)
		r += w[i];

	ll ans = abs(l - r);
	rep(i, 1, n - 1)
	{
		l += w[i];
		r -= w[i];
		ans = min(ans, abs(l - r));
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define all(a)                      a.begin(), a.end()
#define pb                          push_back
#define ll							long long
#define index(a)            		order_of_key(a)
#define value(a)					find_by_order(a)
#define count_1 					__builtin_popcount
#define mod(x, m)					((((x) % (m)) + (m)) % (m))
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll dp[100005],h[100005];
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout<<setprecision(12);
	
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>h[i];
	dp[0]=INT_MAX;
	
	for(int i=2;i<=n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

int N;
int M;
int p;
int d[10010];
int ans = 0;

int main()
{
	cin >> N >> M >> p;

	for (int i = 0; i < M; i++)
	{
		cin >> d[i];

		d[i] -= p;
		
		if (d[i] < 0)d[i] += N;
	}

	sort(&d[0], &d[M]);

	ans = d[M-1] *100;

	ans = min(ans, ((N - d[0]) * 100));

	for (int i = 0; i < M - 1; i++)
	{
		int c1 = 2 * (d[i] * 100);
		int c2 = ((N - d[i + 1]) * 100);

		ans = min(ans, c1 + c2);
	}

	for (int i = M - 1; i > 0; i--)
	{
		int c1 = 2 * ((N - d[i]) * 100);
		int c2 = (d[i - 1] * 100);

		ans = min(ans, c1 + c2);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main() {
       long long n,z=1;
       cin>>n;
       for(int i=1;i<=n;i++){
              z*=i;
              z%=1000000007;


       }

	cout<<z;
    return 0;
    }




Measured memory_bytes: 3128
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
#define mod 1000000007;

int main (void){
	int a,b,x;
	cin >> a >> b >> x;
	if(a<=x&&a+b>=x) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	resolve(parseProblem(os.Stdin))
}

func parseProblem(r io.Reader) int {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	return scanInt(sc)
}

func resolve(n int) {
	// n/1.08 <= i < (n+1)/1.08: =>  ceil(n/1.08) <= i <= floor((n+1)/1.08)
	for i := int((100*float64(n) + 107) / 108); i <= int((float64(n)+1)/1.08); i++ {
		if int(float64(i)*1.08) != n {
			continue
		}
		fmt.Println(i)
		return
	}
	fmt.Println(":(")
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char str[1010];
char out[110][60];
int main(){
	int a,b,c,d;
	while(scanf("%d",&a),a){
		scanf("%d%d%d",&b,&c,&d);
		gets(str);
		int now=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<c*b+d*(b-1);j++)out[i][j]='.';
			out[i][c*b+d*(b-1)]=0;
		}
		while(1){
			gets(str);
			if(str[0]=='?')break;
			int len=strlen(str);
			//printf("%s\n",str);
			int at=0;
			for(int i=0;i<len;i++){
				out[now%a][at+(now/a)*(c+d)]=str[i];
				at++;
				if(at==c){
					at=0;now++;
					if(now==a*b){
						now=0;
						for(int j=0;j<a;j++)printf("%s\n",out[j]);printf("#\n");
						for(int j=0;j<a;j++)for(int k=0;k<c*b+d*(b-1);k++)out[j][k]='.';
					}
				}
			}
			if(len==0||at){
				now++;
				if(now==a*b){
					now=0;
					for(int i=0;i<a;i++)printf("%s\n",out[i]);printf("#\n");
					for(int j=0;j<a;j++)for(int k=0;k<c*b+d*(b-1);k++)out[j][k]='.';
				}
			}
		}
		if(now){	
			for(int i=0;i<a;i++)printf("%s\n",out[i]);
			printf("#\n");
		}printf("?\n");
	}
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProjectContest
{
    class Test
    {
        static void Main()
        {
            const int mod = 1000000007;
            var nm = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
            int n = nm[0], m = nm[1];
            var F = new int[n + 1];
            F[0] = F[1] = 1;
            var a = new int[m+1];
            for (int i = 0; i < m; i++) a[i] = Convert.ToInt32(Console.ReadLine());
            a[m] = 0;
            int count = 0;
            if (a[0] == 1) { F[1] = 0; count = 1; }
            for (int i = 2; i < n + 1; i++)
            {
                if ( i == a[count]) { F[i] = 0; count++; }
                else
                {
                    F[i] = (F[i - 1] + F[i - 2]) % mod;
                }
            }
            Console.WriteLine(F[n]);
        }

    }
}

Measured memory_bytes: 13268
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  cout << t << s << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
import java.util.Scanner;
	class Main{

		public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
int W;
int H;
int x;
int y;
int r;
int flag=9;

W=sc.nextInt();
H=sc.nextInt();
x=sc.nextInt();
y=sc.nextInt();
r=sc.nextInt();

if((x-r)>=0 && (x+r)<=W){
	if((y-r)>=0 && (y+r)<=H){
		flag = 0;
	}
}

if(flag==0){
	System.out.println("Yes");
} else {
	System.out.println("No");
}

	}
	}

Measured memory_bytes: 26320
#include<bits/stdc++.h>
using namespace std;
int main() {
  int h,m,i,j;
  cin>>h>>m;
  vector<int> x(m),y(m)/*,dp(m)*/;
  vector<vector<int>> dp(m+1,vector<int>(h+1,1e8));
  for(i=0;i<=m;i++) dp[i][0]=0;
  for(i=0;i<m;i++) cin>>x[i]>>y[i];
  for(i=0;i<m;i++){
    for(j=1;j<=h;j++){
      dp[i+1][j]=min(min(dp[i][j],dp[i][max(0,j-x[i])]+y[i]),dp[i+1][max(0,j-x[i])]+y[i]);
    }
  }
/*  for(i=0;i<=m;i++){
    for(j=0;j<=h;j++) cout<<dp[i][j]<<' ';
    cout<<endl;
  }*/
  cout<<dp[m][h]<<endl;
}

Measured memory_bytes: 42308
#include <bits/stdc++.h>
using namespace std;
int tab[200005];
int main(){
	int n, k; cin>>n>>k;
	for(int i = 0; i < n; i ++) cin >> tab[i];
	sort(tab, tab+n);
	long long ans = 0;
	for(int i = 0; i < n-k; i ++) ans += tab[i];
	cout << ans;
}

Measured memory_bytes: 1024
def main():
    n = input()
    ps = input().split(' ')
    count = 0
    for i in range(1, len(ps) - 1):
        if int(ps[i]) > min(int(ps[i - 1]), int(ps[i + 1])):
            if int(ps[i]) <= max(int(ps[i - 1]), int(ps[i + 1])):
                count += 1
    print(str(count))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int main(){
	int a,b,c,k,i,ans;
	scanf("%d %d %d %d",&a,&b,&c,&k);
	if(k<=a){
		printf("%d\n",k);
	}else if(k<=a+b){
		printf("%d\n",a);
	}else{
		printf("%d\n",a-(k-a-b));
	}
	
	return 0;
}

Measured memory_bytes: 1720
#include <iostream>
#include <algorithm>
using namespace std;
struct node
{
	string a;
	int ind;
	int b,result;
}p[105];
int cmp1(struct node x,struct node y)
{
	if(x.a!=y.a)
		return x.a<y.a;
	return x.ind>y.ind;
}
//int cmp2(struct node x,struct node y)
//{
//	return x.b<y.b;
//}
int main()
{
    int n,i;
    cin>>n;
    for(i=0;i<n;i++)
	{
		cin>>p[i].a>>p[i].ind;
		p[i].b=i+1;
	}
	sort(p,p+n,cmp1);
	for(i=0;i<n;i++)
	{
		cout<<p[i].b<<endl;
	}

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

struct UnionFind
{
    vector<int> root;
    int n;
    void __init__(int sz)
    {
        n = sz;
        root.resize(n, -1);
    }
    int find(int x)
    {
        if (root[x] >= 0)
        {
            root[x] = find(root[x]);
            return root[x];
        }
        return x;
    }
    void unit(int a, int b)
    {
        int ra, rb;
        ra = find(a);
        rb = find(b);
        if (ra == rb)
        {
            return;
        }
        else if (root[ra] <= root[rb])
        {
            root[ra] += root[rb];
            root[rb] = ra;
        }
        else
        {
            root[rb] += root[ra];
            root[ra] = rb;
        }
        return;
    }
    int count()
    {
        set<int> cnt;
        rep(i, n)
            cnt.insert(find(i));
        return cnt.size();
    }
};

int main()
{
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind road, metro;
    road.__init__(n);
    metro.__init__(n);
    rep(i, k)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        road.unit(x, y);
    }
    rep(i, l)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        metro.unit(x, y);
    }
    map<int, pii> data;
    map<pii, int> cnt;
    rep(i,n){
        int r,m;
        r=road.find(i);
        m=metro.find(i);
        data[i] = mp(r, m);
        cnt[mp(r, m)]++;
    }
    rep(i,n){
        cout << cnt[data[i]] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 25600
N, A, B = map(int, input().split())
v = map(int, input().split())

v = sorted(v)[::-1]

v_ref = sum(v[:A])# / A

i = A
## n = 1
n_min = A
n_max = B
while (i<B):
    ## v_new = (i*v_ref + v[i]) / (i+1)
    v_new = v_ref + v[i]
    ## if v_new < v_ref:
    if i*v_new < (i+1)*v_ref:
        n_max = i
        break
    ## if v_new > v_ref:
    if i*v_new > (i+1)*v_ref:
        n_min = i+1
    v_ref = v_new
    i+=1

def comb(n, k):
    r = 1
    for x,y in zip(range(n,n-k,-1), range(1,k+1)):
        r = r * x
        assert r % y == 0
        r = r // y
    return r

result = 0
for n in range(n_min, n_max+1):
    v_min = min(v[:n])
    num_min = sum([v_ == v_min for v_ in v])
    num_fixed = sum([v_ > v_min for v_ in v[:n]])
    num_selected = n - num_fixed
    result += comb(num_min, num_selected)

v_max_avg = sum(v[:n_min]) / n_min

print(f"{v_max_avg:.6f}")
print(result)


Measured memory_bytes: 9188
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl


int main(){
	li a[3];
	li n;
	cin>>n;
	
	rin{
		cin>>a[0]>>a[1]>>a[2];
		sort(a,a+3);
		if(a[0]*a[0]+a[1]*a[1]!=a[2]*a[2])puts("NO");
		else puts("YES");
	}
	
	return 0;
}

Measured memory_bytes: 1132
// -*- coding:utf-8-unix -*-

use proconio::input;

fn pcnt(x: i32) -> i32 {
    x.count_ones() as i32
}

fn f(x: i32) -> i32 {
    if x == 0 {
        0
    } else {
        f(x % pcnt(x)) + 1
    }
}

fn main() {
    input! {
        n: u64,
        s: String,
    }

    let x: Vec<u8> = s.chars().map(|c| if c == '0' { 0 } else { 1 }).collect();
    let pc: i32 = x.iter().filter(|&i| *i == 1).count() as i32;
    let mut ans = Vec::with_capacity(n as usize);
    for _i in 0..n {
        ans.push(0);
    }

    for b in 0..2 {
        let mut npc = pc;
        if b == 0 {
            npc += 1;
        } else {
            npc -= 1;
        }
        if npc <= 0 {
            continue;
        }

        let mut r0 = 0;
        for i in 0..n {
            r0 = (r0 * 2) % npc;
            r0 += x[i as usize] as i32;
        }
        let mut k = 1;
        for i in (0..n).rev() {
            // `ii` 桁目を見ている際には `2^ii` が求まっている
            if x[i as usize] == b as u8 {
                let mut r = r0;
                if b == 0 {
                    r = (r + k) % npc;
                } else {
                    r = (npc + r - k) % npc;
                }
                ans[i as usize] = f(r) + 1;
            }
            k = (k * 2) % npc;
        }
    }

    for i in 0..n {
        println!("{}", ans[i as usize]);
    }
}


Measured memory_bytes: 3500
x,n = map(int,input().split())
p = list(map(int,input().split()))
if n == 0:
    print(x)
else:
    for i in range(n+1):
        if not x-i in p:
            print(x-i)
            break
        elif not x+i in p:
            print(x+i)
            break

Measured memory_bytes: 9180
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int n, m;
    cin >> n >> m;
    if (n == m)
        print("Yes");
    else
        print("No");

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
ll a[100005];
ll b[5];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    int h=0;
    for(int i=n-1;i>=0; )
    {
        if(h<2)
        {
            if(a[i]==a[i-1])
            {
                b[h]=a[i];
                h++;
                i=i-2;
                if(h==2)
                    break;
            }
            else
                i=i-1;
        }
    }
    ll s=(ll)b[0]*b[1];
    printf("%lld\n",s);

    return 0;
}



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

using namespace std;
int main() {
int N;cin>>N;
// input
vector<int> A(N); 
for(int i=0;i<N;++i){
cin >> A[i];
--A[i];
 }
vector<int> B(N); 
 for(int i=0;i<N;++i){
cin >> B[i]; }
vector<int> C(N-1); 
 for(int i=0;i<N-1;++i){
cin >> C[i]; }
// calc
int ans=0; 
for(int i=0;i<N;++i){
ans += B[A[i]];
if (i > 0 && A[i] == A[i-1]+1) {
ans += C[A[i-1]]; }
}
// output
cout << ans << endl; 
}

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

int main(){
  string S;
  cin >> S;
  int N = S.length();

  // R が並んでいたら右に行く Lが並んでいたら左に行く
  // 止まるのはRLの境界のみ。それ以外は0
  // 偶数回移動するので、境界から奇数番目はRに、偶数番目はLに入る

  // 境界の数だけ配列を作り、そのidxとLRの数を保存したい
  char tmp = S[0];
  int cnt = 0;
  for (int i=0; i<N; i++){
    if (tmp != S[i]){
      cnt++;
    }
    tmp = S[i];
  }
  int seg_num = (cnt+1) / 2;

  vector<int> R(seg_num); // そのセグメントのRの数
  vector<int> L(seg_num); // そのセグメントのLの数
  vector<int> idx(seg_num); // そのセグメントの境界（Rの方）の位置

  cnt = 0;
  int r_cnt = 0;
  int l_cnt = 0;
  int flag = 0; // 0: R, 1: L
  int seg_idx = 0;
  for (int i=0; i<N; i++){
    //左から見ていく
    if (flag == 0){
      if (S[i] == 'R'){
        r_cnt++;
      } else{
        // R L の境界
        R[seg_idx] = r_cnt;
        idx[seg_idx] = i-1;
        l_cnt = 1;
        flag = 1;
      }
    } else{
      if (S[i] == 'R'){
        // L R の境界
        L[seg_idx] = l_cnt;
        seg_idx++;
        r_cnt = 1;
        flag = 0;
      } else{
        l_cnt++;
      }
    }
  }

  L[seg_idx] = l_cnt;


  vector<int> Masu(N);
  for (int i=0; i<N; i++){
    Masu[i] = 0;
  }

  for (int i=0; i<seg_num; i++){
    // 偶数の時は半々で分ける
    // 奇数の時は、Rの場合はRにひとつ多く Lの時はLにひとつおおく入る
    if (R[i] % 2 ==0){
      Masu[idx[i]] += R[i] / 2;
      Masu[idx[i]+1] += R[i] / 2;
    } else{
      Masu[idx[i]] += R[i] / 2 + 1;
      Masu[idx[i]+1] += R[i] / 2;
    }
    if (L[i] % 2 == 0){
      Masu[idx[i]] += L[i] / 2;
      Masu[idx[i]+1] += L[i] / 2;
    } else{
      Masu[idx[i]] += L[i] / 2;
      Masu[idx[i]+1] += L[i] / 2 + 1;
    }
  }

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


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

using namespace std;

struct drink_t {
  int price;
  int stock;
};

int64_t solve(int m, const std::vector<drink_t>& drinks) {
  int64_t ret = 0;
  for (const auto& drink : drinks) {
    if (drink.stock >= m) {
      ret += int64_t(drink.price) * m;
      return ret;
    }
    ret += int64_t(drink.price) * int64_t(drink.stock);
    m -= drink.stock;
  }
  assert(false);
  return 0;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n, m;
  std::cin >> n >> m;
  std::vector<drink_t> drinks(n);
  for (auto& drink : drinks) {
    std::cin >> drink.price >> drink.stock;
  }
  std::sort(drinks.begin(), drinks.end(), [](const auto& lhs, const auto& rhs) {
    return lhs.price < rhs.price;
  });
  std::cout << solve(m, drinks) << std::endl;
  return 0;
}

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

int main() {
	int a,b;
  	cin >> a >> b;
  int Ans = 0;
  int Num = 1;
  
  while(Num < b){
  	Ans ++;
    Num --;
    Num += a;
  }
  
  cout << Ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var S = sc.ReadStr();
        var K = sc.ReadLong();

        if (S.All(p => p == S[0]))
        {
            Console.WriteLine(S.Length * K / 2);
            return;
        }

        var c = S[0];
        var f = S.TakeWhile(p => p == c).Count() % 2;
        var l = S.Reverse().TakeWhile(p => p == c).Count() % 2;

        var count = 1;
        long ans = 0;
        for (int i = 1; i < S.Length; i++)
        {
            if (S[i] == c)
            {
                count++;
            }
            else
            {
                ans += count / 2;
                count = 1;
            }
            c = S[i];
        }
        if (f + l == 2)
        {

            ans += (count + 1) / 2;
            ans *= K;
            ans -= 1;
        }
        else
        {
            ans += count / 2;
            ans *= K;
        }
        Console.WriteLine(ans);
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 13268