akhauriyash/Code-Regression huggingface dataset:
t=input()

tla=list(t)
tlb=list(t)
pd1=0
pd2=0

for i in range(len(tla)):
  if tla[i]=="?":
    if i==0:
      pass
    elif i==len(tla)-1:
      tla[i]="D"
    elif tla[i-1]=="P":
      tla[i]="D"
    elif tla[i+1]=="D":
      tla[i]="P"
    elif tla[i+1]=="?":
      tla[i]="P"
    else:
      tla[i]="D"
  if tla[i]=="D":
    if i==0:
      pass
    elif tla[i-1]=="P":
      pd1+=1
d1=tla.count('D')
s1=d1+pd1

for i in range(len(tlb)):
  if tlb[i]=="?":
    tlb[i]="D"
  if tlb[i]=="D":
    if i==0:
      pass
    elif tlb[i-1]=="P":
      pd2+=1
d2=tlb.count('D')
s2=d2+pd2

if s1>=s2:
  print(''.join(tla))
else:
  print(''.join(tlb))

Measured memory_bytes: 12384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <utility>
#include <tuple>
#include <map>
using namespace std;


int main() {
    long n, d, x, y;
    int count = 0;
    cin >> n >> d;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        if (x * x + y * y <= d * d) {
            count++;
        }
    }
    cout << count;
    return 0;
}

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

using namespace std;
map <string,int> cnt;
set <string> set1;
int main()
{
    int n,m;
    cin>>n;
    string s;
    for(int i=0;i<n;i++){
        cin>>s;
        cnt[s]++;
        set1.insert(s);
    }cin>>m;
    for(int i=0;i<m;i++){
        cin>>s;
        cnt[s]--;
        set1.insert(s);
    }
    int ans=0;
    set<string>::iterator it = set1.begin();
    for(;it!=set1.end() ;it++)
    {
        ans =max(ans,cnt[*it]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <bits/stdc++.h>
#define read(x) int x; cin>>x
#define pi pair<int, int>
#define pl pair<ll, ll>
#define newa(x, type, n) type* x = new type[n] 

typedef long long ll;

using namespace std;

int test()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	read(a);
	read(b);
	if (a >= 13)
		cout << b;
	else if (a >= 6)
		cout << b / 2;
	else
		cout << 0;
	return 0;
}

int main()
{
	test();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for(int i = 0;i <= a;i++)
    {
        for(int j = 0;j <= b;j++)
        {
            for(int k = 0;k <= c;k++)
            {
                int sum = 500 * i + 100 * j + 50 * k;
                if(sum == x)
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		while(scan.hasNext()){
			String[] ss = scan.next().split(",");
			int[] c = new int[14];
			int max = 0;
			
			for(String s:ss){
				max = Math.max(max, ++c[Integer.parseInt(s)]);
			}
			
			if(max == 4){
				System.out.println("four card");
			}else if(max == 3){
				boolean f = false;
				for(int i = 1; i <= 13; i++){
					if(c[i] == 2){
						f = true;
						break;
					}
				}
				System.out.println(f?"full house":"three card");
			}else if(max == 2){
				int k = 0;
				for(int i = 1; i <= 13; i++){
					if(c[i] == 2)k++;
				}
				System.out.println(k==2?"two pair":"one pair");
			}else{
				boolean f = false;
				for(int i = 1; i <= 10; i++){
					if(c[i] == 1){
						boolean ff = true;
						for(int j = i + 1; j <= i + 4; j++){
							if(c[(j-1) % 13 + 1] != 1){
								ff = false;
								break;
							}
						}
						f |= ff;
					}
				}
				System.out.println(f?"straight":"null");
			}
		}
	}
}

Measured memory_bytes: 25988
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N, K;
    cin >> N >> K;
    vi l(N);
    rep(i, N) cin >> l[i];
    GSORT(l);

    int res = 0;
    rep(i, K) res += l[i];

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define ARRAY_LENGTH( array ) ( sizeof( array ) / sizeof( array[ 0 ] ))

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <class T> inline bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> inline bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
ll cnt = 0;
void eratosthenes( int* prime_array, int N ){
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		rep( j, i * 2, N + 1 ){
			if (prime_array[ j ] == 0)
				continue;
			cnt++;
			if (j % i == 0){
				prime_array[ j ] = 0;
			}
		}
	}
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}

int main( void ){
	int Q;
	cin >> Q;
	vector <vector <int> > vec( Q, vector <int>( 2 ));
	int maximum = 0;
	rep( i, 0, Q ){
		cin >> vec[ i ][ 0 ] >> vec[ i ][ 1 ];
		maximum = max( maximum, max( vec[ i ][ 0 ], vec[ i ][ 1 ] ));
	}
	int* array = new int[ maximum + 1 ];
	eratosthenes( array, maximum );
	rep_d( i,  maximum + 1, 2 ){
		if (!( array[ i ] == 1 && array[ ( i + 1 ) / 2 ] == 1 ))
			array[ i ] = 0;
	}
	cumulative_sum( array, maximum );
	for(auto v: vec){
		int ans = array[ v[ 1 ] ] - array[ v[ 0 ] - 1 ];
		cout << ans << endl;
	}
}


Measured memory_bytes: 6528
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int n;
  cin>>n;
  int i=-1;
  while(1){
    i++;
    if(jo(2,i)>n){
      break;
    }
  }
    cout<<jo(2,i-1);
}

// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

using namespace std;

typedef long long ll;
const int MAX_SIZE = 1e4 + 10;

ll A[MAX_SIZE], B[MAX_SIZE];

int main()
{
	int n;
	cin >> n;
	ll sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> A[i];
		sum1 += A[i];
	}
	for(int i = 0; i < n; i++)
	{
		cin >> B[i];
		sum2 += B[i];
		sum3 += max((ll)0, A[i] - B[i]);
		if(((B[i] - A[i]) % 2 == 1) && B[i] >= A[i])
		{
			sum4 += (B[i] - A[i] + 1) / 2;
			sum3 += 1;
		}
		else
		{
			sum4 += max((ll)0, (B[i] - A[i]) / 2);
		}
	}
	if(sum2 - sum1 >= sum3 && (sum2 - sum1) >= sum4)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
n, k = gets.chomp.split.map(&:to_i)
pn = gets.chomp.split.map(&:to_r)

sums = []*n
n.times do |i|
  sums[i] = (pn[i] + 1) / 2
end

sum = sums.take(k).inject(&:+)
head = 0
max = sum
(k...n).to_a.each do |i|
  max = [max, sum - sums[head] + sums[i]].max
  sum = sum - sums[head] + sums[i]
  head += 1
end
puts max.to_f

Measured memory_bytes: 50512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

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

  int current = 1;
  for (int i = 0; i < n; i++) {
    current = min(current * 2, current + k);
  }

  cout << current << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_M = 1000;
static const int MAX_N = 1000;

int M, N, K;
char s[MAX_M][MAX_N + 1];
int memo[3][MAX_M + 1][MAX_N + 1];

int main(){
	cin >> M >> N >> K;
	for(int i = 0; i < M; i++) cin >> s[i];
	fill(memo[0][0], memo[3][0], 0);
	for(int i = 0; i < M; i++){
		for(int j = 0; j < N; j++){
			if(s[i][j] == 'J') memo[0][i + 1][j + 1]++;
			if(s[i][j] == 'O') memo[1][i + 1][j + 1]++;
			if(s[i][j] == 'I') memo[2][i + 1][j + 1]++;
		}
	}
	for(int i = 0; i < 3; i++){
		for(int j = 0; j <= M; j++){
			for(int k = 0; k <= N; k++){
				if(k == 0) continue;
				memo[i][j][k] += memo[i][j][k - 1];
			}
		}
		for(int j = 0; j <= N; j++){
			for(int k = 0; k <= M; k++){
				if(k == 0) continue;
				memo[i][k][j] += memo[i][k - 1][j];
			}
		}
	}
	for(int i = 0; i < K; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--; b--;
		for(int j = 0; j < 3; j++){
			cout << memo[j][c][d] - memo[j][c][b] - memo[j][a][d] + memo[j][a][b];
			if(j == 2) cout << endl;
			else cout << ' ';
		}
	}
	return 0;
}


Measured memory_bytes: 15808
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    ans = 0
    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                if a*500 + b*100 + 50*c == X:
                    ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
import heapq

a=[]
heapq.heapify(a)
while(1):
    ope=input().split()
    if(ope[0]=="end"):
        break

    elif(ope[0]=="insert"):
        heapq.heappush(a,-1*int(ope[1]))
       

    elif(ope[0]=="extract"):
        print(f"{-1*heapq.heappop(a)}")


Measured memory_bytes: 45316
N, K = map(int, input().split())
p = list(map(int, input().split()))
p = list(map(lambda x: (x + 1)/2, p))
ans = 0
for i in range(1, len(p)):
    p[i] += p[i - 1]
for i in range(K - 1, len(p)):
    if i == K - 1:
        ans = p[i]
    else:
        ans = max(ans, p[i] - p[i - K])
print(ans)

Measured memory_bytes: 99180
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    ll X = abs(A - B);
    ll E = D - C;
    ll right = N / 2;
    while (true) {
        ll left = (N - 1) - right;
        if (left < 0) {
            cout << "NO" << endl;
            return 0;
        }
        if ((right - left) * C - left * E <= X && X <= (right - left) * C + right * E) {
            cout << "YES" << endl;
            return 0;
        }
        if (X < (right - left) * C - left * E) {
            cout << "NO" << endl;
            return 0;
        }
        right++;
    }
}



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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;


void solve()
{
    int a, b, c; cin >> a >> b >> c;
    if(a+b==c||b+c==a||c+a==b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
void checkpoint1()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/**#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif*/
}
int main()
{
	checkpoint1();
	char c;
	cin>>c;
	if(c>=97)
		cout<<"a";
	else
		cout<<"A";
	return 0;
}

Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        int n = 4;
        int[] array = new int[n];
        String s = sc.next();
        for (int i = 0; i < n; i++) {
            array[i] = Integer.parseInt(String.valueOf(s.charAt(i)));
        }
        
        for (int op1 = 0; op1 < 2; op1++) {
            int tmp = 0;
            if (op1 == 0) {
                tmp = array[0] + array[1];
            } else {
                tmp = array[0] - array[1];
            }
            for (int op2 = 0; op2 < 2; op2++) {
                int tmp2 = 0;
                if (op2 == 0) {
                    tmp2 += array[2];
                } else {
                    tmp2 -= array[2];
                }
                for (int op3 = 0; op3 < 2; op3++) {
                    int tmp3 = 0;
                    if (op3 == 0) {
                        tmp3 += array[3];
                    } else {
                        tmp3 -= array[3];
                    }
                    
                    if (tmp + tmp2 + tmp3 == 7) {
                        String str = "";
                        str += array[0];
                        if (op1 == 0) {
                            str += "+";
                        } else {
                            str += "-";
                        }
                        str += array[1];
                        if (op2 == 0) {
                            str += "+";
                        } else {
                            str += "-";
                        }
                        str += array[2];
                        if (op3 == 0) {
                            str += "+";
                        } else {
                            str += "-";
                        }
                        str += array[3];
                        str += "=7";
                        System.out.println(str);
                        return;
                    }
                }
            }
        }
    }
}

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

int main(){
	int l[10], v1, v2, suml, i;
	double t, cross;
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2) != EOF){
		suml = 0;
		for(i=0;i<10;i++){
			suml += l[i];
		}
		t = suml / double(v1+v2);
		cross = t*v1;
		suml = 0;
		for(i=0;suml<cross;i++){
			suml += l[i];
		}
		cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s, t; cin >> s >> t;
	bool is = false;
	if (s == t)is = true;
	rep(i, 0, s.size() + 10) {
		string a = s[s.size() - 1] + s.substr(0,s.size() - 1);
		s = a;
		if (a == t)is = true;
	}
	cout << (is ? "Yes" : "No") << "\n";

	return 0;
}

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

int selectionsort(int A[] ,int N){
  int i,j,sw=0,minj;

  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j] < A[minj]){
	minj=j;
      }
    }
    swap(A[i],A[minj]);
    if(i!=minj){
      sw++;
    }
  }
  return sw;
}

int main(){
  int A[100],sw,i,j,N;

  cin >> N;

  for(i=0;i<N;i++){
    cin >> A[i];
  }
  sw=selectionsort(A,N);
  for(i=0;i<N;i++){
    if(i)cout << " ";
    cout << A[i];
}
  cout << endl;
  cout << sw<<endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;

int main() {
	ll l, r; int mini=2019; cin>>l>>r;
	
	if(l/2019==r/2019){
		for(int i=l%2019;i<r%2019;i++)
		for(int j=i+1;j<=r%2019;j++) mini=min(mini,(i*j)%2019);
		cout<<mini;
	}
	else cout<<0;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
string a;
void solve()
{
    long long i,l=a.length(),ans=0;
    for (i=0;i<l;i++)
        ans+=a[i]-'0';
    if (ans%9) puts("No");
    else puts("Yes");
}
int main()
{
    while(cin>>a)
        solve();
}

Measured memory_bytes: 3488
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define rerepi(i, a, b) for(ll i = ll(a)-1; i >= b; --i)
#define rerep(i, n) rerepi(i, n, 0)

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; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const long long INF = 1LL << 60;

// 降順ソート
// std::sort(data.begin(),data.end(),std::greater<ll>());
// 昇順ソート
// std::sort(data.begin(),data.end());

// vector型の「data」に xが存在するかを、True or Falseで返す
// vector_finder(data, x)
bool vector_finder(std::vector<ll> vec, ll number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
  }
  else { // 発見できなかったとき
    return false;
  }
}

// ここから開始だよ！
ll A,B,C;

int main() {
	// 呪文エリア
	cin.tie(0);
	ios::sync_with_stdio(false);
	// 詠唱完了
  
  cin >> A >> B >> C;
  
  if (A+B >= C) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    sort(b.begin(), b.end());
    for (int s = 28; s >= 0; s--) {
        int bt = 1 << s;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            int mn = bt - a[i];
            int tmp = lower_bound(b.begin(), b.end(), mn + bt) - lower_bound(b.begin(), b.end(), mn);
            tmp += b.end() - lower_bound(b.begin(), b.end(), mn + bt * 2);
            cnt ^= tmp & 1;
            a[i] &= bt - 1;
        }
        ans += bt * cnt;
        if (!s) break;
        for (int i = 0; i < n; i++) {
            b[i] &= bt - 1;
        }
        sort(b.begin(), b.end());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
typedef long long ll;
const int N=5e5+10,P=998244353;
int n,k,fac[N],ifac[N];ll ans;
int ksm(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%P) if(b&1) ans=1ll*ans*a%P;
	return ans;
}
void pre(int n){
	fac[0]=1;
	rep(i,1,n) fac[i]=1ll*fac[i-1]*i%P;
	ifac[n]=ksm(fac[n],P-2);
	per(i,n,1) ifac[i-1]=1ll*ifac[i]*i%P;
}
int C(int n,int k){
	if(n<k||k<0) return 0;
	return 1ll*fac[n]*ifac[k]%P*ifac[n-k]%P;
}
int main(){
	scanf("%d%d",&n,&k);
	pre(k);
	int r=(k+1)>>1,b=k-r;
	while(b>=0){
		if(r<n){++r,--b;continue;}
		if(r==b) ans+=C(k-1,r)-C(k-1,2*r-n+1);
		else ans+=C(k,r)-C(k,2*r-n+1);
		++r;--b;
	}
	printf("%lld\n",(ans%P+P)%P);
	return 0;
}

Measured memory_bytes: 4096
N = int(input())
A = list(map(int, input().split()))

lst = [0] * N

ans = 0
for i in range(N):
    if i + 1 + A[i] < N: #iは0から始まるので +1 してあげる
        lst[i + A[i]] += 1
    if i + 1 - A[i] >= 1:
        ans += lst[i - A[i]]

print(ans)

Measured memory_bytes: 32300
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift()-0;
var a=arr.shift().split(" ").map(Number);
var cnt=0;
for(var i=0;i<n-1;i++){
   if(a[i]<a[i+1])cnt++;
}
console.log(cnt);


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

/*............................*/

#define uint uint64_t
#define mx 100001
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define mp make_pair
#define pb push_back
#define inf INT_MAX
#define pi acos(-1)
#define eps 1e-8
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define input(ara, n)          \
   for (int i = 0; i < n; i++) \
   scanf("%d", &ara[i])
#define inputl(ara, n)                   \
   for (long long int i = 0; i < n; i++) \
   scanf("%lld", &ara[i])
#define pf(a) printf("%d\n", a);
#define pfl(a) printf("%lld\n", a);
#define pfi(a) printf("%d ", a);
#define pfll(a) printf("%lld ", a);
#define sc(a) scanf("%d", &a)
#define scc(a, b) scanf("%d %d", &a, &b)
#define sccdbl(a, b) scanf("%lf %lf", &a, &b)
#define sccc(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scccdbl(a, b, c) scanf("%lf %lf %lf", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define sccl(a, b) scanf("%lld %lld", &a, &b)
#define scccl(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
using namespace std;
int main()
{
   // int t;
   // sc(t);
   // while (t--)
   // {

   // }
   int n,sum=0;
   sc(n);
   int a[n],b[n],c[n-1];
   for(int i=0;i<n;i++){
      sc(a[i]);
      a[i]--;
   }
   input(b,n);
   input(c,n-1);
   for(int i=0;i<n;i++){
      sum+=b[a[i]];
      if(i>0 && a[i]==a[i-1]+1){
         sum+=c[a[i-1]];
      }
   }
   pf(sum);
   return 0;
}


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

using namespace std;

typedef long long int64;

const int64 mod = 1e9 + 7LL;

int64 fact[1000010], invfact[1000010];

int64 power(int64 a, int64 x)
{
  if(x == 0) return 1;
  int64 ret = power(a, x/2LL);
  ret = (ret*ret) % mod;
  if(x & 1) ret = (ret*a) % mod;
  return ret;
}

int64 inverse(int64 a)
{
  return power(a, mod-2);
}

void factorial()
{
  fact[0] = invfact[0] = 1LL;
  for(int i = 1; i < 1000000; i++) {
    fact[i] = (fact[i-1]*i) % mod;
    invfact[i] = inverse(fact[i]);
  }
}

int64 combination(int64 n, int64 r)
{
  if(r < 0 || n < r) return 0LL;
  return (((fact[n]*invfact[r]) % mod)*invfact[n-r]) % mod;
}

int main()
{
  factorial();
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  int64 ans = 0LL;
  for(int i = B; i < W; i++) {
    int64 x = combination(H-A-1 + i, i) % mod;
    int64 y = combination(A-1 + W-i-1, A-1) % mod;
    ans = (ans + (x * y) % mod + mod) % mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15872
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int mod = 998244353;

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

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

const int maxn = (int) 2e5 + 5;
int n;
char tmp[maxn];
string s;

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  scanf("%s", tmp);
  s = tmp;
  return true;
}

int cnt[maxn];

void solve1(int d) {
  int k = n / d;
  if (!(k & 1)) {
    return;
  }
  {
    int val = 0;
    for (int i = 0; i < d; i++) {
      val = mul(val, 2);
      add(val, s[i] - '0');
    }
    add(cnt[d], val);
  }
  bool ok = true;
  for (int i = 0; i < n; i++) {
    int cur = s[i % d] - '0';
    if ((i / d) & 1) {
      cur ^= 1;
    }
    if (s[i] < (char) ('0' + cur)) {
      ok = false;
      break;
    } else if ((char) ('0' + cur) < s[i]) {
      break;
    }
  }
  if (ok) {
    add(cnt[d], 1);
  }
}

void solve() {
  for (int i = 0; i <= n; i++) {
    cnt[i] = 0;
  }
  for (int d = 1; d * d <= n; d++) {
    if (n % d) {
      continue;
    }
    solve1(d);
    if (d * d != n) {
      solve1(n / d);
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (n % i || !((n / i) & 1)) {
      continue;
    }
    if (!cnt[i]) {
      continue;
    }
    add(res, mul(cnt[i], 2 * i));
    for (int j = 2 * i; j <= n; j += i) {
      if (n % j || !((n / j) & 1)) {
        continue;
      }
      add(cnt[j], mod - cnt[i]);
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

char s[MAX_N + 1];

char R(char c) { return c == '1' ? '0' : '1'; }

void solve()
{
  int cnt = 0;
  char prev = s[0];
  for (int i = 1; s[i] != '\0'; i++) {
    if (prev == s[i]) {
      prev = R(s[i]);
      cnt++;
    }
    else {
      prev = s[i];
    }
  }
  printf("%d\n", cnt);
}

int main(void)
{
  scanf("%s", s);
  solve();
  return 0;
}


Measured memory_bytes: 384
use std::collections::{BTreeMap, BTreeSet};

use io::*;
use union_find::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);

    let n: usize = sc.next();
    let m: usize = sc.next();

    let ps: Vec<usize> = (0..n).map(|_| sc.next::<usize>() - 1).collect();

    let xys: Vec<(usize, usize)> = (0..m)
        .map(|_| {
            let x: usize = sc.next();
            let y: usize = sc.next();
            (x - 1, y - 1)
        })
        .collect();

    let mut uf = UnionFind::new(n);

    for &(x, y) in xys.iter() {
        uf.union(x, y);
    }

    let mut unions: BTreeMap<usize, Vec<usize>> = BTreeMap::new();

    for i in 0..n {
        let parent = uf.find(i);
        unions.entry(parent).or_insert(Vec::new()).push(i);
    }

    let mut ans = 0;
    for (_, v) in unions {
        let mut ss = BTreeSet::new();
        for &ix in v.iter() {
            ss.insert(ps[ix]);
        }

        for ix in v {
            if ss.contains(&ix) {
                ans += 1;
            }
        }
    }

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

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

pub mod io {
    use std;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T>(&mut self) -> T
        where
            T: std::str::FromStr,
            <T as std::str::FromStr>::Err: std::fmt::Debug,
        {
            let s = self.iter.next().unwrap();
            s.parse::<T>().unwrap()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}

pub mod union_find {
    pub struct UnionFind(Vec<usize>);

    impl UnionFind {
        pub fn new(n: usize) -> UnionFind {
            UnionFind((0..n).collect())
        }

        pub fn find(&mut self, i: usize) -> usize {
            if self.0[i] == i {
                i
            } else {
                let p = self.0[i];
                self.0[i] = self.find(p);
                self.0[i]
            }
        }

        pub fn union(&mut self, i: usize, j: usize) {
            let ni = self.find(i);
            let nj = self.find(j);
            self.0[ni] = nj;
        }
    }
}


Measured memory_bytes: 18684
const N,T=map(x->parse(Int,x),split(readline()))
function nxt(dp,a,b)
  ret=0
  ndp=dp[:]
  for j=T:-1:1
    if j+a>T
      ret=max(ret,dp[j]+b)
    else
      ndp[j+a]=max(ndp[j+a],dp[j]+b)
    end
  end
  ret,ndp
end
function main()
  A=Pair{Int,Int}[]
  for s=readlines()
    a,b=map(x->parse(Int,x),split(s))
    push!(A,a=>b)
  end
  sort!(A)
  ans=0
  dp=zeros(Int,T)
  for (a,b)=A
    k,dp=nxt(dp,a,b)
    ans=max(ans,k)
  end
  println(ans)
end
main()

Measured memory_bytes: 174972
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int, int> P;
typedef pair<P, int> PP;

int n, q;
priority_queue<PP, vector<PP>, greater<PP> > pq;
set<int> st;

int main() {
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    int s, t, x;
    cin >> s >> t >> x;
    pq.push(PP(P(s-x, 1), x));
    pq.push(PP(P(t-x, -1), x));
  }
 
  while(q--) {
    int d;
    cin >> d;
    while (pq.size() and pq.top().first.first <= d) {
      if (pq.top().first.second == 1) {
        st.insert(pq.top().second);
      } else {
        st.erase(pq.top().second);
      }
      pq.pop();
    }
    if (st.empty()) {
      cout << -1 << endl;
      continue;
    }
    cout << *st.begin() << endl;
  }
  
  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s.size() == 3) reverse(s.begin(), s.end());
    cout << s << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,x;
    scanf("%d%d",&a,&b);
    x=b*2;
    if(x<=a)
    {
        printf("%d\n",a-x);
    }
    else if(x>a)
    {
        printf("0\n");
    }
    else if(b>=a)
    {
        printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
#define MAX_len 1500001

int main(){
     int N,M;
     while(cin>>N>>M,N||M){
	  int h[N],w[M];
	  for(int i=0;i<N;i++)cin>>h[i];
	  for(int i=0;i<M;i++)cin>>w[i];
	  vector<int> h_count(MAX_len),w_count(MAX_len);

	  for(int i1=0;i1<N;i1++){
	       int len=0;
	       for(int i2=i1;i2<N;i2++){
		    len+=h[i2];
		    h_count[len]++;
	       }
	  }
	  for(int i1=0;i1<M;i1++){
	       int len=0;
	       for(int i2=i1;i2<M;i2++){
		    len+=w[i2];
		    w_count[len]++;
	       }
	  }
	  int ans=0;
	  for(int i=1;i<MAX_len;i++){
	       ans+=h_count[i]*w_count[i];
	  }
	  cout<<ans<<endl;
     }
}

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

int main(void){
    int n,q,x,y;
    cin>>n>>q;
    priority_queue<int> Q[n];
    while(q--){
        cin>>x;
        if(x==0){
            cin>>x>>y;
            Q[x].push(y);
        }else if(x==1){
            cin>>x;
            if(Q[x].size()!=0) cout<<Q[x].top()<<endl;
        }else{
            cin>>x;
            if(Q[x].size()!=0)Q[x].pop();
        }
    }
}



Measured memory_bytes: 4032
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int n;
string s;
vector<bool> ans; // true = S, false = W

bool check(){
	bool zero = (ans[0] == ans[n]);
	bool ss = true;
	if(s[0] == 'o'){
		if(ans[0]){
			if(ans[n-1] != ans[1]) ss = false;
		}else{
			if(ans[n-1] == ans[1]) ss = false;
		}
	}else{
		if(ans[0]){
			if(ans[n-1] == ans[1]) ss = false;
		}else{
			if(ans[n-1] != ans[1]) ss = false;
		}
	}

	return (zero&&ss);
}

void circle(bool x,bool y){
	ans[0] = x,ans[1] = y;

	for(int i = 1; i < n; i++){
		if(s[i] == 'o'){
			if(ans[i]) ans[i+1] = ans[i-1];
			else ans[i+1] = !ans[i-1];
		}else{
			if(ans[i]) ans[i+1] = !ans[i-1];
			else ans[i+1] = ans[i-1];
		}
	}
}

int main()
{
	cin >> n >> s;
	bool flag = false;
	ans.resize(n+1);

	for(int i = 0; i < (1<<2); i++){
		circle(1&(i>>0),1&(i>>1));
		if(check()){
			for(int i = 0; i < n; i++){
				if(ans[i]) cout << 'S';
				else cout << "W";
			}printf("\n");
		return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)

typedef long long ll;

int let(char c){
    switch (c){
        case 'm':
            return 1000;
        case 'c':
            return 100;
        case 'x':
            return 10;
        case 'i':
            return 1;
    }
    return -1;
}

int conv(string s){
    int a=0;
    int i=0;
    while(i<s.length()){
        if (s[i]>='2'&&s[i]<='9'){
            int k=s[i]-'0';
            i++;
            a+=k*let(s[i]);            
        }else{
            a+=let(s[i]);
        }
        i++;
    }
    return a;
}

string unconv(int a){
    string s;
    int k=a/1000;
    if (k>0){
        if (k>1)
            s.push_back('0'+k);
        s.push_back('m');
    }
    a %= 1000;
    k = a/100;
    if (k>0){
        if(k>1)
            s.push_back('0'+k);
        s.push_back('c');
    }
    a %= 100;
    k = a/10;
    if (k>0){
        if(k>1)
            s.push_back('0'+k);
        s.push_back('x');
    }
    k = a%10;
    if (k>0){
        if(k>1)
            s.push_back('0'+k);
        s.push_back('i');
    }
    return s;
}


int main(void) {
    int n;
    cin >> n;
    while(n--){
        string s1,s2;
        cin >> s1 >> s2;
        int a = conv(s1)+conv(s2);
        string ans = unconv(a);
        cout << ans << endl;

    }
    
    return 0;
}

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

int x;

void Counting_Sort(int *,int *,int);

main(){
  int *A,*B;
  int i,y;

  scanf("%d",&x);

  A = malloc(sizeof(int)*x);
  B = malloc(sizeof(int)*x);

  for(i=1;i<=x;i++){
    scanf("%d",&A[i]);
  }

  y = 0;

  for(i=1;i<=x;i++){
    if(y<A[i]){
      y = A[i];
    }
  }

  Counting_Sort(A,B,y);

  return 0;
}

void Counting_Sort(int *A,int * B,int k){
  int i,j,*C;

  C = malloc(sizeof(int)*x);

  for(i=0;i<=k;i++){
    C[i] = 0;
  }
  
  for(j=1;j<=x;j++){
    C[A[j]] = C[A[j]] + 1;
  }
  for(i=1;i<=k;i++){
    C[i] = C[i] + C[i-1];
  }
  for(j = x;j>0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]]-1;
  }
  for(i=1;i<=x;i++){
    printf("%d",B[i]);
    if(i<x){
      printf(" ");
    }
  }
  printf("\n");
}

Measured memory_bytes: 16276
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  int N, H, W;
  cin >> N >> H >> W;

  cout << (N - H + 1) * (N - W + 1) << endl;
  return 0;
}

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

int main(){
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << H * W - (h * W + w * H) + h * w << endl;
  return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Numeric

main = do
    ss <- words <$>getLine
    let a:_ = [ read s | s <- ss] ::[Double]
    putStrLn $  (showFFloat (Just 10) (a*a*pi))"" ++" "++ (showFFloat (Just 10)  (a*2*pi))""

Measured memory_bytes: 3948
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

const int INF = 2147483647;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

// セグメント木による RMQ (Range Minimum Query) の実装
// RMQ以外にする場合は、minの部分を全て他の関数に置換する
//
// 計算量
// - 初期化: O(nlogn)
//   - O(n)でも実装できるが、O(nlogn)の実装になっている
//   - init後にupdateで初期化
// - update: O(logn)
// - query: O(logn)

const int MAX_N = 1 << 17;

// セグメント木を持つグローバル配列
int n;
int dat[2 * MAX_N - 1];

// 初期化
void init(int n_) {
  // 簡単のため、要素数を2のべき乗に
  n = 1;
  while (n < n_) {
    n *= 2;
  }

  // すべての値をINFに
  for (int i = 0; i < 2 * n - 1; i++) {
    dat[i] = INF;
  }
}

// k番目の値 (0-indexed) をaに変更
void update(int k, int a) {
  // 葉の節点
  k += n - 1;
  dat[k] = a;
  // 登りながら更新
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}

// [a, b) の最小値を求める
// 後ろのほうの引数は、計算の簡単のための引数。
// kは節点の番号、l, rはその節点が [l, r) に対応づいていることを表す。
// したがって、外からは inner_query(a, b, 0, 0, n) として呼ぶ。
int inner_query(int a, int b, int k, int l, int r) {
  // [a, b) と [l, r) が交差しなければ INF
  if (r <= a || b <= l) {
    return INF;
  }

  // [a, b) が [l, r) を完全に含んでいれば、この節点の値
  if (a <= l && r <= b) {
    return dat[k];
  } else {
    // そうでなければ、2つの子の最小値
    int vl = inner_query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = inner_query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}

// [a, b) の最小値を求める
int query(int a, int b) { return inner_query(a, b, 0, 0, n); }

int n_, q;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n_ >> q;
  init(n_);

  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;

    if (com == 0) {
      update(x, y);
    } else {
      cout << query(x, y + 1) << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 4208
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

int main(){
	int n,a;
	int card[4][13] = {};
	char m;
	
	cin >> n;
	
	for(int i=0; i<n; i++){
		cin >> m >> a;
		
		switch(m){
		  case 'S':
			card[0][a-1] = 1;
			break;
			
		  case 'H':
			card[1][a-1] = 1;
			break;
			
		  case 'C':
			card[2][a-1] = 1;
			break;
			
		  case 'D':
			card[3][a-1] = 1;
			break;
		}
	}
	
		
	for(int i=0; i<4; i++){
		for(int j=0; j<13; j++){
			
			if(!card[i][j]){
					
				switch(i){
				  case 0:
					cout << "S " << j+1 <<endl;
					break;
						
				  case 1:
					cout << "H " << j+1 << endl;
					break;
						
				  case 2:
					cout << "C " << j+1 << endl;
					break;
						
				  case 3:
					cout << "D " << j+1 << endl;
					break;
				}
			}
		}
	}
}
	
			

Measured memory_bytes: 3088
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
for i in range(N):
    AS = list(map(int, input().split()))
    A.append(AS)

ans = 0
for i in range(N):
    if sum([a * b for a, b in zip(A[i], B)]) + C > 0:
        ans += 1
print(ans)


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	if (N == 1) {
		cout << (K == A[0] ? "POSSIBLE" : "IMPOSSIBLE") << "\n";
		return 0;
	}
	allsort(A);
	int d = A[N - 1];
	if (K > d) {
		cout << "IMPOSSIBLE" << "\n";
		return 0;
	}
	rep(i, N - 1) {
		if(A[i+1]-A[i]!=0) d = min(A[i + 1] - A[i], d);
	}
	bool flag = true;
	rep(i, N) {
		if (A[i] % d != 0) {
			flag = false;
			break;
		}
	}
	cout << (flag&&K%d != 0 ? "IMPOSSIBLE" : "POSSIBLE") << "\n";
	return 0;
}

Measured memory_bytes: 640
#define Bobyama
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 1000000;
int N;
string L;
ll dp[2][MAX_N];


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

  cin >> L;
  N = len(L);

  if (L[0] == '1') {
    dp[0][0] = 2;
    dp[1][0] = 1;
  } else {
    dp[0][0] = 1;
    dp[1][0] = 0;
  }

  for (int i = 1; i < N; ++i) {
    if (L[i] == '1') {
      dp[0][i] = mod(dp[0][i-1]*2, MOD);
      dp[1][i] = mod(dp[1][i-1]*3 + dp[0][i-1], MOD);
    } else {
      dp[0][i] = dp[0][i-1];
      dp[1][i] = mod(dp[1][i-1]*3, MOD);
    }
  }

  ll ans = mod(dp[0][N-1] + dp[1][N-1], MOD);

  cout << ans << endl;

  return 0;
}


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

using namespace std;
int n,a[100010],dp[10010];
int main()
{
    cin >>n;
    for (int i=0;i<n;i++)
        cin >>a[i];
    dp[1]=abs(a[1]-a[0]);
    for (int i=2;i<n;i++)
    {
        dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],abs(a[i]-a[i-1])+dp[i-1]);
    }
    cout <<dp[n-1];
    return 0;
}


Measured memory_bytes: 640
import math

N = int(input())

def calc_power(num):
    if num > 1:
        m = 5
        power = 2
        while True:
            if num <= m:
                return_num = power
                break
            else:
                m = m * 4 + 1
                power += 2 
    elif num == 1:
        return_num = 0
    elif num == 0:
        print('0')
        exit()
    else:
        m = -2
        power = 1
        while True:
            if num >= m:
                return_num = power
                break
            else:
                m = m * 4 - 2
                power += 2

    return return_num

num = N
pre_power = calc_power(N) + 1
ans = ''
while num != 0:
    power = calc_power(num)
    num -= (-2) ** power
    if power == pre_power - 1:
        ans += '1'
    else:
        for _ in range(pre_power - 1 - power):
            ans += '0'
        ans += '1'
    if num == 0:
        for _ in range(power):
            ans += '0'
    pre_power = power

print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
from heapq import heapify, heappop, heappush
from random import randint
from collections import defaultdict
from itertools import accumulate
from fractions import gcd
from collections import defaultdict
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7

N = int(input())
X = inpl()
mean = sum(X) // N

ans = 10**9
for i in range(mean-1, mean+2):
    tmp = 0
    for x in X:
        tmp += (i-x)**2
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 66412
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N;
string S;
int main(){
    cin >> N >> S;
    int W = 0;
    int E = 0;
    rep(i,N) if(i && S[i] == 'E') E++;
    int ans = E;
    
    rep(i,N-1){
        if(S[i] == 'W') W++;
        if(S[i+1] == 'E') E--;
        ans = min(ans,E+W);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 720