akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 1e6 + 5;
int id = 0;
int child[N][26];
int is_str[N];
    
  
void solve() {

   int n, ans = 0;
   cin>>n;
   vector<string> s(n);
   vvi pos(n);
   rep(i,0,n){
     cin>>s[i];
     reverse(all(s[i]));
   }
   sort(all(s),[](string &s1, string &s2){
      return sz(s1)<sz(s2);
   });
  rep(i,0,n){
     string str = s[i];
     int node = 0;
     pos[i].pb(node);
     trav(ch,str){
       if(!child[node][ch-'a'])
          child[node][ch-'a']=++id;
       node = child[node][ch-'a'];
       pos[i].pb(node);
     }
   
     si heap;
     frev(j,0,sz(str)-1){
       heap.insert(str[j]-'a');
       int nd = pos[i][j];
       trav(ch,heap)
         ans+=is_str[child[nd][ch]];
     }
     is_str[node]=1;
  }
  cout<<ans;
          
}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}




int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}


int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}


Measured memory_bytes: 224760
def solve():
  while(True):
    N = int(input())
    if N == 0:
      break
    l = list(map(int,input().split()))
    ave = sum(l)//len(l)
    ans = 0
    for a in l:
      if a <= ave:
        ans+=1
    print(ans)
if __name__ == '__main__':
  solve()


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

int main() {

	using namespace std;

	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	vector<long long> answers(4);

	answers[0] = a * c; answers[1] = a * d; answers[2] = b * c; answers[3] = b * d;

	cout << *max_element(answers.begin(), answers.end()) << endl;

	return 0;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <cxxabi.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    ((ll)1ll<60)
#define INF     ((int)1<<30)
#define EPS     (1e-9)
#define MOD     (1000000007)
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool b=1;for(auto s:t)os<<(exchange(b,0)||strlen(abi::__cxa_demangle(typeid(S).name(),0,0,0))>20?"":" ")<<s;return os<<endl;}

using Node=tuple<int,int,int,double>; //L,R,W,X


vector<Node> node;
vvi edge;

bool isStable(int p){
	int L,R,W;
	double X;
	tie(L,R,W,X)=node[p];
	X*=W;
	bool ok=true;
	for(auto child:edge[p]){
		int l,r,w;
		double x;
		ok&=isStable(child);
		tie(l,r,w,x)=node[child];
		W+=w;
		X+=w*x;
	}
	X/=W;
	node[p]=Node(L,R,W,X);
	return ok and L<X and X<R;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int w,h;
	while(cin>>w>>h,w){
		node.clear();
		edge.clear();
		vector<string> input(h);
		vvi field(h,vi(w,-1));
		
		rep(i,h)cin>>input[i];
		rep(i,h)rep(j,w)if(input[i][j]!='.'){
		    int L=100,R=0,W=0;
		    double X=0;
		    vi N(60,0);
		    char tgt=input[i][j];
		    queue<pii> q; q.emplace(i,j);
		    while(!q.empty()){
		        int y,x; tie(y,x)=q.front(); q.pop();
		        if(input[y][x]=='.') continue;
		        W++;
		        N[x]++;
		        input[y][x]='.';
		        field[y][x]=node.size();
		        int v[]={1,0,-1,0};
		        rep(k,4){
		            int ny=y+v[k], nx=x+v[k^1];
		            if(ny<0 or nx<0 or ny>=h or nx>=w or input[ny][nx]!=tgt) continue;
		            q.emplace(ny,nx);
		        }
		    }
			rep(i,60){
				X+=(i+0.5)*N[i];
			}
		    node.emplace_back(L,R,W,X/W);
		}
		int n=node.size(),p=-1;
		edge.resize(n);
		range(i,1,h)rep(j,w){
		    if(field[i][j]!=-1 and field[i-1][j]!=-1 and field[i-1][j]!=field[i][j]){
		        edge[field[i][j]].push_back(field[i-1][j]);
				get<0>(node[field[i-1][j]])=min(get<0>(node[field[i-1][j]]),j);
				get<1>(node[field[i-1][j]])=max(get<1>(node[field[i-1][j]]),j+1);
		    }
			if(i==h-1 and field[i][j]!=-1){
				p=field[i][j];
				get<0>(node[p])=min(get<0>(node[p]),j);
				get<1>(node[p])=max(get<1>(node[p]),j+1);
			}
		}
		for(auto &e:edge){
		    sort(all(e));
			e.erase(unique(all(e)),e.end());
		}
		cout<<(isStable(p)?"STABLE":"UNSTABLE")<<endl;
	}
	return 0;
}
 



Measured memory_bytes: 3116
N, M = map(int, input().split())
py = ['' for _ in range(M)]
for i in range(M):
    py[i] = list(map(int, input().split())) + [i] + [0]

py.sort(key = lambda x: (x[0], x[1]))

p = 0
for i in range(M):
    if py[i][0] != p:
        cnt = 1
        p = py[i][0]
    else:
        cnt += 1
    py[i][3] = str(p).zfill(6) + str(cnt).zfill(6)

py.sort(key = lambda x: x[2])
for i in range(M):
    print(py[i][3])


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

int main()
{
    int a, b, c, cst = 0, min;
    cin >> a >> b >> c;

    cst = abs(a - b) + abs(b - c);
    min = cst;

    cst = abs(a - c) + abs(c - b);
    if (min > cst) min = cst;

    cst = abs(b - a) + abs(a - c);
    if (min > cst) min = cst;

    cst = abs(b - c) + abs(c - a);
    if (min > cst) min = cst;

    cst = abs(c - a) + abs(a - b);
    if (min > cst) min = cst;

    cst = abs(c - b) + abs(b - a);
    if (min > cst) min = cst;

    cout << min << endl;
}

Measured memory_bytes: 256
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long x, a, b;
    scan(x, a, b);
    long A = abs(x - a);
    long B = abs(x - b);
    if (min(A, B) == A)
    {
        writeln('A');
    }
    else
    {
        writeln('B');
    }
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3612
# B - Shift only

N = int(input())
A = list(map(int, input().split()))

count = 0
for i in range(max(A)//2):
    for j in range(N):
        if A[j] % 2 == 1:
            print(count)
            exit()
        else:
            A[j] = A[j]//2
    count += 1

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int q;
  cin>>q;
  while(q--){
    string s;
    cin>>s;
    string t=s;
    t.erase(unique(t.begin(),t.end()),t.end());
    if(s.size()!=t.size()){
      cout<<"No"<<endl;
      continue;
    }
    if((int)s.size()<3){
      cout<<"Yes"<<endl;
      continue;
    }
    bool f=0;
    for(int k=0;k<2;k++){
      bool ff=1;
      char l=s[k],r=s[!k];
      if(l=='R'||r=='L'){
	ff=0;
      }
      for(int i=2;i<(int)s.size();i++){
	if((i+k)%2) r=s[i];
	else l=s[i];
	if(l=='R'||r=='L'){
	  ff=0;
	  break;
	}
      }
      f|=ff;
    }
    if(f) cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
  }
  return 0;
}

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

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
string board[2510];

int main(void) {
  int X, Y;
  cin >> X >> Y;
  for (int i = 0; i < X; i++) {
    cin >> board[i];
  }
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      if (board[i][j] == '#') {
        int counter = 0;
        for (int k = 0; k < 4; k++) {
          int x = i + dx[k];
          int y = j + dy[k];

          if (x >= 0 && x < X && y >= 0 && y < Y && board[x][y] == '#') {
            counter++;
          }
        }
        if (!counter) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	string s;
	cin >>s;
	int ans;
	for (int i=0;i<s.size();i++){
		if (s[i]=='+'){
			ans++;
		}
		if (s[i]=='-') ans--;
	}
	cout <<ans;
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,i,j,l,u,k;
  int v[101][101];
  int a[101][101];
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d %d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&v[i][j]);
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      a[i][j] = 0;
    }
  }
    
    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
	for(l=1;l<=n;l++){
	if(v[i][j] == l) a[i][l] = 1;
      }
    }
    }
       for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
	printf("%d",a[i][j]);
	if(j != n) printf(" ");
      }
      printf("\n");
       }

       return 0;
  }

Measured memory_bytes: 2796
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int count = 0;
		for(int i=0;i < N;i++) {
			long x = Long.parseLong(sc.next());
			long y = Long.parseLong(sc.next());
			if(Math.sqrt(x*x+y*y) <= D) {
				count++;
			}
		}
		System.out.println(count);
	}
}



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

int main() {
  int a;
  cin >> a;
  int ans=a + a*a + a*a*a; 
  cout << ans << endl;
  
}


Measured memory_bytes: 3592
#include <iostream>
#include <cassert>
#include <fstream>
#include <sstream>
#include <math.h>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <time.h>
#include <stdio.h>
#include <deque>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define POW(n) ((n)*(n))
#define ALL(a) (a).begin(),(a).end()
#define cerr if(false) cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

ll N, X;

ll getLength(ll a, ll b){
	if (a == b)return a;
	if (b < a)swap(a, b);

	if (b % a != 0){
		return getLength(a, b%a) +2 * (b / a)*a;
	}
	else{
		return (b/a -1) * a * 2 + a;
	}
}

void solve() {
	ll ans = 0;

	ans += N;
	ans += getLength(X, N - X);

	cout << ans << endl;
}

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

	solve();

	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

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

	long long int power = 1;

	for (int i = 1; i <= n; i++) {
		power = power*i % 1000000007;
	}
	cout << power << endl;
	return 0;
}

Measured memory_bytes: 256
def add(a, b):
    return b+a
def sub(a, b):
    return b-a
def mul(a, b):
    return b*a
def div(a, b):
    if a!=0:
        return b/a
    else:
        return 10000
operators = {'+':add, '-':sub, '*':mul, '/':div}

def calc_PRN(symbols):
    stack = []
    for s in symbols:
        if s in operators.keys():
            stack.append(operators[s](stack.pop(), stack.pop()))
        else:
            stack.append(int(s))
    return stack[-1]


if __name__ == '__main__':
    symbols = input().split()
    print(int(calc_PRN(symbols)))

Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char s;
  cin >> s;
  if (s=='a' || s=='e' || s=='i' || s=='o' || s=='u'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

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

using namespace std;

long long cnt [10][10];
void add(int a)
{
    int last=a%10;
    while(a>9)
    a=a/10;
    int first =a;
    cnt[first][last]++;
    return;
}


int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        add(i);
    }
    long long ans=0;
    for(int i=1;i<=9;i++)
    for(int j=1;j<=9;j++)
    ans+=cnt[i][j]*cnt[j][i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
d = ((0, 0), (0, 1), (1, 1), (1, 0))
n, a, b = map(int, input().split())
c = 0
p = a ^ b
z, o = [], []
for i in range(n):
    if (p >> i) & 1:
        o.append(i)
    else:
        z.append(i)
if len(o) % 2 == 0:
    print('NO')
    exit(0)
print('YES')
ans = [0] * pow(2, n)
if n % 2:
    i = o.pop()
    for j in range(pow(2, n - 1), pow(2, n)):
        ans[j] += pow(2, i)
else:
    i = o.pop()
    j = z.pop()
    for k in range(4):
        tmp = pow(2, n) // 4
        for l in range(tmp):
            ans[k * tmp + l] += pow(2, i) * d[k][0] + pow(2, j) * d[k][1]
t = 1
while o:
    tmp = pow(2, n) // t // 8
    i = o.pop()
    j = o.pop()
    idx = 0
    for l in range(tmp):
        if l == 0:
            for p in range(4):
                for q in range(t):
                    ans[idx] += d[p][0] * \
                        pow(2, i) + d[p][1] * pow(2, j)
                    idx += 1
            for p in range(4):
                for q in range(t):
                    ans[idx] += d[p - 1][0] * \
                        pow(2, i) + d[p - 1][1] * pow(2, j)
                    idx += 1
        else:
            for p in range(4):
                for q in range(t):
                    ans[idx] += d[p - 2][0] * \
                        pow(2, i) + d[p - 2][1] * pow(2, j)
                    idx += 1
            for p in range(4):
                for q in range(t):
                    ans[idx] += d[1 - p][0] * \
                        pow(2, i) + d[1 - p][1] * pow(2, j)
                    idx += 1
    t *= 4
while z:
    tmp = pow(2, n) // t // 8
    i = z.pop()
    j = z.pop()
    idx = 0
    for l in range(tmp):
        for p in range(4):
            for q in range(t):
                ans[idx] += d[p][0] * \
                    pow(2, i) + d[p][1] * pow(2, j)
                idx += 1
        for p in range(4):
            for q in range(t):
                ans[idx] += d[3 - p][0] * \
                    pow(2, i) + d[3 - p][1] * pow(2, j)
                idx += 1
    t *= 4
print(' '.join(map(lambda x: str(x ^ a), ans)))
# for i in range(pow(2, n) - 1):
#    print(ans[i + 1] - ans[i], end=' ')


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

int main(){
	int n;
	cin>>n;
	int sum=0;
	int t=1;
	int a;
	bool flag=true;
	for(int i=1;i<=n;i++){
		cin>>a;
		if(a==1)flag=false;
		if(a!=t){
			sum++;
		}
		else{
			t++;
		}
	}
	if(flag==true)cout<<-1;
	else cout<<sum;
	return 0;
}


Measured memory_bytes: 384
// 拡張ダイクストラ
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)

int main()
{
	fast();

	using P = pair<int, int>;

	// d[0] : うえ, d[1] : みぎ, d[2] : した, d[3] : ひだり
	int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> grid(H);
	vector<vector<vector<P>>> d(H);

	int sx, sy, gx, gy;

	cin >> sx >> sy >> gx >> gy;
	sx--, sy--, gx--, gy--;

	for (int i = 0; i < H; i++)
	{
		cin >> grid[i];
	}

	for (int i = 0; i < H; i++) // init
	{
		d[i] = vector<vector<P>>(W, vector<P>(4, P(inf, inf)));
	}

	// (最短距離, その方向に進んだ回数), (x, y), dir
	priority_queue<pair<P, pair<P, int>>, vector<pair<P, pair<P, int>>>, greater<pair<P, pair<P, int>>>> pq;

	for (int i = 0; i < 4; i++)
	{
		d[sx][sy][i] = P(1, 0);
		pq.push({d[sx][sy][i], {{sx, sy}, i}});
	}

	while (!pq.empty())
	{
		auto v = pq.top();
		pq.pop();
		int vx = v.second.first.first, vy = v.second.first.second, dir = v.second.second;

		for (int i = 0; i < 4; i++) // 向きを変える
		{
			P ncost = make_pair(d[vx][vy][dir].first + 1, 0);
			if (d[vx][vy][i] <= ncost)
				continue;
			d[vx][vy][i] = ncost;
			pq.push({ncost, {{vx, vy}, i}});
		}

		// 直進する
		int nx = vx + dx[dir], ny = vy + dy[dir];
		if (nx < 0 || nx >= H || ny < 0 || ny >= W) // grid の外
			continue;
		if (grid[nx][ny] == '@') // 行き止まり
			continue;
		int df = d[vx][vy][dir].first, ds = d[vx][vy][dir].second;
		P ncost = make_pair(df + (ds + 1) / (K + 1), ds % K + 1);
		if (d[nx][ny][dir] <= ncost)
			continue;
		d[nx][ny][dir] = ncost;
		pq.push({ncost, {{nx, ny}, dir}});
	}

	int min_cost = (*min_element(d[gx][gy].begin(), d[gx][gy].end())).first;

	cout << (min_cost == inf ? -1 : min_cost) << "\n";
}


Measured memory_bytes: 85188
#include <iostream>
#include <string>

using namespace std;
typedef unsigned int ui;

int main()
{
  int N, A, B;
  string S;
  cin >> N >> A >> B;
  cin >> S;

  int a = 0, b = 0;
  string out;
  for(int i = 0; i < S.size(); i++){
    out = "No";
    if(S[i] == 'a' &&
        a + b < A + B){
      a++;
      out = "Yes";
    }
    if(S[i] == 'b' &&
        a + b < A + B && b < B){
      b++;
      out = "Yes";
    }
    cout << out << endl;
  }

  return 0;
}


Measured memory_bytes: 1336
using System;
using System.Text;

namespace ABC131_E___FriendShips
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static string solver()
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NK[0];
            var K = NK[1];

            if (K > (N - 1) * (N - 2) / 2) return "-1";

            var graph = new StringBuilder();
            graph.AppendLine((N - 1 + ((N - 1) * (N - 2) / 2 - K)).ToString());
            for (int i = 2; i <= N; i++) graph.AppendLine($"1 {i}");

            var counter = 0;
            for (int i = 2; i < N; i++)
            {
                for (int j = i + 1; j <= N; j++)
                {
                    if (K == (N - 1) * (N - 2) / 2 - counter) return graph.ToString().TrimEnd('\r', '\n');
                    graph.AppendLine($"{i} {j}");
                    counter += 1;
                }
            }
            return graph.ToString().TrimEnd('\r', '\n');
        }
    }
}

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

 int main() {
   int A1,A2,A3;
   cin >> A1 >> A2 >> A3;
   
   int ans = max(max(A1,A2),A3) - min(min(A1,A2),A3);
   cout << ans << endl;
 }

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    string str;
    int sum = 0;
    cin >>  str;
    int n = stoi(str);
    for(auto ch : str) {
        int i = stoi(string(1,ch).c_str());
        sum += i;
    }
    if(n % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int delicious = 0;
		boolean poison = false;

		for(int i = 0; c > 0; i++) {

			// 2連続毒
			if(poison) {
				c--;
				break;
			}

			// Cを食べる
			c--;
			delicious++;

			poison = true;

			// 解毒
			if(b > 0) {
				b--;
				delicious++;
				poison = false;
			} else if(a > 0) {
				a--;
				poison = false;
			}
		}

		delicious += b;
		System.out.println(delicious);
	}
}


Measured memory_bytes: 23508
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
#from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.buffer.readline().strip().decode()
def mdata(): return map(int, data().split())
out=sys.stdout.write
#sys.setrecursionlimit(100000)
INF=int(1e9)
mod=int(1e9)+7


n,m=mdata()
matrix = [data() for i in range(n)]
dp=[[0]*m for i in range(n)]
if matrix[0][0]!='#':
    dp[0][0]=1
for i in range(n):
    for j in range(m):
        if matrix[i][j]=='#':
            continue
        if i>0:
            dp[i][j]=(dp[i][j]+dp[i-1][j])%mod
        if j>0:
            dp[i][j]=(dp[i][j]+dp[i][j-1])%mod
print((dp[-1][-1])%mod)





Measured memory_bytes: 51312
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

const int Max = 10000;
int v[Max + 5] = {};

int main(int, const char**)
{
    int maxIndex = 0;
    rep(i, 100)
    {
        rep(j, 100)
        {
            rep(k, 100)
            {
                auto x = i + 1;
                auto y = j + 1;
                auto z = k + 1;
                auto index = x * x + y * y + z * z + 
                    (x * y) + (y * z) + (x * z);
                
                if(index > Max)
                {
                    continue;
                }
                v[index]++;
                maxIndex = max(maxIndex, index);
            }
        }
    }

    int n;
    cin >> n;
    rep(i, n)
    {
        cout << v[i + 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5;
typedef long long ll;

int main(){
	int a, b, k;
	cin >> k >> a >> b;
	int x = k;
	while(k < a) k += x;
	if(k <= b) printf("OK");
	else printf("NG");
	return 0;
}



Measured memory_bytes: 3764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        int N = cin.nextInt();
        int I = cin.nextInt();

        WriteLine(N - I + 1);
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
x1,y1,x2,y2 = map(int,input().split())
x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)
x4 = x3 - (y3-y2)
y4 = y3 + (x3-x2)
print(x3,y3,x4,y4)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

bool IsPrime(int num)//素数判定
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {

    int N;
    cin >> N;
    int result=pow(N,3);

    cout << result << endl;

}



Measured memory_bytes: 768
#include<stdio.h>
#include<limits.h>
#define N 150
  
int m[N][N];
  
  
  
void MCO(int* p,int x){
  int i,j,k,q,l,n;
n=x-1;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INT_MAX;
      for(k=i;k<=j-1;k++){
    q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
    if(m[i][j]>q)m[i][j]=q;
      }
  
    }
  
  
  
  }
  
 printf("%d\n",m[i][j]);
  
}
  
int main(){
  int i,j,n,A[N],B[N];
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d %d",&A[i],&B[i]);
  }
  A[n+1]=B[n];
   
  MCO(A,n+2);
  
  
  
  return 0;
}

Measured memory_bytes: 656
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;

	char buf[L], *S , *T, c;

	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}

	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}

	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	char B[45], *outs=B+40, *outr=B+40;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;

		if(!a)*--outs = '0';
		else
			while(a)
				*--outs = (a % 10) + 48, a /= 10;

		if(x)
			*--outs = x;

		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

const int MOD = 998244353;
const int INF = 1000000000;
const int MAXN = 100010;

int n, a[MAXN];

int main()
{
	/*
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i)
		scanf("%d", &a[i]);
	*/
	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 c = n-i*r-j*g;
			if (c >= 0 && c%b == 0) ans ++;
		}
	cout << ans << endl;
	
	return 0;
}


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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    string s;
    cin>>k>>s;
    if(s.size() > k)
    {
        f1(i,0,k)
        cout<<s[i];
        cout<<"..."<<endl;
    }
    else
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  string s;
  cin>>n;
  cin>>s;

  int ans=0;
  
  int i=0;
  while(i<n){
    int j=i;
    while(j<n&&s[i]==s[j]) j++;
    ans++;
    i=j;
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

const int N=3e5+2;

void solve(){
	int h, w, m;
	cin >> h >> w >> m;
	
	set<pii> s;
	vpii row(N, {0, 0}), col(N, {0, 0});
	for(int i=0 ; i<N ; ++i)row[i].F = i, col[i].F = i;
	int x, y;
	for(int i=0 ; i<m ; ++i){
		cin >> x >> y;
		++row[x].S;
		++col[y].S;
		s.insert({x, y});
	}
	
	sort(all(row), [](pii p1, pii p2) -> bool{
		return p1.S > p2.S;
	});
	sort(all(col), [](pii p1, pii p2) -> bool{
		return p1.S > p2.S;
	});
	
//	for(int i=0 ; row[i].S ; ++i)cout << row[i].F << " " << row[i].S << endl;
//	for(int i=0 ; col[i].S ; ++i)cout << col[i].F << " " << col[i].S << endl;
	
	int mxR = row[0].S, mxC = col[0].S;
	if(!mxR){
		cout << "0";
		return;
	}
	int ans = mxR + mxC - 1;
	vi r, c;
	for(int i=0 ; mxR == row[i].S ; ++i)r.pb(row[i].F);
	for(int i=0 ; mxC == col[i].S ; ++i)c.pb(col[i].F);

	for(int i=0 ; i<r.size() ; ++i){
		for(int j=0 ; j<c.size() ; ++j){
			if(s.find({r[i], c[j]}) == s.end()){
				ans = mxR + mxC;
				break;
			}
		}
		if(ans == mxR + mxC)break;
	}	
	cout << ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cout << fixed << setprecision(10);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


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

int main(void){
    int a,b,c;
    cin >> a>>b>>c;
    int i, count=0;
    for(i=a;i<=b;i++){
        if(c%i==0) count++;
    }
    cout <<count<<endl;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  ll X, Y;
  cin >> X >> Y;
  ll ans = 0;
  while (X <= Y) {
    ans++;
    X *= 2;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

case class Coord(x: Double, y: Double) extends Ordered[Coord] {

  def this(p: (Double, Double)) = this(p._1, p._2)

  def compare(that: Coord): Int = {
    if (this.x != that.x)
      this.x.compare(that.x)
    else
      this.y.compare(that.y)
  }

  def +(co: Coord): Coord = {
    Coord(this.x + co.x, this.y + co.y)
  }

  def -(co: Coord): Coord = {
    Coord(this.x - co.x, this.y - co.y)
  }

  def toPair: (Double, Double) = (x, y)

  def dist(that: Coord): Double = {
    import Math.{sqrt, pow}
    sqrt(pow(this.x - that.x, 2) + pow(this.y - that.y, 2))
  }

  def moveTo(that: Coord, ratio: Double): Coord = {
    import Math.{sqrt, pow, abs}
    val dx = abs(x - that.x) * ratio
    val dy = abs(y - that.y) * ratio

    val gx =
      if (x > that.x) x - dx
      else x + dx
    val gy =
      if (y > that.y) y - dy
      else y + dy

    Coord(gx, gy)
  }

}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val p = new Array[Coord](N)
  for (i <- 0 until N) {
    val x, y = in.next().toInt
    p(i) = Coord(x, y)
  }

  //
  var now = Coord(0.0, 0.0)
  var vol = 1.0
  for (n <- 1 to 1500000) {
    var hoge: Coord = null
    var maxDist = 0.0
    for (c <- p) {
      if (now.dist(c) > maxDist) {
        maxDist = now.dist(c)
        hoge = c
      }
    }

    now = now.moveTo(hoge, vol)
    vol *= 0.999
  }

  var maxDist = 0.0
  for (c <- p) {
    if (now.dist(c) > maxDist) {
      maxDist = now.dist(c)
    }
  }

  println(maxDist)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


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

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

	if (abs(c - a) <= d) {
		cout << "Yes" << endl;
	}
	else if (abs(b - a) <= d && abs(c - b) <= d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = list(map(int, input().split()))

cnt = 0
endflag = False

while(True):
  for i in range(0,a):
    if ((b[i] %2 ) == 0):
      b[i] = b[i] / 2
    else:
      endflag = True
      break
  if (endflag):
    break
  cnt = cnt + 1

print(cnt)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n,k) for(long long int i=k; i<n; ++i)
#define drep(i,n,k) for(long long int i=n-1; i>=k; --i)
using namespace std;

int main(){
  int n;
  cin >> n;
  long long int ans = 0;
  long long int a[n-1];
  rep(i,n-1,0) cin >> a[i];
  rep(i,n-2,0) ans += min(a[i], a[i+1]);
  ans += a[0];
  ans += a[n-2];
  cout << ans << endl;
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
A = [[0] * N for _ in range(N)]
for _ in range(M):
    l, m = map(int, input().split())
    A[l - 1][m - 1] += 1

questions = []
for _ in range(Q):
    p, q = map(int, input().split())
    questions.append((p - 1, q - 1))


D = []
for l in range(N):
    s = 0
    d = []
    for r in range(N):
        s += A[l][r]
        d.append(s)
    D.append(d)

T = []
for r in range(N):
    s = 0
    t = []
    for l in range(N):
        s += D[N - l - 1][r]
        t.append(s)
    T.append(list(reversed(t)))

for question in questions:
    print(T[question[1]][question[0]])


Measured memory_bytes: 26080
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main(){
    string s;
    cin >>s;
    int k;
    cin >> k;
    int n=s.size();
    int i=0;
    while(k>0){
        if(s[i]-'a'>0){
            if(('z'-s[i]+1)<=k){
                k-=('z'-s[i]+1);
                s[i]='a';
                i++;
            }else{
                if(i!=n-1){
                    i++;
                }else{
                    s[i]='a'+((k+s[i]-'a')%26);
                    k=0;
                }
            }
        }else{
            i++;
        }
        if(i==n){
            s[n-1]='a'+((k+s[n-1]-'a')%26);
            k=0;
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3728
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

ll n,mid,ans=0;

int main()
{
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  rep(i,n) a[i]=a[i]-(i+1);
  sort(a.begin(),a.end());

  if(n%2==1)
  {
    mid=n/2+1;
    ll b=a[mid-1];
    rep(i,n)
    {
      if(a[i]>b) ans+=(a[i]-b);
      else ans+=(b-a[i]);
    }
  }
  else
  {
    mid=n/2;
    ll b=(a[mid-1]+a[mid])/2;
    rep(i,n)
    {
      if(a[i]>b) ans+=(a[i]-b);
      else ans+=(b-a[i]);
    }
  }

  cout<<ans<<endl;


}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int N;
vector<int>tree[1010];
int K[1010];
string S[1010];

void rec(int k,int p){
    REP(i,p)cout<<'.';
    cout<<S[k]<<endl;
    
    REP(i,tree[k].size()){
        rec(tree[k][i],p+1);
    }
}

int main(){
    cin>>N;
    REP(i,N){
        cin>>K[i]>>S[i];
        tree[K[i]-1].PB(i);
    }
    rec(0,0);
}

Measured memory_bytes: 3440
import itertools


n,m,x = map(int,input().split())

c = [0]*n
a = [[0]*m for _ in range(n)]

for i in range(n):
    tmp=list(map(int,input().split()))
    c[i] = tmp.pop(0)
    a[i] = tmp

min_cost = float('inf')
for i in range(1,n+1):
    for seq in itertools.combinations(range(n),i):
        tmp_a = [0]* m
        flag = True
        sum_cost = 0
        for j in seq:
            sum_cost += c[j]
            for k in range(m):
                tmp_a[k]+= a[j][k]
                
        for k in range(m):
            if tmp_a[k] < x:
                flag = False
                break
        if flag:
            if min_cost > sum_cost:
                min_cost = sum_cost

if min_cost == float('inf'):
    print('-1')
else:
    print(min_cost)




Measured memory_bytes: 9240
#include <stdio.h>
#include <algorithm>
#include <queue>

using namespace std;

const int NN = 220000;
int n;
int a[NN];
deque < int > q;
int ans[NN];
void work () {
	int i;
	scanf ( "%d" , &n );
	for ( i = 1 ; i <= n ; i++ ) {
		scanf ( "%d" , &a[i] );
		if ( i % 2 == 0 ) q.push_back ( a[i] );
		else q.push_front ( a[i] );
	}
	if ( n % 2 == 1 ) {
		for ( i = 1 ; i <= n ; i++ ) {
			ans[i] = q.front ();
			q.pop_front();
		}
	}
	else {
		for ( i = 1 ; i <= n ; i++ ) {
			ans[i] = q.back ();
			q.pop_back ();
		}
	}
	for ( i = 1 ; i <= n ; i++ ) printf ( "%d%c" , ans[i] , i==n?'\n':' ' );
}
int main () {
	work ();
	return 0;
}

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

typedef long long ll;
int N;
vector<ll> A;
vector<vector<int> > adj;

vector<ll> up;
bool dfs(int u, int p) {
    if(adj[u].size() == 1) {
        up[u] = A[u];
        return true;
    }
    ll sum = 0;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        if(!dfs(v, u)) return false;
        sum += up[v];
    }
    if(sum < A[u]) return false;
    if(2*A[u] - sum < 0) return false;
    up[u] = 2*A[u] - sum;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        if(2*up[v] > sum) {
            ll mm = sum - up[v];
            if(sum - A[u] <= mm) return true;
            else return false;
        }
    }
    ll mm = sum / 2;
    if(sum - A[u] <= mm) return true;
}
int main() {
    scanf("%d", &N);
    A.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    adj.resize(N);
    for(int i = 0; i < N - 1; i++) {
        int u, v; scanf("%d %d", &u, &v);
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if(N == 2) {
        if(A[0] == A[1]) printf("YES");
        else printf("NO");
        return 0;
    }
    up.resize(N);
    for(int i = 0; i < N; i++) if(adj[i].size() != 1) {
        if(dfs(i, -1) && !up[i]) printf("YES");
        else printf("NO");
        return 0;
    }
}


Measured memory_bytes: 13952
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,c=0,a;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a>k-a) c+=(k-a)*2;
    else c+=a*2;
  }
  cout<<c;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
const long long MOD = 1000000007;
 
long long num[30];
int main() {
    int N; string S; cin >> N >> S;

    for (auto c : S) num[c - 'a']++;
    long long res = 1;
    for (int i = 0; i < 26; ++i) {
        res *= num[i] + 1;
        res %= MOD;
    }
    cout << (res + MOD - 1) % MOD << endl;
}


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

int main(){
	int n;
  	cin >> n;
  	vector<int> a(n);
  	rep(i, n) cin >> a[i];
  
  	vector<int> dp(n);
  	dp[0] = 0;
  	dp[1] = abs(a[1] - a[0]);	

  	for(int i = 2; i < n; i++){
    	dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]), dp[i-2]+abs(a[i-2]-a[i]));
    }
  
  	cout << dp[n - 1] << endl;
}	

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    # https://atcoder.jp/contests/abc070/tasks/abc070_d
    # https://atcoder.jp/contests/abc070/submissions/11681543
    from heapq import heapify, heappop, heappush
    
    N = int(input())
    inf = 10 ** 17
    
    
    def dijkstra_heap(start, edge):
        # 始点から各頂点への最短距離(頂点番号:0~N-1)
        d = [inf] * N
        used = [False] * N
        d[start] = 0
        used[start] = True
        edgelist = []
        # a:重み(//), b:次の頂点(%)
        for a, b in edge[start]:
            heappush(edgelist, a * (10 ** 6) + b)
    
        while len(edgelist):
            # まだ最短距離が決まっていない頂点の中から最小の距離のものを探す
            minedge = heappop(edgelist)
            if used[minedge % (10 ** 6)]:
                continue
            node = minedge % (10 ** 6)
            d[node] = minedge // (10 ** 6)
            used[node] = True
    
            for e in edge[node]:
                if not used[e[1]]:
                    heappush(edgelist, (e[0] + d[node]) * (10 ** 6) + e[1])
        return d
    
    
    # N:頂点数   W:辺数
    edge = [[] for i in range(N)]
    # edge[i] : iから出る道の[重み,行先]の配列
    for _ in range(N - 1):
        x, y, z = map(int, input().split())
        edge[x - 1].append((z, y - 1))
        edge[y - 1].append((z, x - 1))
    
    q, k = map(int, input().split())
    d = dijkstra_heap(k - 1, edge)
    
    for _ in range(q):
        x, y = map(int, input().split())
        print(d[x - 1] + d[y - 1])
    
resolve()

Measured memory_bytes: 84016
s=input()
t=input()
S,T=[0],[0]
for i in range(len(s)):
  if s[i]=="A":
    S.append((S[-1]+1)%3)
  elif s[i]=="B":
    S.append((S[-1]+2)%3)
for i in range(len(t)):
  if t[i]=="A":
    T.append((T[-1]+1)%3)
  elif t[i]=="B":
    T.append((T[-1]+2)%3)
    
Q=int(input())
for q in range(Q):
  a,b,c,d=map(int,input().split())
  if (S[b]-S[a-1])%3==(T[d]-T[c-1])%3:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 54300
function div(y, x){
    return Math.floor(y/x);
}
function readInt(str){
    return parseInt(str, 10);
}
function range(begin, end){
    if(begin > end) return range(end, begin).reverse();
    const ans=[];
    for(let i=begin; i<=end; i++){
        ans.push(i);
    }
    return ans;
}
function solve(S:string){
    const arrS:string[]=Array.from(S);
    const count0=arrS.filter(x=>x==="0").length;
    const count1=arrS.filter(x=>x==="1").length;
    return Math.min(count0, count1)*2;
}
function Main(raw) {
    
    //出力
    console.log("%d", solve(raw));
}

//DO NOT EDIT
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  


Measured memory_bytes: 15152
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
typedef long long ll;

typedef struct pair {
	ll b, a;
}pair;

int asc(const void* a, const void* b) { return *(int*)a - *(int*)b; }

int main() {
	ll n;
	scanf("%lld",&n);
	pair t[200000];
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &t[i].a, &t[i].b);
	}
	bool flag=true;
	qsort(t, n, 2 * sizeof(ll), asc);
	ll sumA = 0;
	for (int i = 0; i < n; i++) {
		sumA += t[i].a;
		if (t[i].b < sumA) flag = false;
	}

	if (flag) printf("Yes");
	else printf("No");

	return 0;
}

Measured memory_bytes: 7944