akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long inf = 1000000000000;
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; }
int main() {
	int n, m;
	cin >> n >> m;
	if (n <= m) {
		for (int i = 0; i < m; i++) {
			cout << n;
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			cout << m;
		}
	}
	return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() { 
    
    int a,b,c,i=0,j=0;

    cin >> a >> b >> c;
    for(i=a ; i<=b;i++){
    	if(c%i==0) j++;
    }


    cout << j << endl;


    


    return 0;
}


Measured memory_bytes: 3100
A = []
B = []
ans = 0
for i in range(5):
    num = int(input())
    if num%10 == 0:
        ans += num
    else:
        A.append(num)
        B.append(num+(10-num%10))
a = []
if len(A) == 0:
    print(ans)
else:
    for i in A:
        a.append(i%10)
    print(ans+sum(B)-(10-min(a)))

Measured memory_bytes: 3060
def abc081_b():
    _ = int(input())
    a = list(map(int, input().split()))
    ans = 100000
    for num in a:
        tmp = 0
        while num % 2 == 0:
            num /= 2
            tmp += 1
        if tmp < ans:
            ans = tmp
    print(ans)


abc081_b()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
//#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF (1<<31)-1;
#define mem(a) (memset(a,0,sizeof(a)))
struct P{
    int x,y;
}H[200000];
vector<int>G[200000];
int POS(int k,int value){
    int mid;
    int left = 0;
    int len = G[k].size();
    int right = len - 1;
    //cout<<" "<<k<<"A"<<value<<endl;
    while(left <= right){

        // 确保中点靠近区间的起点
        mid = left + (right-left)/2;
        //cout<<mid<<endl;
        //cout<<"mid= "<<mid<<" "<<left<<" "<<right<<endl;
        // 如果找到则返回
        if(G[k][mid] == value) return mid;
        // 将中点赋给终点
        else if(G[k][mid] > value) right = mid;
        // 将中点加一赋给起点
        else left = mid + 1;
    }
    return -1;
}
set<int>::iterator it;
int main()
{
    set<int>s;
    int N,M;
    int x,y;
    cin>>N>>M;
    for(int i=1;i<=M;i++){
        cin>>x>>y;
        H[i].x = x;
        H[i].y = y;
        G[x].push_back(y);
        s.insert(x);
    }
    for(int i=1;i<=N;i++){
        sort(G[i].begin(),G[i].end());
    }


    for(int i=1;i<=M;i++){
        cout<<setw(6)<<setfill('0')<<H[i].x;
        cout<<setw(6)<<setfill('0')<<POS(H[i].x,H[i].y)+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 15488
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<regex>
#include<set>
#include<initializer_list>
#include<tuple>
#include<queue>
#include<functional>
#include<random>
#include<cstdlib>
#include<fstream>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()

const int INFTY = 100000000;
const long long LINFTY = 1e20;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;

int main()
{
	string s;
	cin >> s;
	vector<bool> v(4, false);
	for (auto& c : s)
	{
		if (c == 'N') v[0] = true;
		if (c == 'W') v[1] = true;
		if (c == 'S') v[2] = true;
		if (c == 'E') v[3] = true;
	}
	if (v[0] != v[2]) cout << "No" << endl;
	else if (v[1] != v[3]) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int A[20];
    int x[20][20],y[20][20];
    cin >> N;
    REP(i,N){
        cin >> A[i];
        REP(j,A[i]){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int Ans=0;
    for(int j=0;j<(1<<N);j++){
        int num=0;
        bool lie=true;
        //cout << j << "  ";
        REP(i,N){
            //cout << (j>>(N-i-1))%2 << " ";
            if((j>>(N-i-1))%2==1){
                num++;
                REP(k,A[i]){
                    if((j>>(N-x[i][k]-1))%2!=y[i][k]){
                        lie=false;
                    }
                }
            }
        }//cout << endl;
        if(lie){
            Ans=max(Ans,num);
            //cout << j << endl;
        }
    }
    cout << Ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
const int MAXN = 1e5+5;
int A[MAXN], rain[MAXN];
int N;

/*
A[0] = A[N]
M[N+1] = M[1]

A[i] = M[i] + M[i+1]
M[i] = M[1] + sum_(j=1)^(i-1) A[j] * (-1)^(i - j - 1)

A[N] = M[N] + M[1]
M[N] = M[1] + sum_(j=1)^(N-1) A[j] * (-1)^(N - j - 1)
*/

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; ++i) {
        scanf("%d", &A[i]);
    }
    rain[1] = A[N];
    for (int i = 1; i < N; ++i) {
        if ((N - i) & 1) {
            rain[1] -= A[i];
        } else {
            rain[1] += A[i];
        }
    }
    rain[1] >>= 1;
    for (int i = 2; i <= N; ++i) {
        rain[i] = A[i-1] - rain[i-1];
    }
    for (int i = 1; i <= N; ++i) {
        printf("%d ", rain[i] * 2);
    }
    putchar('\n');
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const int maxn = 200000;
int a[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    long long p=2147483647,z,sum1=0,sum2=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum1+=a[i];
    }
    for(int j=n-1;j>0;j--)
    {
        sum1-=a[j];
        sum2+=a[j];
        z=abs(sum1-sum2);
        if(z<p)
            p=z;
    }
    printf("%d\n",p);
    return 0;
}


Measured memory_bytes: 1024
/*
 *  Created on: 3 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

//#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)

ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ll mod = 1e9 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed
        ll n, k; cin >> n >> k;
    map<ll, ll>mp;
    while (k--)
    {
        ll x; cin >> x;
        loop(i, 0, x)
        {
            ll a; cin >> a;
            mp[a]++;
        }
    }
    ll ans = n - sz(mp);
    cout << ans;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
 
int main(){
    int i,n;
    double s[1000],ave,sum,answer;
    char input[4001],*p;
     
    while(1){
        sum=0.0;
        fgets(input,sizeof input,stdin);
        sscanf(input,"%d",&n);
         
        if(n==0){
            break;
        }
         
        fgets(input,sizeof input,stdin);
         
        p=strtok(input," ");
        s[0]=strtod(p,NULL);
        sum+=s[0];
        for(i=1;i<n;i++){
            p=strtok(NULL," ");
            s[i]=strtod(p,NULL);
            sum+=s[i];
        }
        //??????
        ave=sum/(double)n;
        //??????
        for(i=0;i<n;i++){
            s[i]-=ave;
        }
        sum=0.0;
        //?????£
        for(i=0;i<n;i++){
            sum+=s[i]*s[i];
        }
        ave=sum/(double)n;
        //?¨??????????
        answer=sqrt(ave);
        printf("%f\n",answer);
    }
    return 0;
}




Measured memory_bytes: 2048
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    d = [0]*(n+1)
    for i in range(1, n+1):
        for j in range(i, n+1, i):
            d[j] += 1
    ans = 0
    for i in range(n+1):
        if i%2 and d[i] == 8:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9152
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N=1e6+2;
int a[N],b[N];
int main()
{
    ft
    int i,j,n,m,x,l=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    for(i=0;i<n;i++)
    {
        x=a[i];
        if(b[x]<2 && b[1]==0)
        {
            int f=0,d;
            for(j=2;j<=(x/j);j++)
            {
                if(x%j==0)
                {
                    d=x/j;
                    if(b[j]>0 || b[d]>0)
                    {
                        f=1;
                        break;
                    }
                }
            }
            if(f==0)
            {
                l++;
            }
        }
    }
    if(b[1]==1)
    {
        l++;
    }
    cout<<l<<"\n";
    return 0;
}

Measured memory_bytes: 8220
n=gets.to_i
a=[];b=[]
n.times{a<<gets}
m=gets.to_i
m.times{b<<gets}
c=0
for v in a;d=0;for w in a;d+=v==w ?1:0;end;for w in b;d-=v==w ?1:0;end;c=[c,d].max;end
puts c

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;



int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count=0;
  rep(i,1000){
    string v = to_string(i);
    string zero = "";
    rep(k,3-(int)v.size()) zero+="0";
    v= zero+v;

    int p1=0,p2=0,p3=0;
    while(v[0]!= s[p1] && p1 < n) p1++;
    if(p1>=n) continue;
    p2 = p1+1;
    while(v[1]!= s[p2] && p2 < n) p2++;
    if(p2>=n) continue;
    p3 = p2+1;
    while(v[2]!= s[p3] && p3 < n) p3++;
    if(p3>=n) continue;

    count++;
  
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b;
  cin >> a >> b;

  int mx = max(a, b);
  //int mn = min(a, b);
  if (a == b) cout << a + b << endl;
  else cout << 2 * mx - 1 << endl;
}


Measured memory_bytes: 3564
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

char n[110];
int szN;
int k;

long long f[110][5];

void init()
{
//	f[0][0] = 1;
//	f[1][0] = 1;
//	f[1][1] = 9;
//	f[2][0] = 1;
//	f[2][1] = 18;
//	f[2][2] = 81;
//	f[3][0] = 1;
//	f[3][1] = 27;
//	f[3][2] = 243;
//	f[3][3] = 729;

	f[0][0] = 1;
	f[1][0] = 1;
	f[1][1] = 9;
	f[2][0] = 1;
	f[2][1] = 18;
	f[2][2] = 90;
	f[3][0] = 1;
	f[3][1] = 27;
	f[3][2] = 243;
	f[3][3] = 729;
	
	for (int i = 4 ; i <= 100 ; i++) {
		f[i][0] = 1;
		f[i][1] = 9 + f[i-1][1];
		f[i][2] = i * (i - 1) / 2 * 9 * 9;
		f[i][3] = i * (i - 1) * (i - 2) / 6 * 9 * 9 * 9;
	}

}
		
int main()
{
	init();	
	
	scanf("%s\n", n);
	szN = strlen(n);
		
	scanf("%d", &k);
	
	long long count = 0;
	int level = szN;
	int curK = k;
	int curOnes = 0;
	for (int i = 0 ; i < szN ; i++, level--) {
		if (curK <= 0) {
			break;
		}
		
		long long ans = 0;
		int cc = n[i] - '0';
		if (cc == 0) {
			continue;
		} else {
			curOnes++;
			if (curOnes == k)
				count++;
			ans = ans + f[level - 1][curK];
			for (int j = 1 ; j < cc ; j++) {
				ans = ans + f[level - 1][curK - 1];
			}
			curK--;
		}
		
		
		count = count + ans;
	}
	
	
	
	printf("%lld\n", count);
	
	
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include<string.h>

int main(){
  int i=0,A[100];
  char stack[100];
 

  while(scanf("%s",stack)!=EOF){
    if(stack[0]=='+'){
      A[i-2]=A[i-2]+A[i-1];
      i--;
    }
    else if(stack[0]=='-'){
      A[i-2]=A[i-2]-A[i-1];
      i--;
    }
    else if(stack[0]=='*'){
      A[i-2]=A[i-2]*A[i-1];
      i--;
    }
    else{
      A[i]=atoi(stack);
      i++;
    }
  }
  printf("%d\n",A[i-1]);      
  return 0;
}

Measured memory_bytes: 548
#include <iostream>
#include <vector>
#include <set>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){

  string str;
  string hint;

  cin >> str >> hint;

  int ind = str.size()-hint.size();

  vector<string> vec;
  REP(i,ind+1){
    string tmp = str.substr(i,hint.size());
    bool flag = true;
    REP(j,(int)hint.size()){
      if(tmp[j] != '?' && tmp[j] != hint[j]){
        flag = false;
        break;
      }
    }
    if(flag){
      string candidate = str.substr(0,i) + hint;
      if(hint.size()+ind <= str.size()){
        candidate += str.substr(i+hint.size(),ind-i);
      }
      //cout << candidate << endl;
      vec.push_back(candidate);
    }
  }

  set<string> st;

  REP(i,(int)vec.size()){
    REP(j,(int)vec[i].size()){
      if(vec[i][j] == '?'){
        vec[i][j] = 'a';
      }
    }
    st.insert(vec[i]);
  }

  if((int)hint.size() == 1){
    REP(i,(int)str.size()){
      if(str[i] == hint[0]){
        auto itr = st.begin();
        ++itr;
        cout << *itr << endl;
        return 0;
      }
    }
  }


  if(!st.empty()){
    cout << *st.begin() << endl;
  }else{
    cout << "UNRESTORABLE" << endl;
  }  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
int a[202020], memo[202020];

int main(){
    
    // 1. 入力情報.
    int N;
    LL K;
    scanf("%d %lld", &N, &K);
    rep(i, N) scanf("%d", &a[i + 1]);
    
    // 2. 周期を求める.
    int cur = 1;        // 町1 が スタート.
    vector<int> v1, v2; // 訪問した町を記録.
    while(memo[cur] < 2){
        // 訪問したことを記録.
        memo[cur]++;
        
        // テレポートした町を保存.
        if(memo[cur] == 1) v1.pb(cur); // 1回目訪問.
        if(memo[cur] == 2) v2.pb(cur); // 2回目訪問.
        
        // 次の町へ.
        cur = a[cur];
    }
    
    // 3. 1回訪問した町 と 2回訪問した町を分ける.
    LL one = (LL)(v1.size() - v2.size());
    LL two = (LL)v2.size();
    
    // 4. K回テレポートした場合は？
    int ans = 0;
    if(one >= K){
        ans = v1[(int)K];
    }else{
        LL res = (K - one) % two;
        ans = v2[(int)res];
    }
    
    // 5. 出力.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 6996
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

const int N = 1e5 + 7;
const long long INF = 1LL << 60;

int n, a[N], k;
long long sum[N], ans;
long long f[N][2];

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sum[i] = sum[i - 1] + a[i];
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < 2; j++) {
			f[i][j] = -INF;
		}
	}
	f[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 2; j++) {
			f[i + 1][j] = max(f[i][j] + max(0, a[i + 1]), f[i + 1][j]);
		}
		if (i + k <= n) {
			f[i + k][1] = max(f[i + k][1], f[i][0] + max(0LL, sum[i + k] - sum[i]));
		}
	}
	cout << f[n][1] << endl;
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string S;
  cin >> S;
  long long temp = 0;
  rep(i, S.size())
  {
    temp += S[i] - '0';
  }
  long long ans = (S.size() - 1) * 9;
  ans += S[0] - '0' - 1;

  ans = max(temp, ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def hersCode(l, r, n, N):
  ok = l
  ng = r + 1
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if mid * n <= N:
      ok = mid
    else:
      ng = mid
  return ng


N, K = list(map(int, input().split()))
MOD = 10 ** 9 + 7

if N == 1:
  print(1)
  exit()

L = []
t = 1
n = N
while t <= N:
  L.append(t)
  t = hersCode(t, N, N // t ,N)

D = [0] * len(L)
L.append(N + 1)
for i in range(len(L) - 1):
  D[i] = (L[i + 1] - L[i]) % MOD
DP = [[0] * (len(D)) for _ in range(K)]
for i in range(len(D)):
  DP[0][i] = D[i]

for i in range(1, K):
  S = [0] * len(D)
  S[0] = DP[i - 1][0]
  for j in range(1, len(D)):
    S[j] = S[j - 1] + DP[i - 1][j]
  for j in range(len(D)):
    DP[i][j] = S[-1 -j] * D[j] % MOD

print(sum(DP[K - 1]) % MOD)
    

Measured memory_bytes: 106844
#include <stdio.h>


int main(void){
  int n,ans=1;

  scanf("%d\n",&n );
  char s[n];
  scanf("%s",s );

  for (int i = 0; i < n-1; i++) {
    if (s[i]!=s[i+1]) {
      ans+=1;
    }
  }
  printf("%d\n",ans );

  return 0;
}


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

const int MAXN = 1e5;

int n, m;
bool can_be_red[MAXN+1];
int n_of_balls[MAXN+1];

int main() {
	scanf("%d%d", &n, &m);
	
	can_be_red[1] = 1;
	for(int i = 0; i < n; i++) n_of_balls[i+1] = 1;
	
	for(int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		if(can_be_red[x]) can_be_red[y] = 1;
		if(n_of_balls[x] == 1) can_be_red[x] = 0;
		n_of_balls[x]--;
		n_of_balls[y]++;
	}
	printf("%d\n", (int)count(can_be_red+1, can_be_red+n+1, 1));
	return 0;
}

Measured memory_bytes: 768
// abc123_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt");
    cin.rdbuf(in.rdbuf());
#endif

    ull X,Y,Z,K;
    cin >> X >> Y >> Z >> K;

    ull A[1000],B[1000],C[1000];
    REP(i, X) cin >> A[i];
    REP(i, Y) cin >> B[i];
    REP(i, Z) cin >> C[i];

    vector<ull> ab{};
    REP(i, X) REP(j, Y) ab.emplace_back(A[i] + B[j]);
    sort(ALL(ab));

    int k, sz;
    sz = (int) ab.size();
    k = min(sz, 3000);
    vector<ull> abc{};
    REPN_REV(i, sz-k, sz) REP(j, Z) abc.emplace_back(ab[i] + C[j]);
    sort(ALL(abc));

    sz = (int) abc.size();
    k = min(sz, (int)K);
    REPN_REV(i, sz-k, sz) print(abc[i]);

    return 0;
}


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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 1e5 + 5;

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

  ll n, color = 1;
  cin >> n;
  vector < ll > a(n + 1), c(n + 1);
  for(int i = 1; i <= n; i++) cin >> a[i];

  set < pair < ll, ll > > s;
  s.insert({a[1], 1});
  for(int i = 2; i<= n; i++){
    auto it = s.lower_bound({a[i], LLONG_MIN});
    if(it != s.begin()){
      --it;
      s.insert({a[i], it -> second});
      s.erase(it);
    }else{
      color++;
      s.insert({a[i], color});
    }
  }

  cout << color << endl;
}


Measured memory_bytes: 8064
#include <stdio.h>
 
class Dice{
public:
    Dice(){
        number = new int[6];
        work = new int[6];
    };
    ~Dice(){
        delete[] number;
        delete[] work;
    };
 
    void setLabel(int index,int num){
        number[index] = num;
    };
 
    void roll(char dst){
        for(int i = 0; i < 6; i++) work[i] = number[i];
        switch(dst){
        case 'E':
            setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
            break;
        case 'N':
            setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
            break;
        case 'S':
            setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
            break;
        case 'W':
            setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
            break;
        }
    };
 
    int returnPeek(){
        return number[0];
    }
 
private:
    void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    }
 
private:
    int* number;
    int* work;
};
 
int main(){
    Dice dice;
    int label;
    char ch;
    for(int i = 0; i < 6; i++){
        scanf("%d",&label);
        dice.setLabel(i,label);
    }
    getchar(); 
    while((ch = getchar()) != '\n'){
        dice.roll(ch);
    }
    printf("%d\n",dice.returnPeek());
}


Measured memory_bytes: 2696
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  int n, h;
  cin >> n >> h;

  vec a(n), b(n);
  REP(i, n) cin >> a[i] >> b[i];

  int a_max = *max_element(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<int>());

  int ans = 0;
  REP(i, b.size()){
    h -= max(a_max, b[i]);
    ans++;
    if(h <= 0) break;
  }

  ans += ceil((D)max(h, 0ll) / a_max);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>

using namespace std;

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

  long long ans = 0;
  for(int i = 1; i <= n; i++){
    if(i%3 != 0 && i%5 != 0) ans += i;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

    int x1,y1,x2,y2;

    cin >> x1 >> y1 >> x2 >> y2;

    int tmp1 = x2-x1;
    int tmp2 = y2-y1;

    int x3 = x2-tmp2;
    int y3 = y2+tmp1;
    int x4 = x3-tmp1;
    int y4 = y3-tmp2;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;


    return 0;
}

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

int main() {
int n,x;
int LAYERS[100];
cin>>n;
int min = 101;
int c = 0;
for(int i=0;i<n;i++){
cin>>LAYERS[i];
}
sort(LAYERS,LAYERS+n);
for(int i=n-1;i>=0;i--){
	if(LAYERS[i] < min){
		c++;
		min = LAYERS[i];
	}
}
cout<<c;
	return 0;
}

Measured memory_bytes: 256
j, a = 0, []
def f(l, r):
    if l < r:
        global j, a
        c = P[j]
        j += 1
        m = I.index(c)
        f(l, m)
        f(m + 1, r)
        a += [c]


N = int(input())
P = input().split()
I = input().split()
f(0, N)
print(*a)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int

const int MAXN = 4e5 + 10; //dummy
const ll MOD = 1e9 + 7;

template<typename T>
T fast_powerModulo( T a, T b, T M){T res = (T)1;a %= M;while( b ){if( b & 1 ) res = (res * a) % M;b >>= 1;a *= a;a %= M; }return res;}

void solve(){
	int h , a;
	cin >> h >> a;
	cout << (h + a - 1) / a << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
	//int t; cin >> t;
	//while( t-- )
		solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n1,n2=0,n;
    cin>>n;
    n1=n;
    while(n){
        n2=n2*10+n%10;
        n/=10;
    }
    if(n1==n2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
n, k, q = map(int, input().split())
a = list(range(n))
b = list(range(q))
for i in range(q):
  b[i] = int(input())
  a[b[i]-1] += 1
for i in range(n):
  a[i] -= i
  if a[i] > q-k:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 11692
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    xs <- getIntList
    let (ml:mr:_) = drop ((n ` div` 2) - 1) $ sort xs
    forM_ xs $ \x -> print $ if x <= ml then mr else ml

Measured memory_bytes: 51324
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,k,s;
    cin>>n>>k>>s;
    for(i=1;i<=k;i++){
        cout<<s<<" ";
    }
    if(s==1000000000){
        s=1;
    }
    else{
        s=s+1;
    }
    for(i=k+1;i<=n;i++){
        cout<<s<<" ";
    }
}


Measured memory_bytes: 1280
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto N = readln.chomp.to!int;
    long s, last;
    foreach (a; readln.split.to!(long[])) {
        if (a >= last) {
            last = a;
        } else {
            s += last - a;
        }
    }
    writeln(s);
}

Measured memory_bytes: 11720
package main

import (
	"fmt"
	"strconv"
)

func main() {
	// Code for C - To Infinity
	var S string
	var K int
	fmt.Scanf("%s", &S)
	fmt.Scanf("%d", &K)

	var count int
	var A int
	for i := 0; i < len(S); i++ {
		A, _ = strconv.Atoi(string(S[i]))
		if A == 1 {
			count++
		} else {
			fmt.Println(A)
			break
		}

		if count == K {
			fmt.Println("1")
			break
		}
	}

}


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

string S; int N, M, V[509], U[22], power[19], num[22], cl[22], cr[22], col[22], cnts; long long mod = 1000000007;
vector<int>vec, X[22], G[22];

void dfs(int pos) {
	if (col[pos] >= 1) return;
	col[pos] = cnts; G[cnts].push_back(pos);
	for (int i = 0; i < X[pos].size(); i++) dfs(X[pos][i]);
}

int main() {
	cin >> N >> M >> S;
	for (int i = 0; i < M; i++) {
		char c1; int c2; cin >> c1 >> c2; U[i] = c2;
		for (int j = 0; j < S.size(); j++) {
			if (S[j] >= '0' && S[j] <= '9') V[j] = 100 + (int)(S[j] - '0');
			else if (S[j] == c1) V[j] = i;
		}
	}

	power[0] = 1; for (int i = 1; i <= 10; i++) power[i] = power[i - 1] * 3;

	long long ans = 0;
	for (int i = 0; i < power[M]; i++) {
		vec.clear();
		int bit[3]; for (int j = 0; j < M; j++) bit[j] = (i / power[j]) % 3;
		num[0] = 0; for (int j = 1; j <= M; j++) { if (bit[j - 1] == 0) num[j] = num[j - 1] + 1; else num[j] = num[j - 1] + 2; }

		for (int j = 0; j < N; j++) {
			if (V[j] >= 100) vec.push_back(V[j]);
			else {
				vec.push_back(num[V[j]]);
				if (bit[V[j]] >= 1) vec.push_back(num[V[j]] + 1);
			}
		}

		for (int j = 0; j < 22; j++) { cl[j] = 0; cr[j] = 9; X[j].clear(); G[j].clear(); cnts = 0; col[j] = 0; }
		for (int j = 0; j < M; j++) {
			if (bit[j] == 0) {
				if (U[j] < 9) { cl[num[j]] = 0; cr[num[j]] = U[j]; }
				else { cl[num[j]] = 0; cr[num[j]] = 9; }
			}
			if (bit[j] == 1) {
				cl[num[j]] = 1; cr[num[j]] = (U[j] / 10) - 1;
				cl[num[j] + 1] = 0; cr[num[j] + 1] = 9;
			}
			if (bit[j] == 2) {
				cl[num[j]] = max(1, U[j] / 10); cr[num[j]] = (U[j] / 10);
				cl[num[j] + 1] = 0; cr[num[j] + 1] = (U[j] % 10);
			}
		}

		bool OK = false;

		for (int j = 0; j < vec.size(); j++) {
			int p1 = vec[j], p2 = vec[vec.size() - 1 - j];
			if (p1 > p2) swap(p1, p2);
			if (p1 < 100 && p2 >= 100) {
				cl[p1] = max(cl[p1], p2 - 100);
				cr[p1] = min(cr[p1], p2 - 100);
			}
			else if (p2 < 100) {
				X[p1].push_back(p2);
				X[p2].push_back(p1);
			}
			else {
				if (p1 != p2) OK = true;
			}
		}

		for (int j = 0; j < num[M]; j++) {
			if (col[j] >= 1) continue;
			cnts++; dfs(j);
		}

		long long rem = 1;
		for (int j = 1; j <= cnts; j++) {
			int minv = 0, maxv = 9;
			for (int k = 0; k < G[j].size(); k++) { minv = max(minv, cl[G[j][k]]); maxv = min(maxv, cr[G[j][k]]); }
			rem *= max(0, maxv - minv + 1); rem %= mod;
		}
		if (OK == true) rem *= 0;
		ans += rem; ans %= mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3220
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ATakoyaki solver = new ATakoyaki();
        solver.solve(1, in, out);
        out.close();
    }

    static class ATakoyaki {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt(), x = in.readInt(), t = in.readInt();
            System.out.println((int) (Math.ceil(n * 1.0 / x) * t));
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



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

int main() {
	vector<int> pf(1000);
	
	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		int t = i;
		for (int j = 2; j <= t; j++) {
			while (t % j == 0) {
				pf[j]++;
				t /= j;
			}
		}
	}

	const int mod = 1e9 + 7;

	long long ans = 1;
	for (int i = 1; i < 1000; i++) {
		ans *= pf[i] + 1;
		ans %= mod;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int A, B;
    cin >> A >> B;
    cout << max(A - B * 2, 0) << endl;
}


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

int main(){
  string a,b; cin >> a >> b;
  bool x = true;
  for (int i; i < a.size(); i++)
    if (a[i] != b[i]) x = false;
  if(x) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc142/abc142_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;
  double p = 1 - (double)(N / 2) / N;
  printf("%.8lf", p);
}

Measured memory_bytes: 3740
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Arrays;

public class Main {
	public static class SegmentTree {
		int[] tree;
		int initial = 0;
		public SegmentTree(int n) {
			int d = (int)Math.ceil(Math.log((double)n) / Math.log(2.0));
			tree = new int[(int)Math.pow(2, d+1)];
			Arrays.fill(tree, initial);
		}

		public void update(int i, int x) {
			i += tree.length/2-1;
			tree[i] += x;
			while(i > 0) {
				i = (i - 1) / 2;
				tree[i] = tree[i*2+1] + tree[i*2+2];
			}
		}

		// usage
		// query(a, b, 0, 0, seg.tree.length/2)
		public int query(int a, int b, int k, int l, int r) {
			if(r <= a || b < l) return initial;
			if(a <= l && r-1 <= b) return tree[k];
			else {
				int vl = query(a, b, k*2+1, l, (l+r)/2);
				int vr = query(a, b, k*2+2, (l+r)/2, r);
				return vl + vr;
			}
		}

		public void print() {
			for(int i=0; i<tree.length; i++) {
				System.out.print(tree[i]+" ");
			}
			System.out.println();
		}
	}

	public static void main(String[] args) {
		FS r = new FS();
		int n = r.nextInt();
		int q = r.nextInt();
		SegmentTree seg = new SegmentTree(n);
		for(int i=0; i<q; i++) {
			int c = r.nextInt();
			int x = r.nextInt();
			int y = r.nextInt();
			if(c == 0) {
				seg.update(x-1, y);
			} else {
				System.out.println(seg.query(x-1, y-1, 0, 0, seg.tree.length/2));
			}
		}
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

Measured memory_bytes: 38332
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
#define LL  long long
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
int main(){
    int ans = 0;
    CIN(H);CIN(W);
    vector<vector<char> > vec;
    REP(a,H){
        V<char> v;
        REP(a,W){
            char c;cin >> c;
            if(c=='.')ans++;
            v.pb(c);
        }
        vec.pb(v);
    }
    int d[100][100];
    REP(a,100){
        REP(b,100){
            d[a][b]=INF;
        }
    }

    int times = 0;
    queue<pair<int,int> > que;
    que.push(make_pair(0,0));
    d[0][0]=0;
    while(!que.empty()){
        P p = que.front();
        que.pop();
        if(p.first==H-1&&p.second==W-1){
            break;
        }
       if(p.first+1<=H-1){
           if(vec.at(p.first+1).at(p.second)=='.'&&d[p.first+1][p.second]==INF){
               que.push(make_pair(p.first+1,p.second));
           d[p.first+1][p.second]=d[p.first][p.second]+1;
           }
       }
       if(p.first-1>=0){
           if(vec.at(p.first-1).at(p.second)=='.'&&d[p.first-1][p.second]==INF){
               que.push(make_pair(p.first-1,p.second));
           d[p.first-1][p.second]=d[p.first][p.second]+1;
           }
       }
       if(p.second+1<=W-1){
           if(vec.at(p.first).at(p.second+1)=='.'&&d[p.first][p.second+1]==INF){
               que.push(make_pair(p.first,p.second+1));
           d[p.first][p.second+1]=d[p.first][p.second]+1;
           }
       }
       if(p.second-1>=0){
           if(vec.at(p.first).at(p.second-1)=='.'&&d[p.first][p.second-1]==INF){
               que.push(make_pair(p.first,p.second-1));
           d[p.first][p.second-1]=d[p.first][p.second]+1;
           }
       }
    }
    if(d[H-1][W-1]==INF){
        COUT(-1);
    }else{
        COUT(ans-d[H-1][W-1]-1);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

typedef unsigned long long ull;
#define B1 100000007
#define B2 1000000007

bool rolling_hash(string const &S, int t_start, int m)
{
    int s_start = t_start + m;

    // B^mを用意する
    ull pow_B_m_1 = 1, pow_B_m_2 = 1;
    for (int k = 0; k < m; k++)
    {
        pow_B_m_1 *= B1, pow_B_m_2 *= B2;
    }

    // sとtの先頭m文字のハッシュ値sh,thを計算
    ull sh1 = 0, sh2 = 0, th1 = 0, th2 = 0;
    for (int k = 0; k < m; k++)
    {
        th1 = th1 * B1 + S[t_start + k], th2 = th2 * B2 + S[t_start + k];
        sh1 = sh1 * B1 + S[s_start + k], sh2 = sh2 * B2 + S[s_start + k];
    }

    // sをずらしてハッシュ値を更新
    for (int k = 0; s_start + k < S.length(); k++)
    {
        if (sh1 == th1 && sh2 == th2)
            return true;
        if (k + s_start < S.length())
        {
            sh1 = sh1 * B1 + S[s_start + m + k] - S[s_start + k] * pow_B_m_1;
            sh2 = sh2 * B2 + S[s_start + m + k] - S[s_start + k] * pow_B_m_2;
        }
    }
    return false;
}

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int left = -1, right = (n / 2) + 1;
    while (right - left > 1)
    {
        // cout << "left:" << left << " right:" << right << endl;
        int length = (left + right) / 2;
        bool exist_same = false;
        // 基準文字列の始点
        for (int i = 0; i < n && !exist_same; i++)
        {
            if (rolling_hash(s, i, length))
            {
                exist_same = true;
                break;
            }
        }
        if (exist_same)
        {
            left = length;
        }
        else
        {
            right = length;
        }
    }
    cout << left << endl;
    return 0;
}


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

int main() {

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

	ll sum = 0, ans1 = 0;
	for(int i=0; i<n; i++) {
		sum += a[i];
		if(i%2 == 0 && sum <= 0) {
			ans1 += 1 - sum;
			sum = 1;
		}
		if(i%2 == 1 && sum >= 0) {
			ans1 += 1 + sum;
			sum = -1;
		}
	}
	sum = 0;
	ll ans2 = 0;
	for(int i=0; i<n; i++) {
		sum += a[i];
		if(i%2 == 1 && sum <= 0) {
			ans2 += 1 - sum;
			sum = 1;
		}
		if(i%2 == 0 && sum >= 0) {
			ans2 += 1 + sum;
			sum = -1;
		}
	}

	cout << min(ans1, ans2) << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int

const int mod = 1000003;
long long inv(long long a, long long b = mod){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int p(int base, int ex){
    if(ex == 0)return 1;
    int sub = p(base, ex/2);
    sub *= sub;
    sub %= mod;
    if(ex & 1)sub *= base;
    sub %= mod;
    return sub;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int q;cin >> q;
    vi fac(mod + 2);
    fac[0] = 1;
    FOR1(i, mod+1)fac[i] = fac[i-1]* i, fac[i] %= mod;
    while(q--){
        int a, d, n;
        cin >> a >> d >> n;
        //debug(a);
        if(d== 0){
            cout << p(a, n) << endl;
            continue;
        }
        if(n >= mod){
            cout << 0 << endl;
            continue;
        }
        int start = a*inv(d);
        int end = a*inv(d) + n-1;
        
//        cout << start << "  " << end <<endl;
        if(start/mod < end/mod){
            cout << 0 << endl;
            continue;
        }
        end %= mod, start %= mod;
        int ans = fac[end] * inv(fac[max(1LL, start- 1)]);
        ans %= mod;
        ans *= p(d, n);
        ans %= mod;
        cout << ans << endl;
    }
    
}




Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,k;cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[n];
    dp[0] = 0;dp[1] = abs(a[1]-a[0]);
    for(int i=1;i<n;i++){
        dp[i] = INT_MAX;
        int count=0;
        for(int j=i-1;j>=0 && count<k;j--){
            dp[i] = min(dp[i],abs(a[i]-a[j])+dp[j]);
            count++;
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

const int mod = (int)1e9 + 7;
int n, w, a[200], dp[10001];

int main()
{
	int sum = 0, ans = 0;
	
	cin >> n >> w;
	rep(i, n) cin >> a[i], sum += a[i];
	sort(a, a + n);
	dp[0] = 1;
	if(sum < w) ans++;
	for(int i = n-1; i >= 0; i--){
		for(int j = w-a[i]; j >= 0; j--) if(dp[j]){
			(dp[j + a[i]] += dp[j]) %= mod;
		}
		for(int j = max(0, w - sum + 1); j <= w - sum + a[i] - (i ? a[i-1] : 0); j++)
			(ans += dp[j]) %= mod;
		sum -= a[i];
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <unordered_set>
#include <cctype>
#include <cassert>


using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("angle2.in", "r", stdin);
	//freopen("angle2.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;

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

	vector<int>dp(n, 2e9);
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k && i - j >= 0; j++) {
			dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
		}
	}

	cout << dp[n - 1];
 	return 0;
}

Measured memory_bytes: 1024