akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()

	ans = 0
	for i in range(1, N+1):
		tmp = str(i)
		tmp = len(tmp)
		if tmp % 2 == 1:
			ans += 1

	print(ans)


if __name__ == "__main__":
	main()


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 10000000000;

using namespace std;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	long long g = gcd(a, b);
	return a / g * b;
}

int main() {
	ll a, b, c, d; cin >> a >> b >> c >> d;

	//重複を取り除くために必要
	ll g = gcd(c, d);
	ll p = c * d / g;
	
	ll x1 = b / c;
	ll x2 = b / d;

	ll x3 = b - (x1 + x2);

	ll y1 = (a - 1) / c;
	ll y2 = (a - 1) / d;

	ll y3 = (a - 1) - (y1 + y2);

	cout << x3 - y3 + (b / p) - (a - 1) / p<< endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;

#define pb push_back
#define mp make_pair

int n, w;
int weight[100], value[100];
vector<pii> a;
map<int, int> d[110];
int step = 1000000005;
int ans = 0;

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> w;
    for(int i = 0; i < n; i++){
        cin >> weight[i] >> value[i];
        step = min(weight[i], step);
    }
    int sumW = 0, sumV = 0;
    for(int i = 0; i < n; i++){
        sumW += weight[i];
        sumV += value[i];
    }
    if(sumW <= w){
        cout << sumV << endl;
        exit(0);
    }
    a.pb(mp(0, 0));
    for(int i = 0; i < n; i++){
        if(weight[i] > w) continue;
        a.pb(mp(weight[i], value[i]));
    }
    if(a.size() == 1){
        cout << 0 << endl;
        exit(0);
    }
    for(int i = 1; i < a.size(); i++){
        for(int u = 0; u <= w; u += step){
            for(int j = u; j < u + 4 * i && j <= w; j++){
                d[i][j] = d[i - 1][j];
                if(j >= a[i].first && (d[i - 1][j - a[i].first] + a[i].second > d[i][j])){
                    d[i][j] = d[i - 1][j - a[i].first] + a[i].second;
                    ans = max(ans, d[i][j]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 95872
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<math.h>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
//#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
const int INF=0x3f3f3f3f;
inline int mul(int a,int b){ return (a*1ll*b)%mod; }
inline int add(int a,int b){ a+=b;if(a>=mod) a-=mod; return a;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1) rt=rt*a;a=mul(a,a);b>>=1;} return rt;}
//for(int i=0;i<n;i++)
ll mxm(ll a,ll b){
    if(a>b) return a;
    else return b;
}

int gcd(int a,int b){
    if(b==0) return a;
    else return gcd(b,a%b);
}
//for(int i=0;i<n;i++)

void solve(){
   string n;cin>>n;
   ll ans=0;
   for(char c:n) ans+=c-'0';
   if(ans%9==0)
   cout<<"Yes"<<"\n";
   else
   cout<<"No"<<"\n";
}

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

Measured memory_bytes: 3732
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int ans=(a+b)/2;
    
 	if(a%2==1&&b%2==0){
    		System.out.println("IMPOSSIBLE");
    	}else if(a%2==0&&b%2==1){
     		System.out.println("IMPOSSIBLE");
   	 }else{

    	System.out.println(ans);
    }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define loop(i, a, b) for(ll i = a; i < b; i++)
#define rloop(i, e, s) for(ll i = e; i >= s; i--)
const ll mod = 1e9 + 7;
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr);

int main()
{
    //Typical Stairs
    int n, m, x;
    cin >> n >> m;
    int a[100005] = {0};
    loop(i, 1, m+1) {
        cin >> x;
        a[x] = 1;
    }
    int r[100005];
    r[0] = 1;
    loop(i, 1, n+1){
        if(a[i] != 1) r[i] = (r[i-1]+r[i-2])%mod;
        else r[i] = 0;
    } 
    cout << r[n] << endl;
}

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

int main() {
  int n,l;
  cin >> n >> l;
  int L,R,e;
  L = l;
  R = n + l -1;
  if(R < 0){
    e = R;
  }
  else if(L > 0){
    e = L;
  }
  else{
    e = 0;
  }
  cout << (L+R)*n/2 - e << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans;
vector<int>e[100001];
int col[1000001];
int dep[1000001];
void dfs(int u,int fa)
{
	dep[u]=dep[fa]+1;
	int c=0;
	for(int i=0;i<e[u].size();i++)
		if(e[u][i]!=fa)
		{
			++c;
			if(c==col[u])
				++c;
			col[e[u][i]]=c;
			dfs(e[u][i],u);
		}
	ans=max(ans,c);
}
int u[100001],v[1000001];
signed main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		e[u[i]].push_back(v[i]);
		e[v[i]].push_back(u[i]);
	}
	dfs(1,0);
	printf("%d\n",ans);
	for(int i=1;i<n;i++)
	{
		if(dep[u[i]]<dep[v[i]])swap(u[i],v[i]);
		printf("%d\n",col[u[i]]);
	}
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  if (N >= 2) {
    if (N >= 4) {
      if (N >= 8) {
        if (N >= 16) {
          if (N >= 32) {
            if (N >= 64) {
              cout << 64;
            }
            else {
              cout << 32;
            }
          }
          else {
            cout << 16;
          }
        }
        else {
          cout << 8;
        }
      }
      else {
        cout << 4;
      }
    }
    else {
      cout << 2;
    }
  }
  else {
    cout << 1;
  }
}

Measured memory_bytes: 256
c = [1.1,0.6,0.2,0.0]
r = [0 for i in range(8)]
while 1:
    try:
        e = map(float, raw_input().split())
        for i in range(2):
            for j in range(4):
                if e[i] >= c[j]:
                	r[i+2*j] += 1
                	break
    except:
        break
for i in range(0,8,2):
	print r[i],r[i+1]

Measured memory_bytes: 4240
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define getchar getchar_unlocked
#define pb push_back
using namespace std;
constexpr int MAXN = 1e5 + 10;
vector <int> G[MAXN];
bool visit[MAXN];
bool color[MAXN];
bool ck;
int n, m;
inline void dfs(int s)
{
	for(auto u : G[s])
	{
		if(visit[u] == false)
		{
			color[u] = color[s] ^ 1;
			visit[u] = true;
			dfs(u);
		}
		else
		{
			if(color[u] != 1 - color[s])
				ck = true;
		}
	}
}
template <class T>
inline void _read(T &x)
{
	x = 0;
	char t = getchar();
	while(!isdigit(t) && t != '-') t = getchar();
	if(t == '-')
	{
		_read(x);
		x *= -1;
		return ;
	}
	while(isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
int main()
{
	_read(n), _read(m); 
	for(int i = 1, a, b; i <= m; ++i)
	{
		_read(a), _read(b);
		G[a].pb(b);
		G[b].pb(a);
	}

	dfs(1);
	if(ck)
		printf("%lld", 1ll * n * (n - 1) / 2 - m);
	else
	{
		int cnt = 0;
		for(int i = 1; i <= n; ++i)
			cnt += color[i];
		printf("%lld", 1ll * cnt * n - 1ll * cnt * cnt - 1ll * m);
	}
}

Measured memory_bytes: 7552
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

			String in = br.readLine();
			String chr[] = in.split("");
			String inp = br.readLine();
			String chrp[] = inp.split("");
			String inpu = br.readLine();
			String chrpu[] = inpu.split("");

			System.out.println(chr[0]+chrp[1]+chrpu[2]);

		}
	}
}

Measured memory_bytes: 25348
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//[)
const int MAX_N = 2010;
ll row,col;
ll rui[MAX_N][MAX_N];
ll ele[MAX_N][MAX_N];
void make_sum(){
  for(int i=0;i<row;i++)
    for(int j=0;j<col;j++)
      rui[i+1][j+1] = ele[i][j] + rui[i+1][j] + rui[i][j+1] - rui[i][j];
}

ll get_sum(int lx,int ly,int rx,int ry){
  if(lx>rx||ly>ry)return 0;
  else return rui[rx][ry] - rui[lx][ry] - rui[rx][ly] + rui[lx][ly]; 
}

string ch[1111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w,k;cin>>h>>w>>k;
  row = h;col = w;
  for(int i=0;i<h;i++){
    cin>>ch[i];
    for(int j=0;j<w;j++){
      ele[i][j] = ch[i][j]-'0';
    }
  }
  make_sum();
  if(get_sum(0,0,h,w) <= k){
    cout<<0<<endl;
    return 0;
  }

  ll ans = llINF;
  for(int i=0;i<BITLE(h-1);i++){

    ll cnt = 0;
    for(int j=0;j<h-1;j++)
      if(i&(BITLE(j)))cnt++;

    bool fl = true;
    ll pre2 = 0;

    for(int jj=0;jj<w;jj++){
      ll pre = 0;
      bool fll = false;
      //cout<<jj<<endl;
      //      cout<<"!"<<endl;
      for(int j=0;j<h-1;j++){

	if(i&BITLE(j)){
	  // cout<<jj<<endl;
	  if(get_sum(pre,pre2,j+1,jj+1) > k){
	    //cout<<pre2<<" "<<jj<<endl;
	    if(jj == pre2){

	      fl = false;
	      break;
	    }
	    fll = true;
	    break;
	  }
	  pre = j+1;
	}
      }
      // cout<<"!"<<endl;
      if(get_sum(pre,pre2,h,jj+1) > k){
	if(pre2 == jj)fl = false;
	fll = true;
      }

      if(fll){
	pre2 = jj;
	jj--;
	cnt++;
      }
      if(fl == false)break;
    }
    //cout<<i<<endl;
    if(fl == false)continue;

    ans = min(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
	int n,x;
	cin >> n >> x;
	int m;
	int sum = 0;
	int anko = 1e9;
	rep(i,n){
		cin >> m;
		sum += m;
		if(anko > m){
			anko = min(anko,m);
		}			
	}
	int ans = n;
	ans += (x-sum)/anko;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, m; cin >> n >> m;
    priority_queue<int> que;
    rep(i, n) {
        int price;
        cin >> price;
        que.push(price);
    }

    rep(i, m) {
        int p = que.top();
        que.pop();
        p /= 2;
        que.push(p);
    }

    ll ans = 0;
    while (!que.empty()) {
        int p = que.top();
        que.pop();
        ans += p;
    }
    cout << ans << endl;

}

Measured memory_bytes: 892
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

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

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

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);


	int s;
	cin >> s;
	
	vector<int> data(s);
	rep(i, 0, s) {
		cin >> data[i];

	}
	
	int ans = 0;

	rep(i, 0, s) {

		ans += data[i] - 1;;
	}

	cout << ans << endl; 


}
	

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

int main()
{
    string n;
    cin >> n;
    if((n[0] == n[1] && n[0] == n[2]) || (n[1] == n[2] && n[1] == n[3]))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
	using namespace std;

	int main() {
		int N;
		cin >> N;
		double A = N - N / 2;
		cout << A / N << endl;
		
	}
		



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}

int main() {
	int r,g,b;
	cin >>r>>g>>b;
	if((10*g+b)%4==0){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

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

typedef long long ll;

ll getInversePair(vector<ll>& nums, int start, int end, vector<ll>& copy) {
    if (start >= end) {
        return 0;
    }
    int mid = (end - start) / 2 + start;
    ll leftCnt = getInversePair(nums, start, mid, copy);
    ll rightCnt = getInversePair(nums, mid + 1, end, copy);
    int p = start;
    int q = mid + 1;
    int index = start;
    ll cnt = 0;
    while (p <= mid && q <= end) {
        if (nums[p] <= nums[q]) {
            copy[index++] = nums[p++];
            cnt += end - q + 1;
        } else {
            copy[index++] = nums[q++];
        }
    }
    while (p <= mid) copy[index++] = nums[p++];
    while (q <= end) copy[index++] = nums[q++];
    for (int i = start; i <= end; ++i) {
        nums[i] = copy[i];
    }
    return (leftCnt + rightCnt + cnt);
}

bool check(ll m, ll lim, const vector<ll> &nums, vector<ll> &sums, vector<ll> &copy) {
    sums[0] = 0;
    for (int i = 0; i < nums.size(); ++i) {
        sums[i + 1] = sums[i];
        if (nums[i] >= m) {
            sums[i + 1]++;
        } else {
            sums[i + 1]--;
        }
    }
    ll res = getInversePair(sums, 0, sums.size() - 1, copy);
    return res >= lim;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> nums(n);
    vector<ll> copy(n + 1);
    ll l = LONG_LONG_MAX;
    ll r = LONG_LONG_MIN;
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
        l = min(l, nums[i]);
        r = max(r, nums[i]);
    }
    vector<ll> sums(n + 1);
    ll lim = (n * (n + 1) / 2 + 1) / 2;
    ll m;
    ll ans = 0;
    while (l <= r) {
        m = (r - l) / 2 + l;
        if (check(m, lim, nums, sums, copy)) {
            ans = m;
            l = m + 1;
        } else {
            r = m - 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2688
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int jdg = Math.abs(a-b);
        if(jdg > 1){
            System.out.println(":(");
        }else{
            System.out.println("Yay!");
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const int mod = 1e9 + 7;
#define int long long int

int32_t main() {
    IOS ;
    // int t ; cin >> t ; while(t--) {}
    
    int n, k ; cin >> n >> k ; 
    int arr[n+1], dp[n+1][k+1] ;  
    
    for(int i=1; i<=n; i++) cin >> arr[i] ; 
    
    dp[0][0] = 1 ;
    for(int i=1; i<=k; i++) dp[0][i] = 0 ; 
    for(int i=1; i<=n; i++) dp[i][0] = 1 ;
    
    for(int i=1; i<=n; i++) {
        
        int sum[k+1] ; sum[0] = dp[i-1][0] ; 
        for(int j=1; j<=k; j++) 
        sum[j] = (sum[j-1] + dp[i-1][j]) % mod ;
        
        for(int j=1; j<=k; j++)
        if(j - arr[i] - 1 >= 0) 
        dp[i][j] = (sum[j] - sum[j-arr[i]-1]+ mod) % mod ; 
        else dp[i][j] = sum[j] ;
    }
    
    cout << dp[n][k] ; 
    
    return 0 ;
}


Measured memory_bytes: 83232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		long x = fs.nextLong();
		long k = fs.nextLong();
		long d = fs.nextLong();
		
		long restK;
		if(k % 2 == 0) {
			restK = k;
		}else {
			if(x < 0) {
				x += d;
			}else {
				x -= d;
			}
			restK = k - 1;
		}
		
		long step = 2 * d;
		long sho = Math.abs(x / step);
		if(restK >= 2 * sho) {
			if(x > 0) {
				x -= sho * step;
			}else {
				x += sho * step;
			}
			
			restK -= 2 * sho;
		}else {
			if(x > 0) {
				x -= step * (restK / 2);
			}else {
				x += step * (restK / 2);
			}
			restK = 0;
		}
		
		if(restK > 0) {
			if(x > 0) {
				System.out.println(Math.min(Math.abs(x), Math.abs(x - step)));
			}else {
				System.out.println(Math.min(Math.abs(x), Math.abs(x + step)));
			}
		}else {
			System.out.println(Math.abs(x));
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 32864
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;
typedef pair<ll,int> P;


int main(){
  int n;
  cin>>n;
  pair<pair<string,int>,int> p[100];
  for(int i=0;i<n;i++){
    string s;
    int temp;
    cin>>s>>temp;
    p[i]=make_pair(make_pair(s,-temp),i);
  }
  sort(p,p+n);
  for(int i=0;i<n;i++) cout<<p[i].second+1<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int c,d,w,x;
	while(cin>>c>>d>>w>>x,c+d+w+x){
		vvi dp(x+1,vi(w+1,-inf));
		dp[0][0]=0;
		vvi e(c,vi(d));
		vvi f(c,vi(d));
		rep(i,c)rep(j,d)cin>>e[i][j];
		rep(i,c)rep(j,d)cin>>f[i][j];
		rep(i,d){
			vvi ndp=dp;
			rep(j,c)if(e[j][i]){
				int sume=0,sumf=0;
				loop(k,j,c){
					if(e[k][i]==0)break;
					sume+=e[k][i];
					sumf+=f[k][i];
					rep(l,x+1)rep(q,w+1)if(dp[l][q]!=-inf){
						int L=(j==k?l:l+1);
						if(L>=x+1||q+sumf>=w+1)continue;
						ndp[L][q+sumf]=max(ndp[L][q+sumf],dp[l][q]+sume);
					}
				}
			}
			dp=ndp;
//			rep(j,x+1){
//				rep(k,w+1)cout<<" "<<(dp[j][k]==-inf?0:dp[j][k]);cout<<endl;
//			}
//			cout<<endl;
		}
		int out=0;
		rep(i,x+1)rep(j,w+1)out=max(out,dp[i][j]);
		cout<<out<<endl;
	}
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
//#define DEBUG
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

ll fight(ll n){
    if( n == 1){
        return 1;
    }else{
        return 1 + fight(n/2) * 2;
    }
}
void solve(){
    ll h;
    cin >> h;
    cout << fight(h) << "\n";
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

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

const int MAXN=100005;

vector< pair<int,int> > edge[MAXN];
int n,m,in[MAXN],f[MAXN];

int main(){
    memset(in,0,sizeof(in));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        edge[a].push_back(make_pair(b,c));
        in[b]++;
    }
    queue<int> q;
    int num=n;
    for(int i=1;i<=n;i++){
        f[i]=-1;
    }
    for(int i=1;i<=n;i++){
        if (in[i]==0){
            f[i]=0;
            q.push(i);
            num--;
        }
    }
    int tag=1;
    while(!q.empty()){
        int u=q.front(); q.pop();
        for(int i=0;i<edge[u].size();i++){
            int v=edge[u][i].first;
            int dis=edge[u][i].second;
            in[v]--;
            if (f[v]==-1){
                f[v]=f[u]+dis;
            }
            else{
                if (f[v]!=f[u]+dis){
                    tag=0;
                }
            }
            if (in[v]==0){
                q.push(v);
                num--;
            }
        }
    }
    if (num!=0 || tag==0){
        puts("No");        
    }
    else puts("Yes");
    return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N+1);
    rep(i,0,N)cin >> V[i+1];
    rep(i,1,N+1){
        if(V[i-1] < V[i]){
            V[i]--;
        }
        if(V[i-1] > V[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define print(n) cout << n << "\n"

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

    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    if(a[n-m] * 4 * m >= accumulate(a.begin(),a.end(),0LL)) print("Yes");
    else print("No");

    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[2000][2000], a[200000], b[200000];
string str, ss;
bool f;
char c[800][800];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<Edge>vec[20000];
vector<edge>ed;
vector<LL>v[23];
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m >> k;
	cout << min(m, k) << " " << (m+k<=n?0:m+k-n) << endl;
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  long long N; cin>>N;
  vector<int> H(N+1);
  map<long long, long long> L;
  for(long long i=1; i<=N; i++){
    long long h;
    cin>>h;
    H.at(i)=h;
    L[i+h]++;
  }
  long long count=0;
  for(long long i=1; i<=N; i++){
    if(L.count(i-H.at(i))) count+=L[i-H.at(i)];
  }
  cout<<count<<endl;
}


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

def main():
    from itertools import chain
    S = input()
    Q = int(input())
    Queries = [input().split() for _ in range(Q)]
    H_T = H, T = [], []
    flag = 0
    for query in Queries:
        if len(query) == 1:
            flag ^= 1
            continue
        _, f, c = query
        H_T[(int(f) + flag - 1) % 2].append(c)
    t = ''.join(chain(reversed(H), S, T))
    if flag:
        t = reversed(t)
    print(''.join(t))


if __name__ == '__main__':
    main()


Measured memory_bytes: 43768
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <iomanip>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, K;
  double n;
  std::cin >> N >> K;
  n = N;
  double ans=0;
  double bunsi=0;
  std::vector<int> up;
  double over = 0;
  if(N>=K){
    over = N-K+1;
    N=K-1;
  }
  int reg;
  double count=2;
  while(K>1){
    if(K%2==0){
      reg=K/2;
    }else reg=K/2+1;
    double num;
    if(N>=reg) {
      num=N-reg+1;
      N=reg-1;
    }else {
      num = 0;
    }
    count*=2;
    up.push_back(num);
    K=reg;
  }
  count/=2;
  int po = 1;
  for(int i=up.size()-1;i>=0;i--){
    up[i]*=po;
    po*=2;
    bunsi+=up[i];
  }
  //std::cout << bunsi << '\n' << count  << '\n'<< over << '\n';
  ans = (double)((bunsi+(count*over))/(count*n));
  std::cout << std::setprecision(12) << ans;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
struct data{
	long long ch[11],s;
}t[2600001];
long long n,m,ans,cnt=1,l[101];
char s[101];
void dfs(long long a,long long fa){
	if(a==26){
		ans=ans+t[fa].s;
		t[fa].s++;
		return;
	}
	if(!t[fa].ch[l[a]]){
		cnt++;
		t[fa].ch[l[a]]=cnt;
	}
	dfs(a+1,t[fa].ch[l[a]]);
}
int main(){
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++){
		scanf("%s",s+1);
		for(long long j=0;j<=30;j++)l[j]=0;
		for(long long j=1;j<=10;j++){
			long long w=s[j]-'a';
			l[w]++;
		}
		dfs(1,1);
	}
	printf("%lld\n",ans);
}

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

using namespace std;

int main()
{
	int a = 0;
	cin >> a;
	if (a == 23) cout << "Christmas Eve Eve" << endl;
	if (a == 24) cout << "Christmas Eve" << endl;
	if (a == 25) cout << "Christmas" << endl;
	if (a == 22) cout << "Christmas Eve Eve Eve" << endl;
	return 0;

}

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

int main()
{
  int k;
  cin >> k;
  int x = 7 % k;
  int i = 1;
  set<int> s;
  while(s.count(x) == 0) {
      if(x == 0) {
          cout << i << endl;
          return 0;
      }
    s.insert(x);
    x = (x * 10 + 7) % k;
    i++;
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 50396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.HashMap;


public class Main {
	public static final String EOF = System.lineSeparator();
	public static long l=0,l2=0;
	public static void main(String[] args) throws IOException {
		l = System.currentTimeMillis();
		new Main().exec();
		l2 = System.currentTimeMillis();
		
	}
	
	public void exec() throws IOException {
		InputUtil in = new InputUtil();
		PrintWriter out = new PrintWriter(System.out);
		int N = in.nextInt();
		int[] array_a = in.nextInt(new int[N]);
		int count_not_multiple_2 = 0;
		boolean exists_multiple_2 = false;
		int count_multiple_4 = 0;
		for(int a : array_a) {
			if(a%4 == 0) 
				count_multiple_4 ++;
			else if(a%2 == 0)
				exists_multiple_2 = true;
			else 
				count_not_multiple_2 ++;
		}
		if(exists_multiple_2){
			if(count_not_multiple_2 <= count_multiple_4) {
				out.println("Yes");
			}else{
				out.println("No");
			}
		}else{
			if(count_not_multiple_2 <= count_multiple_4 + 1 ) {
				out.println("Yes");
			}else{
				out.println("No");
			}
		}
		out.flush();
	}
	
}


class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private char[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private BufferedReader br = null;
	
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {br = new BufferedReader(new InputStreamReader(this.in = in));}
	protected void initBuf(int bufsiz) {buf = new char[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && br.ready()) {
			if(max>0) Arrays.fill(buf,0,max,(char)0);
			max = br.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(char b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(char b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		char c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

}

Measured memory_bytes: 23608
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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













string s;

ll memo[100005][2];

ll rec(ll k, bool tight){
    if(k == s.size()) return 1;
    if(~memo[k][tight]) return memo[k][tight];
    
    ll res = 0;
    if(s[k] == '1'){
        if(tight){
            res += rec(k + 1, true) * 2;
            res += rec(k + 1, false);
        }
        else{
            res += rec(k + 1, false) * 3;
        }
    }
    else{
        if(tight){
            res += rec(k + 1, true);
        }
        else{
            res += rec(k + 1, false) * 3;
        }
    }
    res %= MOD;
    
    return memo[k][tight] = res;
}




int main(){
    cin >> s;
    memset(memo, -1, sizeof(memo));
    cout << rec(0, true) << endl;
}

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


int main() {
        
    int n, a[110];
    
    cin >> n;
    for(int i=0; i < n; i++)
        cin >> a[i];

    int maxdif = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            maxdif = max(maxdif, abs(a[i] - a[j]));
        }
    }
    cout << maxdif << "\n";
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        d[a[i] + i + 1] += 1
    ans = 0
    for i in range(n):
        x = i + 1 - a[i]
        ans += d[x]
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 151960
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


int main()
{
	ll n; cin >> n;
	ll r = ceil(sqrt((double)n)) + 1;

	for (ll d = r; d > 0; --d)
	{
		if (!(n % d))
		{
			ll ans = max(SZ(to_string(d)), SZ(to_string(n / d)));
			cout << ans << endl;
			return 0;
		}
	}

}


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

namespace abc168_a
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力された値を読み込む
            int N = int.Parse(Console.ReadLine());

            int M = N % 10;

            if (M == 3)
            {
                Console.WriteLine("bon");
            }

            else if (M == 1 || M == 0 || M == 6 || M == 8)
            {
                Console.WriteLine("pon");

            }

            else
            {
                Console.WriteLine("hon");
            }

            Console.Read();

        }
    }
}


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

using namespace std;

int count(const vector<string>& grid,int x1,int y1,int x2,int y2)
{
	assert(x1==x2 || y1==y2);
	int res=0;
	if(x1==x2){
		if(y1>y2) swap(y1,y2);
		for(int y=y1;y<=y2;y++)
			res+=grid[y][x1]!='.';
	}
	else{
		if(x1>x2) swap(x1,x2);
		for(int x=x1;x<=x2;x++)
			res+=grid[y1][x]!='.';
	}
	return res;
}

bool canerase(const vector<string>& grid,const vector<int>& x,const vector<int>& y)
{
	int x1=x[0],x2=x[1],y1=y[0],y2=y[1];
	if(x1==x2 || y1==y2){
		return abs(x2-x1)+abs(y2-y1)>=2 && count(grid,x1,y1,x2,y2)==2;
	}
	else{
		return count(grid,x1,y1,x2,y1)+count(grid,x2,y1,x2,y2)==2
			|| count(grid,x1,y1,x1,y2)+count(grid,x1,y2,x2,y2)==2;
	}
}

int main()
{
	for(int h,w;cin>>h>>w && h|w;){
		vector<string> grid(h);
		for(int i=0;i<h;i++) cin>>grid[i];
		
		vector<vector<int>> xs(26),ys(26);
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				if(grid[i][j]!='.'){
					int k=grid[i][j]-'A';
					xs[k].push_back(j);
					ys[k].push_back(i);
				}
		
		int res=0;
		for(;;){
			bool flg=false;
			for(int i=0;i<26;i++){
				vector<int>& x=xs[i],y=ys[i];
				if(x.size() && canerase(grid,x,y)){
					grid[y[0]][x[0]]=grid[y[1]][x[1]]='.';
					x.clear(),y.clear();
					res+=2;
					flg=true;
				}
			}
			if(!flg) break;
		}
		
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1484
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size()+1;
  s = '>' + s + '<';
  vector<int> ans(n);
  rep(i, n) {
    if(s[i] == '>' && s[i+1] == '<') {
      for(int j=i; j<n; j++) {
        chmax(ans[j], j-i);
        if(s[j+1] == '>') break;
      }
      for(int j=i; j>=0; j--) {
        chmax(ans[j], i-j);
        if(s[j] == '<') break;
      }
    }
  }
  cout << accumulate(all(ans), 0LL) << endk;
  return 0;
}


Measured memory_bytes: 5784
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>

using namespace std;

int a[15][15];

void solve(int n){
	memset(a,0,sizeof(a));
	int x = n/2,y = x+1;
	for (int i = 1; i <= n*n; i++,x++,y++){
		while(true){
			if(y < 0) y += n;
			if(y >= n) y -= n;
			if(x < 0) x += n;
			if(x >= n) x -= n;
			if(a[y][x] == 0) break;
			x--; y++;
		}
		a[y][x] = i;
	}

	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			printf("%4d",a[i][j]);
		}
		puts("");
	}
}

int main(){
	int n;
	while(cin>>n,n){
		solve(n);
	}
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
int main(int argc, char const *argv[]) {
  long long N, ans=0;
  std::cin >> N;
  bool flag = 1;
  while(N > 9){
    if(N%10!=9) flag = 0;
    N/=10, ans+=9;
  }
  std::cout << (flag ? ans + N :ans+(N - 1));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<ll> a(N);
  vector<ll> b(N,0);
  rep(i,N) cin >> a[i];
  sort(all(a),greater<ll>());
  ll maximum = a[0];
  ll K = 0;
  while(maximum >= N){
    rep(i,N){
      b[i] = a[i]/N;
      K+=b[i];
      a[i] %= N;
    }
    rep(i,N){
      rep(j,N) if(i!=j) a[i] += b[j];
    }
    sort(all(a),greater<ll>());
    maximum = a[0];
  }
  cout << K << endl;
  return 0;
}


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

//macro
#define REP(i, n) for(LL i = 0; i < n; ++i)
#define REPR(i, n) for(LL i = n; i >= 0; --i)
#define FOR(i, n, m) for(LL i = m; i < n; ++i)
#define LL long long

using namespace std;

typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;


int main(){
    LL n, a, b;
    cin >> n >> a >> b;

    LL cnt = b - a;
    if(cnt < 0 || (n == 1 && a != b)){
        cout << 0 << endl;
        return 0;
    }

    cnt += 1;

    LL maxnum = (n - 1) * b + a;
    LL minnum = (n - 1) * a + b;

    LL ans = maxnum - minnum + 1;

    cout << ans << endl;
}

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

#define int long long
#define M 1000000009
#define M2 998244353

signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int n;
	cin >> n;
	int ind=1;
	int a[n];
	queue<pair<int,int> > q;
	for(int i=0;i<n;i++){
		cin >> a[i];
	} 
	sort(a,a+n,greater<int>());
	int cnt=1;
	int val=a[0];
	int ans=0;
	for(int i=1;i<n;i++){
		if(cnt!=0){
			cnt--;
			ans+=val;
			q.push(make_pair(a[i],2));
		}
		else{
			pair<int,int> p=q.front();
			q.pop();
			val=p.first;
			cnt=2;
			cnt--;
			ans+=val;
			q.push(make_pair(a[i],2));
		}
	}
	cout << ans << endl;
}


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


int main() {

  int N, K;
  cin >> N >> K;

  vector<int> x(N);
  vector<int> y(N);
  vector<char> c(N);

  // 黒か否か
  vector<bool> black(N);
  
  // 2 * K
  int KK = 2 * K;

  // 二次元累積和
  vector<vector<int>> table(KK + 1, vector<int>(KK + 1));
  
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> c[i];
    // x を x % 2K 、
    // y を y % 2K で考えていい
    x[i] %= KK;
    y[i] %= KK;
    if (c[i] == 'B') {
      black[i] = true;
    } else {
      black[i] = false;
    }
    if (K <= x[i]) {
      x[i] -= K;
      black[i] = !black[i];
    }
    if (K <= y[i]) {
      y[i] -= K;
      black[i] = !black[i];
    }  
    // 二次元累積和
    if (black[i]) {
      table[0][0]++;
      table[0][y[i] + 1]--;
      table[x[i] + 1][0]--;
      table[x[i] + 1][y[i] + 1] += 2;
    } else {
      table[0][y[i] + 1]++;
      table[x[i] + 1][0]++;
      table[x[i] + 1][y[i] + 1] -= 2;
    }
  }

  for (int i = 0; i < K; i++) {
    for (int j = 1; j < K; j++) {
      table[i][j] += table[i][j - 1];
    }
  }

  for (int i = 0; i < K; i++) {
    for (int j = 1; j < K; j++) {
      table[j][i] += table[j - 1][i];
    }
  }

  int answer = 0;

  for (int i = 0; i < K; i++) {
    for (int j = 0; j < K; j++) {
      table[i][j] = max(table[i][j], N - table[i][j]);
      answer = max(answer, table[i][j]);
    }
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 16896
#include <stdio.h>

int main(void)
{
	int n, m, l;
	int i, j, k;
	long long int matrixa[101][101] = {};
	long long int matrixb[101][101] = {};
	long long int answerc[101][101] = {};
	scanf("%d%d%d", &n, &m, &l);

	//Matrix A (n * m) input.
	i = 0;
	while(i < n)
	{
		j = 0;
		while(j < m)
		{
			scanf("%lld", &matrixa[i][j]);
			j++;
		}
		i++;
	}

	//Matrix B (m * l) input.
	i = 0;
	while(i < m)
	{
		j = 0;
		while(j < l)
		{
			scanf("%lld", &matrixb[i][j]);
			j++;
		}
		i++;
	}


	//Matrix Multiplication, Matrix C.
	i = 0;
	while(i < n)
	{
		k = 0;
		while(k < l)
		{
			j = 0;
			while(j < m)
			{
				answerc[i][k] += matrixa[i][j] * matrixb[j][k];
				j++;
			}
			k++;
		}
		i++;
	}


	//Display C.
	i = 0;
	while(i < n)
	{
		k = 0;
		while(k < l)
		{
			printf("%lld", answerc[i][k]);
			if(k == l - 1)
				printf("\n");
			else
				printf(" ");
			k++;
		}
		i++;
	}

	return (0);
}



Measured memory_bytes: 2148
#include<iostream>
using namespace std;
int main()
{
	int a, b;

	cin >> a;
	cin >> b;

	if (a < b) cout << "a < b" << endl;
	else if (a > b) cout << "a > b" << endl;
	else if (a == b) cout << "a == b" << endl;
	
}

Measured memory_bytes: 1156