akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <tuple>
#include <queue>
#include <map>

using Point = std::tuple<int, int, int>;
using roll_func = Point (*)(const Point &p, int N);

constexpr int INF   = (1 << 29);
constexpr int LIMIT = 10;

Point roll_x(const Point &p, int N)
{
    int x, y, z;
    std::tie(x, y, z) = p;
    return Point{N - y - 1, x, z};
}

Point roll_y(const Point &p, int N)
{
    int x, y, z;
    std::tie(x, y, z) = p;
    return Point{x, N - z - 1, y};
}

Point roll_z(const Point &p, int N)
{
    int x, y, z;
    std::tie(x, y, z) = p;
    return Point{N - z - 1, y, x};
}

Point roll_n(const Point &p, int n, int N, roll_func func)
{
    Point ret = p;
    for (int i = 0; i < n; i++) {
        ret = func(ret, N);
    }
    return ret;
}

Point operator + (const Point &a, const Point &b)
{
    int ax, ay, az, bx, by, bz;

    std::tie(ax, ay, az) = a;
    std::tie(bx, by, bz) = b;

    return Point{ax + bx, ay + by, az + bz};
}

int manhattan_distance(const Point &a, const Point &b)
{
    int ax, ay, az, bx, by, bz;

    std::tie(ax, ay, az) = a;
    std::tie(bx, by, bz) = b;

    return abs(ax - bx) + abs(ay - by) + abs(az - bz);
}

int bfs(int N, const Point &s, const Point &t)
{
    std::queue<Point> Q;
    Q.push(s);

    std::map<Point, int> min_times;
    min_times[s] = 0;

    int ret = INF;
    
    while (!Q.empty()) {
        Point curr = Q.front(); Q.pop();
        int curr_time = min_times[curr];

        ret = std::min(ret, curr_time + manhattan_distance(curr, t));
        
        if (curr_time == LIMIT) {
            continue;
        }

        constexpr Point dp[] = {Point{1, 0, 0}, Point{0, 1, 0}, Point{0, 0, 1}};
        for (int i = 0; i < 3; i++) {
            Point np = curr + dp[i];
            if (min_times.count(np) == 0) {
                min_times[np] = curr_time + 1;
                Q.push(np);
            }
        }
        
        for (int n : {1, 3}) {
            auto get = [](const Point &p, int k) -> int {
                switch (k) {
                    case 0: return std::get<0>(p);
                    case 1: return std::get<1>(p);
                    case 2: return std::get<2>(p);
                }
            };

            int coord = 2;
            for (roll_func func : {roll_x, roll_y, roll_z}) {                
                if (get(curr, coord) !=  get(t, coord)) {
                    Point np = roll_n(curr, n, N, func);
                    if (min_times.count(np) == 0) {
                        min_times[np] = curr_time + 1;
                        Q.push(np);
                    }
                }

                coord = (coord + 1) % 3;
            }
        }
    }

    return ret;
}

int main()
{
    int N;
    int sx, sy, sz, tx, ty, tz;

    std::cin >> N >> sx >> sy >> sz >> tx >> ty >> tz;

    Point s{sx, sy, sz}, t{tx, ty, tz};    
    std::cout << bfs(N, s, t) << std::endl;
    
    return 0;
}

Measured memory_bytes: 4168
#include <stdio.h>

int main(void)
{
	int H, W, i, j;

	do
	{
		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0)break;

		for (i = 0; i < H; i++)
		{
			for (j = 0; j < W; j++)
				printf("#");
			putchar('\n');
		}

		putchar('\n');

	} while (!(H == 0 && W == 0));

	return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n, m; cin >> n >> m;
    set<int> S;
    for (int i = 0; i < m; i++) {
        S.insert(i);
    }
    vector<pair<int, int>> a;
    for (int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        a.emplace_back(y, x);
    }
    sort(a.rbegin(), a.rend());
    ll res = 0;
    for (int i = 0; i < n; i++) {
        int days = a[i].second, cost = a[i].first;
        auto it = S.upper_bound(m - days);
        if (it != S.begin()) {
            it--;
            S.erase(it);
            res += cost;
        }
    }
    cout << res << "\n";
}


Measured memory_bytes: 6140
def haiku(lst):
    w5 = 2
    w7 = 1

    for h in lst:
        if h == '5':
            w5 -= 1

            if w5 < 0:
                return False
        elif h == '7':
            w7 -= 1

            if w7 < 0:
                return False
        else:
            return False

    return True

lst = input().split()

print('YES' if haiku(lst) else 'NO')

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

int main()
{
  int n,r,p,c;

  while(cin >> n >> r && n)
  {
    int yama[n];
    for(int i = 0; i < n; i++)
    {
      yama[i] = n-i;
    }
    for(int i = 0; i < r; ++i)
    {
      cin >> p >> c;
      rotate(yama,yama+p-1,yama+ p+ c -1);
    }
    printf("%d\n", yama[0] );
  }
}



Measured memory_bytes: 3236
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;
const int MOD = 256;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> l(n+1);
        for(int i=1; i<=n; ++i)
            cin >> l[i];

        double H = DBL_MAX;
        int S, A, C;
        for(int s=0; s<=15; ++s){
            for(int a=0; a<=15; ++a){
                for(int c=0; c<=15; ++c){
                    vector<int> r(n+1);
                    r[0] = s;
                    for(int i=1; i<=n; ++i)
                        r[i] = (a * r[i-1] + c) % MOD;

                    vector<int> o(n+1);
                    for(int i=1; i<=n; ++i)
                        o[i] = (l[i] + r[i]) % MOD;

                    vector<int> x(MOD, 0);
                    for(int i=1; i<=n; ++i)
                        ++ x[o[i]];

                    double h = 0.0;
                    for(int i=0; i<MOD; ++i){
                        if(x[i] > 0)
                            h -= x[i] / (double)n * log(x[i] / (double)n);
                    }
                    if(h < H - EPS){
                        H = h;
                        S = s;
                        A = a;
                        C = c;
                    }
                }
            }
        }

        cout << S << ' ' << A << ' ' << C << endl;
    }
}

Measured memory_bytes: 1244
A=input()
B=input()
C=input()
s="a"
while (len(A)!=0 or s!="a") and (len(B)!=0 or s!="b") and (len(C)!=0 or s!="c"):
  if s=="a":
    s=A[0]
    A=A[1:]
  elif s=="b":
    s=B[0]
    B=B[1:]
  else:
    s=C[0]
    C=C[1:]
if len(A)==0 and s=="a":
    print("A")
elif len(B)==0 and s=="b":
    print("B")
else:
    print("C")


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main()
{
    double a, b, C;
    scanf("%lf %lf %lf", &a, &b, &C);
    C = C * M_PI / 180;
    printf("%f\n", 0.5*a*b*sin(C));
    printf("%f\n", a + b + sqrt(a*a+b*b-2*a*b*cos(C)));
    printf("%f\n", b * sin(C));
    return 0;
}


Measured memory_bytes: 2048
N,K = map(int,input().split())
S = list(input())
ans = ''
if S[K-1] == 'A':
  S[K-1] = 'a'
elif S[K-1] == 'B':
  S[K-1] = 'b'
else:
  S[K-1] = 'c'
for i in range(N):
  ans += S[i]
print(ans)

Measured memory_bytes: 3060
N = int(input())


def digit(N):
    d = 0
    while N >= 1:
        N /= 10
        d += 1
    return d


f = []
i = 1
while i * i <= N:
    if N % i == 0:
        d1 = digit(i)
        d2 = digit(int(N/i))
        f.append(max(d1, d2))
    i += 1

print(min(f))


Measured memory_bytes: 9212
#include <iostream>
typedef long long ll;
using namespace std;

ll W[101], V[101], DP[101][100001];

int main(){
    ll NMAX, WMAX;
    cin >> NMAX >> WMAX;
    
    for(int i=0;i<NMAX;i++) cin >> W[i] >> V[i];
    for(int i=0;i<=NMAX;i++){
        for(int v=0;v<=100001;v++) {
            if(v==0) DP[i][v] = 0;
            else DP[i][v] = 1000000001;
        }
    }
    for(int i=0;i<NMAX;i++){
        for(int v=1;v<=100001;v++) {
            if(v>=V[i]) DP[i+1][v] = min(DP[i][v], DP[i][v-V[i]]+W[i]);
            else DP[i+1][v] = DP[i][v];
        }
    }
    for(int v=100000;v>=0;v--){
        if(DP[NMAX][v]<=WMAX) {
            cout << v << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)

//int a[1001][1001] //aise global me hi

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//memset can initialize to 0 or -1 ONLY //memset(str, 't', sizeof(str)); // string
//memset(a, 0, sizeof(a));  //1D array    // memset(a,0,sizeof(a[0][0])*n*n); //2D array
// set.insert(),find()    // sort(v.begin(),v.end(),compare)

void solve()
{
int n;cin>>n;
int a[n];
f(i,0,n)
cin>>a[i];
int ans=-1;ll ma=-1;

f(i,1,1000)
{ll tmp=0;

	f(j,0,n)
	{
		tmp+=(a[j]-i)*(a[j]-i);
	}
	if(tmp<ma||ma<0)
	{
		ma=tmp;ans=i;
	}

}
cout<<ma;
}


int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
   // cin>>t;
    while(t--)
    {
    
    solve();
    
    }

}

Measured memory_bytes: 256
n,m = map(int, input().split())
a = set([int(input()) for _ in range(m)])

nums = [0]*(n+1)
nums[0] = 1
if 1 not in a: nums[1] = 1

for i in range(2,n+1):
  if i not in a: nums[i] = nums[i-1] + nums[i-2]
print(nums[n]%(10**9+7))

Measured memory_bytes: 465912
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

// #define fisier 1

using namespace std;

typedef long long ll;

int x, y, a, b, c;
int ag[100002], ar[100002], ac[100002];


int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> x >> y >> a >> b >> c;
    for(int i = 1; i <= a; ++i)
        cin >> ar[i];
    for(int i = 1; i <= b; ++i)
        cin >> ag[i];
    for(int i = 1; i <= c; ++i)
        cin >> ac[i];
    sort(ar + 1, ar + a + 1);
    sort(ag + 1, ag + b + 1);
    sort(ac + 1, ac + c + 1);
    ll ans = 0;
    for(int i = a - x + 1; i <= a; ++i)
        ans += ar[i];
    for(int i = b - y + 1; i <= b; ++i)
        ans += ag[i];
    ar[a+1] = (1<<30);
    ag[b+1] = (1<<30);
    int aa = a - x + 1;
    int bb = b - y + 1;
    for(int i = c; i >= 1; --i)
    {
        int pa = min(ar[aa], ag[bb]);
        if(ac[i] > pa)
        {
            ans += ac[i] - pa;
            if(ar[aa] < ag[bb])
                ++aa;
            else
                ++bb;
        }
        else
            break;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1408
x,y = gets.split.map(&:to_i)
a = 10**10
a = y-x if y > x
ans = 0
while x != y
    if (x.abs < y.abs && x < 0) || (x.abs > y.abs && x > 0)
        ans += 1
        x *= -1
    elsif x.abs != y.abs
        ans += (x.abs-y.abs).abs
        x += (x.abs-y.abs).abs
    else
        ans += 1
        x *= -1
    end
end
puts [ans,a].min

Measured memory_bytes: 1788
#include <functional>
#include <list>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <deque>
#include <stack>
#include <cassert>
using namespace std;
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define ALL(x) (x).begin(),(x).end()
#define CASET2 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d:\n", case_n++) : 0), ___T-- > 0)
#define CASET1 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d: ", case_n++) : 0), ___T-- > 0)
#define CASET int ___T; scanf("%d ", &___T); while (___T-- > 0)
#define SZ(X) ((int)(X).size())
#define LEN(X) strlen(X)
#define REP(i,n) for(int i=0;i<int(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=int(b);i++)
#define PER1(i,a,b) for(int i=(a);i>=(b);i--)
#define REPL(i,x) for(int i=0;x[i];i++)
#define PER(i,n) for(int i=(n)-1;i>=0;i--)
#define RI1(x) scanf("%d",&x)
#define RI2(x,y) RI1(x), RI1(y)
#define RI3(x,y...) RI1(x), RI2(y)
#define RI4(x,y...) RI1(x), RI3(y)
#define RI5(x,y...) RI1(x), RI4(y)
#define RI6(x,y...) RI1(x), RI5(y)
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define RI(argv...) GET_MACRO(argv, RI6, RI5, RI4, RI3, RI2, RI1)(argv)
#define DRI(argv...) int argv;RI(argv)
#define WRI(argv...) while (RI(argv) != EOF)
#define DWRI(x...) int x; WRI(x)
#define RS(x) scanf("%s",x)
#define MP make_pair
#define PB push_back
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define X first
#define Y second
#define V(x) vector<x >

typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int INF = 1000000000;

void print(int i) { printf("%d", i); }
void print(LL i);
template<class T> void PI(T i) { print(i); puts(""); }
template<class T> void PIS(T i) { print(i); printf(" "); }

template<class T>
void PV(T const &v, int N) {
    REP(i, N) {
        print(v[i]);
        printf("%c", i == N-1 ? '\n' : ' ');
    }
}

template<class T> void PV(T const &v) { PV(v, SZ(v)); }

template<class T, class S> bool has_bit(T mask, S i) { return (mask >> i) & 1; }
long long shift(int i) { return 1ll << i; }

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
int popcount(int x) { return __builtin_popcount(x); } 
int popcount(long long x) { return __builtin_popcountll(x); } 

#include <unordered_set>
#include <unordered_map>
#define EB emplace_back
#define RL(x) scanf("%lld", &(x))
#define PL(x) printf("%lld\n", x)
#define DRL(x) LL x; RL(x)

int main() {
    DRI(A, B, C, X, Y);
    if (A + B > C * 2) {
        int m = min(X, Y);
        int ans = m * C * 2;
        if (A > C * 2) {
            ans += 2 * C * (X - m);
        } else {
            ans += A * (X - m);
        }
        if (B > C * 2) {
            ans += 2 * C * (Y - m);
        } else {
            ans += B * (Y - m);
        }
        PI(ans);
    } else {
        PI(X * A + Y * B);
    }
    return 0;
}


Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,ko;
    ll x,y,w,z;
    char hoge,fuga;
    cin>>a>>b>>c>>d;
    if(a+b>c+d) cout<<"Left"<<endl;
    if(a+b==c+d) cout<<"Balanced"<<endl;
    if(a+b<c+d) cout<<"Right"<<endl;

    return 0;
}


Measured memory_bytes: 3588
main=do
    (x1:y1:x2:y2:_)<-map read.words<$>getLine::IO[Int]
    --
    let x3 = x2 + (y1-y2)
    let y3 = y2 - (x1-x2)
    let x4 = x1 + (y1-y2)
    let y4 = y1 - (x1-x2)

    putStrLn $ unwords $ map show [x3,y3,x4,y4]

Measured memory_bytes: 508
N, X = gets.split(' ').map(&:to_i)

@layer = [1]
@meat = [1]
1.upto(N) do |i|
  @layer[i] = @layer[i - 1] * 2 + 3
  @meat[i] = @meat[i - 1] * 2 + 1
end

def search(n, x)
  return 0 if x <= 0
  return 1 if n == 0 && x == 1
  if x <= @layer[n - 1] + 1
    return search(n - 1, x - 1)
  elsif x == @layer[n - 1] + 2
    return @meat[n - 1] + 1
  elsif x <= @layer[n - 1] * 2 + 2
    return @meat[n - 1] + 1 + search(n - 1, x - @layer[n - 1] - 2)
  else
    return @meat[n - 1] * 2 + 1
  end
end

puts search(N, X)

Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>

int main()
{
    int numOfStrings;
    scanf("%d", &numOfStrings);

    int numBxA = 0, numBeginB = 0, numEndA = 0, numAB = 0;
    char str[11] = {0};
    for (int i = 0; i < numOfStrings; i++)
    {
        scanf("%s", str);
        int len = strlen(str);

        if (str[0] == 'B' && str[len - 1] == 'A') // 'B' ではじまり 'A' で終わる文字列を考慮する
            numBxA++;
        else if (str[0] == 'B')
                numBeginB++;
        else if (str[len - 1] == 'A')
            numEndA++;

        for (int j = 0; j < len - 1; j++)
        {
            if (str[j] == 'A' && str[j + 1] == 'B')
                numAB++;
        }
    }
    if (numBeginB + numEndA != 0)
        numAB += numBxA + ((numBeginB < numEndA) ? numBeginB : numEndA);
    else if (numBxA != 0)
        numAB += numBxA - 1;

    printf("%d\n", numAB);
    return 0;
}


Measured memory_bytes: 128
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x);
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

vvi adj(2e5); vi vis(2e5), sign(2e5);

void bfs (int s)
{
    vis[s] = 1;
    queue <int> q; q.push(s);

    while(!q.empty())
    {
        int cur = q.front();
        q.pop();

        for (int i : adj[cur])
        {
            if(!vis[i]) {vis[i] = 1; q.push(i); sign[i] = cur;}
        }
    }
}

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

    #ifndef ONLINE_JUDGE 
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        freopen ("OUTPUT_ERROR.txt" , "w" , stderr);
    #endif

    //start from here

    readb(n, m)
    int x, y;

    fori (i, 1, m)
    {
        cin >> x >> y;
        adj[x].pb(y); adj[y].pb(x);
    }

    bfs(1);

    fori (i, 1, n) if(!vis[i]) {print("No") return 0;}

    print("Yes")

    fori (i, 2, n) print(sign[i])

    return 0;
}


Measured memory_bytes: 17716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		// すべてのa[i]に含まれる約数2の数を調べればいい
		int ans = 0;
		for (int i = 0; i < a.length; i++) {
			while (a[i]%2 == 0) { //2で割り続け、奇数になったらループを抜ける
				a[i] /= 2;
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 36344
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

signed main() {
	string s;
	cin >> s;
	rep(i, s.size()) {
		if ((i % 2 == 0 and s[i] == 'L') or (i % 2 == 1 and s[i] == 'R')) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


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

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

using namespace std;

using ll = long long;

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

    ll n;
    string s;
    cin >> n >> s;

    auto pre = s[0];
    auto ans = 0;
    FOR(i, 1, n) {
        if (pre != s[i]) {
            ++ans;
            if (i != n - 1) {
                pre = s[i + 1];
                ++i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3332
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
double dist(ll i, ll j)
{
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}

int main()
{
    ll n;string str;cin>>n>>str;
    if(n<3200)cout<<"red"<<endl;
    else cout<<str<<endl;
}


Measured memory_bytes: 4992
a, b, c = map(int, input().split())

if b - a + 1 > 2 * c:
    for i in range(a, a+c):
        print(i)
    for i in range(b-c+1, b+1):
        print(i)
else:
    for i in range(a, b+1):
        print(i)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
    string s; cin >> s;
    int L = s.size(), cnt = 0;
    int left = 0, right = L - 1;
    bool flag = true;

    while (left < right && flag) {
        if (s[left] == s[right]) left++, right--;
        else if (s[left] == 'x') left++, cnt++;
        else if (s[right] == 'x') right--, cnt++;
        else flag = false;
    }
    if (flag) cout << cnt << endl;
    else cout << -1 << endl;


}



Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<queue>
using namespace std;
void solve(vector<int> &d,vector<vector<int>> l,int k){
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
	pair<int,int> p,p2;
	p.first=0;
	p.second=k;
	q.push(p);
//	vector<int> use(d.size(),1);
	d[k]=0;
	while(q.size()){
		p=q.top();
		q.pop();
		for(int i=0;i<l[p.second].size();i++){
			p2.first=p.first+1;
			p2.second=l[p.second][i];
			if(d[p2.second]==-1){
				d[p2.second]=p2.first;
				q.push(p2);
			}

		}

	}
}

int main() {
	int n;cin>>n;
	vector<int> a(n),b(n);
	vector<vector<int>> l(n,vector<int>(0));
	for(int i=0;i<n-1;i++){
		cin>>a[i]>>b[i];
		a[i]--;
		b[i]--;
		l[a[i]].push_back(b[i]);
		l[b[i]].push_back(a[i]);
	}

	vector<int> d1(n,-1),dn(n,-1);
	solve(d1,l,0);
	solve(dn,l,n-1);
	int a1=0;
	int an=0;
	for(int i=0;i<n;i++){
		if(d1[i]>dn[i]){
			an++;
		}else{
			a1++;
		}
	}
	if(a1>an){
		cout<<"Fennec"<<endl;
	}else{
		cout<<"Snuke"<<endl;
	}
	return 0;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int m;
	cin >> m;
	VI a;
	LL r=0;
	REP(i,m){
		int d;
		LL c;
		cin >> d >> c;
		while(c >= 10){
			r += (c/10)*(d+9);
			c = c/10 + c%10;
		}
		REP(j,c){
			a.push_back(d);
		}
	}
	while(a.size()!=1){
		int s = a.size();
		int t = a[s-1] + a[s-2];
		a.pop_back();
		a.pop_back();
		if(t >= 10){
			a.push_back(t/10);
			a.push_back(t%10);
		}
		else{
			a.push_back(t);
		}
		r++;
	}
	cout << r << endl;

	

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 6384
#include <vector>
#include <math.h>
#include <iostream>

using namespace std;

long long dp[101][100001];
long long w[101];
long long v[101];
  
int main(){

  
  int N, W;
  cin >> N >> W;
  for(int i=1; i<=N; i++){
    cin >> w[i] >> v[i];
  }

  for(int i=0; i <=N * 1000; i++){
    dp[0][i] = 2e18;
  }
  dp[0][0] = 0;
  

  int max_val = 0;
  
  for(int j=1; j <= N; j++){
    for(int i=0; i <= N * 1000; i++){
      if (v[j] > i){
	dp[j][i] = dp[j-1][i];
      }
      else{
	dp[j][i] = min(dp[j-1][i], dp[j-1][i - v[j]] + w[j]);
      }
      if(dp[j][i] <= W){
	max_val = max(max_val, i);
      }
    }
  }

  cout << max_val << "\n";
  
  return 0;
}


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


const int MAXN = 1e5 + 1;
const long long INFTY = 1e18;

long long dp[MAXN];


int main()
{
    std::ios::sync_with_stdio(false);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);

    std::fill_n(dp, MAXN, INFTY);
    dp[0] = 0;

    int items; long long maxWeight;
    std::cin >> items >> maxWeight;

    for (int iItem = 0; iItem < items; iItem++)
    {
        long long weight; int value;
        std::cin >> weight >> value;

        for (int iVal = MAXN - 1; iVal >= value; iVal--)
            dp[iVal] = std::min(dp[iVal], dp[iVal - value] + weight);
    }

    int maxValue = MAXN - 1;
    while (dp[maxValue] > maxWeight)
        maxValue--;
    std::cout << maxValue << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair <int, int> pr;
priority_queue <pr> qua;
int a, b, c;
int t[3];
int ans;

int main() {
	cin >> a >> b >> c;
	t[1] = abs(a - b), t[2] = abs(b - c), t[3] = abs(a - c);
	sort(t + 1, t + 4);
	ans = t[1] + t[2];
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}
		long ans = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i + 1; j < n; j++) {
				ans += d[i] * d[j];
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	double a[n],sum=0.00;
	string b[n];
	for(i=0;i<n;i++)  cin>>a[i]>>b[i];
	for(i=0;i<n;i++)
	{
		if(b[i]=="JPY")
			sum+=a[i];
		else
			sum+=a[i]*380000.00;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::{Bytes, Chars, Isize1, Usize1};

fn main() {
    input! {
        n: usize,
        c: [Chars; n], // h*wのグリッドを Vec<Vec<char>> として読み込む
    }

    let mut vec = vec![0; 4];
    for i in 0..n {
        if c[i][0] == 'A' {
            vec[0] += 1;
        } else if c[i][0] == 'W' {
            vec[1] += 1;
        } else if c[i][0] == 'T' {
            vec[2] += 1;
        } else {
            vec[3] += 1;
        }
    }

    println!("AC x {}",vec[0]);
    println!("WA x {}",vec[1]);
    println!("TLE x {}",vec[2]);
    println!("RE x {}",vec[3])
}


Measured memory_bytes: 7820
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;

using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;


template< class T >
struct CumulativeSum2D {
  vector< vector< T > > data;

  CumulativeSum2D(int W, int H) : data(W + 1, vector< int >(H + 1, 0)) {}

  void add(int x, int y, T z) {
    ++x, ++y;
    if(x >= data.size() || y >= data[0].size()) return;
    data[x][y] += z;
  }

  void build() {
    for(int i = 1; i < data.size(); i++) {
      for(int j = 1; j < data[i].size(); j++) {
        data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
      }
    }
  }

  T query(int sx, int sy, int gx, int gy) {
    return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
  }
};

int main() {
  int n,m,q;
  cin>>n>>m>>q;
  CumulativeSum2D<int> s(n,n);
  rep(i,m){
    int l,r;
    cin>>l>>r;
    l--;r--;
    s.add(l,r,1);
  }
  s.build();
  rep(_,q){
    int l,r;
    cin>>l>>r;
    l--;r--;
    int ans = s.query(l,l,r+1,r+1);
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 1920
N= int(input())
Wn = list(input() for i in range(N))
ans = True
if len(set(Wn)) == len(Wn):
    lastst = Wn[0][-1]
    ans = True
    for i in range(len(Wn)-1):
        if Wn[i+1][0] == lastst:
            lastst = Wn[i+1][-1]
        else:
            ans = False
            break
    if ans == True:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [w, a, b] <- map strToInt . words <$> getLine
    let mini = min a b
        maxi = max a b
    -- 出力
    putStrLn $ show $ max 0 (maxi - mini - w)


Measured memory_bytes: 508
#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,b,c,d;
  cin >>a>>b>>c>>d;
  bool judge=true;
  while (judge){
    c-=b;
    if (c<=0){
      cout <<"Yes"<<endl;
      return 0;
    }
    a-=d;
    if(a<=0){
      cout <<"No"<<endl;
      return 0;
    }
    
  }
  return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define t int t ; cin>>t; while(t--)
#define u(x,a,b) for(int x=a;x<b;x++)
#define what(x) cerr << #x << "=" << x<<endl;
#define lli long long int
#define endl "\n"
lli Mod = 1000000007;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	lli n,d;
	cin>>n;
	lli a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		b[i] = a[i];
	}
	sort(b,b+n);

	for(int i=0;i<n;i++){
		if(a[i] == b[n-1]){
			cout<<b[n-2]<<endl;
		}else{
			cout<<b[n-1]<<endl;
		}
	}
	
    return 0;
}
                                                                                                                                 

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n;
	map<string, int> mp;
	cin >> n;
	while(n--)
	{
		string x;
		cin >> x;
		sort(ALL(x));
		mp[x]++;
	}
	
	LL ans = 0;
	for(auto i: mp) ans += i.Y * (LL) (i.Y - 1) / 2;
	cout << ans << endl;
	
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 11264
N=int(input())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
U=list(map(int,input().split()))
S.sort()
T.sort()
U.sort()
#print(S)
#print(T)
#print(U)


count=0
def is_ok(index,key):
    if key>S[index]:
        return True
    else:
        return False


def meguru_bisect(key):
    ng=N
    ok=-1
    
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid,key):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(index,key):
    if key<U[index]:
        return True
    else:
        return False


def meguru_bisect2(key):
    ng=-1
    ok=N
    
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid,key):
            ok = mid
        else:
            ng = mid
    return ok
ans=0
for i in range(N):
    ans+=(N-meguru_bisect2(T[i]))*(meguru_bisect(T[i])+1)
print(ans)



Measured memory_bytes: 29440
n=int(input())
a=list(input().split())
b=[]
if len(a)%2==0:
  for i in range(n-1,0,-2):
    b.append(a[i])
  for i in range(0,n-1,2):
    b.append(a[i])
else:
  for i in range(n-1,-1,-2):
    b.append(a[i])
  for i in range(1,n-1,2):
    b.append(a[i])
print(' '.join(b))


Measured memory_bytes: 25232
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int a,b,c; cin >> a >> b >> c;
    int out=0;
    if(a==b && a==c) out=1;
    else if(a==b || a==c || b==c) out=2;
    else out=3;
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <valarray>
//#include "../cxx-prettyprint/prettyprint.hpp"

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

    std::valarray<int> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &a[i]);
    }

    std::cout << (a - 1).sum() << std::endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int count[] = new int[6];
                for (int i = 0; i < N; i++) {
                        double len = sc.nextDouble();
                        len -= 160.0;
                        len /= 5;
                        int lenint = (int)len;
                        if (lenint < 0) {
                                lenint = 0;
                        }
                        if (lenint > 5) {
                                lenint = 5;
                        }
                        count[lenint]++;
                }
                for (int i = 0; i < 6; i++) {
                        System.out.print(i + 1 + ":");
                        for (int j = 0; j < count[i]; j++) {
                                System.out.print("*");
                        }
                        System.out.println("");
                }
        }
}

Measured memory_bytes: 28180
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut a = read::<String>();
    match &a[..] {
        "SUN" => {
            println!("7")
        },
        "SAT" => {
            println!("1")
        },
        "FRI" => {
            println!("2")
        },
        "THU" => {
            println!("3")
        },
        "WED" => {
            println!("4")
        },
        "TUE" => {
            println!("5")
        },
        "MON" => {
            println!("6")
        },
        _ => {
            return;
        }
    }
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
signed main(){
	int L, R, d;
	cin >> L >> R >> d;
	int sum = 0;
	for(int i = L; i <= R; i++){
		if(i%d == 0){
			++sum;
		}
	}
	cout << sum << endl;
 
	return 0;
}

Measured memory_bytes: 3592
#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<functional>
#define eps 0.01
#define pi acos(-1)
#define e exp(1)
using namespace std;
typedef long long ll;
const int maxn = 2e5;
int n;
ll a[maxn + 10];
int main() {
    while (cin >> n) {
        for(int i = 1; i <= n; ++i) {
            cin >> a[i];
            a[i] -= i;
        }
        sort(a + 1, a + n + 1);
        ll num = 0;
        if (n & 1)
            num = a[n / 2 + 1];
        else
            num = (a[n / 2] + a[n / 2 + 1]) / 2;
        //cout << num << endl;
        ll ans = 0;
        for (int i = 1; i <= n; ++i) {
            ans += abs(num - a[i]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
//067D 
import java.util.*;
public class Main {
	static int N;
	static List<ArrayList<Integer>> to;
	static List<Integer> distList;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		to = new ArrayList<>();
		for(int i=0;i<N;i++)to.add(new ArrayList<Integer>());
		for(int i=0;i<N-1;i++) {
			int a = sc.nextInt()-1, b = sc.nextInt()-1;
			to.get(a).add(b);
			to.get(b).add(a);
		}
		sc.close();

		distList = new ArrayList<>();
		dfs(0, -1);
		int size = distList.size();
		int half = (size+1)/2;
		int fen_node = distList.get(size - half);
		int sun_node = distList.get(size - half - 1);
		
		int fen = cntdfs(fen_node, -1, sun_node);
		int sun = cntdfs(sun_node, -1, fen_node);
		
		System.out.println(fen>sun? "Fennec":"Snuke");
	}
	
	static int cntdfs (int v, int parent, int opp) {
		int res = 1;
		for(int next:to.get(v)) {
			if(next == parent || next == opp) continue;
			res += cntdfs(next, v, opp);
		}
		return res;
	}
	
	static boolean dfs(int v, int parent) {
		
		boolean pathToOpp = false;
		
		if(v == N-1) {
			distList.add(v);
			return true;
		}
		
		for(int next :to.get(v)) {
			if(next == parent)continue;
			pathToOpp = dfs(next, v);
			if(pathToOpp) {
				distList.add(v);
				break;
			}
		}
		return pathToOpp;
	}
}


Measured memory_bytes: 114056
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  for(;;){
    int h;
    cin >> h;
    if(!h) return 0;
    int field[16][8];
    REP(i,16) REP(j,8) field[i][j]=0;
    while(h--)
      REP(i,5) cin >> field[h][i];
    int answer=0;
    bool flag=true;
    while(flag){
      flag=false;
      REP(i,10){
	if(field[i][2]==0) continue;
	int l=2,r=2;
	while(l>0&&field[i][l-1]==field[i][2]) --l;
	while(r<4&&field[i][r+1]==field[i][2]) ++r;
	if(r-l>=2)
	  for(int j=l;j<=r;++j){
	    answer+=field[i][j];
	    field[i][j]=0;
	    flag=true;
	  }
      }
      bool fall=true;
      while(fall){
	fall=false;
	REP(i,10) REP(j,5)
	  if(field[i+1][j]&&!field[i][j]){
	    field[i][j]=field[i+1][j];
	    field[i+1][j]=0;
	    fall=true;
	  }
      }
    }
    cout << answer << endl;
  }
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;

public class AtCoderB
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();

        if (n % 2 == 1)
        {
            Console.WriteLine("No");
            return;
        }

        for (int i = 0; i < n / 2; i++)
        {
            if (!s.Substring(i, 1).Equals(s.Substring(i + n / 2, 1)))
            {
                Console.WriteLine("No");
                return;
            }
        }

        Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 11092
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    a = 0
    for s1 in input():
        a = (a + int(s1)) % 3

    print("Yes" if a == 0 else "No")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 68044
import java.util.Scanner;
public class Main{
    static void PRINT(int x,int y){
        for(int i=0;i<x;i++){
            for(int j=0;j<y;j++){
                if(i==0||i==x-1)System.out.print("#");
                else if(j==0||j==y-1)System.out.print("#");
                else System.out.print(".");
                	
            }
            System.out.println("");
        }
        System.out.println("");
    }


    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0&&W==0)break;
            else PRINT(H,W);
        }
        sc.close();
    }

}



Measured memory_bytes: 32528
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes"; else cout<<"No";
}

Measured memory_bytes: 512
#include <stdio.h>

int main() {
    int a, b;
    while(~scanf("%d%d", &a, &b)) {
        if(a > b) {
            printf("a > b\n");
        } else if (a == b) {
            printf("a == b\n");
        } else {
            printf("a < b\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 2692
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <set>

using namespace std;

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

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef vector<int> Array;
typedef vector<int> LArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

int itiv;
inline int getInt() { return (cin >> itiv, itiv); }
void readAll(Array& vec, int n) { for (int i = 0; i < n; i++) cin >> vec[i]; }
inline bool between(int first, int last, int n) { return first <= n && n <= last; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int d, n;
int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };

// day, cloth
int dp[201][201];
int main(void)
{
	while(cin >> d >> n && n)
	{
		Array t(d), a(n), b(n), c(n);
		readAll(t, d);
		for (int i = 0; i < n; i++)
			cin >> a[i] >> b[i] >> c[i];
		memset(dp, 0, sizeof(dp));

		int ans = 0;
		for (int i = 1; i < d; i++)//日にち
		{
			for (int j = 0; j < n; j++)//今日着る
			{
				if(!between(a[j], b[j], t[i])) continue;

				for (int k = 0; k < n; k++)//昨日着た
				{
					if(!between(a[k], b[k], t[i-1])) continue;

					dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(c[j] - c[k]));
					ans = max(ans, dp[i][j]);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    using namespace std;
    unsigned long H;
    cin >> H;
    vector<unsigned long> dp(H + 10000, numeric_limits<unsigned long>::max() / 5);
    dp[0] = 0;
    unsigned long N;
    cin >> N;
    for(unsigned long i{0}, A, B; i < N; ++i){
        cin >> A >> B;
        for(unsigned long j{0}; j + A < H + 10000; ++j){
            dp[j + A] = min(dp[j + A], dp[j] + B);
        }
    }
    cout << *min_element(dp.begin() + H, dp.end()) << endl;
    return 0;
}

Measured memory_bytes: 384