akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
// #define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
// #define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
// using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int BinarySearch(int key,int n,int S[]){
	int l=0,r=n;
	while(r-l>1){
		int mid=(l+r)/2;
		if(S[mid]>key)r=mid;
		else l=mid;
	}
	return S[l]==key?1:0;
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

const int INF=10e9+11; 
int cnt;

void merge(int *A,int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int L[n1+1],R[n2+1];
  for(int i=0;i<n1;i++) L[i]=A[left+i];
  for(int i=0;i<n2;i++) R[i]=A[mid +i];
  L[n1]=INF;
  R[n2]=INF;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]) A[k]=L[i++];
    else A[k]=R[j++];
  }
}
void mergeSort(int *A,int left,int right){
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;
  cin>>n;
  int S[n];
  for(int i=0;i<n;i++) cin>>S[i];
  cnt=0;
  mergeSort(S,0,n);
  for(int i=0;i<n;i++) cout<<S[i]<<" \n"[i==n-1];
  cout<<cnt<<endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

signed main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N), B(M);
  rep(i, N) {
    cin >> A[i];
    if (i > 0) {
      A[i] += A[i - 1];
    }
  }
  rep(i, M) {
    cin >> B[i];
    if (i > 0) {
      B[i] += B[i - 1];
    }
  }
  int ans = 0;
  rep(i, N) {
    if (A[i] <= K) {
      //cout << A[i] << endl;
      //cout << (int)(upper_bound(all(B), K - A[i]) - B.begin()) << endl;
      chmax(ans, i + 1 + (int)(lower_bound(all(B), K - A[i]+1) - B.begin()));
    }
  }

  chmax(ans, (int)(lower_bound(all(B), K + 1) - B.begin()));

  cout << ans << endl;
}

Measured memory_bytes: 6368
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    a, b, h = map(int, open(0).read().split())
    s = (a+b)*h//2
    print(s)


if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; 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; }

int main()
{
	ll h, n;
	ll a[10005], b[10005];
	ll dp[100005];
	ll maxa = 0;
	ll ans = INF;

	cin >> h >> n;
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));

	rep(i, 100005)
		dp[i] = INF;

	rep(i, n)
	{
		cin >> a[i] >> b[i];
		chmax(maxa, a[i]);
	}


	dp[0] = 0;

	// hを超えない陽に選んだ時の消費魔力の最小値を求める
	rep(i, n)
	{
		for (ll j = 0; j < h; j++)
			dp[j + a[i]] = min(dp[j + a[i]], dp[j] + b[i]);
	}

	for (ll i = h; i <= h + maxa; i++)
		ans = min(ans, dp[i]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define hell 1000000007  
#define endl "\n"
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX_SIZE 1000000000000
set<pair<int, int>> divs;

void f(int n)
{
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            pair<int, int> t(i, n/i);
            divs.insert(t);
        }
    }
} 


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

    f(n);

    int count = 1000000000001;


    for(auto x:divs)
    {
        count = min(count, (x.first-1 + x.second-1));
    }

    cout<<count;

    

return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
using namespace std;

int main(void){
  int face_val[6], i, j, q, front, top, ind_front, ind_top;
  int cor[6][6] = {{-1,3,1,4,2,-1},{2,-1,5,0,-1,3},{4,0,-1,-1,5,1},{1,5,-1,-1,0,4},{3,-1,0,5,-1,2},{-1,2,4,1,3,-1}};

  for(i=0;i<6;i++){
    cin >> face_val[i];
  }

  cin >> q;

  for(i=0;i<q;i++){
    cin >> front >> top;
    for(j=0;j<6;j++){
      if(face_val[j]==front)break;
    }
    ind_front = j;
    for(j=0;j<6;j++){
      if(face_val[j]==top)break;
    }
    ind_top = j;

    cout << face_val[cor[ind_top][ind_front]] << endl;
  }

  return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,x,m;
    cin>>n>>x;
    std::deque<int> deq;
    int count=0;
    for (int i=0;i<n;i++) {
        cin>>m;
        count++;
        x-=m;
        deq.emplace_back(m);
    }
    sort(deq.begin(),deq.end());
    if (x!=0) {
        count+=x/deq[0];
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val m = scanner.nextInt()
    val user = (1..n).map {
        Pair(scanner.nextInt(),scanner.nextInt())
    }.toMutableList()
    val point = (1..m).map {
        Pair(scanner.nextInt(),scanner.nextInt())
    }.toMutableList()
    
    user.forEach { spos ->
        var distlist = 
        point.map { cpos -> 
            Math.abs((spos.first - cpos.first)) + Math.abs((spos.second - cpos.second))
        }.toList()
        println(distlist.indexOf(distlist.min())+1)
    }
   
}


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



public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        str = br.readLine();//34 116 + 20 5 - 5 - 1 * +
        String[] strs = str.split("\\s");
        int[] stack = new int[200];

        int l = 0;
        for(int i=0;i<strs.length;i++){
            if(strs[i].equals("+")){
                l--;
                int x = stack[l+1];
                int y = stack[l];
                stack[l] =  x + y;
                //System.out.println(stack[l]);
            }else if(strs[i].equals("-")){
                l--;
                int x = stack[l+1];
                int y = stack[l];
                stack[l] =  y - x;
                //System.out.println(stack[l]);
            }else if(strs[i].equals("*")){
                l--;
                int x = stack[l+1];
                int y = stack[l];
                stack[l] = x * y;
                //System.out.println(stack[l]);
            }else{
                l++;
                stack[l] = Integer.parseInt(strs[i]);
            }
        }
        
        System.out.println(stack[l]);
        
        br.close();
    }
   
}



Measured memory_bytes: 24556
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];

int check(llong P) {
    int i = 0;
    for ( int j = 0; j < k; j++ ) {
        llong s = 0;
        while( s + T[i] <= P ) {
            s += T[i];
            i++;
            if ( i == n ) return n;
        }
    }
    return i;
}

int solve() {
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while ( right - left > 1 ) {
        mid = (left + right) / 2;
        int v = check(mid);
        if ( v >= n ) right = mid;
        else left = mid;
    }
    
    return right;
}

main() {
    cin >> n >> k;
    for ( int i = 0; i < n; i++ ) cin >> T[i];
    llong ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3872
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back


const int N = 5e5 + 51 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

//gp_hash_table<int, int> table;

int a[N], dp[N];

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        dp[i] = INF;
    }
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        if (i + 2 < n) {
            dp[i + 2] = min(dp[i + 2], abs(a[i] - a[i + 2]) + dp[i]);
        }
        dp[i + 1] = min(dp[i + 1], abs(a[i] - a[i + 1]) + dp[i]);
    }
    cout << dp[n - 1];
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 22;
const int mod = (int) 1e9 + 7;

int n;
int a[N][N];
int dp[2][1 << (N - 1)];
int LOG[(1 << N) + 1];

//int calc(int idx, int msk) {
//	if (idx == n)
//		return msk == (1 << n) - 1;
//	int &ret = dp[idx][msk];
//	if (ret != -1)
//		return ret;
//	ret = 0;
//	for (int i = 0; i < n; i++) {
//		if (!(msk & (1 << i)) && a[idx][i]) {
//			(ret += calc(idx + 1, msk | (1 << i))) %= mod;
//		}
//	}
//	return ret;
//}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];
	for (int i = 0; i < n; i++)
		LOG[1 << i] = i;
//	MMS(dp, -1);
//	cout << calc(0, 0) << endl;
	dp[n & 1][(1 << n) - 1] = 1;
	for (int idx = n - 1; idx >= 0; idx--) {
		for (int msk = 0; msk < (1 << n); msk++) {
			dp[idx & 1][msk] = 0;
			int curMsk = (~msk) & ((1 << n) - 1);
			while (curMsk) {
				int i = LOG[(curMsk & (-curMsk))];
				if (a[idx][i]) {
					dp[idx & 1][msk] += dp[(idx + 1) & 1][msk | (1 << i)];
					if (dp[idx & 1][msk] >= mod)
						dp[idx & 1][msk] -= mod;
				}
				curMsk -= curMsk & (-curMsk);
			}
		}
	}
	cout << dp[0][0] << endl;
	return 0;
}


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

int main()
{
  int N,T,A;scanf("%d\n%d %d",&N,&T,&A);
  int H[N];
  for(int i=0;i<N;i++)scanf("%d ",&H[i]);
  double AA=abs(A-T+H[0]*0.006);
  int ans=1;
  for(int i=1;i<N;i++)
  {
    if(AA>abs((double)A-T+H[i]*0.006)){AA=abs(A-T+H[i]*0.006);ans=i+1;}
  }
  printf("%d",ans);
}

Measured memory_bytes: 3776
s = input()

l = 0
r = len(s) - 1

ans = 0
while r > l:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == "x":
        l += 1
        ans += 1
    elif s[r] == "x":
        r -= 1
        ans += 1
    else:
        ans = -1
        break

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
int main(){
    ll N,sum=0,count=0;
    cin >> N;
    vector<ll> data(N);
    rep(i,N){
        cin >> data.at(i);
    }

    map<ll,ll> sayuri;
    rep(i,N){
        sayuri[data.at(i)]++;
    }

    for(auto it : sayuri){
        count+=(it.second)*(it.second-1)/2;
    }

    for(int i=0; i<N; i++){
        ll x=sayuri[data.at(i)];
        cout << count-x*(x-1)/2+(x-1)*(x-2)/2 << endl;
    }

}

Measured memory_bytes: 12928
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++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(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    long long a;
    long double b;
    cin >> a >> b;
    cout << (ll)floor(a*b) << endl;
    return 0;
}

Measured memory_bytes: 3732
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		private const int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			//System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start();
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			string s = Console.ReadLine();

			int[][] count = new int[n][];
			int r = 0, g = 0, b = 0;
			for (int i = n - 1; i >= 0; i--) {
				count[i] = new int[] { r, g, b };
				switch (s[i]) {
				case 'R':
					r++;
					break;
				case 'G':
					g++;
					break;
				case 'B':
					b++;
					break;
				}
			}
			//Debug(n, s, count);
			long ans = 0;
			for (int i = 0; i < n - 2; i++) {
				for (int j = i + 1; j < n - 1; j++) {
					if (s[i] == s[j]) {
						continue;
					}
					int k = j + (j - i);
					//System.Diagnostics.Debug.Write($"s[{i,2}]={s[i]} s[{j,2}]={s[j]} s[{k,2}]={(k < n ? s[k] : '*')} ");
					if (s[i] != 'R' && s[j] != 'R') {
						ans += count[j][0];
						if (k < n && s[k] == 'R') {
							ans--;
						}
						//System.Diagnostics.Debug.WriteLine($"countR={count[j][0],2} ans={ans}");
					} else if (s[i] != 'G' && s[j] != 'G') {
						ans += count[j][1];
						if (k < n && s[k] == 'G') {
							ans--;
						}
						//System.Diagnostics.Debug.WriteLine($"countG={count[j][1],2} ans={ans}");
					} else {
						ans += count[j][2];
						if (k < n && s[k] == 'B') {
							ans--;
						}
						//System.Diagnostics.Debug.WriteLine($"countB={count[j][2],2} ans={ans}");
					}
				}
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
			//System.Diagnostics.Debug.WriteLine(stopwatch.Elapsed);
		}

		private static void Debug(int n, string s, int[][] count)
		{
			System.Diagnostics.Debug.Write("  ");
			for (int i = 0; i < n; i++) {
				System.Diagnostics.Debug.Write($"{s[i],2} ");
			}
			System.Diagnostics.Debug.WriteLine("");
			System.Diagnostics.Debug.Write("R:");
			for (int i = 0; i < n; i++) {
				System.Diagnostics.Debug.Write($"{count[i][0],2} ");
			}
			System.Diagnostics.Debug.WriteLine("");
			System.Diagnostics.Debug.Write("G:");
			for (int i = 0; i < n; i++) {
				System.Diagnostics.Debug.Write($"{count[i][1],2} ");
			}
			System.Diagnostics.Debug.WriteLine("");
			System.Diagnostics.Debug.Write("B:");
			for (int i = 0; i < n; i++) {
				System.Diagnostics.Debug.Write($"{count[i][2],2} ");
			}
			System.Diagnostics.Debug.WriteLine("");
		}

	}
}


Measured memory_bytes: 27572
n = int(input())
a = list(map(int,input().split()))


def gcd(x,y):
    m1 = min(x,y)
    m2 = max(x,y)
    if m1 == 0:
        return m2
    else:
        return gcd(m2%m1,m1)

l = [0 for i in range(n+1)]
r = [0 for i in range(n+1)]
l[0] = 0
r[n] = 0
for i in range(n):
    l[i+1] = gcd(l[i],a[i-1])
for i in range(n-1,-1,-1):
    r[i] = gcd(r[i+1],a[i-1])

m = [0 for i in range(n+1)]
for i in range(n):
    m[i] = gcd(l[i],r[i+1])
print(max(m))

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

int main() {
    int m,d,ans=0;cin>>m>>d;
    if (d>=22) {
        for (int i=1;i<m+1;i++) {
            for (int j=22;j<d+1;j++) {
                if (j%10>1 and i == (j/10) * (j%10)) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
P = 10**9+7
B, W = map(int, input().split())

inv2 = [1]
fact = [1]
for i in range(B+W+10):
    inv2.append((inv2[-1] + (inv2[-1] % 2) * P)//2)
    fact.append(fact[-1] * (i+1) % P)

def C(a, b):
    return fact[a]*pow(fact[b]*fact[a-b]%P, P-2, P) % P

L, R = 0, 0
for i in range(B+W):
    if i >= B:
        L *= 2
        L += C(i-1, B-1)
        L %= P
    if i >= W:
        R *= 2
        R += C(i-1, W-1)
        R %= P
    if i < min(B, W):
        aa = print(inv2[1])
    else:
        bb = print(((R-L)*inv2[i+1]+inv2[1])%P)
    

Measured memory_bytes: 20960
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>

/*
 *変数
 */
char b;

/*
 *関数
 */
int ctoi(char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

/*
 *解 
 */
void solve(){
    if(b=='C')printf("G");
    else if(b=='G')printf("C");
    else if(b=='A')printf("T");
    else printf("A");
     
}

/*
 *入力 
 */
int main(){
       std::cin.tie(0);
       std::ios::sync_with_stdio(false);
       std::cin>>b;
       solve();
       return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include <wchar.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
作りうるすべての数を作るdp
*/

ll n,w,c[110],v[110],dp[100010],dp2[100010],ans=0;

int main(void){
	cin>>n>>w;
	rep(i,n)cin>>c[i]>>v[i];
	reg(j,0,100000)dp[j]=1e18;
	dp[0]=0;//価値0なら重さ0
	rep(i,n){
		reg(j,0,100000)dp2[j]=dp[j];
		reg(j,0,100000){
			if(j+v[i]>100000)break;
			dp2[j+v[i]]=min(dp2[j+v[i]],dp[j]+c[i]);//同じ価値で軽い方を選ぶ
		}
		reg(j,0,100000)dp[j]=dp2[j];
	}
	ireg(j,0,100000){
		if(dp[j]<=w){
			ans=j;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
flg = 1
cnt = 0
ans = 0
while flg == 1:
  for i in range(len(a)):
    if a[i] %2 ==0:
      a[i] = a[i]/2
      cnt += 1
    else:
      flg = 0
      break
  if cnt == len(a):
    ans += 1
  cnt = 0

print(ans)

Measured memory_bytes: 3064
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    int a[] = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.next());
    }
    Arrays.sort(a);
    int ans = 0;
    for (int i = 0; i < k; i++) {
      ans += a[i];
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 38500
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll u(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll d(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll z(ll a){
  if(a<0)return -a;
  return a;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll nCr(int n,int k){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(void){
  int n;
  ll ans=1;
  scanf("%d",&n);
  int a,x[3]={0,0,0};
  FOR(n){
    scanf("%d",&a);
    int cnt=0,flg=1;
    FOR(3){
      if(x[i]==a){
        if(flg){
          flg--;
          x[i]++;
        }
        cnt++;
      }
    }
    ans*=cnt;
    ans%=mod;
  }
  PRL(ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  int max=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    max+=a[i]-1;
  }
  cout << max << endl;
  return 0;
}


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

int main(){
  long long int N;
  cin >> N;
  vector<long long int> v;
  for(long long int i=0;i<3*N;++i){
    long long int t; cin >> t;
    v.push_back(t);
  }
  sort(v.rbegin(),v.rend());
  long long int sum = 0;
  for( long long int i=0; i<N;++i){
    //sum+=v[i];
    sum += v[2*i+1];
  }
  cout << sum << endl;
  return 0;
}


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

int main() {
	int X, A, B;

	cin >> X >> A >> B;

	int ex = B - A;

	if (ex <= 0)
		cout << "delicious" << endl;
	else if (ex >= X + 1)
		cout << "dangerous" << endl;
	else
		cout << "safe" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
using Graph = vector<vector<int>>;

bool g[10][10]; 

int main(){
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < m; ++i){
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a][b] = g[b][a] = true;
  }

  vector<int> perm;
  for(int i = 0; i < n; ++i)perm.push_back(i);

  int count = 0;
  do{
    if(perm[0] != 0)break; 
    bool flg = true;
    for(int i = 0; i < n - 1; ++i){
      if(!g[perm[i]][perm[i + 1]])flg = false;
    }
    if(flg)++count;
  }while(next_permutation(perm.begin(), perm.end()));
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define F first
#define S second


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    pair<int, int> A[N*2];
    set<int> st;
    set<int>::iterator it;
    rep(i, N) {
        cin >> A[i].F >> A[i].S;
        A[i].F = A[i].F * 10 + 1;
    }
    rep(i, N) {
        cin >> A[N+i].F >> A[N+i].S;
        A[N+i].F = A[N+i].F*10;
    }
    sort(A, A+2*N);
    int ans = 0;
    rep(i, 2*N) {
        if (A[i].F % 2) st.insert(A[i].S);
        else {
            it = st.lower_bound(A[i].S);
            if(it != st.begin()) {
                it--;
                st.erase(it);
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
   int N, A, B;
   cin >> N >> A >> B;
   int maxv, minv, diff;
   if(A > B)
   {
      maxv = B;
      diff = N - A;
      minv = B - diff;
   }
   else{
      maxv = A;
      diff = N - A;
      minv = B - diff;
   }
   if(minv < 0){minv=0;}
   cout << maxv<<" " <<minv << endl;
   return 0;
}


Measured memory_bytes: 384
class UnionFind:
    def __init__(self, n):
        self.v = [-1] * n

    def find(self, x):
        if self.v[x] < 0:
            return x
        else:
            self.v[x] = self.find(self.v[x])
            return self.v[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        else:
            if self.v[x] > self.v[y]:
                x, y = y, x
            self.v[x] += self.v[y]
            self.v[y] = x
            return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.v[self.find(x)]


def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())

    es = []
    for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())
        es.append((a, b))
    es.reverse()
    es.pop()

    uf = UnionFind(N)
    ans = [N * (N - 1) // 2]
    t = ans[-1]
    for a, b in es:
        if not uf.same(a, b):
            t -= uf.size(a) * uf.size(b)
        ans.append(t)
        uf.unite(a, b)
    ans.reverse()

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 24088
import java.util.*;

public class Main
{
  public static void main(String []args)
  {
    Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
    sc.nextLine();
    String s = sc.nextLine();
    int red = 0;
    int white = 0;
    for(int i = 0 ; i < s.length() ; i++)
    {
      if(s.charAt(i) == 'R')
        red++;
    }
    int ans = Integer.MAX_VALUE;
    for(int i = 0 ; i <s.length() ; i++)
    {
      ans = Math.min(ans , Math.max(white , red));
      if(s.charAt(i) == 'W')
        white++;
      
      else
        red--;
    }
     ans = Math.min(ans , Math.max(white , red));
    System.out.println(ans);
    }
  }


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

int kaijou(int n){
    if(n == 1){
        return 1;
    }
    else
    {
        return n * kaijou(n - 1);
    }
}

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

    vector<int> x(n);
    vector<int> y(n);

    for (auto i = 0; i < n; i++)
    {
        int xi, yi;
        cin >> xi >> yi;
        x[i] = xi;
        y[i] = yi;
    }

    vector<int> perm(n);

    for (auto i = 0; i < n; i++)
    {
        perm[i] = i;
    }

    double sum = 0;

    do{
        for (auto i = 0; i < n-1; i++)
        {
            sum += sqrt(pow(x[perm[i]] - x[perm[i + 1]], 2) + pow(y[perm[i]] - y[perm[i + 1]], 2));
        }

    } while (next_permutation(perm.begin(), perm.end()));

    cout << fixed << setprecision(10) << sum / kaijou(n) << endl;

}

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

int main() {
    long long n;
    cin>>n;
    long long answer=1,mod=1000000007;

        for (long long i=1;i<=n;i++) {
        answer=(answer*i)%mod;
        }

    cout<<answer<<endl;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<55)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli dToC[3][600];
lli d[40][40];
lli c[600][600];

int main(){

    lli N,C;
    cin>>N>>C;

    REP(i,0,C)REP(j,0,C)cin>>d[i][j];
    REP(i,0,N)REP(j,0,N){
        cin>>c[i][j];
        c[i][j]--;
    }

    REP(i,0,C){
        lli cSum[3]={0,0,0};

        REP(j,0,N)REP(k,0,N){
            cSum[(j+k)%3] += d[c[j][k]][i];
        }

        REP(j,0,3)dToC[j][i] = cSum[j];
    }

    lli ans = INF;
    REP(i,0,C)REP(j,0,C){
        if(i==j)continue;
        REP(k,0,C){
            if(i==k || j==k)continue;
            ans = min(ans,dToC[0][i]+dToC[1][j]+dToC[2][k]);
        }
    }
    cout<<ans<<endl;

    return 0;
}


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

#define fst first
#define snd second
#define mp make_pair
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define per(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

template <typename T1, typename T2>
inline bool umin(T1& x, const T2& y){return x>y ? x=y,true : false;}

template <typename T1, typename T2>
inline bool umax(T1& x, const T2& y){return x<y ? x=y,true : false;}

typedef long long ll;
typedef long double ld;

const int N    = (int)1e6+7;
const int mod  = (int)1e9+7;
const int INF  = (int)1e9+17;
const ll LLINF = (ll)1e18+17;



int n, k;
int h[N];
ll dp[N];


template <typename T>
class MStack {
public:
    MStack() = default;
    void push(const T& x) {
        if (st.empty()) {
            st.emplace_back(x, x);
        } else {
            st.emplace_back(x, min(x, st.back().snd));
        }
    }
    void pop() { st.pop_back(); }
    T top() const { return st.back().fst; }
    T min() const { return st.back().snd; }
    size_t size() const { return st.size(); }
    bool empty() const { return st.empty(); }
private:
    vector<pair<T, T>> st;
};

template <typename T>
class MQueue {
public:
    MQueue() = default;
    void push(const T& x) { add.push(x); }
    void pop() {
        if (rem.empty()) {
            while (!add.empty()) {
                rem.push(add.top());
                add.pop();
            }
            rem.pop();
        }
    }
    T min() const {
        if (!add.empty() && !rem.empty())
            return min(add.min(), rem.min());
        if (!add.empty())
            return add.min();
        return rem.min();
    }
    size_t size() const { return add.size() + rem.size(); }
    bool empty() const { return add.empty() && rem.empty(); }

private:
    MStack<T> add;
    MStack<T> rem;
};


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    #define FILENAME ""
//    freopen(FILENAME".in", "r", stdin);
//    freopen(FILENAME".out", "w", stdout);
#endif

    cin >> n;
    k = 2;
    rep(i, 0, n) cin >> h[i];
    fill(dp, dp+n, LLINF);
    dp[0] = 0;
    rep(i, 0, n) rep(j, 1, k+1) {
        umin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 5120
#include<iostream>
using namespace std;
int main(){
  int x,y,z,w;
  w=0;
  cin >> x;
  cin >> y;
  for(int i=0;i<=x;i++){
    z=x-i;
    if(i*2+z*4==y){
      w=1;
    }
  }
  if(w==1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3536
def quick_sort(plices):
    if len(plices) == 1:
        return plices


    cri = plices[0]
    left = []
    right = []

    for i in range(1, len(plices)):
        if plices[i] < cri:
            left.append(plices[i])

        else:
            right.append(plices[i])

    left.append(cri)

    return quick_sort(left) + quick_sort(right)

def cal_sum(sorted_plices, K):
    min_sum = 0
    for i in range(K):
        min_sum += sorted_plices[i]

    return min_sum


if __name__ == "__main__":

    N, K = map(lambda x:int(x), input().split())
    plices = [int(i) for i in input().split()]

    # sorted_plices = quick_sort(plices)
    sorted_plices = sorted(plices)
    # print(sorted_plices)
    min_sum = cal_sum(sorted_plices, K)

    print(min_sum)

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    int64_t ans = 0;
    for (auto i : irange(1L, n + 1)) {
        int64_t a;
        cin >> a;

        if (i % 2 == 1 && a % 2 == 1) {
            ++ans;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define fora(i,a,b) for(int i=a,Wub=b;i<Wub;++i)
#define ford(i,a,b) for(int i=a,Wub=b;i>=Wub;--i)
#define SPEEDIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 1000000
#define MOD 1073741824
using namespace std;
typedef long long ll;

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout << "YES\n";
    else cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
ll gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll lcm=c*d/gcd(c,d);
    cout<<(b-a+1)-((b/c+b/d-b/(lcm))-((a-1)/c+(a-1)/d-(a-1)/(lcm)))<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3


def gcd(m, n):
    if m < n:
        return gcd(n, m)
    if m % n == 0:
        return n
    return gcd(n, m % n)


def lcm(m, n):
    return n // gcd(m, n) * m


def solv(a, b, c, d):
    if b <= a:
        return 0

    lcm_cd = lcm(c, d)
    if a == 0:
        c0 = 0
    else:
        a = a - 1
        c0 = a - (a // c) - (a // d) + (a // lcm_cd)
    c1 = b - (b // c) - (b // d) + (b // lcm_cd)
    return c1 - c0


if __name__ == '__main__':

    a, b, c, d = map(int, input().split())

    # print(gcd(c, d))
    # print(lcm(c, d))

    ans = solv(a, b, c, d)

    print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main(){
  while(1){
    char str[100000], tmp[100000];
    int n, i, j;
    scanf("%d", &n);
    if(n == 0)return 0;
    scanf(" %s", str);
    for(i = 0;i < n;i++){
      char now = str[0];
      int cnt = 1, pos = 0;
      for(j = 1;j < strlen(str);j++){
	if(str[j] == now)cnt++;
	else{
	  int buf;
	  sprintf(tmp + pos, "%d%c%n", cnt, now, &buf);
	  pos += buf;
	  cnt = 1;
	  now = str[j];
	}
      }
      sprintf(tmp + pos, "%d%c", cnt, now);
      strcpy(str, tmp);
    }
    printf("%s\n", str);
  }
}

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

#define ll long long
#define ull unsigned long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define all(v) (v).begin(), (v).end()

//ofstream out("debug.txt");

const int MxN = 1e5, md = 1e9 + 7;

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

    string s;
    cin >> s;
    ll n = 0;
    for (char c : s)
        n += c - '0';
    cout << ((n % 9) ? "No" : "Yes") << '\n';
}

Measured memory_bytes: 3768
def calc_divisors(n)
  puts divisors = []
  for i in 1..n
    if n % i == 0
      divisors << i
    end
  end
  return divisors
end

n = gets.to_i

num = 0
for i in 1..n
  next if i % 2 == 0
  divisors = calc_divisors(i)
  if divisors.length == 8
    num += 1
  end
end
puts num


Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20191021
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Console.WriteLine(n * n * n);

        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    string S;
    while (cin >> N >> S) {
        int res = 0;
        for (int i = 0; i < N; ) {
            int j = i;
            while (j < N && S[j] == S[i]) ++j;
            ++res;
            i = j;
        }
        cout << res << endl;
    }
}


















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

using namespace std;

int main(){
	int n; cin >> n;
	int ans = 0;
	int i;
	for(i = 1; i <= n; ++i){
		if((i*i+i)/2 > n)break;
	}
	int wo = (i*i+i)/2-n;
	for(int j = 1; j <= i; ++j){
		if(j == wo)continue;
		cout << j << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int n,m,q,from,to;
int rank[100000],parent[100000];

int find(int x){
	if(x == parent[x])return x;
	else{
		return parent[x] = find(parent[x]);
	}
}

bool isSame(int x,int y){
	return find(x) == find(y);
}

void unite(int x,int y){
	x = find(x);
	y = find(y);

	if(x == y)return;

	if(rank[x] < rank[y]){
		parent[x] = y;
	}else{
		parent[y] = x;
		if(rank[x] == rank[y])rank[x]++;
	}
}

int main(){

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

	for(int i = 0; i < n; i++){
		rank[i] = 0;
		parent[i] = i;
	}

	for(int i = 0; i < m; i++){
		scanf("%d %d",&from,&to);

		if(isSame(from,to))continue;
		unite(from,to);
	}

	scanf("%d",&q);

	int left,right;

	for(int i = 0; i < q; i++){
		scanf("%d %d",&left,&right);

		if(isSame(left,right))printf("yes\n");
		else{
			printf("no\n");
		}
	}
	return 0;
}


Measured memory_bytes: 3404
// atcoder/abc152/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> v(n);
    cin >> v;

    int cnt = 0;

    int mn = v.front();
    each (i, v) {
      cnt += (i <= mn);
      setmin(mn,i);
    }

    cout << cnt << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>

bool listen_input(int &inputNum)
{
	using namespace std;
	
	cin>>inputNum;
	if(cin.eof())
	{
		return false;
	}
	else
	{
		return true;
	}
}

class Sums//コンストラクタで全10000通りの和を格納、count_~の呼び出しでこれらを数え上げる
{
private:
	int sum[10000];
	void calc_increase(int []);
	void increase_eachDigit(const int,int[]);
public:
	Sums();
	int count_combination(const int);
};

Sums::Sums()
{
	int nums[5]={};
	int tmp_sum=0;
	
	sum[0]=0;//(a,b,c,d)=(0,0,0,0)
	for(int roop=1;1;roop++)
	{
		calc_increase(nums);//(a,b,c,d)=(1,0,0,0)から全解探索
		if(nums[4])
		{
			break;
		}
		
		tmp_sum=0;
		for(int roop_sum=0;roop_sum<4;roop_sum++)
		{
			tmp_sum+=nums[roop_sum];
		}
		sum[roop]=tmp_sum;
	}
	
	std::sort(sum,sum+10000);
}

void Sums::calc_increase(int nums[])
{
	nums[0]++;
	for(int roop=0;roop<4;roop++)
	{
		increase_eachDigit(roop,nums);
	}
}

void Sums::increase_eachDigit(int digitNum,int nums[])
{
	if(nums[digitNum]==10)
	{
		nums[digitNum]=0;
		nums[digitNum+1]++;
	}
}

int Sums::count_combination(const int inputNum)
{
	int count=0;
	
	for(int roop=0;roop<10000;roop++)
	{
		if(sum[roop]==inputNum)
		{
			count++;
		}
		else if(sum[roop]>inputNum)
		{
			break;
		}
	}
	
	return count;
}

int main()
{
	Sums inst_sum;
	
	int inputNum;
	while(listen_input(inputNum))
	{
		std::cout<<inst_sum.count_combination(inputNum)<<std::endl;
	}
	
	return 0;
}

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

using namespace std;

constexpr int MAX_V = 1014;
constexpr int INF = 100000;

struct Edge{
    Edge(int t, int c, int r) 
    : to(t), cap(c), rev(r) {}

    int to;
    int cap;
    int rev;
};

vector<Edge> G[MAX_V];
bool used[MAX_V];
bool can[MAX_V][MAX_V];

void add_edge(int from, int to, int cap){
    G[from].push_back(Edge(to, cap, G[to].size()));
    G[to].push_back(Edge(from, 0, G[from].size() - 1));
}

int dfs(int v, int t, int f){
    if(v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++){
        Edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f,e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    while (1){
        fill(used, used+MAX_V, 0);
        int f = dfs(s, t, INF);
        if(f == 0) return flow;
        flow += f;
    }
}

int gcd(int m, int n){
    if (n == 0 || m == 0) return 0;

    if (m < n) swap(m, n);
    while (int r = m % n){
        m = n;
        n = r;
    }
    return n;
}

int main(int argc, char const *argv[]){
    int m, n;

    while (cin>>m>>n, m||n){
        int s = m + n;
        int t = s + 1;
        int blue[500] = {};
        int red[500] = {};

        for (int i = 0; i < m; i++){
            cin>>blue[i];
            add_edge(s, i, 1);
        }

        for (int i = 0; i < n; i++){
            cin>>red[i];
            add_edge(m+i, t, 1);
        }

        for (int i = 0; i < m; i++){
            for (int j = 0; j < n; j++){
                if (gcd(blue[i], red[j]) > 1){
                    can[i][j] = true;
                }
            }
        }

        for (int i = 0; i < m; i++){
            for (int j = 0; j < n; j++){
                if (can[i][j]){
                    add_edge(i, m + j, 1);
                }
            }
        }

        cout<<max_flow(s, t)<<endl;

        for (int i = 0; i < MAX_V; i++){
            G[i].clear();
            fill(can[i], can[i]+MAX_V, false);
        }
    }
    return 0;
}

Measured memory_bytes: 10172
#include <iostream>
using namespace std;
#define ll long long

int main () {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll stat = 1;
    for (ll i = 0; i < n; i++) {
        if (a[i] == stat) {
            stat++;
        }
    }
    if (stat == 1) {
        cout << -1 << endl;
    }
    else {
        stat--;
        cout << n - stat << endl;
    }
}

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

int N, M, X[200001], Y[200001];
bool C[200001];

int main(){
	bool val = false;
	memset(C, false, sizeof(C));
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		if(a == 1){
			C[b] = true;
		}
		X[i] = a, Y[i] = b;
	}
	for(int i = 0; i < M; i++)
		if(Y[i] == N && C[X[i]]) val = true;
	if(val) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}


Measured memory_bytes: 2048