akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
LL lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}

int cmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}

int main(){
  LL N,K,i,ans=0;
  scanf("%lld%lld",&N,&K);
  LL H[N];
  FOR(i,0,N)scanf("%lld",&H[i]);
  if(N<=K){
    printf("0\n");
    return 0;
  }
  qsort(H,N,sizeof(LL),cmp);
  FOR(i,0,N)if(i>=K)ans+=H[i];

  printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3324
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      double[] array = new double[n];
      double sum = 0;
      for(int i = 0;i < n;i++){
      	array[i] = (double) sc.nextInt();
        sum += (double) 1/array[i];
      }
      System.out.println(1/sum);
    }
}

Measured memory_bytes: 21716
#include <stdio.h>

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

int lcm(int a,int b)
{
    return a * b / gcd(a,b); 
}

int main()
{
    int n,a[100],sum = 0;
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
    }
    int r = a[0];
    for (int i = 1; i < n; i++)
    {
        r = lcm(r,a[i]);
    }
    for (int i = 0; i < n; i++)
    {
        sum += r / a[i];
    }
    printf("%lf",(double)r / sum);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pll             pair<ll,ll>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;   }
ll lcm(ll a, ll b) { ll r=((a*b)/gcd(a,b)); return r;}
ll isOnBit(ll n, ll b) {return (n >> b) & 1;         }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll digsum(ll n)    { ll cnt=0; while(n){cnt+=(n%10); n/=10;} return cnt;}
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}


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

    ll a[n];
    forn(i,0,n)
    cin>>a[i];
    
    ll ans=0;
    forn(i,1,n-1)
    {
        if((a[i]<a[i+1] && a[i]>a[i-1]) ||(a[i]>a[i+1] && a[i]<a[i-1]))
            ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int A,B; cin >> A >> B;
    string S; cin >> S;
    int cnt = 0;
    rep(i,A+B+1) {
        if(i == A) {
            if(S[i] != '-'){
                cout << "No" << endl;
                return 0;
            }
        }
        if(S[i] == '-') cnt++;
    }
    if(cnt == 1) cout<< "Yes" <<endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    set<int> squares;
    for (int i = 1; i < 128; i++) {
        int square = i * i;
        // DEBUG(square);
        squares.insert(square);
    }

    int N, D;
    cin >> N >> D;
    int X[10][10] = {0};

    rep(i, N) {
        rep(j, D) {
            int xij;
            cin >> xij;
            X[i][j] = xij;
            // DEBUG(i);
            // DEBUG(j);
            // DEBUG(X[i][j]);
        }
    }

    // cout << "------------" << endl;
    int result = 0;
    rep(y, N) {
        rep(z, N) {
            int sum = 0;
            rep(j, D) {
                sum += (X[y][j] - X[z][j]) * (X[y][j] - X[z][j]);
            }
            // DEBUG(y);
            // DEBUG(z);
            // DEBUG(sum);
            if (squares.count(sum) > 0) result++;
        }
    }

    cout << (result / 2) << endl;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}

int64_t dp[1000][1000];

int main(){
    int H, W;
    cin >> H >> W;
    string S[1000];
    for(int i=0; i<H; i++) cin >> S[i];

    dp[0][0] = 1;
    for(int i=0; i<H; i++) for(int j=0; j<W; j++){
        if(S[i][j] == '#') continue;
        if(i>0) add(dp[i][j], dp[i-1][j]);
        if(j>0) add(dp[i][j], dp[i][j-1]);
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  ll N; cin >> N;
  vector<ll> d(N);
  for(int i = 0;i < N;i++)cin >> d[i];

  sort(d.begin(),d.end());

  cout << d[N/2] - d[N/2-1] << endl;
}


Measured memory_bytes: 1024
#input
#N = list(map(int,input().split()))
#H = list(map(int,input().split()))
[N, K] = list(map(int,input().split()))
S = str(input())
tmp = 1
list_S = []
for i in range(N):
    if i == N-1:
        list_S.append(tmp)
        break
    if S[i] != S[i+1]:
        list_S.append(tmp)
        tmp = 1
    else:
        tmp += 1
M = len(list_S)+1
list_S = list_S + [0]*(2*K+5)
if S[0] == "0":
    list_S = [0] + list_S
    
tmp = sum(list_S[0:2*K + 1])
ans = sum(list_S[0:2*K + 1])
for i in range(0,M+2,2):
    tmp = tmp - list_S[i] -list_S[i+1]
    tmp = tmp + list_S[i+2*K+1] + list_S[i+2*K+2]
    if tmp > ans:
        ans = tmp
print(ans)
    

Measured memory_bytes: 6388
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N, K;
vector<int>A;

int main() {
	cin >> N >> K;
	A.resize(N);
	map<int, int>mp;
	int counter = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		mp[i] = A[i];
	}
	for (int j = 0; j < K; j++) {
		map<int, int>np;
		map<int, int>imos;
		for (auto p : mp) {
			int i = p.first;
			int val = p.second;
			imos[max(0, i - val)] += 1;
			imos[min(N, i + val + 1)] -= 1;
		}
		int nowsum = counter;
		vector<pair<int, int>>ves;
		for (auto& p : imos) {
			nowsum += p.second;
			ves.push_back({ p.first,nowsum });
		}
		vector<int>del;
		for (auto& p : mp) {
			auto itr = upper_bound(ves.begin(), ves.end(), pair<int, int>(p.first, N + 1));
			itr--;
			p.second = itr->second;
			if (p.second == N) {
				del.push_back(p.first);
				counter++;
			}
		}
		for (int elm : del) {
			mp.erase(elm);
		}
	}
	for (int i = 0; i < N; i++) {
		if (mp.count(i)) {
			cout << mp[i];
		}
		else {
			cout << N;
		}
		if (i == N - 1) {
			cout << endl;
		}
		else {
			cout << " ";
		}
	}
	return 0;
}


Measured memory_bytes: 26404
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 2000001;
int heap[MAX];

void maxHeapify(int* A, int i, int H)
{
	int l = 2 * i, r = 2 * i + 1, largest;
	if (l <= H && A[l] > A[i])
		largest = l;
	else
		largest = i;
	if (r <= H && A[r] > A[largest])
		largest = r;

	if (largest != i) {
		swap(A[i], A[largest]);
		maxHeapify(A, largest, H);
	}
}

int main(void)
{
	int H = 0, key, max;
	string ss;
	while (1) {
		cin >> ss;
		if (ss == "end")
			break;
		else if (ss == "insert") {
			cin >> key;
			H++;
			heap[H] = key;
			for (int i = H; i > 1 && heap[i / 2] < heap[i]; i = i / 2)
				swap(heap[i], heap[i / 2]);
		}
		else {
			max = heap[1];
			heap[1] = heap[H];
			H--;
			maxHeapify(heap, 1, H);
			cout << max << endl;
		}
	}
	return 0;
}




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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<bool> used(n, false);
    rep(i, n) {
        ll tmp ;
        cin >> tmp;
        tmp--;
        a[i] = tmp;
    }
    // ループの開始を求める(nowが結果)
    ll now = a[0];
    used[0] = true;
    while(!used[now]) {
        used[now] = true;
        now = a[now];
    }
    // ループ周期と含まれるものを求める(rot, mem)
    ll rot = 0, start = now;
    vector<ll> mem;
    mem.push_back(now);
    now = a[now];
    rot++;
    while(now != start) {
        mem.push_back(now);
        now = a[now];
        rot++;
    }

    // 答えの計算
    now = 0;
    while(now != start) {
        now = a[now];
        k--;
        if(k == 0) {
            cout << now+1 << endl;
            return 0;
        }
    }

    cout << mem[k%rot]+1 << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}



Measured memory_bytes: 6832
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;
double condition = 0.0;

void func()
{
	int M, N;
	cin >> N >> M;

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

	int ok = 0;
	sort(A.begin(), A.end(), greater<int>());
	for (int i = 0; i < N; ++i)
	{
		if (4*M*A[i] >= sum)
			ok++;
		if (ok == M)
		{
			cout << "Yes\n";
			return;
		}
	}
	
	cout << "No\n";
	return;
}

int main() {
	//while(1)
	func();
	return 0;
}


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

b=0
X=0
K=0

for a in range(N):
    try:
        while X+A[b]==X^A[b]:
            X+=A[b]
            b+=1
    except:
        pass

    K+=b-a
    X-=A[a]

print(K)

Measured memory_bytes: 99488
#include <iostream>

using namespace std;

int main()
{
    int num;
    const string kei[] = {".,!? ",
                          "abc",
                          "def",
                          "ghi",
                          "jkl",
                          "mno",
                          "pqrs",
                          "tuv",
                          "wxyz" };

    cin >> num;
    for (int i = 0; i < num; i++) {
        string inp;
        char bf = '0';
        int cnt = 0;

        cin >> inp;
        for (int i = 0; i < inp.size(); i++) {
            if (inp[i] != '0') {
                bf = inp[i];
                cnt++;
            }
            else if (inp[i] == '0' && bf != '0') {
                int ind = bf - '0' - 1;
                cnt--;
                cnt = cnt % kei[ind].size();

                cout << kei[ind][cnt];
                cnt = 0;
                bf = '0';
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1212
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

K, N = gets_i_list
a_list = gets_i_list

diff_list = []

a_list.each_with_index do |a, i|
  if a_list[i+1].nil?
    next_a = a_list[0] + K
  else
    next_a = a_list[i+1]
  end
  diff_list.push(next_a - a)
end
puts K - diff_list.max


Measured memory_bytes: 18552
program ABC087B;
var
	a,b,c,x,i,j,k,r: integer;
begin
	read(a);
	read(b);
	read(c);
	read(x);
	r:=0;
	for i:=0 to x div 500 do begin
		for j:=0 to (x-500*i) div 100 do begin				k:=x-500*i-100*j;
			if (k mod 50=0) and (c>=k div 50) and (a>=i) and (b>=j) then begin
				r:=r+1;
			end;
		end;
	end;
	writeln(r);
end.


Measured memory_bytes: 128
n = int(input())
h = list(map(int,input().split()))
ans = 0
u = 0
for i in range(n):
    for j in range(i):
        if h[i] < h[j]:
            u = 1
            break
    if u == 0:
        ans += 1
    elif u == 1:
        u = 0
print(ans)

Measured memory_bytes: 3064
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	int n;
	string s;
	set<string> st;
	cin >> n;
	cin.ignore();
	while (n--) {
		getline(cin, s);
		st.insert(s);
	}
	string t = "SHCD";
	for (int i = 0; i < 4; ++i) {
		for (int j = 1; j <= 13; ++j) {
			string f = string(1, t[i]) + " " + to_string(j);
			if (st.find(f) == st.end())
				cout << f << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3192
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while (false)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main(); return 0;
}
#endif

void Main() {
  int n; cin >> n;
  cout << ((n + 1) / 2) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int a[55], x, y, n, m;
int main() {
   cin >> n >> m;
   while (m--) {
       cin >> x >> y;
       a[x]++; a[y]++;
   }
   for (int i=1; i<=n; i++) cout << a[i] << endl;
}

Measured memory_bytes: 3608
#include <iostream>

int main()
{
    int a,b[10000],c[10000];
    std::cin>>a;
    for(int i=0;i<a;i++){
       std::cin>>b[i]>>c[i];
        if(b[i]%c[i]==0)
            std::cout<<c[i]<<std::endl;
        else std::cout<<b[i]%c[i]<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 1172
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N=100005;
int n;
int a[N];
int sum[N];
int m;
LL k;
int bel[N];
int x[N];
int f[N],tmp[N];
void Pow (LL x)
{
	if (x==1)	{for (int u=1;u<=n;u++) f[u]=bel[u];return ;}
	Pow(x>>1);
	for (int u=1;u<=n;u++) tmp[u]=f[f[u]];
	for (int u=1;u<=n;u++) f[u]=tmp[u];
	if (x&1)
	{
		for (int u=1;u<=n;u++) tmp[u]=bel[f[u]];
		for (int u=1;u<=n;u++) f[u]=tmp[u];
	}
}
int ans[N];
int main()
{
	scanf("%d",&n);
	for (int u=1;u<=n;u++) scanf("%d",&a[u]);
	for (int u=1;u<=n;u++) sum[u]=a[u]-a[u-1];
	//printf("YES\n");
	scanf("%d%lld",&m,&k);
	for (int u=1;u<=n;u++) bel[u]=u;
	for (int u=1;u<=m;u++) 	{int x;scanf("%d",&x);swap(bel[x],bel[x+1]);}
	//printf("NO\n");
	Pow(k);	
	/*for (int u=1;u<=n;u++) printf("%d ",f[u]);
	printf("\n");*/
	for (int u=1;u<=n;u++) ans[u]=sum[f[u]];
	//for (int u=1;u<=n;u++) printf("%d ",ans[u]);
	LL sum=0;
	for (int u=1;u<=n;u++)
	{
		sum=sum+ans[u];
		printf("%lld.0\n",sum);
	}
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct Union_Find_Tree{
    vector<int> par, rank, num;
    
    Union_Find_Tree(int N){
        par.assign(N, -1);
        rank.assign(N, 0);
        num.assign(N, 1);
    }
    
    int root(int x){
        if(par[x] < 0 || par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x, num[x] += num[y];
        return true;
    }
    
    int size(int x) {return num[root(x)];}
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void clear(){
        fill(all(par), -1);
        fill(all(rank), 0);
        fill(all(num), 1);
    }
};

struct edge{int u, v;};

vector<int> G[500];
vector<bool> used(500, false);
int s, t;

void dfs(int now){
    used[now] = true;
    for(auto &e: G[now]){
        if(now == s && e == t) continue;
        if(used[e]) continue;
        dfs(e);
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    int MAX = 10000;
    vector<edge> es[MAX+1];
    rep(i, M){
        int u, v, c;
        cin >> u >> v >> c;
        u--, v--;
        es[c].eb((edge){u, v});
    }
    vector<edge> check[MAX+1];
    Union_Find_Tree uf(N);
    rep2(i, 1, MAX){
        for(auto &e: es[i]){
            if(uf.unite(e.u, e.v)) check[i].eb(e);
        }
    }
    int cnt = 0, sum = 0;
    rep2(i, 1, MAX){
        for(auto &e: es[i]){
            G[e.u].pb(e.v), G[e.v].pb(e.u);
        }
        for(auto &e: check[i]){
            s = e.u, t = e.v;
            dfs(s);
            if(!used[t]) cnt++, sum += i;
            fill(all(used), false);
        }
    }
    cout << cnt << ' ' << sum << endl;
}


Measured memory_bytes: 4720
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    int m, n;
    for (int i = 0; i < s.length() - 1; i++)
    {
        if (s[i] == 'A')
        {
            m = i;
            break;
        }
    }
    for (int i = s.length(); i > 0; i--)
    {
        if (s[i] == 'Z')
        {
            n = i + 1;
            break;
        }
    }
    cout << n - m;
}

Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  string s;
  cin >> s;
  stack<char> st;
  st.push(s[0]);
  int ans=0;
  for (int i=1;i<s.size();i++){
      //cout << i << endl;
      if (st.empty()){
        st.push(s[i]);
        continue;
      }
      char pre = st.top();
      if (s[i]!=pre){
        st.pop();
        ans+=2;
      }
      else{
        st.push(s[i]);
      }
      //cout << i << ": " << st.size() << endl;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.);
int x[233],y[233],n,sz;
double ans,st[666];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
		scanf("%d%d",x+i,y+i);
	for(int i=1;i<=n;i++){
		sz=0;
		for(int j=1;j<=n;j++)
			if(i^j)
				st[++sz]=atan2(x[j]-x[i],y[j]-y[i]);
		sort(st+1,st+sz+1);
		st[0]=st[sz]-2.*pi;
		ans=0;
		for(int j=1;j<=n;j++)
			ans=max(ans,st[j]-st[j-1]-pi);
		printf("%.8f\n",ans/2./pi);
	}
}


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

#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)

using ll = long long;
#define INF 1e9

int N, M;
vector<int> a, b;

int main(){
  cin >> N >> M;
  a.resize(M), b.resize(M);
  vector<vector<int>> g(N);
  REP(i, M){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    if(a[i]== 0 || b[i] == N-1){
      g[a[i]].push_back(b[i]);
    }
    if(a[i] == N-1 || b[i] == 0){
      g[b[i]].push_back(a[i]);
    }
  }
  bool ans = false;
  REP(i, g[0].size()){
    if(g[g[0][i]].size() == 1){
      ans = true;
    }
  }
  if(ans){
    cout << "POSSIBLE" << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }


  return 0;
}


Measured memory_bytes: 9976
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		try(Scanner sc = new Scanner(System.in)){
			String str = sc.next();
			String[] strArray = str.split("");
			int[] s = new int[4];
			int flag = 0;
			String ans = "";
			
			for(int i=0;i<4;i++) {
				s[i] = Integer.parseInt(strArray[i]);
			}
			
			for(int i=0;i<2;i++) {
				if(s[i+1] != s[i+2]) break;
				else if(s[i] == s[i+2] && s[i+1] == s[i+2]) {
					flag = 1;
					break;
				}
			}
			
			if(flag == 0)ans = "No";
			else if(flag == 1) ans = "Yes";
			System.out.print(ans);
		}
	}
}



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

int main(){
    int64_t N, D, count;
    cin >> N >> D;
    count = 0;
    vector<int64_t> vec1(N), vec2(N);
    for (int i = 0; i < N; i++){
        cin >> vec1.at(i) >> vec2.at(i);
    }
    for (int i = 0; i < N; i++){
        if (D * D >= vec1.at(i) * vec1.at(i) + vec2.at(i) * vec2.at(i))
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 6436
#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  char a;
  cin >> a;
  int x = a - 'a';
  if (x >= 0) cout << 'a' << endl;
  else cout << 'A' << endl;
  
  return 0;
}

Measured memory_bytes: 3620
M=10**9+7
r=[[(j-i)*4%13 for i in range(10)]for j in range(13)]
d=[1]+[0]*12
for c in input():
  if c>"9":
    d=[(sum(d[i] for i in j))%M for j in r]
  else:
    d=[d[((j-int(c))*4%13)] for j in range(13)]
    
print(d[5])

Measured memory_bytes: 3188
def examA():
    N, i = LI()
    ans = N - i + 1
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()

"""

"""

Measured memory_bytes: 4972
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

int main()
{
    int N;
    int Y;
    cin >> N >> Y;

    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= N - i; j++)
        {
            int k = N - i - j;
            if (Y - 10000 * i - 5000 * j - 1000 * k == 0)
            {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

typedef long long ll;
ll inf = 1e17;
ll INF = 1e18;
struct starryskytree{
	static const int N=1<<18;
	ll mn[N*2],ad[N*2];
	starryskytree(){
		rep(i,N*2) mn[i]=inf,ad[i]=0;
	}
	void add(int a,int b,ll v,int l=0,int r=N,int k=1){
		if(b<=l||r<=a) return;
		if(a<=l&&r<=b){
			ad[k]+=v;
			return;
		}
		add(a,b,v,l,(l+r)/2,k*2);
		add(a,b,v,(l+r)/2,r,k*2+1);
		mn[k]=min(mn[k*2]+ad[k*2],mn[k*2+1]+ad[k*2+1]);
	}
	void assign(int x,ll v){
		ll now = getmin(x,x+1);
		if(v-now<0) add(x,x+1,v-now);
	}
	ll getmin(int a,int b,int l=0,int r=N,int k=1){
		if(b<=l||r<=a) return INF;
		if(a<=l&&r<=b) return mn[k]+ad[k];
		return ad[k]+min(getmin(a,b,l,(l+r)/2,k*2),getmin(a,b,(l+r)/2,r,k*2+1));
	}
}Ap,Am,Bp,Bm;

const int MQ = 200000;
ll xs[MQ];

void assignA(int x,ll v){
	Ap.assign(x,v+x);
	Am.assign(x,v-x);
}
void assignB(int x,ll v){
	Bp.assign(x,v+x);
	Bm.assign(x,v-x);
}
int main(){
	int N,Q,A,B;
	cin>>N>>Q>>A>>B;
	A--,B--;
	assignA(B,0);
	assignB(A,0);

	rep(t,Q) cin>>xs[t],xs[t]--;

	rep(qt,Q){
		ll x = xs[qt];

		//change fix
		ll Af = min(Bm.getmin(0,x+1) + x , Bp.getmin(x,N) - x);
		ll Bf = min(Am.getmin(0,x+1) + x , Ap.getmin(x,N) - x);

		{	//prev A fix
			ll px = (qt==0 ? A : xs[qt-1]);
			Ap.add(0,N,abs(x-px));
			Am.add(0,N,abs(x-px));
		}
		{	//prev B fix
			ll px = (qt==0 ? B : xs[qt-1]);
			Bp.add(0,N,abs(x-px));
			Bm.add(0,N,abs(x-px));
		}
		{	//prev A fix
			ll px = (qt==0 ? A : xs[qt-1]);
			assignB(px,Bf);
		}
		{	//prev B fix
			ll px = (qt==0 ? B : xs[qt-1]);
			assignA(px,Af);
		}
	}
	ll ans = inf;
	rep(i,N) chmin(ans,Ap.getmin(i,i+1)-i);
	rep(i,N) chmin(ans,Bp.getmin(i,i+1)-i);
	cout<<ans<<endl;
}


Measured memory_bytes: 34560
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  var a, b = new Array[Int](n)
  for (i <- Range(0, n)) {
    a(i) = sc.nextInt()
    b(i) = sc.nextInt()
  }
  a = a.sorted
  b = b.sorted
  if (n % 2 == 1) {
    println(b(n / 2) - a(n / 2) + 1)
  } else {
    println(b(n / 2) + b(n / 2 - 1) - a(n / 2) - a(n / 2 - 1) + 1)
  }
}


Measured memory_bytes: 62532
#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define ff first
#define ss second

using ll = int64_t;

const int M = 1e9 + 7;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

constexpr int N = 16;
const ll inf = 2e18;
ll f[1 << N], s[1 << N];
int a[N][N];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
	rep(S, 0, 1 << n)
		rep(i, 0, n)
			if (S & 1 << i)
				rep(j, i + 1, n)
					if (S & 1 << j)
						s[S] += a[i][j];
	rep(S, 1, 1 << n) f[S] = -inf;
	rep(S, 0, 1 << n)
		for (int x = S; x; --x &= S)
			ckmax(f[S], s[x] + f[S & ~x]);
	cout << f[(1 << n) - 1];
}

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
void solve(void)
{
    int n, d, x;
    cin >> n >> d >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<set<int>> vs(d);
    rep(i, n)
    {
        for (int j = 0; a[i] * j < d; ++j)
        {
            int tmp = a[i] * j;
            vs[tmp].insert(i);
        }
    }
    int ans = 0;
    for (auto i : vs)
        ans += i.size();
    cout << ans + x << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3724
N,K = map(int,input().split())
print((((N+1)*(N+2-K)*(K+N+1))//2 - ((N+1)*(N+2)*(2*N+3))//6 + (K*(K-1)*(2*K-1))//6 + N + 2 - K) % (10**9 + 7))

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

int main()
{
	int money=100000;
	int n,tmp;
	cin>>n;
	for(int i=0;i<n;i++){
		money*=1.05;
		tmp=money%1000;
		if(tmp!=0){
			money-=tmp;
			money+=1000;
		}
	}
	cout<<money<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main (){
    int h,n;cin>>h>>n;
    vector<int> V(n);
    for(int i=0;i<n;i++){
            cin>>V[i];
    }
    if(accumulate(V.begin(),V.end(),0)>=h)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


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

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def cell(c, H, W, S, i, j):
    if c == '#':
        return c

    return sum([
        int(i - 1 >= 0 and S[i - 1][j] == '#'),
        int(j + 1 <= W - 1 and S[i][j + 1] == '#'),
        int(i + 1 <= H - 1 and S[i + 1][j] == '#'),
        int(j - 1 >= 0 and S[i][j - 1] == '#'),
        int(i - 1 >= 0 and j - 1 >= 0 and S[i - 1][j - 1] == '#'),
        int(i - 1 >= 0 and j + 1 <= W - 1 and S[i - 1][j + 1] == '#'),
        int(i + 1 <= H - 1 and j + 1 <= W - 1 and S[i + 1][j + 1] == '#'),
        int(i + 1 <= H - 1 and j - 1 >= 0 and S[i + 1][j - 1] == '#'),
    ])


def main():
    H, W = read_h()
    S = read_v(H, typ=str)

    for i, row in enumerate(S):
        ans_row = ''.join([str(cell(c, H, W, S, i, j)) for j, c in enumerate(row)])
        print(ans_row)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
s = input()
c = []
ans = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        ans += 1
    else:
        c.append(ans)
        ans = 0
c.append(ans)
print(max(c))


Measured memory_bytes: 9108
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll A, B, M;

    cin >> A >> B >> M;

    ll a[A];
    ll b[B];
    ll x[M];
    ll y[M];
    ll c[M];
    ll aMin, bMin, mMin;
    ll ans;

    aMin = 100000;
    for(ll i = 0; i < A; i++){
        cin >> a[i];
        if(aMin > a[i]){
            aMin = a[i];
        }
    }
    bMin = 100000;
    for(ll i = 0; i < B; i++){
        cin >> b[i];
        if(bMin > b[i]){
            bMin = b[i];
        }
    }
    mMin = 200000;
    for(ll i = 0; i < M; i++){
        cin >> x[i] >> y[i] >> c[i];
        if(mMin > a[x[i] - 1] + b[y[i] - 1] - c[i]){
            mMin = a[x[i] - 1] + b[y[i] - 1] - c[i];
        }
    }

    if(aMin + bMin <= mMin){
        ans = aMin + bMin;
    }else{
        ans = mMin;
    }

    cout << ans << endl;

    return 0;
}


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

vector<int> A;
int N, M, Q;
int maxValue = 0;
vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;
void dfs(int n) {
    if(n == N + 1) {
        int temp = 0;
        rep(i, Q) {
            if(A[b[i]] - A[a[i]] == c[i]) {
                temp += d[i];
            }
            if(temp > maxValue) maxValue = temp;
        }
        return;
    }
    for(int i = A[n - 1]; i <= M; i++) {
        A[n] = i;
        dfs(n + 1);
    }
}

int main() {
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    rep(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    A.resize(N + 1);
    fill(A.begin(), A.end(), 1);
    dfs(1);
    cout << maxValue;
    return 0;
}

Measured memory_bytes: 3612
A, B = map(int, input().split(' '))
cnt = 0

def isAnagram(num):
    n = list(str(num))
    r = list(reversed(str(num)))
    t = 0
    for i in range(len(n)):
        t += 0 if n[i] == r[i] else 1
    return 1 if t == 0 else 0

for i in range(A, B+1):
    cnt += isAnagram(i)

print(cnt)


Measured memory_bytes: 3060
/*Filename: aoj0020.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cctype>

using namespace std;

string toUpperStr(string s){
	string upperS;

	for(int i = 0; i < s.size(); ++i){
		upperS += toupper(s[i]);
	}

	return upperS;
}

int main(){
	string s;

    while(getline(cin, s)){
        cout << toUpperStr(s) << endl;
    }

	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

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

#define MAX 100005
#define INF 1001001001

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

  rep(i,1<<n) {
    bitset<18> b(i);
    if (b.count() != k) continue;
    cout << i << ":";
    rep(j,n) if (b[j]) cout << " " << j;
    cout << endl;
  }

  return 0;
}



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

inline int _max(int m1,int m2){ return (m1>m2)?(m1):(m2);}

typedef struct{
  int s;
  int e;
  int cnt;
} Data;

int main(){
  int n,w;
  while(cin>>n>>w,n){
    vector<Data> vec;
    w--;
    int s=0;
    int max=0;
    int c_max=1;
    Data d;
    d.cnt=0;
    while(true){
      d.s=s;
      s+=w;
      d.e=s;
      vec.push_back(d);
      if(s>=100){
	break;
      }
      s++;
    }
    /*
    for(int i=0;i<(int)vec.size();i++){
      cout<<vec[i].s<<" "<<vec[i].e<<endl;
    }
    */
    int size=(int)vec.size();
    for(int i=0;i<n;i++){
      int a;
      cin>>a;
      for(int j=0;j<size;j++){
	if(vec[j].s <= a && a <= vec[j].e){
	  vec[j].cnt++;
	  max = _max(j,max);
	  c_max=_max(c_max,vec[j].cnt);
	  break;
	}
      }
    }
    double ans=0.01;
    double temp=1.0/c_max;
    double t=1.0/max;
    for(int i=0;i<=max;i++){
      ans+=((max-i)*t*vec[i].cnt*temp);
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

import collections
import sys
input=sys.stdin.readline

n=int(input())
ans=[0]*n
tmp=[]
for x in range(1,int(n**0.5)+1):
    for y in range(1,int(n**0.5)+1):
        for z in range(1,int(n**0.5)+1):
            tmp.append(x**2+y**2+z**2+x*y+y*z+z*x)

cnt=collections.Counter(tmp)
for i in range(1,n+1):
    print(cnt[i])


Measured memory_bytes: 50856
// ABC 161 D LUNLUN number.


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

int main()

{
  ll n,i,count=2,temp;
  cin>>n;
  n-=1;
  if(n==1){
    cout<<1<<"\n";
    return 0;
  }

  for(i=2;i*i<n;i++)
    {
      if(n%i==0)count+=2;
    }
    if(n/i==i)count++;

    n++;

    for(i=2;i*i<=n;i++)
    {
       if(n%i==0)
       {
        temp=n;
        while(temp%i==0)
        {
          temp/=i;
        }
        if(temp%i==1)count++;
       }
    }

cout<<count<<"\n";


      return 0;
}




Measured memory_bytes: 256
S = int(input())
x0,y0,x1,y1 = 0,0,10**9,1

if S % 10**9 == 0:
    x2, y2 = 0, S // 10**9
else:
    x2, y2 = 10**9 - (S % 10**9), S // 10**9 + 1

print(x0,y0,x1,y1,x2,y2)

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

h, w = map(int, input().split())
field = []
for _ in range(h):
    line = input().rstrip()
    field.append(line)

dp = [[-1] * w for _ in range(h)]

st = deque() 
if field[h-1][w-1] == ".":
    st.append((h-1, w-1, 1))
    dp[h-1][w-1] = 0
else:
    st.append((h-1, w-1, 0))
    dp[h-1][w-1] = 1
delta = [(-1, 0), (0, -1)]
while st:
    x, y, c = st.popleft()
    for dx, dy in delta:
        if dx + x < 0 or y + dy < 0:
            continue
        if dp[dx + x][dy + y] != -1:
            continue
        dst_color = field[dx + x][dy + y] == "."
        if dst_color == c:
            dp[x + dx][y + dy] = dp[x][y]
            st.appendleft((dx + x, dy + y, dst_color))
        else:
            if dst_color == 0:
                dp[x + dx][y + dy] = dp[x][y] + 1
            else:
                dp[x + dx][y + dy] = dp[x][y]
            st.append((dx + x, dy + y, dst_color))


print(dp[0][0])

Measured memory_bytes: 42480
class Node:
    def __init__(self, label):
        self.label = label
        self.left = None
        self.right = None

def bst_insert(node, label):
    if node is None:
        return Node(label)

    elif label< node.label:
        node.left = bst_insert(node.left, label)
    else:
        node.right = bst_insert(node.right, label)
    return node

def bst_find(node, label):
    if node is None:
        return False
    elif label == node.label:
        return True
    elif label< node.label:
        return bst_find(node.left, label)
    elif label > node.label:
        return bst_find(node.right, label)




def bst_inorder(node):
    global In
    if (node.left is not None):
        bst_inorder(node.left)
    In.append(node.label)
    if (node.right is not None):
        bst_inorder(node.right)
    return

def bst_preorder(node):
    global Pre
    Pre.append(node.label)
    if (node.left is not None):
        bst_preorder(node.left)
    if (node.right is not None):
        bst_preorder(node.right)
    return

n= int(input())
tree = None
for i in range(n):
    cmmd = list(input().split( ))
    if cmmd[0] == "insert":
        k =int(cmmd[1])
        tree = bst_insert(tree, k)
    elif cmmd[0] == "find":
        k = int(cmmd[1])
        flag = bst_find(tree,k)
        if flag:
            print("yes")
        else:
            print("no")
        
    else:
        In =[]
        bst_inorder(tree)
        print("",*In)
        Pre =[]
        bst_preorder(tree)
        print("",*Pre)


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

int main(){
    int r,g,b,n;
    cin>>r>>g>>b>>n;

    int ans=0;
    for(int i=0;i<=3000;i++){
        for(int j=0;j<=3000;j++){
            int v=i*r+j*g;
            if(n>=v&&(n-v)%b==0) ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	cnt := len(s)
	cnt = calc(cnt, s, 'A')

	s = reversed(s)
	cnt = calc(cnt, s, 'Z')

	fmt.Println(cnt)
}

func reversed(s string) string {
	r := make([]rune, len(s))
	j := 0
	for i := len(s) - 1; i >= 0; i-- {
		r[j] = rune(s[i])
		j++
	}
	return string(r)
}

func calc(cnt int, s string, c rune) int {
	for i := 0; rune(s[i]) != c || cnt < 0; i++ {
		cnt--
	}
	return cnt
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#define mod 1000000000+7;
typedef long long ll;
using namespace std;


int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	string s,t; cin >> s >> t;
	int ans{};
	for(int i{}; i<s.size(); i++){
		if(s[i] == t[i]){
			
		}else{
			ans++;
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
    int a;
    cin >> a;
    a = a % 10;
    if( a == 0 || a== 1 || a == 6 || a == 8)
    cout << "pon";
    else if (a == 3)
    cout << "bon";
    else
    cout << "hon";

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    map<int, int> D;
    rep(i, N) {
        int d;
        cin >> d;
        if (d <= 12) D[d]++;
        else D[24 - d]++;
    }

    repd(i, 1, 12) {
        if ((D.count(0) != 0 && D[0] >= 1) ||
            (D.count(12) != 0 && D[12] >= 2) ||
            (D.count(i) != 0 && D[i] >= 3)) 
        {
            cout << 0 << endl;
            return 0;
        }
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << 11); bit++) {
        vector<int> t(24, 0);
        t[0] = 1; t[12] = (int)D.count(12);
        rep(i, 11) {
            if (D.count(i + 1) == 0) continue;
            if (bit & (1 << i)) {
                if (D[i + 1] == 2) t[24 - (i + 1)] = 1;
                t[i + 1] = 1;
            }
            else {
                if (D[i + 1] == 2) t[i + 1] = 1;
                t[24 - (i + 1)] = 1;
            }
        }
        int mi = 1e9;
        rep(i, 24) {
            if (t[i] == 0) continue;
            repd(j, i + 1, 24) {
                if (t[j] == 0) continue;
                chmin(mi, min(j - i, 24 - (j - i)));
            }
        }
        chmax(ans, mi);
    }

    cout << ans << endl;
    return 0;
}

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

/** defines and macros */
#define ll long long
#define ull unsigned long long
#define loop(n) for(int i = 0; i < n; i++)
#define loop1(n) for(int i = 1; i <= n; i++)
#define all(v) ((v).begin()), ((v).end())
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vvi vector<vi>
#define vvpii vector<vii>
#define PB push_back

#define fw(fileName) freopen(fileName, "w", stdout)
#define fr(fileName) freopen(fileName, "r", stdin)
#define fc(stream) fclose(stream);

#define faster_IO_stream ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define endl "\n"

/*To compile and run

	g++ -o main main.cpp && ./main

*/

/*
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣀⣤⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣤⣀⡀⠄⠄⠄⠄⠄⣰⣷⡀⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⣀⣀⣀⠄⠄⠄⠄⠄⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⠄⠄⢠⣿⣿⣷⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠤⠒⠛⠛⠛⠛⠻⠷⣦⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⣿⣿⣿⠟⠁⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⢀⣤⣤⣶⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣡⡤⠐⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⢀⣶⣿⣿⠿⢛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠁⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⢠⣿⠟⠉⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠘⠁⠄⢀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠻⣿⣿⣿⣿⣿⣿⣿⡛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⣾⣿⡿⣽⡿⢹⣿⣿⣟⣿⢻⠇⢀⢹⣿⢿⣿⣿⣿⣿⣿⣦⣙⢿⣿⢷⣈⠻⢿⣟⢿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⢿⡿⠁⡿⠁⢸⣿⣿⢹⡇⢸⠄⠈⠄⠻⣏⠻⣿⡿⣿⣿⣿⣌⠛⢿⡌⠙⢧⣀⠙⢳⡹⢻⣿⣿⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠘⡇⠄⡇⢠⣼⣿⣿⠈⡇⠘⠤⠤⠤⠤⢜⣢⣘⡻⢮⡛⢿⣿⣷⣬⡤⠤⠤⠤⠥⠤⠥⢬⣿⣧⡄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠁⠄⠄⠘⢿⡏⠛⠄⠄⠄⠄⠄⠄⠄⠄⠄⠙⣿⣿⣿⡿⠋⠉⠛⠉⠄⠄⠄⠄⠄⠄⠄⢹⡿⠃⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⡟⠁⠈⢳⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠱⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⡜⠁⠄⠄⠈⢇⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠑⠦⢄⣀⣀⣀⣀⣀⠴⠊⠄⠄⠄⠄⠄⠄⠑⠤⢀⣀⣀⣀⡀⠠⠔⠋⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣶⣦⣄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣤⣶⣆⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣿⣿⣿⣿⣶⣄⣀⣀⣀⣀⣤⣾⣿⣿⣿⣿⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣿⣿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣿⣿⣿⣿⣿⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⣿⣿⣿⣿⠟⠁⠄⠄⠄⠄⠙⢿⣿⣿⣿⡟⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⠟⠋⠁⠄⠄⠄⠄⠄⠄⠄⠄⠉⠛⠿⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
*/

const double pi = 3.14159265358979323846;
const int module = 1e9 + 7;

int main() {
	faster_IO_stream

	int n;
	cin >> n;

	ll sq = sqrt(n), res = 0;
	for(int i = 1; i <= sq; i++) {
		for(int j = i; i * j < n; j++) if(i * j < n && i != j) res += 2; else if(i * j < n) res++;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

LL MAX_N = 1000000;
LL p = 1E9 + 7;
vector<LL> factorials(MAX_N+1,0);
vector<LL> ifactorials(MAX_N+1,0);


LL getPow(LL val, LL n){
    // バイナリ法
    LL ans = 1;
    while(n > 0){
        ans = ans % p;
        if((n & 1) == 1){
            ans = (ans * (val%p)) % p;
        }
        val = ((val%p) * (val%p))%p;
        n = n >> 1;
    }
    return ans%p;
}

LL combination(LL n, LL k){
    if(k==0){return 1;}
    LL val1 = factorials[n];
    LL val2 = ifactorials[k]; //getPow(factorials[k], p-2);
    LL val3 = ifactorials[n-k]; //getPow(factorials[n-k], p-2);
    
    return ((val1 * val2)%p * val3)%p;
}



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

    LL val1 = getPow(10, N);
    LL val2 = (2*getPow(9, N))%p;
    LL val3 = getPow(8,N);

    LL ans = (val1 - val2 + val3)%p;

    if(ans < 0){ans += p;}
    cout << ans << endl;
    return 0;
     
}

Measured memory_bytes: 18688