akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>

#define INF (2000000000000000000L)

using namespace std;

long mod(long n, long k) { return n % k >= 0 ? n % k : n % k + k; }

long pow(long x, long k, long num_mod) {
  long ret = 1, p = mod(x, num_mod);
  while (k > 0) {
    if (k % 2 == 1) {
      ret = mod(ret * p, num_mod);
    }
    p = mod(p * p, num_mod);
    k /= 2;
  }
  return ret;
}

long calc_e(long l, long r, long num_mod) {
  if (l == 0) {
    return 0;
  }
  if (l % 2 == 0) {
    const long l0 = l / 2, rpowl0 = pow(r, l0, num_mod),
               e0 = calc_e(l0, r, num_mod);
    return mod((rpowl0 + 1) * e0, num_mod);
  } else {
    const long l0 = l - 1, rpowl0 = pow(r, l0, num_mod),
               e0 = calc_e(l0, r, num_mod);
    return mod(1 + r * e0, num_mod);
  }
}

long calc_d(long l, long r, long num_mod) {
  if (l == 0) {
    return 0;
  }
  if (l % 2 == 0) {
    const long l0 = l / 2, rpowl0 = pow(r, l0, num_mod),
               d0 = calc_d(l0, r, num_mod), e0 = calc_e(l0, r, num_mod);
    const long t1 = mod((1 + rpowl0) * d0, num_mod),
               t2 = mod(mod(mod(l0, num_mod) * rpowl0, num_mod) * e0, num_mod);
    return mod(t1 + t2, num_mod);
  } else {
    const long l0 = l - 1, rpowl0 = pow(r, l0, num_mod),
               d0 = calc_d(l0, r, num_mod), e0 = calc_e(l0, r, num_mod);
    return mod(r * (d0 + e0), num_mod);
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  long L, A, B, M;
  scanf("%ld %ld %ld %ld", &L, &A, &B, &M);

  // calculate vs[k]
  //     vs[k] : min(min_i {i | s_i >= 10^{k-1}}, L)
  vector<long> vs;
  vs.push_back(0);  // let vs[0] = 0
  for (long k = 1; k <= 19; k++) {
    const long ten_pow_km1 = pow(10, k - 1, INF);
    long le = -1, ri = L;
    while (ri - le > 1) {
      const long m = (le + ri) / 2;
      if (A + B * m >= ten_pow_km1) {
        ri = m;
      } else {
        le = m;
      }
    }
    vs.push_back(ri);
    // printf("k = %ld, vs[k] = %ld\n", k, vs[k]);
  }

  // solve
  long ans = 0;
  for (long k = 1; k < 19; k++) {
    // we need to be very careful taking the mod of l
    const long v_kp1 = vs[k + 1], v_k = vs[k], n_k = v_kp1 - v_k;
    const long l = n_k, a = mod(A + B * (v_kp1 - 1), M), b = mod(B, M),
               r = pow(10, k, M);
    const long d0 = calc_d(l, r, M), e0 = calc_e(l, r, M);
    const long c_k = mod(mod(a * e0, M) - mod(b * d0, M), M);
    ans = mod(mod(pow(r, n_k, M) * ans, M) + c_k, M);
    // printf("k = %ld, e0 = %ld, d0 = %ld, c_k = %ld, a = %ld, b = %ld\n", k,
    // e0,
    //        d0, c_k, a, b);
    // printf("k = %ld, e0 = %ld, d0 = %ld, c_k = %ld, l = %ld, r = %ld\n", k, e0,
    //        d0, c_k, l, r);
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 256
import math
while True:
    n=int(input())
    k=math.factorial(n)
    if n==0:
        break
    cnt=0
    while k%5==0:
        k //=5
        cnt += 1
    
    s=0
    while k%2==0:
        k //=2
        s +=1
    if cnt > s:
        print(s)
    else:
        print(cnt)
print("", end='')



Measured memory_bytes: 5784
import math
h, w, d = map(int, input().split())
a = [[0, 0] for i in range(h*w+1)]
for i in range(h):
    ai = list(map(int, input().split()))
    for j in range(w):
        a[ai[j]] = [i+1, j+1]

def dist(p1, p2):
    return abs(a[p1][0] - a[p2][0]) + abs(a[p1][1] - a[p2][1])

# MAX_LOG = math.ceil(math.log2(h*w))
MAX_LOG = 18
b = [[0 for j in range(MAX_LOG)] for i in range(h*w+1)]
for j in range(MAX_LOG):
    for i in range(1, h*w+1):
        if j == 0:
            if i + d < h*w + 1:
                b[i][j] = dist(i, i + d)
        elif i + d*(1<<j) < h*w + 1:
            b[i][j] = b[i][j-1] + b[i + d*(1<<(j-1))][j-1]

# for bi in b:
#     print(bi)

def query(l, bit):
    if bit == 0:
        return 0
    j = 0
    while (bit>>j) & 1 == 0:
        j += 1

    return b[l][j] + query(l + d * (1<<j), bit ^ (1<<j))


q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(query(l, (r-l)//d))


Measured memory_bytes: 107004
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

    int n = sc.nextInt();
    int k = sc.nextInt();

    int[] h = new int[n];
    for (int i = 0; i < n; i++) {
        h[i] = sc.nextInt();
    }
    
    long ans = Arrays.stream(h).filter(x -> x >= k).count();
    System.out.println(ans);
  }
}

Measured memory_bytes: 50004
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
sum1 = 0
sum2 = 0
ans_list = []
for i in range(n):
    sum2 += a2[i]
if n != 1:    
    for i in range(n-1):
        sum1 += a1[i]
        sum2 -= a2[i]
        ans1 = sum1 + sum2 + a1[i+1]
        ans2 = sum1 + sum2 + a2[i]
        ans_list.append(ans1)
        ans_list.append(ans2)   
else:
    ans_list.append(a1[0]+a2[0])
print(max(ans_list))    

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct UnionFind {
  int N;
  vector<int> sz_tree, parent;
  UnionFind() {}
  UnionFind(int N) : N(N), sz_tree(N, 1), parent(N) {
    iota(parent.begin(), parent.end(), 0);
  }
  int root(int x) {
    return parent[x] == x ? x : parent[x] = root(parent[x]);
  }
  void merge(int x, int y) {
    if ((x = root(x)) == (y = root(y))) return;
    if (sz_tree[x] < sz_tree[y]) swap(x, y);
    sz_tree[x] += sz_tree[y];
    parent[y] = x;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sz_tree[root(x)];
  }
};

int N, M;
int p[100010];
int x[100010], y[100010];
int pos[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    pos[p[i]] = i + 1;
  }
  for (int i = 0; i < M; i++) {
    cin >> x[i] >> y[i];
  }
  UnionFind uf(N + 1);
  for (int i = 0; i < M; i++) {
    uf.merge(x[i], y[i]);
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += uf.same(i, pos[i]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <assert.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int hp_init, hp_max;
int R, C;
char mas[101][101];
int T, S, P;
map<char, int> mp;
vector<int> step; // damege in each step
vector<int> po;

int dp[1010][1<<12];

const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const string dir = "DRUL";

bool in(int y, int x) {
  return 0<=y&&y<R&&0<=x&&x<C;
}

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

  while(cin >> hp_init >> hp_max, hp_init+hp_max) {
    mp.clear();
    step.clear();
    po.clear();
    cin >> R >> C;
    rep(i, R) rep(j, C) cin >> mas[i][j];
    cin >> T;
    rep(i, T) {
      char c; int d;
      cin >> c >> d;
      mp[c] = d;
    }
    cin >> S;
    int y = 0, x = 0;
    rep(i, S) {
      char c; int d;
      cin >> c >> d;
      int idx = dir.find(c);
      rep(j, d) {
	y += dy[idx], x += dx[idx];
	assert(in(y, x));
	step.push_back(mp[mas[y][x]]);
      }
    }
    cin >> P;
    rep(i, P) {
      int p; cin >> p;
      po.push_back(p);
    }
    fill(dp[0], dp[1010], 0);
    dp[0][0] = hp_init;
    rep(i, step.size()) {
      rep(j, 1<<P) {
	if(dp[i][j] == 0) continue;
	chmax(dp[i+1][j], dp[i][j]-step[i]);
	rep(k, P) if(!((j>>k)&1)) {
	  chmax(dp[i][j|(1<<k)], min(hp_max, dp[i][j]+po[k]));
	  chmax(dp[i+1][j|(1<<k)], min(hp_max, dp[i][j]+po[k])-step[i]);
	}
      }
    }
    bool flag = false;
    rep(i, 1<<P) if(dp[step.size()][i] > 0) flag = true;
    cout << (flag ? "YES" : "NO") << endl;
  }

  return 0;
}

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

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

  while( N >= 500 ) {
    N -= 500;
    //cout << "N:" << N << endl;
  }
  
  if( N <= A )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli n;

int main(void){
	cin >> n;
	vector<lli> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	lli x = a[n-1];
	lli y = -1;
	lli d = 1e18;
	rep(i, n-1){
		if(abs(2*a[i]-x) < d){
			d = abs(2*a[i]-x);
			y = a[i];
		}
	}
	cout << x << " " << y << endl;
	return 0;
}


Measured memory_bytes: 3952
/***************************************************************
	File name: B.cpp
	Author: ljfcnyali
	Create time: 2019年07月20日 星期六 20时02分05秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 

int main()
{
    int n, d;
    scanf("%d%d", &n, &d);
    int x = n / (2 * d + 1);
    if ( x * (2 * d + 1) < n ) ++ x;
    printf("%d\n", x);
    return 0;
}

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

int main() {

    int N;
    cin >> N;

    int cnt = 0;
    ll now = 11;
    while (cnt < N) {
        bool flag = true;
        for (int i = 2; i <= sqrt(now); i++) {
            if (now % i == 0)
                flag = false;
        }

        if (flag) {
            cout << now << " ";
            cnt++;
        }

        now += 5;
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int n, m,a; CI n >> m>>a;

	CO max(n, max(m, a)) - min(n, min(m, a)) EN;

	return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
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;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;


int main() {
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  // ans = 0;
  if (a >= k) {
    cout << k << endl;
    return 0;
  }
  if ((a+b) >= k) {
    cout << a << endl;
    return 0;
  }
  int am;
  am = k - (a + b);
  cout << a - am << endl;
}


Measured memory_bytes: 3192
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(i==0||i==h-1||j==0||j==w-1)
	  cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int s[510][510];
int main(){
    int n,m,q;cin>>n>>m>>q;
    int l,r;
    for (int i=0; i<m; ++i){
        cin>>l>>r;
        for (int j=r; j<=500; ++j)++s[l][j];//累積和は後にふつうに求めたほうがいいかもしれないです。今回はどちらでも余裕
    }
    int ans;
    for (int i=0; i<q; ++i){
        cin>>l>>r;
        ans=0;
        for (int j=l; j<=r; ++j)
            ans+=s[j][r]-s[j][l-1];
        cout<<ans<<endl;
    }
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    A,B=input().split()
    A=int(A)
    
    C=B.split(".")
    B=int(''.join(map(str,C)))
    ans=(A*B)//100
    
    print(ans)

main()


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

using namespace std;

int main(){
    int n;
    cin>>n;
    multiset<int> st;
    int t;
    int ans=0;
    for (int i = 0; i < n; ++i) {
        cin>>t;
        auto it=st.lower_bound(t);
        if(it==st.begin()){
            st.insert(t);
            ++ans;
        }
        else{
            --it;
            st.erase(it);
            st.insert(t);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define debug(x) cerr<<#x<<":"<< (x)<<endl;

//
// eratosthenes
//  + 値は1-indexedで格納されている
//  + prime
//    - 素数か否かがbool型で格納
//    - prime[n] ? 素数 : 素数ではない
//  + prime_factorize
//    - 素因数分解をする関数
//    - 引数nを素因数分解して, 
//      どの素数がどれだけ含まれているかをvector< pair<int,int> >で返す 
//    - e.g.) n=20 => (2,2), (5,1)

struct Eratosthenes {
	// 1-indexedで検索可能
  vector< bool > prime;
  // sizeは1e6くらいまでならおk
  Eratosthenes(int _size) {
    init(_size);
  }	
	
  void init(int n) {
    prime.resize(n + 1);
    for(int i=0; i<prime.size(); ++i) prime[i] = true;
    prime[0] = prime[1] = false;
    for(int i=2; i*i<=n; i++) {
      if (prime[i]) {
        for (int j=0; i*(j + 2)<n; ++j) {
					prime[i*(j+2)] = false;
				}
      }
    }
  }

	vector< pair< int, int > > prime_factorize(int n) {
		vector< pair< int, int > > res;
		for (int p=2; p*p<=n; ++p) {
			if (n%p != 0) continue;
			int num = 0;
			while (n%p == 0) ++num, n /= p;
			res.push_back(make_pair(p, num));
		}
		if (n != 1) res.push_back(make_pair(n, 1));
		return res;
	}
};

signed main() {
  int n,p;cin>>n>>p;
  Eratosthenes e(1);
  vector< pair<int,int> > ps = e.prime_factorize(p);
  int ans = 1;
  for(int i=0;i<ps.size();++i){
    if (ps[i].second/n==0) continue;
    for (int j=0;j<ps[i].second/n;++j){
      ans *= ps[i].first;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int t=0,n,k,ans,p,Link[2010]; 
struct dsa {int x,y;}a[2010];
struct edge{int nex,v;}e[4010];
void Insert(int xx,int yy) {e[++t].nex=Link[xx];e[t].v=yy;Link[xx]=t;}
void dfs(int now,int fa,int len) 
{
	if (len>k/2) ans++;
	for (int i=Link[now];i;i=e[i].nex) {
		if (e[i].v==fa||e[i].v==p) continue;
		dfs(e[i].v,now,len+1);
	}
	return ;
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;i++) {
		scanf("%d%d",&a[i].x,&a[i].y);
		Insert(a[i].x,a[i].y);
		Insert(a[i].y,a[i].x);
	}
	if (k&1) {
		int Min=1e9;
		for (int i=1;i<n;i++) {
			ans=0;
			p=a[i].y;dfs(a[i].x,0,0);
			p=a[i].x;dfs(a[i].y,0,0);
			Min=min(ans,Min);
		}
		printf("%d\n",Min);
	}
	else {
		int Min=1e9;
		for (int i=1;i<=n;i++) {
			ans=0;
			dfs(i,0,0);
			Min=min(ans,Min);
		}
		printf("%d\n",Min);
	}
	return 0;
}

Measured memory_bytes: 384
H, W = map(int, input().split())

A = [input() for i in range(H)]

row = []
column = []

for i in range(len(A)):
        for j in range(len(A[i])):
                if A[i][j] == "#":
                        row.append(i)
                        break

for i in range(W):
        for j in range(len(A)):
                if A[j][i] == "#":
                        column.append(i)
                        break


for i in range(len(A)):
        flag = True
        for j in range(len(A[i])):
                if i in row:
                        if j in column:
                                print(A[i][j], end = "")
                else:
                        flag = False
                        continue
        if flag:
                print("")

Measured memory_bytes: 43884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

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

    int n;
    cin >> n;
    vector<int> x(n + 1), ans(n * n + 1), cnt(n + 1), dnt(n + 1), ord;
    vector<pair<int, int>> tmp;
    rep(i, 1, n + 1) {
        cin >> x[i];
        ans[x[i]] = i;
        cnt[i] = i - 1;
        dnt[i] = n - i;
        tmp.emplace_back(x[i], i);
    }
    sort(tmp.begin(), tmp.end());
    rep(i, 0, n) ord.emplace_back(tmp[i].second);
    int k = 0;
    bool used = false;
    rep(i, 1, n * n + 1) {
        debug(i);
        if (ans[i] != 0) {
            if (cnt[ans[i]] == 0 && dnt[ans[i]] == n - ans[i]) continue;
            debug(ans);
            debug(cnt[ans[i]], dnt[ans[i]]);
            cout << "No" << endl;
            return 0;
        } else if (!used) {
            while (k != n && cnt[ord[k]] == 0) {
                k++;
            }
            if (k == n) {
                used = true;
                k = 0;
                if (dnt[ord[0]] == 0) k = 1;
                debug(k);
                ans[i] = ord[k];
                dnt[ord[k]]--;
                continue;
            }
            ans[i] = ord[k];
            cnt[ord[k]]--;
        } else {
            while (k != n && dnt[ord[k]] == 0) {
                k++;
            }
            ans[i] = ord[k];
            dnt[ord[k]]--;
        }
    }
    cout << "Yes" << endl;
    rep(i, 1, n * n + 1) {
        cout << ans[i] << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

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

    char[] s = scanner.next().toCharArray();
    boolean good = true;
    for (int i = 0; i < s.length - 1; i++) {
      if (s[i] == s[i + 1]) good = false;
    }
    if (good) System.out.println("Good");
    else System.out.println("Bad");
  }
}


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

int main() {
  int n;
  cin>>n;
  vector<P> v[20];
  rep(i,n) {
    int a;
    cin>>a;
    rep(j,a) {
      int x,y;
      cin>>x>>y;
      x--;
      v[i].push_back({x,y});
    }
  }
  int ans=0;
  rep(bit,1<<n) {
    bool flag=true;
    rep(i,n) {
      if(bit&(1<<i)) {
	rep(j,v[i].size()) {
	  if((bit>>v[i][j].first&1)!=v[i][j].second) {
	    flag=false;
	  }
	}
      }
    }
    int cnt=0;
    if(flag) {
      rep(i,n) {
	if(bit&(1<<i)) cnt++;
      }
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}





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

using namespace std;
using ll = long long;


int main(){
  int N;
  cin >> N;
  
  int cnt = 0;
  for(int i=1; i<=N; i++){
    
    if(0<i and i<10){
      cnt += 1;
    }else if(99<i and i<1000){
      cnt += 1;
    }else if(9999<i and i<100000){
      cnt += 1;
    }
  }

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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;
}
//

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 0; i + 2 < s.size(); i++) {
    string t = "";
    t += s[i];
    t += s[i + 1];
    t += s[i + 2];
    if (t == "ABC") ans++;
  }
  cout << ans << endl;

  return 0;
}

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

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())
#define endl '\n'

#ifdef SANJU
    #define localsys 1
#else
    #define localsys 0
#endif

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;

long long int cons=pow(10,9)+7;

void sanjeev(int kkkk)
{
    int n,m;
    cin>>n>>m;
    vector<vector<int>>visit(n,vector<int>(m,0));

    vector<vector<char>>A;
    for(int i=0;i<n;i++)
    {
        vector<char>temp;
        for(int j=0;j<m;j++)
        {
            char c;
            cin>>c;
            temp.push_back(c);
        }
        A.push_back(temp);
    }

visit[0][0]=1;
    for(int i=0;i<A.size();i++)
    {
        for(int j=0;j<A[i].size();j++)
        {
            if(A[i][j]=='#')continue;
            if(i-1>=0)
            {
                visit[i][j]=(visit[i-1][j]+visit[i][j])%cons;
            }
            if(j-1>=0)visit[i][j]=(visit[i][j-1]+visit[i][j])%cons;
        }
    }
    cout<<visit[n-1][m-1];

    // for(int i=0;i<visit.size();i++)
    // {
    //     cout<<endl;
    //     for(int j=0;j<visit[i].size();j++)cout<<visit[i][j]<<" ";
    // }

}

int main()
{
    if(!localsys) ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { sanjeev(i+1); }
    if(localsys) system("pause");
}


Measured memory_bytes: 5248
A,B=map(int,input().split())
T = []
cnt = 0

while len(T)< B:

    if B==1:

        break

    if len(T)==0:

        T.extend([0]*A)

        cnt += 1

    else :

        
        T.extend([0]*(A-1))

        cnt += 1

print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string input;
	int left, right;
	cin >> input;

	for (int i = 0; i < input.size(); i++)
	{
		if (input[input.size() - 1 - i] == 'A')
			left = input.size() - 1 - i;
		if (input[i] == 'Z')
			right = i;
	}

	cout << right - left + 1 << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 720
#include "bits/stdc++.h"

using namespace std;
using std::vector;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

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

  ll mini = linf;
  ll ans = 0;

  rep(i,5) {
    if(mini > v[i])
      mini = v[i];
  }

  ans = n / mini;
  if(n % mini != 0)
    ans += 1;

  ans += 4;

  pr(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL);
#define fr(i,a,b)  for(int i=a;i<=b;i++)
#define rf(j,b,a)  for(int j=b;j>=a;j--)
#define frr(k,a,b) for(int k=a;k<=b;k++)
#define mp make_pair
#define pb push_back
#define MOD 1000000007
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
signed main()
{   
	IOS
 /*   #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif*/
int n;
cin>>n;
int h[n+1];
for(int i=1;i<=n;i++)
{
	cin>>h[i];
}
int dp[n+1]={0};
dp[1]=dp[0]=0;
dp[2]= abs(h[2]-h[1]);
for(int i =3;i<=n;i++)
{
int a = dp[i-2]+abs(h[i]-h[i-2]);
int b = dp[i-1]+abs(h[i]-h[i-1]);	
dp[i]=min(a,b);
}
cout<<dp[n]<<endl;

}

Measured memory_bytes: 1792
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int s; std::cin >> s;
  int u = s/100;
  int l = s%100;

  bool uyy = false, umm = false, lyy = false, lmm = false;
  if (1 <= u && u <= 12) umm = true;
  if (1 <= l && l <= 12) lmm = true;

  bool yymm = false, mmyy = false;
  if (lmm) yymm = true;
  if (umm) mmyy = true;

  if (yymm && mmyy) std::cout << "AMBIGUOUS" << std::endl;
  else if (yymm) std::cout << "YYMM" << std::endl;
  else if (mmyy) std::cout << "MMYY" << std::endl;
  else std::cout << "NA" << std::endl;
}


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

int main ()
{
	int a,b,c;  cin>>a>>b>>c;
	
	int s=a+b+c;
	if(s==17){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}

}



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

int main() {
    int N;
    std::cin >> N;

    long long a_sum = 0;
    std::vector<int> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
        a_sum += A[i];
    }

    long long x = a_sum;
    for (int i = 1; i < N; i += 2)
        x -= A[i] * 2;

    std::cout << x;
    for (int i = 0; i < N - 1; i++) {
        x = A[i] * 2 - x;
        std::cout << " " << x;
    }
    std::cout << "\n";
}

Measured memory_bytes: 1664
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int A, B, C, D, P;
	cin >> A >> B >> C >> D >> P;

	int X, Y;
	X = P * A;
	Y = (P > C) ? B + (P - C) * D : B;

	cout << min(X, Y) << endl;

	return 0;
}

Measured memory_bytes: 1160
#16D8101012J 伊藤惇 dj Python3
import math

def Prime_Numbers(x):
    i=2
    flag=True
    while i <= math.sqrt(x):
        if x%i==0:
            flag=False  
            break
        i+=1
    return flag
if __name__ == "__main__":
    A=[]
    n=int(input())
    for i in range(n):
        A.append(int(input()))
    sum=0
    for i in A:
        if Prime_Numbers(i):
            sum+=1
    print(sum)



Measured memory_bytes: 6004
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<int> a(n), b(n);
  REP(i, 0, n) { cin >> a[i]; }
  REP(i, 0, n) { cin >> b[i]; }
  VEC<int> ca(n, 0), cb(n, 0);
  ca[0]=a[0];
  cb[0]=b[0];
  REP(i, 0, n-1) {
    ca[i + 1] += a[i + 1] + ca[i];
    cb[i + 1] += b[i + 1] + cb[i];
  }
  //DUMP(ca,cb);
  LL sum = 0;
  LL ans = 0;
  REP(i, 0, n) {
    if (i - 1 >= 0)
      sum = ca[i] - cb[i - 1] + cb[n - 1];
    else
      sum = ca[i] + cb[n - 1];
    ans = max(ans, sum);
    //DUMP(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=500050;

ll modpow(ll x,ll y){
  long long ans=1;
  while(y>0){
    if(y&1){
      ans*=x%MOD;
    }
    x*=x%MOD;
    x%=MOD;
    ans%=MOD;
    y>>=1;
  }
  return ans;
}

ll fac[MAX];
ll faci[MAX];

void modCf(){
  fac[0]=1;
  faci[0]=1;
  for(int i=1;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    faci[i]=modpow(fac[i],MOD-2);
  }
  return;
}

ll modC( ll x,ll y){
  ll ans=fac[x];
  ans*=faci[y]%MOD;
  ans%=MOD;
  ans*=faci[x-y]%MOD;
  return ans%MOD;
}

int main() {
  modCf();
  ll N,M;
  cin>>N>>M;
  ll ans=fac[M];
  ans*=faci[M-N];
  ans%=MOD;
  ll n_ans=ans,c=-1;
  for(int i=1;i<=N;i++){
    //cout<<n_ans<<endl;
    ll n=fac[M-i]*faci[M-N]%MOD;
    n*=modC(N,i);
    n%=MOD;
    if(c==-1){
      n_ans-=n;
    }
    else{
      n_ans+=n;
    }
    if(n_ans<0){
      n_ans+=MOD;
    }
    
    n_ans%=MOD;
    c*=-1;
  }
  ans*=n_ans;
  ans%=MOD;
  cout<<ans;
}


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

long long int n, m, h, k, s[1008], t[1008], a, b, i;
pair<long long int, long long int> l[100008];
priority_queue<long long int> e;

int main(){
    for(;scanf("%lld%lld%lld%lld", &n, &m, &h, &k), n * m * h * k > 0;){
        e = priority_queue<long long int>();
        e.push(0);
        for(i = 0; i < 1008; ++i){
            s[i] = t[i] = 0;
        }
        for(i = 0; i < n; t[i] = ++i){
            scanf("%lld", s + i);
        }
        for(i = 0; i < m; ++i){
            scanf("%lld%lld", &a, &b);
            l[i] = make_pair(b, a);
        }
        sort(l, l + m);
        for(i = 0; i < m; ++i){
            swap(t[l[i].second], t[l[i].second - 1]);
        }
        for(i = m - 1; i >= 0; --i){
            a = l[i].second;
            //cout << s[a - 1] << " " << s[a] << " ";
            if((t[a - 1] + 1) > k && (t[a] + 1) <= k){
                //cout << "a ";
                if(s[a - 1] < s[a]){
                    e.push(s[a] - s[a - 1]);
                }
            }
            if((t[a - 1] + 1) <= k && (t[a] + 1) > k){
                //cout << "b ";
                if(s[a - 1] > s[a]){
                    e.push(s[a - 1] - s[a]);
                }
            }
            swap(t[a - 1], t[a]);
            swap(s[a - 1], s[a]);
            //cout << endl;
        }
        a = accumulate(s, s + k, 0LL);
        cout << a - e.top() << endl;
    }
    return 0;
}

Measured memory_bytes: 4812
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, k;
    cin >> a >> b >> k;
    if(a + k - 1 < b - k + 1) {
        FOR(i, a, a + k - 1) cout << i << endl;
        FOR(i, b - k + 1, b) cout << i << endl;
    } else {
        FOR(i, a, b) cout << i << endl;
    }
    
    return 0;
}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int x, y;
    cin >> x >> y;

    set<int> s1({1, 3, 5, 7, 8, 10, 12});
    set<int> s2({4, 6, 9, 11});
    set<int> s3({2});

    int xp, yp;
    if (s1.find(x) != s1.end())
        xp = 1;
    else if (s2.find(x) != s2.end())
        xp = 2;
    else if (s3.find(x) != s3.end())
        xp = 3;

    if (s1.find(y) != s1.end())
        yp = 1;
    else if (s2.find(y) != s2.end())
        yp = 2;
    else if (s3.find(y) != s3.end())
        yp = 3;

    if (xp == yp)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
import sys
import math

input = sys.stdin.readline
sys.setrecursionlimit(4100000)


def main():
    A, B, H, M = map(int, input().rstrip().split())
    theta_m = 2 * math.pi * M / 60
    theta_h = 2 * math.pi * (H * 60 + M) / (12 * 60)
    theta = abs(theta_m - theta_h)
    if theta > math.pi:
        theta = 2 * math.pi - theta
    ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta))
    # print(theta_m)
    # print(theta_h)
    # print(theta)
    print('{:.20f}'.format(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9476
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

a,b = map(int, input().split())
if a < b:
  for i in range(b):
    print(a, end = '')
else:
  for i in range(a):
    print(b, end = '')
print('')


Measured memory_bytes: 23200
#include <stdio.h>
#include <string.h>
 
int main(){
    char N[200010];
    char T[200010];
    int count=0;
    if ( scanf("%s",N) ){
 
    if ( scanf("%s",T) ){
 
 
    for (int i=0;i<strlen(N);i++){
        if(N[i]!=T[i]){
            count++;
        }
    }
    printf("%d\n",count);
    }
    }
    return 0;
}

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

int main() {

int H, W;
bool check, check2 = false;
cin >> H >> W;
vector<vector<char>> input(H, vector<char>(W));
for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
        cin >> input.at(i).at(j);
    }
}

for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
        if (input.at(i).at(j) == '#'){
            check = true;
        }
    }
    if (check == false){
        for (int k = 0; k < W; k++){
            input.at(i).at(k) = ' ';
        }
    }
    else{
        check = false;
    }
}

check = false;
for (int i = 0; i < W; i++){
    for (int j = 0; j < H; j++){
        if(input.at(j).at(i) == '#'){
            check = true;
        }
    }
    if(check == false){
        for (int k = 0; k < H; k++){
            input.at(k).at(i) = ' ';
        }
    }
    else{
        check = false;
    }
}

for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
        if(input.at(i).at(j) != ' '){
            cout << input.at(i).at(j);
        }
    }
    for (int k = 0; k < W; k++){
        if(input.at(i).at(k) != ' '){
            check2 = true;
        }
    }
    if(check2 == true){
        check2 = false;
        cout << endl;
    }
    else{
        continue;
    }
}

}

Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    if p[i] < p[i+1] < p[i+2] :
        ans += 1
    elif p[i] > p[i+1] > p[i+2] :
        ans += 1
    else:
        continue
else:
    print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int x,y,ans;
	scanf("%d%d",&x,&y);
	if(x%y==0)
	ans=-1; 
	else
	{
		for(ans=2*x;;ans+=x)
		{
			if(ans%y!=0)
			break;
		}
	}
		printf("%d\n",ans);
		return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int num;
  int hoot_num;
  cin >> num >> hoot_num;
  
  int b = 4*num - hoot_num;
  if(b >=0 && b%2 == 0 && b <= 2*num){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
//CODE FESTIVAL 2017 qual A - D
//https://code-festival-2017-quala.contest.atcoder.jp/tasks/code_festival_2017_quala_d
#include <cstdio>

const char c[]={'R','Y','G','B'};
int n,m,d,b;

int main(){
	scanf("%d%d%d",&n,&m,&d);b=10000*d;
	for(int i=0;i<n;++i,putchar(10))
	for(int j=0;j<m;++j)
		putchar(c[(((i+j)/d&1)<<1)|((i-j+b)/d&1)]);
	return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#include <sstream>
#include <complex>
#define BIT(nr) (1ULL << (nr))
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	
#define LL_HALFMAX 9223372036854775807 / 2	
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

using namespace std;

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;

	// libalgo のものに追加、メンバを追加するだけなので互換性は崩さないはず、逆辺のG[e.dstの]インデックスを保持
	int rev;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
	bool operator<(const Edge& right) const {
		return dst < right.dst;
	}
};

using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph& g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph& g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};
signed main() {
	int V, E;
	cin >> V >> E;

	Graph G(V);
	vector<Edge> es;
	rep(i, E) {
		int s, t, w;
		cin >> s >> t >> w;
		add_edge(G, s, t, w);
		es.emplace_back(s, t, w);
		es.emplace_back(t, s, w);
	}

	auto cmp = [&](const Edge& l, const Edge& r) -> bool {
		return l.weight < r.weight;
	};
	
	sort(ALLOF(es), cmp);

	int ans = 0;
	uf_tree uf(V);
	for (auto e : es) {
		if (!uf.is_same(e.src, e.dst)) {
			ans += e.weight;
			uf.unite(e.src, e.dst);
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 23516
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll gcd(ll x,ll y){
  if(x<y) swap(x,y);
  ll r;
  while(y>0){
    r=x%y;
    x=y;
    y=r;
  }
  return x;
}
int main(){
  int n;
  cin>>n;
  ll a[n+1]={};
  ll sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=(a[i]-1);
  }
  cout<<sum<<endl;
  /*ll g=gcd(a[0],a[1]);
  for(int i=2;i<n;i++){
    g=gcd(g,a[i]);
  }
  ll ans=1;
  for(int i=0;i<n;i++){
    ans=(ans/g)*(a[i]/g)*g;
  }
  ll tmp=0;
  for(int i=0;i<n;i++){
    tmp+=(ans-1)%a[i];
  }
  cout<<tmp<<endl;*/
  return 0;
}


Measured memory_bytes: 256
import sys


def calc(a, b, c, d, e, f):

    a2 = a * d
    b2 = b * d
    c2 = c * d

    d2 = d * a
    e2 = e * a
    f2 = f * a

    t1 = c2 - f2
    t2 = b2 - e2

    y = t1 / t2
    x = (c - b * y) / a

    return x, y


for line in sys.stdin:
    datas =line.split()
    if (len(datas)):

        li = list(map(int, datas)) 
        a = li[0]
        b = li[1]
        c = li[2]
        d = li[3]
        e = li[4]
        f = li[5]

        x, y = calc(a, b, c, d, e, f)

        print("%.3f %.3f" % (round(x, 3), round(y, 3)))

    else:
        break

Measured memory_bytes: 7684
#include <stdio.h>
int main(void)
{
    int a,b,c;
    int rec,loz;
    rec=loz=0;
    while(scanf("%d,%d,%d",&a,&b,&c)==3)
    {
        if(a*a+b*b==c*c)
            rec++;
        else if(a==b&&a+b>c&&b+c>a&&c+a>b)
            loz++;
            else continue;
    }
    printf("%d\n%d\n",rec,loz);
    return 0;

}

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

int main() {
  int h, n;
  cin >> h >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int suma = 0;
  for (int i = 0; i < n; i++) suma += a[i];
  cout << (suma < h ? "No" : "Yes") << endl;
}

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N, K;
    cin >> N >> K;

    deque<ll> V;
    FOR(i, 0, N){
        ll v; cin >> v;
        V.push_back(v);
    }

    ll ans = 0;
    // 掘る回数
    FOR(dig, 1, K+1){
        //pn(dig);

        // 左から何回掘るか
        FOR(left, 0, dig+1){
            auto Q = V;
            vector<ll> bag;
            ll right = dig - left;
            ll rest = K - dig;

            FOR(i, 0, left){
                if(Q.size()==0) break;
                ll v = Q.front();
                Q.pop_front();
                bag.push_back(v);
            }

            FOR(i, 0, right){
                if(Q.size()==0) break;
                ll v = Q.back();
                Q.pop_back();
                bag.push_back(v);
            }
            sort(ALL(bag));

            ll sum = 0;
            for(ll a : bag){
                sum += a;
            }
            FOR(i, 0, rest){
                // i番目を捨てる
                if(i<dig && bag[i]<0){
                    sum -= bag[i];
                }
            }

            chmax(ans, sum);
        }
    }


    p(ans);
    
    return 0;
}

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

using namespace std;

typedef long long ll;

#define FOR(index, init, max) for (int index = (init); index < (max); i++)
#define REP(index, max) for (int index = 0; index < (max); i++)
#define FOREACH(x, array) for (auto&& (x) : array)
#define VECCIN(vec) for (auto&& vec_i : vec) cin >> vec_i
#define VECCOUT(vec) for (const auto& vec_i : vec) cout << vec_i << endl

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

    int dp[1001][1001] = {0};

    while(q > 0) {
        string x, y;
        cin >> x >> y;

        for (int x_i = 0; x_i < x.length(); x_i++) {
            for (int y_i = 0; y_i < y.length(); y_i++) {
                if (x[x_i] == y[y_i]) {
                    dp[x_i + 1][y_i + 1] = dp[x_i][y_i] + 1;
                }
                else {
                    dp[x_i + 1][y_i + 1] = max(dp[x_i][y_i + 1], dp[x_i + 1][y_i]);
                }
            }
        }

        cout << dp[x.length()][y.length()] << endl;
        q--;
    }

    return 0;
}


Measured memory_bytes: 7080
#include <bits/stdc++.h>
#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--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s ;
  cin >> s ;
  int n = SZ(s) ;
  int ans = 0 ;
  
  REP(i,n-1){
    if(s[i]!=s[i+1]){
      ans++ ;
    }
  }
  cout << ans <<endl ;
  
  
  
  return 0 ;
}




Measured memory_bytes: 512