akhauriyash/Code-Regression huggingface dataset:
/*=====Bismillahir Rahmanir Rahim=====*\
!                                      !
!(^,^)Ron is back(-o,o-)               !
!         MD. TAREK MAHMUD RONY        !
!            CSE 12th Batch            !
!           Comilla University         !
\*====================================*/
//Think positive, be positive and never use negative words
#include<bits/stdc++.h>
#define ll               long long int
#define test             ll t;cin>>t;while(t--)
#define nl               endl
#define mp(a,b)          make_pair(a,b)
#define F                first
#define S                second
#define vc               vector<int>
#define vcl              vector<ll>
#define pb               push_back
#define vc_sum(a)        accumulate(a.begin(),a.end(),0)
#define vc_max(a)        *max_element(a.begin(),a.end())
#define vc_min(a)        *min_element(a.begin(),a.end())
#define vc_sort(a)       sort(a.begin(),a.end())
#define vc_gsort(a)      sort(a.begin(),a.end(),greater<int>())
#define vc_uni(a)        a.erase(unique(a.begin(),a.end()),a.end())
#define ulta(a)          reverse(a.begin(),a.end())
#define RON              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define yes              cout<<"YES"<<nl
#define no               cout<<"NO"<<nl
#define M                1000000007
#define gcd(a,b)         __gcd(a,b)
#define lcm(a,b)         (a/gcd(a,b))*b
using namespace std;
int main()
{
    RON;
    char n;
    cin>>n;
    ll cnt=(int)n;
    if(cnt>=97) cout<<"a"<<nl;
    else cout<<"A"<<nl;
    return 0;
}




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

int main()
{
    int n;
    cin >> n;
    if(n<10)    cout << n;
    else if(n<100)  cout << "9";
    else if(n==100) cout << "10";
    else if(n<1000)
    {
        int d=n-100;
        d+=10;
        cout << d;
    }
    else if(n==1000)    cout << "909";
    else if(n<10000)    cout << "909";
    else if(n==10000)    cout << "910";
    else if(n<100000)
    {
        int d=n-10000;
        //cout << d;
        d+=910;
        cout << d;
    }
    else    cout << "90909";
    return 0;
}

Measured memory_bytes: 256
DAY = 86400
HOURS = 10801
N = input()
okita = [0 for _ in xrange(DAY)]
t = 0
for _ in xrange(N):
    a, b = map(int, raw_input().split())
    t = (t+a)%DAY
    okita[t] += 1
    t = (t+b)%DAY
okita *= 2
okita.insert(0, 0)
for i in xrange(1, DAY*2):
    okita[i] += okita[i-1]
 
 
ans = 0
for i in xrange(DAY+10):
    ans = max(ans, okita[i+HOURS]-okita[i])
print ans


Measured memory_bytes: 8068
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
string st;
int check(string x)
{
	int sg,h=x.size();
	for(int i=0;i<x.size();i++)
	{
		if(x[i]=='S') sg++;
		if(sg>=1&&x[i]=='T')
		{
			sg--;
			h-=2;
		}
	}
	return h;
}
int main()
{
    cin>>st;
    cout<<check(st)<<endl;

    return 0;
}

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

int field[52][52];
int vw[8] = {-1,0,1,-1,1,-1,0,1};
int vh[8] = {-1,-1,-1,0,0,1,1,1};
void search(int i,int j)
{
	field[i][j] = 0;
	for(int k=0;k<8;k++){
		if(field[i+vw[k]][j+vh[k]] == 1)
			search(i+vw[k],j+vh[k]);
	}
}

int main()
{
	int w,h;
	while(cin >> w >> h){
		if(w == 0 && h == 0)
			break;
		for(int i=0;i<52;i++){
			for(int j=0;j<52;j++){
				field[i][j] = 0;
			}
		}
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin >> field[i][j];
			}
		}

		int count = 0;
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(field[i][j] == 1){
					count++;
					search(i,j);
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

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

int main()
{
    string s;
    getline(cin, s);
    for(int i = 0 ; i < s.length(); i++){
        char c = s[i];
        if(c >= 'a' && c <= 'z'){
            s[i] -= 'a' - 'A';
            continue;
        }
        if(c >= 'A' && c <= 'Z'){
            s[i] += 'a' - 'A';
            continue;
        }
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 3184
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;

int digit_sum(int n, int base = 10) {
    int res = 0;
    while (n > 0) res += n % base, n /= base;
    return res;
}

int main() {
    int n; cin >> n;
    int ans = INF;
    for (int i = 1; i < n; i++) {
        ans = min(ans, digit_sum(i) + digit_sum(n - i));
    }
    cout << ans << endl;
    return 0;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  LL ans = 0;
  while (c + b > 0) {
    if (c > 0) {
      c--;
      ans++;
    }

    if (b > 0) {
      b--;
      ans++;
      continue;
    } else if (a <= 0) {
      break;
    }
    a--;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	string a,b;
	cin>>a>>b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	cout<<(a<b?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 20
#define Q 200

int n,a[N];

int makeCombination(int i,int m){
    int r;
    
    if(m == 0) return 1;
    
    if(i >= n) return 0;
    
    r = makeCombination(i + 1,m) || makeCombination(i + 1,m - a[i]);
}

int main(){
    int q,m[Q],i;
    
    scanf("%d",&n);
    
    for(i = 0;i < n;i++){
        scanf("%d",&a[i]);
    }
    
    scanf("%d",&q);
    
    for(i = 0;i < q;i++){
        scanf("%d",&m[i]);
    }
    
    for(i = 0;i < q;i++){
        if(makeCombination(0,m[i])) printf("yes\n");
        
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2120
import sys
def input():
	return sys.stdin.readline()[:-1]
MOD = 10**9+7
n, K = map(int, input().split())
dp = [[[0 for _ in range(K+1)] for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1

for i in range(1, n+1):
	for j in range(n+1):
		for k in range(K+1):
			if k >= 2*j:
				dp[i][j][k] += (2*j+1) * dp[i-1][j][k-2*j]
			if k >= 2*j and j < n:
				dp[i][j][k] += (j+1) * (j+1) * dp[i-1][j+1][k-2*j]
			if k >= 2*j and j > 0:
				dp[i][j][k] += dp[i-1][j-1][k-2*j]
			dp[i][j][k] %= MOD

print(dp[n][0][K])

Measured memory_bytes: 98780
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 4e18L + 1;
const int IINF = 1e9 + 1;
const int N = 1048576;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#define LOCAL
#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
    #ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #endif
		
	string s;
	cin >> s;
	ll n = SZ(s);
	vector<ll> a(26);
	rep (i, 0, n) {
		a[s[i] - 'a']++;
	}
	ll wyn = 0;
	rep (i, 0, 26) {
		wyn += a[i] * (n - a[i]);
	}
	cout << wyn / 2 + 1;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
const int NIL = -1;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct SegmentTree {
	int n;
	vector<int>d, lazy;
	SegmentTree(int m) {
		for (n = 1; n < m; n <<= 1);
		d.assign(2 * n, 0);
		lazy.assign(2 * n, 0);
	}
	void eval(int k, int l, int r) {
		if (lazy[k] != 0) {
			d[k] += lazy[k];
			if (r - l > 1) {
				lazy[2 * k] += lazy[k] / 2;
				lazy[2 * k + 1] += lazy[k] / 2;
			}
			lazy[k] = 0;
		}
	}
	void add(int a, int b, int x, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return;
		else if (a <= l&&r <= b) {
			lazy[k] = (r - l)*x;
			eval(k, l, r);
		}
		else {
			add(a, b, x, 2 * k, l, (l + r) / 2);
			add(a, b, x, 2 * k + 1, (l + r) / 2, r);
			d[k] = d[2 * k] + d[2 * k + 1];
		}
	}
	int getsum(int a, int b, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return 0;
		else if (a <= l&&r <= b) return d[k];
		else return getsum(a, b, 2 * k, l, (l + r) / 2) + getsum(a, b, 2 * k + 1, (l + r) / 2, r);
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	SegmentTree seg(n);
	rep(i, 0, q) {
		int com; cin >> com;
		if (com) {
			int s, t; cin >> s >> t;
			cout << seg.getsum(s - 1, t) << endl;
		}
		else {
			int s, t, x; cin >> s >> t >> x;
			seg.add(s - 1, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 7064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		// 文字列の入力
		System.out.println(6-a-b);
	}
}

Measured memory_bytes: 21716
using System;
using System.Linq;

public class Program {
	public static void Main() {
		string target = Console.ReadLine();
		int count = 0;
		for(int i = 0; i < target.Length / 2; i++) {
			if(target[i] != target[target.Length - i - 1]) {
				count++;
			}
		}
		Console.WriteLine(count);
	}
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,m,p;
    cin >> n >> m >> p;
    vector<ll> s(m);
    vector<ll> t(m);
    vector<ll> d(m);
    vector<vector<ll>> graph(n);
    for(i = 0;i < m;++i){
        cin >> s.at(i) >> t.at(i) >> d.at(i);
        --s.at(i);  --t.at(i);
        d.at(i) = -d.at(i) + p;
        graph.at(t.at(i)).push_back(s.at(i));
    }

    vector<bool> vdis(n,false);
    queue<ll> que;
    ll top = n-1;
    vdis.at(top) = true;
    que.emplace(top);
    while(!que.empty()){
        ll now = que.front();
        que.pop();
        for(i = 0;i < graph.at(now).size();++i){
            ll next = graph.at(now).at(i);
            if(!vdis.at(next)){
                vdis.at(next) = true;
                que.emplace(next);
            }
        }
    }

    vector<ll> ss;
    vector<ll> tt;
    vector<ll> dd;
    rep(i,m){
        if(vdis.at(s.at(i)) && vdis.at(t.at(i))){
            ss.push_back(s.at(i));
            tt.push_back(t.at(i));
            dd.push_back(d.at(i));
        }
    }
    

    ll INF = (1ll << 60);
    vector<ll> vdist(n,INF);
    top = 0;
    vdist.at(top) = 0;
    rep(j, n){
        bool update = false;
        for(i = 0;i < ss.size();++i){
            if(vdist.at(ss.at(i)) != INF && vdist.at(tt.at(i)) > vdist.at(ss.at(i)) + dd.at(i)){
                vdist.at(tt.at(i)) = vdist.at(ss.at(i)) + dd.at(i);
                update = true;
            }
        }
        if(!update) break;
        else if(j == n-1){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << max(0ll, -vdist.at(n-1)) << endl;

    return 0;
}

Measured memory_bytes: 4036
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;

	cin >> n;

	cout << fixed;
	cout.precision(10);

	cout << ((ceil(n*1.0 / 2)) / n) << '\n';

	return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
T = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    T[a].append(b)
    T[b].append(a)

Point = [0] * N
for q in range(Q):
    p, x = map(int, input().split())
    p -= 1
    Point[p] += x

ans = [0] * N

stack = [[0, Point[0]]]
visited = [False] * N
while stack:
    n, p = stack.pop()
    visited[n] = True
    ans[n] = p
    for to in T[n]:
        if visited[to]:
            continue
        stack.append([to, p + Point[to]])

print(*ans, sep=' ')


Measured memory_bytes: 122160
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct Point {
	int x, y;
	Point(int x=0, int y=0) : x(x), y(y) {}
	bool operator<(const Point &o) const {
		return (x == o.x ? y < o.y : x < o.x);
	}
};

int main() {
	int m, n;
	while (cin >> m, m) {
		vector<Point> cons(m);
		vector<Point> diff(m);

		cin >> cons[0].x >> cons[0].y;
		diff[0].x = diff[0].y = 0;
		for (int i = 1; i < m; i++) {
			cin >> cons[i].x >> cons[i].y;
			diff[i].x = cons[i].x - cons[0].x;
			diff[i].y = cons[i].y - cons[0].y;
		}
		
		cin >> n;
		vector<Point> stars(n);
		for (int i = 0; i < n; i++) {
			cin >> stars[i].x >> stars[i].y;
		}
		sort(stars.begin(), stars.end());

		for (int i = 0; i < stars.size(); i++) {
			bool exist = true;
			for (int j = 0; j < m; j++) {
				if (binary_search(stars.begin(), stars.end(), Point(stars[i].x + diff[j].x, stars[i].y + diff[j].y))) {
					continue;
				} else {
					exist = false;
					break;
				}
			}
			if (exist) {
				cout << stars[i].x - cons[0].x << ' ' << stars[i].y - cons[0].y << endl;
				break;
			}
		}

	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
// j = y
// i = x

int main(){
	int arr[4][4];
	for(int i =1;i<=3;i++){
		for(int j = 1; j<=3;j++){
			scanf("%d",&arr[i][j]);
		}
	}
	int n, input;
	bool found = false;
	scanf("%d",&n);
	int hor1=0,hor2=0,hor3=0,ver1=0,ver2=0,ver3=0,dia1=0,dia2=0;
	for(int i =1;i<=n;i++){
		scanf("%d",&input);
		
			for(int i =1;i<=3;i++){
				for(int j = 1; j<=3;j++){
					if(input == arr[i][j]){
						
						arr[i][j] = -1;
						if(i == 1){
							hor1++;
							if(j == 1){
								dia1++;
								ver1++;
							} 
							else if (j==2) ver2++;
							else if (j==3){
								dia2++;
								ver3++;
							}
						}
						
						else if(i == 2){
							hor2 ++;
							if(j == 1) ver1++;
							else if (j==2){
								dia1++;
								dia2++;
								ver2++;
							}
							else if (j==3) ver3++;
						}
						
						else if(i == 3){
							hor3 ++;
							if(j == 1){
								dia2++;
								ver1++;
							} 
							else if (j==2) ver2++;
							else if (j==3){
								dia1++;
								ver3++;
							}
						}
					}	
					if(hor1 == 3 || hor2 == 3 || hor3 == 3 || ver1 == 3 || ver2 == 3 || ver3 == 3 || dia1 == 3 || dia2 == 3){
						found = true;
						break;
					}
			} 	
		}
	}
	found?printf("Yes\n"):printf("No\n");
	
	
/*	for(int i =1;i<=3;i++){
		for(int j = 1; j<=3;j++){
			printf("%d ",arr[i][j]);=================>Check Bingo Sheet
		}
		printf("\n");
	}	*/
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 1640
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <climits>
 
using namespace std;
 
int main(){
	int w, a, b;
	cin>>w>>a>>b;
	int y = max(a, b);
	int x = min(a, b);
	cout<<max(0, y-(x+w))<<endl;
	return 0;
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;

    int qtd = 1;
    int ans = 0;
    while(qtd < b) {
        ans++;
        qtd--;
        qtd += a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace  std;
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rep(n) for (int i = 0; i < n; ++i)

const int md = 1e9 + 7; //998244353 ;
void addto(int &x, int y) { x = x + y; if (x >= md) x -= md; }
int add(int x, int y) { int z = x + y; return z >= md? z -= md : z;}
void updmin(auto&x, auto y ) { if (y < x) x = y;}
void updmax(auto&x, auto y ) { if (y > x) x = y;}
long long pw(auto x, auto y) {	
	long long s = 1;
	while(y) {
		if (y & 1) s = s * x % md;
		x= 1LL * x * x % md; y /= 2;
	}
	return s;
}


const int maxn = 1e6 + 10;

int T, n, m;

void task() {
	int n, k;  cin >> n >> k;
	vector<int> a(n + 1);
	
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		debug(a[i]);
		if (i > k) {
			cout << (a[i] > a[i - k]?"Yes":"No") << endl;
		}
	}
	
	// you should actually read the stuff at the bottom
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout<<fixed<<setprecision(20);
  T = 1;
  for (int ti = 1; ti <= T; ++ti) {
    task();
  }
  return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* write down
*/


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

int main() {
    int N;
    cin >> N;
    string S[N];
    for(int i = 0; i < N; ++i) cin >> S[i];

    string ans = "Three";
    for(int i = 0; i < N; ++i){
        if(S[i]=="Y") ans = "Four";
    }
    cout << ans << endl;
}

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

int main(){
    int x;
    cin >> x;
    int sum = 0;
    for(int i=1;i<=x;++i){
        sum += i;
        if(sum >= x){
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void allcout(auto V) {
    for(auto x : V) cout << x << ' ';
    cout << endl;
}
int N, A, B;
vector<int> h;
bool judge(int n) {
    int res = 0;
    rep(i, N) {
        int hp = h[i];
        hp -= B * n;
        if(hp <= 0) continue;
        res += (hp + (A - B) - 1) / (A - B);
    }
    return res <= n;
}
signed main() {
    cin >> N >> A >> B;
    h.assign(N, -1);
    int mm = 0;
    rep(i, N) {
        cin >> h[i];
        chmax(mm, (h[i] + B - 1) / B);
    }
    int l = 0, r = mm;
    while(r - l > 1) {
        int mid = (r + l) / 2;
        if(judge(mid))
            r = mid;
        else
            l = mid;
    }
    cout << r << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=100010,mod=1e9+7,A[4][4]={{1,0,0,0},{1,1,0,0},{1,2,2,0},{1,3,6,6}};
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
template<typename T>
inline void read(T &x){
	x=0;
	char ch=getchar();bool f=false;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	if(f) x=-x;
}
int n,a[MAXN],cnt[MAXN],cnt2[MAXN],cnt3[MAXN],ans=1;
int main(){
	read(n);
	FOR(i,1,n) read(a[i]);
	FOR(i,1,n){
		cnt[a[i]]++;cnt2[a[i]]++;cnt3[a[i]]++;
		if(cnt3[a[i]]>3) return puts("0"),0;
		if(a[i]){
			if(cnt3[a[i]]>cnt3[a[i]-1]) return puts("0"),0;
			ans=1ll*ans*A[cnt2[a[i]-1]][cnt[a[i]]]%mod;
			cnt2[a[i]-1]--;cnt[a[i]]--;
		}
	}
	ans=1ll*ans*A[3][cnt3[0]]%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
integer :: a,b
logical :: flag = .false.

read*,a,b

if( mod(a,3)==0 ) flag = .true.
if( mod(b,3)==0 ) flag = .true.
if( mod(a+b,3)==0 ) flag = .true.

if(flag)then
  print*,'Possible'
else
  print*,'Impossible'
end if
end

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std ; 

typedef long long ll ; 

vector<int> adj[2222] ; 

int count(int now, int rem, int father){
    if(rem == 0)
        return 0 ; 
    int rtn = 0 ; 
    for(auto x: adj[now]){
        if(x == father)
            continue ; 
        rtn += count(x, rem-1, now) ; 
    }
    return rtn+1 ; 
}

int w[2222] ; 
int wp1[2222] ; 
int sol(int root, int K){
    memset(w, 0, sizeof(w)) ; 
    memset(wp1, 0, sizeof(wp1)) ; 
    int wsum = 0 ; 
    for(auto x: adj[root]){
        w[x] = count(x, K/2, root) ; 
        wsum += w[x] ; 
    }
    if(K%2){
        for(auto x: adj[root])
            wp1[x] = count(x, K/2+1, root) ; 
        int tot = 0 ; 
        for(auto x: adj[root]){
            tot = max(tot, wsum-w[x]+wp1[x]) ; 
        }
        return tot+1 ; 
    }
    return wsum+1 ; 
}

int main()
{
    int N, K ; 
    scanf("%d%d", &N, &K) ; 
    for(int i = 0 ; i != N-1 ; i++){
        int u, v ; 
        scanf("%d%d", &u, &v) ; 
        adj[u].push_back(v) ; 
        adj[v].push_back(u) ; 
    }
    int ans = 2222 ; 
    for(int i = 0 ; i != N ; i++){
        ans = min(ans, N-sol(i, K)) ; 
    }
    printf("%d\n", ans) ; 
    return 0 ; 
}


Measured memory_bytes: 384
import Data.List
import Data.Char

main = interact $ unlines . map (unwords . map show) . trading . read' . lines
 where read' ss = let (ts_last, (_:ts_this)) = span (not.null) (map (takeWhile isDigit) ss) in [ts_last, ts_this]

trading [ts_last, ts_this] = sort $ map aggregate $ sort $ intersect (nub ts_last) (nub ts_this)
 where aggregate n = [read n, length $ filter (== n) (ts_last ++ ts_this)]

Measured memory_bytes: 3696
#include <stdio.h>

int main(){

  int n;
  scanf("%d",&n);
  int d[n],i,j,ans=0;
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
  }

  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      ans+=d[i]*d[j];
    }
  }

  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
def solve():
    s1 = input()
    s2 = ''
    q = int(input())
    flg = 0
    for i in range(q):
        a = input().split()
        if a[0] == '1':
            flg = 1 - flg
        else:
            if flg == 0 and a[1] == '2' or flg == 1 and a[1] == '1':
                s1 += a[2]
            else:
                s2 += a[2]
    if flg == 0:
        print(s2[::-1] + s1)
    else:
        print(s1[::-1] + s2)
solve()


Measured memory_bytes: 4468
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N; int M;
	while(~scanf("%d%d", &N, &M)) {
		vector<string> s(N);
		rep(i, N) 
			cin >> s[i];
		int ans = 0;
		rep(i, N) rep(j, M) {
			bool ok = i != 0;
			if(j > 0) ok &= s[i][j - 1] == '-';
			ok &= s[i][j] == '-';
			if(j + 1 < M) ok &= s[i][j + 1] == '-';
			rer(dy, -1, 1) rer(dx, -1, 1) {
				int yy = i + dy, xx = j + dx;
				if(0 <= yy && yy < N && 0 <= xx && xx < M)
					ok &= s[yy][xx] != 'x';
			}
			ans += ok;
		}
		printf("%d\n", ans);
	}
	return 0;
}

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


int main(){
 int n,k;
 cin >> n>> k;
 vector<int> a(n);
  rep(i,n) cin >> a[i];
  for(int r = k; r < n; r++){
  int l =r - k;
    if(a[l] < a[r]) cout << "Yes" << endl;
    else cout <<"No" << endl;
  }
  return 0;

}


Measured memory_bytes: 4040
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
var a=[];
var b=[];
Arr.forEach(function(v,i){
if(i<10)a.push(v);
if(i>=10)b.push(v);
});
a.sort(function(a,b){return b-a;});
b.sort(function(a,b){return b-a;});
console.log((a[0]+a[1]+a[2])+" "+(b[0]+b[1]+b[2]));

Measured memory_bytes: 7640
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	
	if(a<b){
		if(b<c){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    int64_t A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    
    int64_t ans = 0;
    
    if (A + B <= 2 * C) {
        ans = X * A + Y * B;
    } else if (X > Y) {
        if (A <= 2 * C) ans = 2 * Y * C + (X - Y) * A;
        else ans = 2 * X * C;
    } else {
        if (B <= 2 * C) ans = 2 * X * C + (Y - X) * B;
        else ans = 2 * Y * C;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MAXN = 301;
set<string> ST;
int N;
int base = 97;

int rec(int cnt, string S, int Max){
    
    if(cnt == N) {ST.insert(S); return 0;}
    for(int i = 0; i <= Max; i++){
        char tmp = (char)(base + i);
        string S_ = S; S_ += tmp;
        rec(cnt+1, S_, max(i+1, Max));
    }
    return 0;
}

int main(){
    cin >> N;
    rec(1, "a", 1);
    for(auto s:ST) cout << s << endl;
    //cout << ST.size() << endl;


}

Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m, d;
	scanf("%d%d%d", &n, &m, &d);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int x = (m + i + j) / d % 2;
			int y = (m + i - j) / d % 2;
			char c = "RGBY"[2 * x + y];
			printf("%c", c);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == -1){
				break;
			}else if(n == 0){
				System.out.println(0);
				continue;
			}
			String ans = "";
			while(n != 0){
				ans = n%4 + ans;
				n /= 4;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 23500
import java.util.*;

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();

        if(A+B>=C){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    } 
}

Measured memory_bytes: 21972
#include <stdio.h>

int main(void)
{
  int i,k,n,longest=0,emc=0;
  scanf("%d",&k);
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(i>=1&&a[i]-a[i-1]>longest)
      longest=a[i]-a[i-1];
  }
  if((a[0]+(k-a[n-1]))>longest)
     longest=a[0]+(k-a[n-1]);
  emc=k-longest;
  printf("%d",emc);
  
  return 0;
}

Measured memory_bytes: 2472
package main

import (
	"bufio"
	"fmt"
	"math"
	"math/rand"
	"os"
	"time"
)

var D int
var cs []int
var ss [][]int

func main() {
	D = ReadInt()
	cs = ReadInts(26)
	ss = make([][]int, D)
	for i := 0; i < D; i++ {
		ss[i] = ReadInts(26)
	}

	// naives
	answers := []int{}
	last := make([]int, 26)
	for d := 1; d <= D; d++ {
		maxT, maxScore := -1, math.MinInt32
		for i := 0; i < 26; i++ {
			s := ss[d-1][i] - cs[i]*(d-last[i])
			if s > maxScore {
				maxT, maxScore = i, s
			}
		}
		last[maxT] = d
		answers = append(answers, maxT+1)
	}

	rand.Seed(12345682)

	lastAnswers := Dup(answers)
	lastScore, _ := scores(lastAnswers)

	start := time.Now()
	timeout := 1900 * time.Millisecond
	for time.Now().Sub(start) < timeout {
		d, q := rand.Intn(D)+1, rand.Intn(26)+1
		newAnswers := Dup(lastAnswers)
		newAnswers[d-1] = q
		newScore, _ := scores(newAnswers)
		if newScore >= lastScore {
			lastAnswers, lastScore = newAnswers, newScore
		}
	}

	for _, v := range lastAnswers {
		fmt.Println(v)
	}
}

func Dup(xs []int) []int {
	return append([]int{}, xs...)
}

func scores(answers []int) (int, []int) {
	scores := []int{}
	last := make([]int, 26)
	score := 0
	for d := 1; d <= D; d++ {
		t := answers[d-1] - 1
		score += ss[d-1][t]
		last[t] = d
		for i := 0; i < 26; i++ {
			score -= cs[i] * (d - last[i])
		}
		scores = append(scores, score)
	}
	return score, scores
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 6608
#include<bits/stdc++.h>
using namespace std;
const int N=4050;
struct data{
  int x,y;
}w[N];
int head[N],num[N],nn[N][2],cnt=1;
#define link(u,v) (nn[++cnt][1]=v,nn[cnt][0]=head[u],head[u]=cnt)
bool vis[N],val[N];
vector<int>ed[N],st[N];
vector<int>::iterator it;
int dfs(int x,int id,int fa,int t){
  if (x==t) return 1;
  for (int i=head[x],y; i; i=nn[i][0])
    if ((y=nn[i][1])!=fa&&dfs(y,id,x,t)){
	ed[id].push_back(i);
	st[i>>1].push_back(id);
	return 1;
      }
  return 0;
}
int main(){
  int n,m,u,v; cin>>n>>m;
  for (int i=2; i<=n; ++i)
    cin>>u>>v,link(u,v),link(v,u);
  for (int i=1; i<=m; ++i){
    cin>>w[i].x>>w[i].y;
    dfs(w[i].x,i,0,w[i].y);
  }
  int ans=0;
  for (int i=1; i<n; ++i)
    num[i]=st[i].size(),ans+=min(2,num[i]);
  for (;;){
    int x;
    for (x=1; x<n; ++x){
      if (num[x]==1&&vis[x<<1]!=vis[x<<1|1]) break;
    }
    if (x==n){
      for (x=1; x<n&&!num[x]; ++x);
      if (x==n) break;
    }
    while(val[st[x].back()]) st[x].pop_back();
    int p=st[x].back(),rev=0;
    val[p]=1;
    for (it=ed[p].begin(); it!=ed[p].end(); ++it)
      if ((*it)/2==x){
	if (vis[*it])
	  rev=1,swap(w[p].x,w[p].y);
	break;
      }
    for (it=ed[p].begin(); it!=ed[p].end(); ++it)
      vis[*it^rev]=1,--num[*it>>1];
  }
  cout<<ans<<endl;
  for (int i=1; i<=m; ++i)
    cout<<w[i].x<<" "<<w[i].y<<endl;
  return 0;
}

Measured memory_bytes: 13952
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()


def f(ss):
	n = len(ss) 
	LCSRe = [[0 for x in range(n + 1)] 
				for y in range(n + 1)] 
	res = ""
	res_length = 0

	index = 0
	for i in range(1, n + 1): 
		for j in range(i + 1, n + 1): 
			if (ss[i - 1] == ss[j - 1] and
				LCSRe[i - 1][j - 1] < (j - i)): 
				LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1
				if (LCSRe[i][j] > res_length): 
					res_length = LCSRe[i][j] 
					index = max(i, index)
			else: 
				LCSRe[i][j] = 0
	if (res_length > 0): 
		for i in range(index - res_length + 1, index + 1): 
			res = res + ss[i - 1] 

	return res_length

n = ni()
s = ns()
print(f(s))



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

int main() {
  string T;
  cin >> T;
  for(int i = 0; i < T.size(); i++) {
    if(T.at(i) == '?') {
      cout << "D";
    }
    else {
      cout << T.at(i);
    }
  }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

inline bool is_prime(i32 n) {
  if (n < 2) {
    return 0;
  }
  for (i32 i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

vi32 prime_list(i32 n) {
  vi32 f(n, 1);
  f[0] = f[1] = 0;
  repi(i, 2, n) {
    if (!f[i]) continue;
    for (int j = i * 2; j < n; j += i) {
      f[j] = 0;
    }
  }
  return f;
}

void solve() {
  vi32 primes = prime_list(300000);
  rep(i, primes.size() - 1) primes[i + 1] += primes[i];
  
  while (true) {
    int n; cin >> n;
    if (n == 0) return;
    cout << primes[n * 2] - primes[n] << '\n';
  }
}



Measured memory_bytes: 4080
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;

typedef long long ll;


int main(){

  int N;
  cin>>N;
  int AC=0,WA=0,TLE=0,RE=0;

  string str;
  rep(i,N){
    cin>>str;
    if(str=="AC"){
      ++AC;
    }else if(str=="WA"){
      ++WA;
    }else if(str=="TLE"){
      ++TLE;
    }else if(str=="RE"){
      ++RE;
    }else{

    }

  }

  cout<<"AC x "<<AC<<endl;
  cout<<"WA x "<<WA<<endl;
  cout<<"TLE x "<<TLE<<endl;
  cout<<"RE x "<<RE<<endl;

}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
using namespace std;
int main(){
    int N;
    cin >> N;
    int minodd = 1000;
    int sum = 0;
    REP(i,N){
        int d;
        cin >> d;
        sum += d;
        if(d&1){
            minodd = min(minodd,d);
        }
    }
    cout << (sum - minodd * (sum&1==1))/2 << endl;
    return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(){
  int N;
  cin>>N;
  set<int> ss[1000];

  bool flag=false;

  int n,m;
  for(int i=2;i*(i-1)<=2*N;i++){
    if(i*(i-1)==2*N){
      flag=true;
      n=i;m=i-1;
    }
  }
  if(!flag){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;

  int tmp=1;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=i;j++){
      ss[j].insert(tmp++);
    }
  }

  tmp=1;
  for(int i=2;i<=n;i++){
    for(int j=2;j<=i;j++){
      ss[i].insert(tmp++);
    }
  }
  cout<<n<<endl;
  for(int i=1;i<=n;i++){
    cout<<m<<" ";
    for(auto itr=ss[i].begin();itr!=ss[i].end();++itr){
      cout<<*itr<<" ";
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 10752
#include <stdio.h>
#include <stdlib.h>

long abso(long);
int int_sort(const void *, const void *);

int main()
{
  long n, a[200000], i, b, ans;

  scanf("%ld", &n);

  for (i = 0; i < n; ++i)
  {
    scanf("%ld", &(a[i]));
  }

  for(i = 0; i < n; ++i)
  {
    a[i] -= i + 1;
  }

  qsort((void *)a, n, sizeof(a[0]), int_sort);

  if (n % 2 == 0)
  {
    b = a[n / 2 - 1];
  }
  else
  {
    b = a[(n + 1) / 2 - 1];
  }

  ans = 0;
  for (i = 0; i < n; ++i)
  {
    ans += abs(a[i] - b);
  }

  printf("%ld\n", ans);

  return 0;
}

long abso(long a)
{
  if (a < 0) a = - a;

  return a;
}

int int_sort( const void * a , const void * b )
{
  if (*( long *)a < *(long *)b)
  {
    return -1;
  }
  else if (*( long *)a == *(long *)b)
  {
    return 0;
  }
  return 1;
}


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

int main(){
    string s; cin >> s;
    for(int i = 0; i < 12; i++){
        cout << s[i];
        if(i == 3) cout << ' ' ;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
long long a[1001][1002];
int main()
{
        IO;
        string s; int i, n, j;
        cin>>s;
        if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  ll a,b,x,m=1;
  cin >> a >> b >> x;
  ll ans=b/x-(a-m)/x;
  if (a==0) ans=b/x+1;
  cout << ans << endl;
}


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

 int kaibun (int i) {
   int num = i;
   int remaind, reverse = 0;
   while (num != 0){
     remaind = num % 10;
     reverse = reverse * 10 + remaind;
     num /= 10;
   }
   return reverse;
 }

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  
  for (int i = A; i <= B; i++) {
    int num = i;
    int r_num = kaibun(i);
    if (num == r_num)
      count++;
  }
  cout << count << endl;
}


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

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    
    // Nの桁数を求める。
    int keta = 0;
    int tmp = N;
    do {
        keta++;
        tmp /= 10;
    }while (tmp > 0);
    
    int ans = 0;
    switch (keta) {
        case 1:
            ans = N;
            break;
        case 2:
            ans = 9;
            break;
        case 3:
            ans = 9;
            ans = ans + N - 99;
            break;
        case 4:
            ans = 909;
            break;
        case 5:
            ans = 909;
            ans = ans + N - 9999;
            break;
        case 6:
            ans = 90909;
            break;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 888
c500 = gets.chomp.to_i
c100 = gets.chomp.to_i
c50 = gets.chomp.to_i
x = gets.chomp.to_i
count = 0
(0..c500).each do |i|
  (0..c100).each do |j|
    (0..c50).each do |k|
      if i*500 + j*100+ k*50 == x
        count += 1
      end      
    end
  end
end
puts(count)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
ll inf=1e18;
ll p= 998244353;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
   while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,j,y,x,k,z,w,g,m,t,n,a,b;
	ll t2,t3,t4,t1;
	    string s;
	    cin>>n;
	    ll ans=0;
	    map<ll,ll>mp;
	    for(i=0;i<n;i++)
	    {
	        cin>>x;
	        mp[x]++;
	        ans+=x;
	    }
	    ll q;
	    cin>>q;
	    while(q--)
	    {
	        cin>>x>>y;
	        if(mp[x]>0)
	        {
	            ans+=(y*mp[x]);
	            ans-=(x*mp[x]);
	            mp[y]+=mp[x];
	            
	            mp[x]=0;
	        }
	        cout<<ans<<"\n";
	    }
	   
	     
	 return 0;
	 
           
}

Measured memory_bytes: 9356
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

bool is_prime(ll n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else if (n % 2 == 0) {
        return false;
    }
 
    for (ll i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

void solve() {
    int n;
    cin >> n;
    int a;
    cin >> a;
    int mn = a;
    int ans = -INF;
    REP(i, n - 1) {
        cin >> a;
        chmax(ans, a - mn);
        chmin(mn, a);
    }
    cout << ans << endl;
}




Measured memory_bytes: 3216
while (n = gets.chomp.to_i) != 0
  sum = 0
  max = -1
  min = 1001

  n.times do
    s = gets.chomp.to_i
    sum += s
    
    if s > max
      max = s
    end
    if s < min
      min = s
    end
  end

  sum -= (min + max)
  puts sum/(n-2)
end

Measured memory_bytes: 8628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

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

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

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}

/* modつき二分累乗法 */
ll modpow(ll a, ll b) {
    ll res = 1;
    for (a = modu(a); b; a = modu(a * a) , b >>= 1){
        if (b & 1) res = modu(res * a);
    }
    return res;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(), M = in();
    vector<vector<int>> answer(M+1,vector<int>(modpow(2,N),mod));
    answer[0][0] = 0;
    REPS(i,M){
        int a = in(),b = in();
        int open = 0;
        REP(l,b){
            open += modpow(2,in()-1);
        }
        REP(l,modpow(2,N)){
            answer[i][l | open] = min({answer[i-1][l | open],answer[i-1][l] + a,answer[i][l | open]});
        }
        REP(l,modpow(2,N)){
            answer[i][l] = min(answer[i-1][l],answer[i][l]);
        }
    }
    if(answer[M][modpow(2,N)-1] != mod){
        cout << answer[M][modpow(2,N)-1] << "\n";
    }else{
        cout << -1 << "\n";
    }
}

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

using namespace std;

#define int long long
//#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int q;
  cin >> q;
  bitset<64> bit;
  rep(i, q) {
    int k; cin >> k;
    if(k < 3) {
      int i; cin >> i;
      switch(k) {
      case 0: cout << bit.test(i) << endl; break;
      case 1: bit.set(i); break;
      case 2: bit.reset(i); break;
      }
    } else {
      switch(k) {
      case 3: cout << bit.all() << endl; break;
      case 4: cout << bit.any() << endl; break;
      case 5: cout << bit.none() << endl; break;
      case 6: cout << bit.count() << endl; break;
      case 7: cout << bit.to_ullong() << endl; break;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3200
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

ans = 0
for d in range(60):
    mask = 1 << d
    Z = len([0 for a in A if (a & mask) == 0])
    ans += mask * Z * (N - Z)
    ans %= MOD
print(ans)


Measured memory_bytes: 42156