akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

struct UnionFind {

    vector<int> par;
    vector<int> sizes;

    UnionFind(int N) :
            par(N), sizes(N, 1) {
        for (int i = 0; i < N; i++) par[i] = i;
    }

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

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

        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);

        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int getSize(int x) {
        return sizes[find(x)];
    }

};

struct edge {
    int from;
    int to;
    int cost;
};

bool comp(const edge &e1, const edge &e2) {
    return e1.cost < e2.cost;
}

int main() {

    while (true) {

        int N, M;
        cin >> N >> M;

        if (!(N | M)) break;

        vector<edge> edges;
        for (int i = 0; i < M; i++) {
            int a, b, w;
            cin >> a >> b >> w;
            a--, b--;
            edges.push_back({a, b, w});
            edges.push_back({b, a, w});
        }

        sort(edges.begin(), edges.end(), comp);

        int ans = INT_MAX;
        for (int i = 0; i < edges.size(); i++) {

            UnionFind UF(N);

            int minV = INT_MAX;
            int maxV = INT_MIN;

            for (int j = i; j < edges.size(); j++) {
                if (!UF.same(edges[j].from, edges[j].to)) {
                    UF.unite(edges[j].from, edges[j].to);
                    minV = min(minV, edges[j].cost);
                    maxV = max(maxV, edges[j].cost);
                }
            }

            bool good = true;
            for (int j = 0; j < N; j++)if (!UF.same(0, j)) good = false;

            if (good) {
                ans = min(ans, maxV - minV);
            }
        }


        cout << (ans == INT_MAX ? -1 : ans) << endl;

    }

    return 0;
}














































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

int main(){
  int N, T;
  cin >> N >> T;
  int c, t;
  int Ans=10000; 
  for(int i=0; i<N; i++){
    cin >> c >> t;
    if(t<=T){
      Ans=min(Ans, c);
    }
  }
  if(Ans<10000){
    cout << Ans << endl;
  }
  else{
    cout << "TLE" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    
    int n,i,j,minv,maxv;
	
    scanf("%d",&n);
    
    int r[n];
	
    for(i=0; i<n; i++){ 
        scanf("%d",&r[i]);
        
    }
	
	minv=r[0];
	maxv = r[1]-r[0];
	for(j=1; j<n; j++){
	    (maxv > r[j]-minv) ? (maxv = maxv) : (maxv = r[j]-minv);
	    (minv < r[j]) ? (minv = minv) : (minv = r[j]);
	}
	
	printf("%d\n",maxv);
    
    return 0;
}


Measured memory_bytes: 2600
#include <bits/stdc++.h>
using namespace std;
const int INF=1<<29,MAX=200001;
typedef pair<int,int> P;

int main() {
  int n,x,d[MAX];
  cin >> n >> x;
  for(int i=0; i<MAX; i++) d[i]=(i?INF:0);
  P a[n];
  for(int i=0; i<n; i++) cin >> a[i].first >> a[i].second;
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,0));
  while(!que.empty()) {
    int now=que.top().second,cost=que.top().first;que.pop();
    if(d[now]>cost) continue;
    if(now==x) break;
    for(int i=0; i<n; i++) {
      for(int j=-1; j<=1; j+=2) {
        int next=now+a[i].first*j;
        if(next>=0 && next<MAX && d[next]>d[now]+a[i].second) {
          d[next]=d[now]+a[i].second;
          que.push(P(d[next],next));
        }
      }
    }
  }
  cout << (d[x]<INF?d[x]:-1) << endl;
  return 0;
}



Measured memory_bytes: 5568
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

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

	int g = GCD(a, b);

	if(c % g == 0) cout << "YES" << endl;
	else cout << "NO" << endl;

	rtn 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1e18
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b,ll m){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a) % m;  a = (a * a) % m;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e5 + 7;
ll i,n,a,b,c,m;
ll p[N], sz[N];
ll find(ll v)
{
    return v == p[v] ? v : p[v] = find(p[v]);
}
void merge(ll a,ll b)
{
    a = find(a); b = find(b);
    if(a != b){
        if(sz[b] > sz[a]) swap(a, b);
        sz[a] += sz[b];
        p[b] = a;
    }
}
set<ll> s;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,1,n + 1){
        sz[i] = 1;
        p[i] = i;
    }
    rep(i,1,m + 1){
        cin>>a>>b>>c;
        merge(a, b);
    }
    rep(i,1,n + 1) s.insert(find(i));
    cout<<s.size();
    return 0;
}

Measured memory_bytes: 6528
while 1:
  n, x = map(int,input().split())
  if n == x == 0:
    exit()
  ans = 0
  for i in range(1,n-1):
    for j in range(i+1,n):
      for k in range(j+1,n+1):
        if i+j+k == x:
          ans += 1
  print(ans)


Measured memory_bytes: 5592
A,B,K = map(int,input().split())
yakusu_a = []
yakusu_b = []

for i in range(1,A+1):
    if(A%i == 0):
        yakusu_a.append(i)

for i in range(1,B+1):
    if(B%i == 0):
        yakusu_b.append(i)

koyakusu = list(set(yakusu_a) & set(yakusu_b))
koyakusu_sort = sorted(koyakusu,reverse=True)
print(koyakusu_sort[K-1])
#print(koyakusu_sort)
#print(yakusu_a)
#print(yakusu_b)


Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std;
int main(){
  long long int n,k,arr[n],sum=0;
  cin>>n>>k;
  for(long long int i=0;i<n;i++){
  cin>>arr[i];
  }
  sort(arr,arr+n);
  
  
  
  for(long long int i=0;i<n-k;i++){
  sum+=arr[i];
  
  }
  cout<<sum;
  
  
  
  
  
 return 0; 
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
void SRAND(){auto duration = std::chrono::system_clock::now().time_since_epoch();auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();srand(millis);}

ll n;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	cout<<n*n*n<<"\n";
	return 0;
}



Measured memory_bytes: 256
from math import gcd

a, b, k = list(map(int, input().split()))
g = gcd(a, b)
l = []
i = 1
while i * i <= g:
    if g % i == 0:
        l.append(i)
        if i != g // i:
            l.append(g // i)
    i += 1
l.sort()
print(l[-k])


Measured memory_bytes: 9068
N, K = map(int, input().split())
a_b = []
for i in range(N):
    a, b = map(int, input().split())
    a_b.append((a, b))

a_b.sort(key=lambda x: x[0])
tmp = 0
for a, b in a_b:
    tmp += b
    if tmp >= K:
        print(a)
        break

Measured memory_bytes: 18192
s = input()
a = int(s[:2])
b = int(s[2:])
if 0 < a < 13:
    if 0 < b < 13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 0 < b < 13:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << endl;}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
string ans = "";
char v[5];
void f(int cnt, int num, string s) {
	if (cnt == 4) {
		if (num == 7) {
			ans = s;
		}
		return;
	}
	f(cnt + 1, num + (v[cnt] - '0'), s + '+' + v[cnt]);
	f(cnt + 1, num - (v[cnt] - '0'), s + '-' + v[cnt]);
}
int main() {
	var(string, s);
	rep(i, 0, 4) v[i] = s[i];
	f(1, (v[0] - '0'), to_string(v[0] - '0'));
	print(ans + "=7");
	return 0;
}


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

int main() {
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
    cout << "Yes" << endl;
    
  }
  else{
    cout << "No" << endl;
  }

  
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, b, a) for (int i = (a - 1); i >= (b); i--)
#define ALL(vec) (vec).begin(), (vec).end()
int get_int() {
  int tmp;
  cin >> tmp;
  return tmp;
}
int main() {
  while (true) {
    const int n = get_int();
    if (n == 0) return 0;
    auto dp = vector<vector<int>>(n + 10, vector<int>(5 * n + 50, -1));
    dp[0][0] = 0;
    REP(ni, n) {
      auto p = get_int();
      int rest = p % 1000;
      int sheet = p / 1000;
      if (rest == 0) {
        FORR(i, 0, n + 1) FORR(j, 0, 5 * n + 1) {
          // 小銭と1000円で買う
          if (i - 1 >= 0 and j - sheet + 1 >= 0 and
              dp[i - 1][j - sheet + 1] >= 0) {
            int buy = dp[i - 1][j - sheet + 1] - 500;
            dp[i][j] = max(dp[i][j], buy);
          }
        }
      } else if (rest > 500) {
        FORR(i, 0, n + 1) FORR(j, 0, 5 * n + 1) {
          // 1000円で買う (小銭のみ得る)
          if (j - 1 - sheet >= 0 and dp[i][j - 1 - sheet] >= 0) {
            int buy = dp[i][j - 1 - sheet] + 1000 - rest;
            dp[i][j] = max(dp[i][j], buy);
          }
          // 小銭と1000円で買う
          if (i - 1 >= 0 and j - sheet >= 0 and dp[i - 1][j - sheet] >= 0) {
            int buy = dp[i - 1][j - sheet] - (rest - 500);
            dp[i][j] = max(dp[i][j], buy);
          }
        }
      } else {
        // 買うに決まっている,ついでにuse_get円得ちゃう
        int use_get = 500 - rest;
        FORR(i, 1, n + 1) FORR(j, sheet, 5 * n + 1) {
          if (dp[i - 1][j - sheet] < 0) continue;
          dp[i][j] = max(dp[i][j], dp[i - 1][j - sheet] + use_get);
        }
      }
    }
    [&]() {
      // C++クソでは
      FORR(i, 0, n + 1) {
        int min_val = 10000000;
        bool is_ok = false;
        FOR(j, 0, 5 * n + 1) {
          if (dp[i][j] == -1) continue;
          auto val = -(dp[i][j] - (500 * i) - (1000 * j));
          if (min_val > val) {
            min_val = val;
            is_ok = true;
          }
        }
        if (is_ok) {
          cout << i << " " << min_val << endl;
          return;
        }
      }
    }();
  }
}


Measured memory_bytes: 3260
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram
{
    public class Program
    {	
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            bool ok = false;
            
            int a = 4;
            while(a <= n)
            {
                if((n-a)%7 == 0) ok = true;
                a += 4;
            }
            a = 7;
            while(a <= n)
            {
                if((n-a)%4 == 0) ok = true;
                a += 7;
            }
            
            if(ok) Console.WriteLine("Yes");
            else Console.WriteLine("No");
      
        }
    }
}

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

void BubbleSort(char C[36][2], int N){
	for(int i = 1; i < N; i ++){
		for(int j = N - 1; j >= i; j --){
			if(C[j][1] < C[j - 1][1]){
				char temp[2];
				temp[0] = C[j][0];
				temp[1] = C[j][1];
				C[j][0] = C[j- 1][0];
				C[j][1] = C[j- 1][1];
				C[j - 1][0] = temp[0];
				C[j - 1][1] = temp[1];
			}
		}
	}
}

void SelectionSort(char C[36][2], int N){
	for(int i = 0; i < N; i ++){
		int min = i;
		for(int j = i; j < N; j ++){
			if(C[j][1] < C[min][1]){
				min = j;
			}
		}
		char temp[2];
		temp[0] = C[i][0];
		temp[1] = C[i][1];
		C[i][0] = C[min][0];
		C[i][1] = C[min][1];
		C[min][0] = temp[0];
		C[min][1] = temp[1];
	}
}

int  main(void){
	char C[36][2], C2[36][2];
	int n;
	
	cin >> n;
	
	for(int i = 0; i < n; i ++) cin >> C[i];
	for(int i = 0; i < n; i ++){
		C2[i][0] = C[i][0];
		C2[i][1] = C[i][1];
	}
	
	BubbleSort(C, n);
	for(int i = 0; i < n; i ++){
		cout << C[i][0] << C[i][1];
		if(i != n - 1)cout << " ";
	}
	cout << endl << "Stable" << endl;
	
	SelectionSort(C2, n);
	for(int i = 0; i < n; i ++){
		cout << C2[i][0] << C2[i][1];
		if(i != n - 1)cout << " ";
	}
	for(int i = 0; i < n; i ++){
		if(C[i][0] != C2[i][0]){
			cout << endl << "Not stable" << endl;
			return 0;
		}
	}
	cout << endl << "Stable" << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;

signed main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(auto& x : s)
        cin >> x;
    vector<vector<int>> dp(h, vector<int>(w, 0));
    dp[0][0] = 1;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(i != h - 1 && s[i + 1][j] != '#')
                dp[i + 1][j] = (dp[i][j] + dp[i + 1][j]) % MOD;
            if(j != w - 1 && s[i][j + 1] != '#')
                dp[i][j + 1] = (dp[i][j] + dp[i][j + 1]) % MOD;
        }
    }
    cout << dp.back().back() << endl;
}


Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main(){
 
    int a[4];
    int b[4];
    while(cin>>a[0]>>a[1]>>a[2]>>a[3]){
        for(int i = 0; i < 4; i++)
            cin>>b[i];
         
        int hit=0;
        int blow=0;
        for(int i = 0; i < 4; i++){
            if(a[i]==b[i])
                hit++;
            else{
                for(int j = 0; j < 4; j++){
                    if(a[i]==b[j]){
                        blow++;
                    }
                }
            }
        }
        cout<<hit<<" "<<blow<<endl;
    }
 
    return 0;
}

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

char c;

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> c;
        if (c == 'A') cout << 'T';
        if (c == 'T') cout << 'A';
        if (c == 'C') cout << 'G';
        if (c == 'G') cout << 'C';
return 0;
}


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

int main() {
  
  string str;
  
  cin >> str;
  
  if(str<="2019/04/30") {
    
    cout << "Heisei" << endl;
    
  } else {
    
    cout << "TBD" << endl;
    
  }
  
  return 0;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i[11111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0;
  string s;
  cin >>a>>b>>c>>d;
  if(abs(c-a)<=d||(abs(b-a)<=d&&abs(b-c)<=d)) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, m;
string s, t;

signed main() {
	cin >> n >> m >> s >> t;
	int lc = lcm(n,m), gc = gcd(n,m);
	rep(i,gc) if (s[n/gc*i]!=t[m/gc*i]) return cout << -1 << endl, 0;
	cout << lc << endl;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		Combination c = new Combination(scan.nextInt());
		c.loadNumbers(scan);
		c.fullComb();
		Iterator<Integer> iter;
		iter = c.getIter();

		int queryNum = scan.nextInt();
		q: for(int i=0 ;i<queryNum; i++){
			iter = c.getIter();
		int tmp = scan.nextInt();
		while(iter.hasNext()){
			if(tmp == iter.next()){
				System.out.println("yes");
				continue q;
			}
		}
			System.out.println("no");
		}
		//iter = c.getIter();
	//	while(iter.hasNext())
		//	System.out.println(iter.next());
	}
}


class Combination {
    int[] c;
    int n;
    int r;
	ArrayList<Integer> numbers = new ArrayList<Integer>();
	HashSet<Integer> sum = new HashSet<Integer>();
    public Combination(int n){
			this.n = n;
    }
	public void loadNumbers(Scanner scan){
	for(int i=0; i <this.n; i++)
		numbers.add(scan.nextInt());
	}

	public void comb(int r){
		this.r = r;
		c = new int[r];
		for(int i=0; i<n-(r-1);i++){
		//	System.out.println("loop:" + i);
			c[0] = numbers.get(i);
			combine(1,i);
		}
	}
	public void fullComb(){
		for(int i=1 ;i<=n;i++){
	//	System.out.println("r : " + i);
			c=new int[i];
			r=i;
			combine(0,0);
		}
	}
    public void combine( int m ,int index){
        if ( m == r ) {
			int tmp = 0;
          for ( int i=0; i<r; i++ ){
           //  System.out.print(" " + c[i]);
          	tmp += c[i];
        	}
        //	System.out.println("");
        	sum.add(tmp);
        }else{
        //  for ( int i = index + 1; i<n-(r-m-1); i++ ){
        for ( int i = index; i<n-(r-m-1); i++ ){
             c[m] = numbers.get(i);
             combine(m+1,i+1);
        }
        }
	}
	Iterator<Integer> getIter(){
			return sum.iterator();
	}
    }

Measured memory_bytes: 38864
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

int main(void) {
  int n;
  cin >> n;
  vector<double> x(n);
  vector<string> u(n);
  rep(i, n) cin >> x[i] >> u[i];
  double sum = 0.0;
  rep(i, n) {
    sum += (u[i] == "JPY" ? x[i] : x[i] * 380000);
  }
  printf("%.6f\n", sum);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
A = tuple(map(int, input().split()))
ma = min(A)
while True:
    ra = set([a%ma for a in A if a%ma > 0])
    if len(ra) == 0:
        print(ma)
        break
    minra = min(ra)
    if ma == minra:
        print(ma)
        break
    ma = minra


Measured memory_bytes: 91524
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

//-------------------------------------------------------------------
#define P 1000000007
#define N_MAX 2000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
    return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
    fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
    for(int i = 2; i <= N_MAX; i++){
        fac[i] = (fac[i-1]*i)%P;
        inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
        finv[i] = (finv[i-1]*inv[i])%P;
    }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  ll ans = 0;
  init();
  std::vector<ll> a(n);
  vvl d = vv(n, 62, 0, ll);
  for(int i=0;i<n;i++) std::cin >> a[i];
  for(int i=0;i<n;i++){
    ll tmp = a[i];
    ll c = 0;
    while(tmp>0){
      if(tmp%2==1) d[i][c] = 1;
      c++,tmp/=2;
    }
    //for(int j=61;j>=0;j--) std::cout << d[i][j];
    //std::cout << '\n';
  }
  std::vector<ll> rui(63, 1);
  for(int i=1;i<62;i++) rui[i] = (rui[i-1] * 2)%P;
  for(int i=0;i<62;i++){
    ll c = 0;
    for(int j=0;j<n;j++) if(d[j][i]==1) c++;
    ans = (ans + ((rui[i]*(((n-c)*c)%P))%P))%P;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 206464
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, a, b; cin >> n >> a >> b;
	int x, y, z; x = y = z = 0;
	while (n--)
	{
		int p; cin >> p;
		if (p <= a)++x;
		else if (b < p)++z;
		else ++y;
	}
	cout << min({ x,y,z }) << endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n, p, q = LI()
    c = [I() for _ in range(n)]
    s = sum(c)
    a = sorted([[c[i]+p*i, i] for i in range(n)])
    r = s
    for i in range(n):
        s -= c[a[i][1]] + p * a[i][1]
        t = s + p*i*(i+1) + p*q*(i+1)
        if t > r:
            r = t

    return r


print(main())




Measured memory_bytes: 111924
n,m=map(int,input().split())
count=0                   
total_list = []          
for i in range(1,n+1):
           l_i=list(map(str,input().split()))
           l_i_ = l_i[1:]
           for j in l_i_:
                       total_list.append(j)
s=list(set(total_list))
for a in range(len(s)):
            if total_list.count(s[a]) ==n:
                        count+=1
print(count)                        
                        




Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a * b % 2 == 0){
			System.out.println("Even");
		}else{
			System.out.println("Odd");
		}
	}
}


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

int main() {
 const long long mod = 998244353;
 int a, b, c, d; cin >> a >> b >> c >> d;

 vector<vector<long long>> dp(c + 1, vector<long long>(d + 1, 0));
 dp[a][b] = 1;


 for (int x = a; x < c + 1; x++) {
  for (int y = b; y < d + 1; y++) {
   if (x != a or y != b) {
    dp[x][y] = dp[x - 1][y] * y + dp[x][y - 1] * x - dp[x - 1][y - 1] * (x - 1) * (y - 1);
    dp[x][y] = dp[x][y]%mod;
    dp[x][y]+=2*mod;
   }
  }
 }
 dp[c][d]+=mod;
  dp[c][d]%=mod;
 cout << dp[c][d]<< endl;
}


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


def solve(N: int):
    if N % 2 == 0:
        N = N // 2
        answer = 0
        div = 5
        while N >= div:
            answer += N // div
            div *= 5
        return answer

    else:
        return 0

    return answer


def main():
    N = int(input())
    answer = solve(N)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9056
n = int(raw_input())

def prime_div(n):
    arr = []
    f = 1
    while f:
        state = 0
        for i in range(2,int(n**2)+1):
            if n % i == 0:
                arr.append(i)
                n /= i
                state = 1
                break
        if state == 0:
            f = 0
    return arr
arr = []
for i in range(n):
    arr += prime_div(i+1)
arr.sort()
num_set = set(arr)
# print num_set
counter = []
counter_num = [0,0,0,0,0]
num_lst = [2, 4, 14, 24, 74]
for num in num_set:
    count = arr.count(num)
    counter.append(count)
    for i in range(5):
        if count >= num_lst[i]:
            counter_num[i]+=1

# print counter_num
ans = 0
# 74
ans += counter_num[4]
# 24 2
if counter_num[3] > 0:
    ans += counter_num[3]*(counter_num[0]-counter_num[3])+counter_num[3]*(counter_num[3]-1)
# 14 4
if counter_num[2] > 0:
    ans += counter_num[2]*(counter_num[1]-counter_num[2])+counter_num[2]*(counter_num[2]-1)
if counter_num[1] > 1:
    ans += counter_num[1]*(counter_num[1]-1)/2*(counter_num[0]-counter_num[1])
if counter_num[1] > 2:
    ans += counter_num[1]*(counter_num[1]-1)/2*(counter_num[1]-2)
print ans


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define sll set<ll>
#define ins insert
#define rep(i,n) for(int i=0;i<n;i++)
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define gp " ";
#define MAX 9999999
#define MOD 1000000007
#define mnn(v2) *min_element(v2.begin(),v2.end());
#define mxx(v2) *max_element(v2.begin(),v2.end());
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t,i,j,n,c=0,d=0,k;
    cin>>n;
   // while(n<5)
    {
             c=n/500;
             k=n%500;
             d=k/5;
    }
    cout<<c*1000+d*5;
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

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

    int t = (c+b-1)/b;
    int ao= (a+d-1)/d;

    //cout <<fixed<<setprecision(16)<< << endl;

    if(t <= ao)cout << "Yes" <<endl;
    else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3624
import java.io.IOException;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        String[] tmp = scanner.nextLine().split(" ");
        scanner.close();
        Integer side1 = Integer.valueOf(tmp[0]);
        Integer side2 = Integer.valueOf(tmp[1]);
        Double angle1 = Math.toRadians(Double.valueOf(tmp[2]));

        Double s = (side1 * side2 * Math.sin(angle1)) / 2;
        Double l = (side1 + side2)
                + Math.sqrt((side1 * side1) + (side2 * side2)
                        - (2 * side1 * side2 * Math.cos(angle1)));
        Double h = side2 * Math.sin(angle1);

        System.out.println(s + "\n" + l + "\n" + h);
    }

}

Measured memory_bytes: 17148
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n)-1; i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int n;  cin >> n;
  vector<pair<int, int>> vec(n);
  REP(i, n){
    int a, b; cin >> a >> b;
    vec[i] = make_pair(b, a);
  }
  sort(ALL(vec));
  int time = 0;
  REP(i, n){
    time += vec[i].second;
    if(time > vec[i].first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1792
list=input().split(" ")
h=int(list[0])
w=int(list[1])
n=int(list[2])

list=input().split(" ")
y=int(list[0])
x=int(list[1])

#l,r,u,d
ato=[x, w-x+1, y, h-y+1]
countt=[0,0,0,0]
counta=[0,0,0,0]
counta2=[0,0,0,0] #dokudan
kano=[0,0,0,0]
#print(ato)

taka=input()
aoki=input()

switch=0

for i in range(n):
    if i>0:
        if aoki[i-1]=='L':
            if counta[0]-countt[1]<x-1:
                counta[0]+=1
        elif aoki[i-1]=='R':
            if counta[1]-countt[0]<w-x:
                counta[1]+=1
        elif aoki[i-1]=='U':
            if counta[2]-countt[3]<y-1:
                counta[2]+=1
        elif aoki[i-1]=='D':
            if counta[3]-countt[2]<h-y:
                counta[3]+=1
    
    if taka[i]=='L':
        countt[0]+=1
    elif taka[i]=='R':
        countt[1]+=1
    elif taka[i]=='U':
        countt[2]+=1
    elif taka[i]=='D':
        countt[3]+=1
    
    
    countn=[countt[0]-counta[1], countt[1]-counta[0], countt[2]-counta[3], countt[3]-counta[2]]
    
    
    #print(countn)
    for j in range(4):
        if countn[j]>=ato[j]:
            switch=1

if switch==1:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3896
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y % MOD;};


int main(){
  ll K; cin >> K;
  vector<ll> A(K); rep(i, K) cin >> A[i];

  ll m = 2, M = 2;
  revrep(i, K){
    if((M / A[i]) <= ((m-1) / A[i])){
      cout << -1 << endl;
      return 0;
    }
    if(m % A[i] != 0) m = m/A[i]*A[i]+A[i];
    if(M % A[i] != 0) M = M/A[i]*A[i]+A[i]-1;
    else M += A[i] - 1;
  }
  cout << m << " " << M << endl;
}


Measured memory_bytes: 1024
import itertools
x = []

for i in range(5):
    x.append(int(input()))
order = list(itertools.permutations(x))
res = 10**17
for l in order:
    t = 0
    for item in l:
        if t%10 == 0:
            t+=item
        else:
            t = (t//10+1)*10
            t += item
    res = min(res,t)
print(res)


Measured memory_bytes: 3060
def start_process(a):
    dict = ['A', 'G', 'T', 'C']

    ans = 0
    count = 0
    for char in list(a):
        if char in dict:
            count += 1
        else:
            if ans < count:
                ans = count
            count = 0
    if ans < count:
        ans = count
    print(ans)


def main():
    a = input()
    start_process(a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
def solve(string):
    if int(string[0]) == int(string[1]) == int(string[2]):
        return string
    elif int(string[0] * 3) > int(string):
        return string[0] * 3
    else:
        return str(int(string[0]) + 1) * 3


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 38256
const base_n = (n,d)=> (n/d >= 1) ? base_n( Math.floor(n/d),d ) + (n%d).toString() : ( (n%d) || '1').toString();function Main(input) {
  input = input.trim().split(' ').map(data=>parseInt(data));
  console.log(base_n(input[0],input[1]).length)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 20044
import sys

import bisect

# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd

import itertools

# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a1 = list(map(int, readline().split()))
    a2 = [a1[i] - (i + 1) for i in range(n)]

    a2.sort()

    b = a2[(n - 1) // 2]
    a3 = [abs(a2[i] - b) for i in range(n)]

    print(sum(a3))


if __name__ == '__main__':
    main()


Measured memory_bytes: 91860
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N=200005;
int n,x,y;
struct node{
    int u,v,nxt;
}B[N*2],R[N*2];
int hB[N];
int hR[N];
int Bcnt,Rcnt;
int eu[N],ev[N];
void add_B(int u,int v){
    Bcnt++;
    B[Bcnt].u=u;
    B[Bcnt].v=v;
    B[Bcnt].nxt=hB[u];
    hB[u]=Bcnt;
}
void add_R(int u,int v){
    Rcnt++;
    R[Rcnt].u=u;
    R[Rcnt].v=v;
    R[Rcnt].nxt=hR[u];
    hR[u]=Rcnt;
}
int deep[N],fa[N];
int dfn[N],efn[N],tot;
void dfs(int u,int dep){
    deep[u]=dep;
    dfn[u]=++tot;
    for(int i=hB[u];i;i=B[i].nxt){
        int v=B[i].v;
        if(v==fa[u])
            continue;
        fa[v]=u;
        dfs(v,dep+1);
    }
    efn[u]=++tot;
}
bool check(int x,int y){//是否是长边
    if(dfn[x]>dfn[y])
        swap(x,y);
    if(dfn[x]<=dfn[y]&&efn[y]<=efn[x])
        return deep[y]-deep[x]>2;
    return fa[x]!=fa[y];
}
bool Longedge[N];
queue<int>q;
bool vis[N];
int dist[N];
void bfs(){
    while(!q.empty())
        q.pop();
    vis[x]=1;
    q.push(x);
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(int i=hR[u];i;i=R[i].nxt){
            int v=R[i].v;
            if(!vis[v]){
                dist[v]=dist[u]+1;
                if(dist[v]<deep[v]){
                    vis[v]=1;
                    q.push(v);
                }
            }
        }
    }
}
int main()
{
    //freopen("captain.in","r",stdin);
    //freopen("captain.out","w",stdout);
    memset(hB,0,sizeof hB);
    memset(hR,0,sizeof hR);
    Bcnt=Rcnt=0;
    memset(fa,0,sizeof fa);
    tot=0;
    memset(Longedge,0,sizeof Longedge);
    memset(vis,0,sizeof vis);
    memset(dist,0,sizeof dist);
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<n;i++){
        scanf("%d%d",&eu[i],&ev[i]);
    }
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add_B(u,v);
        add_B(v,u);
    }
    dfs(y,0);
    for(int i=1;i<n;i++){
        int u=eu[i],v=ev[i];
        if(check(u,v))
            Longedge[u]=Longedge[v]=1;
        else
            add_R(u,v),add_R(v,u);
    }
    bfs();
    int ans=0;
    for(int i=1;i<=n;i++)
        if(vis[i]&&Longedge[i]){
            puts("-1");
            return 0;
        }
        else
            if(vis[i])
                ans=max(ans,deep[i]*2);
    printf("%d\n",ans);
}


Measured memory_bytes: 25472
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

using pt = pair<long long, long long>;

const long long MOD = 1000000007;

long long modpow(long long a, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) {
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    n >>= 1;
  }
  return ans;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long nz = 0;
  vector<pt> np, pp;
  for (long long i = 0; i < N; i++) {
    long long Ai, Bi;
    scanf("%lld%lld", &Ai, &Bi);
    if (Ai == 0 && Bi == 0) {
      nz++;
    } else {
      if (Ai < 0) {
        Ai = -Ai;
        Bi = -Bi;
      } else if (Ai == 0) {
        Bi = 1;
      }
      if (Bi <= 0) {
        np.emplace_back(Ai, Bi);
      } else {
        pp.emplace_back(Ai, Bi);
      }
    }
  }

  auto comp = [](const pt &a, const pt &b) {
    // a.y / a.x < b.y / b.x
    return (__int128_t)a.second * b.first < (__int128_t)b.second * a.first;
  };
  sort(np.begin(), np.end(), comp);
  sort(pp.begin(), pp.end(), comp);

  vector<long long> npg, ppg;
  {
    size_t nnp = np.size();
    size_t stt = 0, end = 0;
    if (nnp) {
      npg.emplace_back(0);
    }
    while (end < nnp) {
      // np[stt].y / np[stt].x != np[end].y / np[end].x
      if ((__int128_t)np[stt].second * np[end].first != (__int128_t)np[end].second * np[stt].first) {
        npg.emplace_back(end);
        stt = end;
      }
      end++;
    }
  }
  {
    size_t npp = pp.size();
    size_t stt = 0, end = 0;
    if (npp) {
      ppg.emplace_back(0);
    }
    while (end < npp) {
      // pp[stt].y / pp[stt].x != pp[end].y / pp[end].x
      if ((__int128_t)pp[stt].second * pp[end].first != (__int128_t)pp[end].second * pp[stt].first) {
        ppg.emplace_back(end);
        stt = end;
      }
      end++;
    }
  }

  long long ans = 1;
  size_t nidx = 0, pidx = 0;
  size_t nnpg = npg.size(), nppg = ppg.size();
  while (nidx < nnpg && pidx < nppg) {
    pt nidxp = np[npg[nidx]], pidxp = pp[ppg[pidx]];
    __int128_t v = (__int128_t)nidxp.first * pidxp.first + (__int128_t)nidxp.second * pidxp.second;
    if (v < 0) {
      long long apn = (nidx == nnpg - 1 ? np.size() : npg[nidx + 1]) - npg[nidx];
      ans *= modpow(2, apn);
      ans %= MOD;
      nidx++;
    } else if (v > 0) {
      long long apn = (pidx == nppg - 1 ? pp.size() : ppg[pidx + 1]) - ppg[pidx];
      ans *= modpow(2, apn);
      ans %= MOD;
      pidx++;
    } else {
      long long apn = (nidx == nnpg - 1 ? np.size() : npg[nidx + 1]) - npg[nidx];
      long long bpn = (pidx == nppg - 1 ? pp.size() : ppg[pidx + 1]) - ppg[pidx];
      ans *= (modpow(2, apn) + modpow(2, bpn) - 1) % MOD;
      ans %= MOD;
      pidx++;
      nidx++;
    }
  }
  while (nidx < nnpg) {
    long long apn = (nidx == nnpg - 1 ? np.size() : npg[nidx + 1]) - npg[nidx];
    ans *= modpow(2, apn);
    ans %= MOD;
    nidx++;
  }
  while (pidx < nppg) {
    long long apn = (pidx == nppg - 1 ? pp.size() : ppg[pidx + 1]) - ppg[pidx];
    ans *= modpow(2, apn);
    ans %= MOD;
    pidx++;
  }
  ans -= 1;
  ans += nz;
  ans = (ans % MOD + MOD) % MOD;
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 8756
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  int p = min(k, a);
  k -= a;
  int z = max(ll(0), min(k, b));
  k -= b;
  int m = max(ll(0), min(k, c));
  cout << p - m << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

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

    vector<int> h(n);
    rep (i, n)
        cin >> h[i];

    sort(h.begin(), h.end());
    int ans = h[k - 1] - h[0];
    for (int i = k; i < n; i++)
        ans = min(h[i] - h[i - (k - 1)], ans);

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

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> data(N);
  int count = 0;
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  int subcount = 1;
  for (int i = 0; i < N - 1; i++) {
    if(data.at(i) == data.at(i + 1)) subcount++;
    else {
      if(subcount % 2 != 0) count++;
      subcount = 1;
    }
  }
  if(subcount % 2 != 0) count++;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 768