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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 1000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll N;
Graph G(100010);
vector<ll> cnt(100010);
vector<tuple<ll,ll,ll>> ans;
ll table[100010];
bool done[100010];
queue<pair<ll,ll>> Q;

/*void bfs(ll s){
    table[s] = 0;
    Q.push(s);
    while(Q.size()){
        ll x = Q.front();
        ll n = G[x].size();
        Q.pop();
        for(int i = 0;i < n;i++){
            ll y = G[x][i];
            if(table[y] == INF){
                table[y] = table[x] + 1;
                Q.push(y);
            }
        }
    }
    return;
}*/


void dfs(ll s){
    Q.push(make_pair(s,0));
    while(Q.size()){
        int x = Q.front().first;
        int c = Q.front().second;
        int n = G[x].size();
        Q.pop();
        int cnt = 1;
        for(int i = 0;i < n;i++){
            int y = G[x][i];
            if(cnt == c){
                cnt++;
            }
            ans.push_back(make_tuple(x,y,cnt));
            Q.push(make_pair(y,cnt));
            cnt++;
        }
    }
}

int main(){
   cin >> N;
   vector<tuple<ll,ll,ll>> E;
   for(int i = 0;i < N-1;i++){
       ll a,b;cin >> a >> b;
       a--;b--;
       E.push_back(make_tuple(a,b,i));
       G[a].push_back(b);
       cnt[a]++;cnt[b]++;
   }
   ll s = 0;
   ll v = 0;
   for(int i = 0;i < N;i++){
       if(s < cnt[i]){
           s = cnt[i];
           v = i;
       }
   }
   sort(cnt.begin(),cnt.end());
   reverse(cnt.begin(),cnt.end());
   ll K = cnt[0];
   dfs(0);
   sort(E.begin(),E.end());
   sort(ans.begin(),ans.end());

   vector<pair<ll,ll>> A(N-1);
   for(int i = 0;i < N-1;i++){
       A[i].first = get<2>(E[i]);
       A[i].second = get<2>(ans[i]);
   }
   sort(A.begin(),A.end());
   cout << K << endl;
   for(int i = 0;i < N-1;i++){
       cout << A[i].second<< endl;
   }
}


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

void Main() {
    // input
    int X, N;
    cin >> X >> N;
    int nums[100+2];
    for (int i = 0; i <= 101; i++) {
        nums[i] = 1;
    }
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        nums[p] = 0;
    }

    // translate
    int ans = 2000;
    int diff = 1000;
    for (int i = 0; i <= 101; i++) {
        if (nums[i] == 1) {
            if (abs(X - i) < diff) {
                diff = abs(X - i);
                ans = i;
            }
        }
    }

    cout << ans << endl;


    // output

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i,m){
        cin >> a[i];
        n -= a[i];
    }
    cout << max(-1,n) << endl;
}

Measured memory_bytes: 3648
n,k=map(int,input().split())
okashi=[0]*n
for i in range(k):
    d=int(input())
    a=list(map(int,input().split()))
    for x in a:
        okashi[x-1]=okashi[x-1]+1
res=0
for x in okashi:
    if x==0:
        res=res+1
print(res)


Measured memory_bytes: 9072
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;


void solve() {
  string s;
  cin >> s;
  ll t = 0;
  for (auto c : s) {
    t += c - '0';
    t %= 9;
  }
  if (t == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

int main() {
  //ll T;
  //cin >> T;
  //rep(_,T)
    solve();
  return 0;
}


Measured memory_bytes: 3736
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
#define fi first
#define se second
map<int,int> mp;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c*d/gcd(c,d);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
int n;
cin>>n;
int m=n*3;
vector<int> a(m);
for(int i=0;i<m;i++){
cin>>a.at(i);
}
sort(a.begin(),a.end(),greater<int>());
ll ans=0;
int cnt=0;
for(int i=0;i<m;i++){
    if(i%2==0)continue;
    else{
        ans+=a.at(i);
        cnt++;
    }
    if(cnt==n)break;
}
cout<<ans<<endl;
}


Measured memory_bytes: 1408
/*
https://atcoder.jp/contests/dp/tasks/dp_c
*/

#include <iostream>

using namespace std;

int dp[100000][3];

int max1(int a,int b,int c){
	return max(a,max(b,c));
}

void happy(int** arr, int N){
	
	if(N == 0){
		for(int j=0;j<3;j++)
			dp[N][j] = arr[N][j];
		return;
	}

	if(dp[N-1][0] == -1){
		happy(arr,N-1);
	}
	
	for(int j=0;j<3;j++)
		dp[N][j] = arr[N][j] + max(dp[N-1][(j+1)%3],dp[N-1][(j+2)%3]);
}


int main(){

	int N;
	cin >> N;
	int** arr = new int*[N];

	for(int i=0;i<N;i++)
		arr[i] = new int[3];

	for(int i=0;i<N;i++){
		for(int j=0;j<3;j++){
			cin >> arr[i][j];
			dp[i][j] = -1;
		}
	}
	
	happy(arr, N-1);

	cout << max1(dp[N-1][0],dp[N-1][1],dp[N-1][2]) << endl;


	return 0;
}

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

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(NULL);
#define endl            "\n"
#define NUM             100005
typedef long long ll;

int main()
{
    FastRead

    ll n,x;
    vector<ll>v;

    cin>>n;

    for(ll i=0;i<n;i++)
    {
        cin>>x;
        if(x%2==0)
            v.push_back(x);
    }

    for(ll i=0;i<v.size();i++)
    {
        if(v[i]%3!=0 and v[i]%5!=0)
        {
            cout<<"DENIED";
            return 0;
        }
    }

    cout<<"APPROVED";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    long long int inputN, inputK, answer = 0;
    scanf("%lld%lld", &inputN, &inputK);
    answer = inputN % inputK;
    if (answer > inputK - answer)
    {
        answer = inputK - answer;
    }
    printf("%lld", answer);

    return 0;
}

Measured memory_bytes: 128
/*  ex3_4
    Graku   */
#include <stdio.h>
#include <math.h>

int main(void) {
    int n; //declaration
    scanf("%d", &n);

    int flag = 0; //if exist i, j in {x in N | 1 <= x <= 9} s.t. n == i * j, flag == 1, else flag == 0
    for (int i = 1; i <= 9; ++i) { //1 <= i <= 9
        if (flag) { //if already find (i, j) s.t. (i, j) s.t. n == i * j, break
            break;
        }
        for (int j = i; j <= 9; ++j) { //i <= j <= 9, dont have to check (i, j) s.t. i > j
            if (n == i * j) { //if find (i, j) s.t. n == i * j, flag = 1
                flag = 1;
                break;
            }
        }
    }

    if (flag) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define PrintArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;
#define PrintPairs(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i].fi <<"," << cont[__i].se<<")";} cout<<endl;
#define Print(v) cout<<v<<endl;
#define PDBG() cout<<"Line:"<<__LINE__<<endl;
#define PrintArray2D(cont, fh, th, fw, tw) for(int __i=fh;__i<th;++__i){for(int __j=fw;__j<tw;++__j) {cout<<cont[__i][__j]<<" ";} cout<<endl;}cout<<endl;
#define Resize2D(cont,H,W,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W,V);
#define Resize3D(cont,H,W,D,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W);for(int i=0;i<H;++i)for(int j=0;j<W;++j)cont[i][j].resize(D,V);
/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 * priority_queue<int,vector<int>, greater<int>> Q;
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
/*
struct PairComp{
    int operator()(P l, P r) const {
        return l.fi==r.fi?l.se<r.se:l.fi<r.fi;
    }
};*/
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
ll DP[3010][3010];
ll mod=998244353;
int main() {
    cout.precision(15);
    cout << fixed;
    ll A,B,C,D;
    cin >>A >>B>>C>>D;
    memset(DP,0,sizeof(DP));
    DP[A][B]=1;
    for(ll i=A;i<=C;++i) {
        for(ll j=B;j<=D;++j) {
            if (i==A&&j==B)continue;
            DP[i][j]=MO(DP[i-1][j]*j);
            DP[i][j]+=MO(DP[i][j-1]*i);
            DP[i][j]=MO(DP[i][j]);
            DP[i][j]-=MO((i-1)*(j-1)*DP[i-1][j-1]);
            DP[i][j]=MO(DP[i][j]);
        }
    }
    cout<<DP[C][D]<<endl;
}


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

int main()
{
  int n;
  cin>>n;
  vector <int> h(n);
  for(int i=0;i<n;i++) cin>>h[i];
  vector <int> dp(n);
  dp[n-1]=0;
  for(int i=n-2;i>=0;i--)
  {
    dp[i]=abs(h[i]-h[i+1])+dp[i+1];
    if(i+2<n)
      dp[i]=min(dp[i],abs(h[i]-h[i+2])+dp[i+2]);
  }

  cout<<dp[0];

  return 0;
}


Measured memory_bytes: 4036
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;

int main()
{ 
  IOS
  ll w,h,x,y;
  cin>>w>>h>>x>>y;
  double area=(w*h)/(double)2;
  cout<<fixed<<setprecision(10)<<area<<" ";
  if(w%2 || h%2)
    cout<<0;
  else
  {
     if(x==(w/2) && y==(h/2))
      cout<<1;
    else
      cout<<0;
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define r_rep(i, n) for(int i = n; i >= 0; i--)
#define ll long long int
#define pb push_back

const long long INF = 1LL << 60;

int main() {
  int h, w;
  cin >> h >> w;
  char c[h][w];

  rep(i, h){
    rep(j, w){
      cin >> c[i][j];
    }
  }

  
  rep(i, h){
    rep(k, 2){
      rep(j, w){
        cout << c[i][j];
      }
      cout << endl;
    }
    
  }
  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

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

void dfs(vector<vector<int>> &g, vector<int> &dist, int x) {
  for (auto nx: g[x]) {
    if (dist[nx] > dist[x]+1) {
      dist[nx] = dist[x]+1;
      dfs(g, dist, nx);
    }
  }
}

int main() {
  int n, x, y; cin>>n>>x>>y;
  --x; --y;
  vector<vector<int>> g(n);
  rep(i, n-1) {
    g[i].emplace_back(i+1);
    g[i+1].emplace_back(i);
  }
  g[x].emplace_back(y);
  g[y].emplace_back(x);

  vector<int> ans(n, 0);

  rep(i, n) {
    vector<int> dist(n, INF);
    dist[i] = 0;
    dfs(g, dist, i);
    rep(j, n) ++ans[dist[j]];
  }
  REP(i, 1, n) print(ans[i]/2);

  return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();

      if(A>B){
        int ans = A+(A-1);
	System.out.println(ans);
      }else if(A<B){
        int ans = B+(B-1);
	System.out.println(ans);  
      }else{
        int ans = A+B;
	System.out.println(ans);        
      }
      }
}

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

using namespace std;

typedef long long ll;
const int N=(int)1e5+7;
int n,a[N],p[N];

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

        cin>>n;
        multiset <int> pos;
        pos.insert(0);
        pos.insert(0);
        pos.insert(n+1);
        pos.insert(n+1);
        for(int i=1;i<=n;i++)
        {
                cin>>a[i];
                p[a[i]]=i;
        }


        ll ans=0;
        for(int x=n;x>=1;x--)
        {
                int i=p[x];
                auto it3=pos.lower_bound(i),it4=it3,it2=it3,it1=it3;
                it4++;
                it2--;
                it1--;
                it1--;

                int p1=*it1,p2=*it2,p3=*it3,p4=*it4;
                ll cnt=(i-p2)*(ll)(p4-p3)+(p3-i)*(ll)(p2-p1);

                ans+=cnt*x;
                pos.insert(i);

        }
        cout<<ans<<"\n";

        return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define dou long double

using namespace std;

const int MAXN = 3e2 + 10;
int a[MAXN];
dou dp[MAXN][MAXN][MAXN];

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

    cout << setprecision(9) << fixed;

    int ii = 0, jj = 0, kk = 0;
    dou n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] == 1)
            ii++;
        else if (a[i] == 2)
            jj++;
        else
            kk++;
    }

    for (int k = 0; k <= n; ++k)
        for (int j = 0; j <= n; ++j)
            for (int i = 0; i <= n; ++i) {
                dou X = 0;
                if (!i && !j && !k)
                    continue;
                if (i)
                    X += (i / n) * dp[i - 1][j][k];
                if (j)
                    X += (j / n) * dp[i + 1][j - 1][k];
                if (k) 
                    X += (k / n) * dp[i][j + 1][k - 1];
                dp[i][j][k] = (X + 1) * (n / (i + j + k));
            }

    cout << dp[ii][jj][kk] << '\n';

    // dp[i][j][k] = (i / n) * dp[i - 1][j][k] + (j / n) * dp[i + 1][j - 1][k] + (k / n) * dp[i][j + 1][k - 1] + ((n - i - j - k) / n) * dp[i][j][k]
    // (i / n) * dp[i - 1][j][k] + (j / n) * dp[i + 1][j - 1][k] + (k / n) * dp[i][j + 1][k - 1] = (((n - i - j - k) / n) - 1) * dp[i][j][k]
    
    // X = ((i / n) * dp[i - 1][j][k] + (j / n) * dp[i + 1][j - 1][k] + (k / n) * dp[i][j + 1][k - 1]))
    // dp[i][j][k] = -1 * X / (((n - i - j - k) / n) - 1)
    // dp[i][j][k] = X * (n / (i + j + k))
   
    return 0;
}


Measured memory_bytes: 452864
//
//  main.cpp

#include <iostream>
#include <queue>
using namespace std;
using ll = long long;
const ll MAX = 10000000000000;
int h,w,n;
bool matrix[1001][1001]={{}};
bool visited[1001][1001]={{}};
pair<int,int> target;
struct state{
	int x;
	int y;
	int depth;
};

ll min(ll x,ll y){
	if(x < y){
		return x;
	}else{
		return y;
	}
}

/*

ll dfs(ll depth,int x,int y){
	if(!matrix[x][y])return MAX;
	if(target.first == x && target.second == y)return depth;
	
	ll a,b,c,d;
	a = b = c = d = MAX;
	if(!visited[x+1][y]){
		visited[x+1][y] = true;
		a = dfs(depth+1,x+1,y);
		visited[x+1][y] = false;
	}
	if(!visited[x-1][y]){
		visited[x-1][y] = true;
		b = dfs(depth+1,x-1,y);
		visited[x-1][y] = false;
	}
	if(!visited[x][y+1]){
		visited[x][y+1] = true;
		c = dfs(depth+1,x,y+1);
		visited[x][y+1] = false;
	}
	if(!visited[x][y-1]){
		visited[x][y-1] = true;
		d = dfs(depth+1,x,y-1);
		visited[x][y-1] = false;
	}
	return min(a,min(b,min(c,d)));
}
*/
ll bfs(int x,int y){
	queue<state> willvisit;
	willvisit.push({x,y,0});
	ll ret;
	while(1){
		if(willvisit.empty())break;
		state now = willvisit.front();
		willvisit.pop();
		
		if(now.x == target.first && now.y == target.second){
			ret = now.depth;
			break;
		}
		if(!visited[now.x+1][now.y]){
			if(matrix[now.x+1][now.y]){
				visited[now.x+1][now.y] = true;
				willvisit.push({now.x+1,now.y,now.depth+1});
			}
		}
		if(!visited[now.x-1][now.y]){
			if(matrix[now.x-1][now.y]){
				visited[now.x-1][now.y] = true;
				willvisit.push({now.x-1,now.y,now.depth+1});
			}
		}
		if(!visited[now.x][now.y+1]){
			if(matrix[now.x][now.y+1]){
				visited[now.x][now.y+1] = true;
				willvisit.push({now.x,now.y+1,now.depth+1});
			}
		}
		if(!visited[now.x][now.y-1]){
			if(matrix[now.x][now.y-1]){
				visited[now.x][now.y-1] = true;
				willvisit.push({now.x,now.y-1,now.depth+1});
			}
		}
	}
	
	return ret;
}

void visitedReset(){
	for(int i=0;i<1001;i++){
		for(int j=0;j<1001;j++){
			visited[i][j] = false;
		}
	}
}

int main(){
	for(int i=0;i<1001;i++){
		for(int j=0;j<1001;j++){
			matrix[i][j] = visited[i][j] = false;
		}
	}
	
	cin >> h >> w >> n;
	pair<int,int> cheese[10];
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			char input;
			cin >> input;
			switch(input){
				case '.':
					matrix[i][j] = true;
					break;
				case 'X':
					matrix[i][j] = false;
					break;
				case 'S':
					matrix[i][j] = true;
					cheese[0] = make_pair(i,j);
					break;
				default:
					matrix[i][j] = true;
					cheese[input - '0'] = make_pair(i,j);
					break;
			}
		}
	}
	
	ll answer=0;
	for(int i=0;i<n;i++){
		target = cheese[i+1];
		visited[cheese[i].first][cheese[i].second] = true;
		answer += bfs(cheese[i].first,cheese[i].second);
		visitedReset();
	}
	/*
	for(int i=0;i<n;i++){
		target = cheese[i+1];
		visited[cheese[i].first][cheese[i].second] = true;
		answer += dfs(0,cheese[i].first,cheese[i].second);
		visited[cheese[i].first][cheese[i].second] = false;
	}
	*/
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 5092
n, m = map(int, input().split())
shop = []
for i in range(n):
  shop.append(list(map(int, input().split())))
shop.sort()
bought = 0
cost = 0
for i in range(n):
  bought += min(m, shop[i][1])
  cost += min(m, shop[i][1]) * shop[i][0]
  m -= min(m, shop[i][1])
print(cost)

Measured memory_bytes: 27760
#include<iostream>
#include<cstdio>

using namespace std;

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


	if (a == 7 && b == 5 && c == 5 )
		cout << "YES" << endl;
	else if (a == 5 && b == 7 && c == 5 )
		cout << "YES" << endl;
	else if (a == 5 && b == 5 && c == 7 )
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	
}


Measured memory_bytes: 256
use proconio::input;

#[allow(unused_imports)]
use std::collections::HashSet;

use std::cmp;


fn main() {
    input! {
        n: usize,
        k: usize,
    }
    solve(n, k);
}

fn prepare(m: usize, k: usize, p :u64) -> Vec<Vec<u64>> {
    let mut v : Vec<Vec<u64>> = Vec::<Vec<u64>>::with_capacity(m + 1);
    let v0 : Vec<u64> = vec![1; 1];
    v.push(v0);
    for i in 1..m+1 {
        let mut vi : Vec<u64>;
        if i <= k {
            vi = vec![0; i+1];
            vi[0] = 1;
            vi[i] = 1;
            for j in 1..i/2+1 {
                vi[j] = (v[i-1][j-1] + v[i-1][j]) % p;
                vi[i-j] = vi[j];
            }
        }
        else {
            vi = vec![0; k+1];
            vi[0] = 1;
            if i < 2 * k {
                for j in 1..i/2+1 {
                    vi[j] = (v[i-1][j-1] + v[i-1][j]) % p;
                    let jx = i - j;
                    if jx <= k {
                        vi[jx] = vi[j];
                    }
                }
            } else {
                for j in 1..k+1 {
                    vi[j] = (v[i-1][j-1] + v[i-1][j]) % p;
                }
            } 
        }
        v.push(vi);
    }
    return v;
}

fn solve(n: usize, k: usize) {
    let p : u64 = (10u32.pow(9u32) + 7) as u64;

    // 1. Calculate all combinations
    let m = cmp::max(k-1, n-k+1);
    let c = prepare(m, k, p);

    // 2. Calculate possible ways
    for i in 1..k+1 {
        if i > n-k+1 { 
            println!("0");
        } else {
            let t =  c[n-k+1][i] * c[k-1][i-1] % p;
            println!("{}", t);
        }
    }
}


Measured memory_bytes: 17776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int q;
    cin >> q;
    while (q--) {
        ll a, b;
        cin >> a >> b;
        if (a == b && b == 1) {
            cout << "0\n";
            continue;
        }
        ll w = a * b - 1;
        ll k = sqrtl(w);
        while (w/k != w/(k+1))
            ++k;
        cout << k + w/k - 2 + (a == b) << '\n';
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 1e5
//123

using namespace std;

string a1,a2;

void dp (string s1, string s2, int n, int m){
    int l[n+1][m+1];

    for (int i=0; i<=n; i++){
        for (int j=0; j<=m; j++){
            if (i==0 or j==0){
                l[i][j]=0;
            }
            else if (s1[i-1]==s2[j-1]){
                l[i][j]=l[i-1][j-1]+1;
            }
            else{
                l[i][j]=max(l[i-1][j], l[i][j-1]);
            }
        }
    }
    while (m>0 and n>0){
        if (s1[n-1]==s2[m-1]){
            a1+=s1[n-1];
            n--;
            m--;
        }
        else if (l[n-1][m]>l[n][m-1]){
            n--;
        }
        else{
            m--;
        }
    }
}

long long n,m,a,b,c;
string s1,s2;

int main(){
    cin>>s1>>s2;
    n=s1.size();
    m=s2.size();
    dp(s1, s2, n, m);
    reverse(a1.begin(), a1.end());
    cout<<a1<<endl;
}


Measured memory_bytes: 38800
m, n = gets.split(" ").map(&:to_i)
mod = 1000000007

def power(m, n, mod)
  if n == 0
    return 1
  elsif n % 2 == 0
    return power((m*m)%mod, n/2, mod)
  else
    return (m * power(m, n-1, mod))%mod
  end
end

puts power(m,n,mod)%mod



Measured memory_bytes: 8880
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

ll n;
ll a[maxn];

int main()
{
    scanf("%lld", &n);
    if (n == 1)
    {
        printf("0\n");
        return 0;
    }
    for (int i = 1; i <= 1000; ++i)
        a[i] = i*(i+1)/2;
    int ans = 0;
    ll x = sqrt(n);
    for (int i = 2; i <= n; ++i)
    {
        if (i > x) 
        {
            ans += 1;
            break;
        }
        int cnt = 0;
        while (n%i == 0)
        {
            ++cnt;
            n /= i;
        }
        if (cnt)
        {
            ll *p = lower_bound(a+1, a+1001, cnt);
            if (*p == cnt) ans += p - a;
            else ans += p - a - 1;
        }
    }
    printf("%d\n", ans);
    return 0; 
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,ans,c,d,e,f;
	cin>>a>>b;
	ans=0;
	for(int i=a;i<b+1;i++){
		c=i/10000;
		d=i/1000-i/10000*10;
		e=i/10-i/100*10;
		f=i%10;
		if(c==f&&d==e){
			ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import math
n = int(input())
mod = 1000000007
all = pow(10, n, mod)
s1 = 2 * pow(9, n, mod) % mod
s2 = pow(8, n, mod) % mod
ans = int(all - s1 + s2)%mod
if ans < 0:
    ans += mod
print(ans%mod)

Measured memory_bytes: 61864
import * as fs from 'fs';

export function Main(input: string) {
    let [h1, s1, h2, s2] = input.split(' ').map(int => parseInt(int));    // ?

    let result = '';
    while (true) {
        // Takahashi
        h2 -= s1;
        if (h2 <= 0) {
            result = 'Yes';
            break;
        }
        h1 -= s2;
        if (h1 <= 0) {
            result = 'No';
            break;
        }
    }

    //output

    console.log(result);
    return result;
}

// Don't edit this line!
Main(fs.readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29624
import numpy as np


def solve(string):
    n, m, c, *ba = map(int, string.split())
    """
    b = np.asarray(ba[:m])
    a = np.asarray(ba[m:])
    a.resize((n, m))
    return str(np.sum(np.dot(a, b.T) > -c))
    """
    ans = 0
    for i in range(n):
        tmp = c
        for j in range(m):
            tmp += ba[j] * ba[(i + 1) * m + j]
        if tmp > 0:
            ans += 1
    return str(ans)


if __name__ == '__main__':
    n, m, o = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, o) + '\n'.join([input() for _ in range(n + 1)])))


Measured memory_bytes: 13488
# p (0..6).to_a.map{|j| [6 ** j, 9 ** j] }.flatten.uniq
a = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 59049, 46656, 531441]

m, dp = gets.to_s.to_i, [0]
(1..m).each {|i|
  cans = a.select {|j| i - j >= 0 }.map{|j| i - j }.uniq
  dp.push(cans.map{|j| dp[j] }.min + 1)
}
p dp.last

Measured memory_bytes: 2940
n, k = map(int, input().split())
mod = 10 ** 9 + 7

cnt = 0

for i in range(k, n + 2):
    hani_max = (n + n - i + 1) * (i) // 2
    hani_min = (i - 1) * i // 2
    cnt += hani_max - hani_min + 1
    cnt %= mod
print(cnt)


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

 
int main() {
  int N;
  bool even=true;
  int count=0;
  vector<int> a;
  cin>>N;
  for(int i=0;i<N;i++){
    int b;
    cin>>b;
    a.push_back(b);
  }
  
  while(even){
  	for(int i=0;i<N;i++){
  	  if(a.at(i)%2==1)goto OUT;
      a.at(i)/=2;
    }
    count++;
  }
  OUT:

  cout<<count<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAXN 2000+5

using namespace std;

int main() {
	int n, z, w;
	int a[MAXN];
	scanf("%d %d %d", &n, &z, &w);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	if (n == 1) {
		printf("%d\n",(int) fabs(a[n] - w));
	}
	else {
		printf("%d\n", (int)max(fabs(a[n] - w), fabs(a[n - 1] - a[n])));
	}

	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static int mod =1000000007;
	public static void main(String[] args) {
		int N=sc.nextInt();
		int a[]=new int[N];
		int b;
		for(int i=0;i<N-1;i++) {
			b=sc.nextInt();
			 a[b-1]++;
		}
		
		 for(int i:a) {
			 p(i);
		 }
		
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 62600
def check_num(n):
    if n % 3 == 0\
    or n % 10 == 3\
    or str(n).find("3") != -1:
        print(" {0}".format(n), end="")

n = int(input())
for i in range(3, n+1):
    check_num(i)
print()

Measured memory_bytes: 8028
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String args[]) {
        String s = scanner.next();
        String t = scanner.next();
        int[] to = new int[] {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
        int[] ds = new int[] {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
        for (int i = 0; i < s.length(); i++) {
            int a = s.charAt(i) - 'a', b = t.charAt(i) - 'a';
            if ((to[a] == -1 ? to[a] = b : to[a]) != b || (ds[b] == -1 ? ds[b] = a : ds[b]) != a) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 28036
/*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/

#include <bits/stdc++.h>
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace __gnu_cxx;*/

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define PI (acos(-1.0))
#define inf INT_MAX/2
#define infll (1LL<<62)
#define abs(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define fbo(k) find_by_order(k) ///returns iterator to the kth largest element counting from 0
#define ook(val) order_of_key(val) ///returns the number of items in a set that are strictly smaller than val

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef multiset<int> msi;
typedef map<int,int> mii;
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_int_set;

///cout << fixed << setprecision(12) << ans << endl;

const int maxn=1e5+5;
const int MOD=1e9+7;

vector <int> edges[205];
int m,person[105],job[105];
bool vis[205];

bool max_bpm (int u)
{
    vis[u]=true;
    int i,n,v;

    n=edges[u].size();
    for (i=0;i<n;i++) {
        v=edges[u][i]-m;
        if (job[v]==-1 || (!vis[job[v]] && max_bpm(job[v]))) {
            job[v]=u;
            person[u]=v;
            return true;
        }
    }

    return false;
}

vector<pii> red,blue;

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

    int n;
    cin>>n;
    for (int i=0;i<n;i++) {
        int x,y;
        cin>>x>>y;
        red.pb(mp(x,y));
    }
    for (int i=0;i<n;i++) {
        int x,y;
        cin>>x>>y;
        blue.pb(mp(x,y));
    }

    m=100;
    for (int i=0;i<n;i++) {
        auto r=red[i];
        for (int j=0;j<n;j++) {
            auto b=blue[j];
            if (r.fi<b.fi && r.se<b.se) {
                edges[i].pb(m+j);
                edges[m+j].pb(i);
            }
        }
    }

    memset(person,-1,sizeof(person));
    memset(job,-1,sizeof(job));
    int ans=0;
    for (int i=0;i<n;i++) {
        memset(vis,0,sizeof(vis));
        ans+=max_bpm(i);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using Int = int64_t;
int main() {
    Int N, even_odd = 0;
    cin >> N;
    vector<Int> A(N);
    for (Int i = 0; i < N; i++) {
        cin >> A[i];
        even_odd += A[i] * (i % 2 ? -1 : 1);
    }
    for (Int i = 0, t = even_odd; i < N; i++) {
        cout << t << (i == N - 1 ? "\n" : " ");
        t = 2 * A[i] - t;
    }
}


Measured memory_bytes: 2048
A, B = map(int, input().split())
cnt = 0
for i in range(A, B + 1):
    lst = list(str(i))
    rvs = lst[4] + lst[3] + lst[2] + lst[1] + lst[0]
    if rvs == str(i):
        cnt += 1
 
    

print(cnt)

Measured memory_bytes: 3064
using System;

public class Hello
{
    public static void Main()
    {
        var btn = new string[] { ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var result = "";
            var s = Console.ReadLine().Trim();
            var number = "";
            for (int j = 0; j < s.Length; j++)
            {
                if (s[j] != '0') number += s[j].ToString();
                else
                {
                    if (number != "")
                    {
                        result += Kakutei(int.Parse(number[0].ToString()) , number.Length,btn );
                        number = "";
                    }
                }
            }
            Console.WriteLine(result);
        }
    }
    public static string Kakutei(int button, int times ,string[] btn)
    {
        var p = times % btn[button - 1].Length - 1;
        if (p < 0) p += btn[button - 1].Length;
        return btn[button - 1][p].ToString();
    }
}

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            //cout<<x<<"/"<<y;
            cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////



int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    ll pos=n-1;
    bool f=true;
    rep(iz,1,n-1){
        
        ans+=a[pos];
        if(f){
            f=false;
            pos--;
        }else{
            f=true;
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 5216
import java.util.Scanner;

public class Main {
    static String[] n;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        n = sc.next().split("");
        boolean result = solve();
        if (result) System.out.println("Yes");
        else System.out.println("No");
    }

    static boolean solve() {
        int i = 0;
        while (true) {
            if (i == n.length - i - 1) break;
            if (!n[i].equals(n[n.length - i - 1])) return false;
            i++;
        }
        return true;
    }
}


Measured memory_bytes: 23764
N = int(input())
A = list(map(int, input().split()))
B = [0]*N

for i in range(N):
    B[i] = A[i]-(i+1)
B.sort()
mid = B[len(B)//2]
ans = 0
for i in range(N):
    ans += abs(B[i]-mid)
print(ans)

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

int m, n, B[500], R[500], P[500], C[500][500];

// P[] カード赤とペアになっている青のカード番号 割り当てなしで -1
// B[i] と R[j] がマッチ可能なとき C[i][j] = 1 不可能なとき 0

bool V[500];
// true ならカード赤に新しい割り当て先はない false なら不明

int gcd( int a, int b ) {

	int c;
	
	while ( a != 0 ) {
	
		c = a;
		a = b % a;
		b = c;

	}

	return b;

}

int judge( int i, int j ) {

	if ( gcd( B[i], R[j] ) >= 2 ) { return 1; }
	else { return 0; }

}

bool match( int i ) {

	if ( i < 0 ) { return true; }
	
	for ( int j = 0; j < n; j++ ) {
	
		if ( C[i][j] == 0 || V[j] ) { continue; }
		
		V[j] = true;
		
		if ( match( P[j] ) ) {
			
			P[j] = i;
			return true;
			
		}
	
	}
	
	return false;

}

int main() {

	while ( cin >> m >> n && m != 0 && n != 0 ) {
	
		for ( int i = 0; i < m; i++ ) { cin >> B[i]; }
		for ( int i = 0; i < n; i++ ) { cin >> R[i]; }
		
		
		for ( int i = 0; i < n; i++ ) { P[i] = -1; }
		
		for ( int i = 0; i < m; i++ ) { for ( int j = 0; j < n; j++ ) { C[i][j] = judge( i, j ); } }
		
		int count = 0;
		
		for ( int i = 0; i < m; i++ ) {
		
			for ( int i = 0; i < n; i++ ) { V[i] = false; }
			
			if ( match( i ) ) { count++; }
			
		}
		
		cout << count << endl;
	
	}

}

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

typedef long long ll;

int main()
{

    //freopen("input.txt", "r", stdin);

    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    c *= 2;

    ll ans = 1e9;
    for (int i = 0; i <= max(x, y); ++i)
    {
        ans = min(ans, i * c + a * max(0ll, x - i) + b * max(0ll, y - i));
    }

    cout << ans;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll dp[65][5];

int main() {
    init();
    ll N;
    cin >> N;
    
    dp[60][0] = 1;
    repr(i, 60){
        if(N>>i & 1){
            dp[i][2] = (3 * dp[i + 1][2] + 2 * dp[i + 1][1]) % MOD;
            dp[i][1] = (dp[i + 1][1] + dp[i + 1][0]) % MOD;
            dp[i][0] = dp[i + 1][0];
        }
        else{
            dp[i][2] = (3 * dp[i + 1][2] + dp[i + 1][1]) % MOD;
            dp[i][1] = dp[i + 1][1];
            dp[i][0] = (dp[i + 1][0] + dp[i + 1][1]) % MOD;
        }        
    }

    cout << accumulate(dp[0], dp[0] + 3, 0ll) % MOD << endl;
}

Measured memory_bytes: 256
/**
*    created: 01.07.2020 15:47:43
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
// const int MOD = 998244353;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

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

    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    rep(i,n) {
        cin >> a[i];
        if (i != 0) sum += abs(a[i] - a[i-1]);
    }
    sum += abs(a[0]);
    sum += abs(a[n-1]);
    rep(i,n) {
        if (i == 0) cout << sum - (abs(a[0]) + abs(a[1] - a[0])) + abs(a[1]) << endl;
        else if (i == n-1) cout << sum - (abs(a[n-1] - a[n-2]) + abs(a[n-1])) + abs(a[n-2]) << endl;
        else cout << sum - (abs(a[i]-a[i-1]) + abs(a[i+1]-a[i])) + abs(a[i+1]-a[i-1]) << endl;;
    }
    return 0;
}

Measured memory_bytes: 3972
n,c,k = map(int,input().split())
t = [int(input()) for i in range(n)]+[float("INF")]
t.sort()
now = 0
count = 0
ans = 0
for i in t:
    if now == 0:
        now = i
        count += 1
    else:
        if i <= now+k:
            if count < c:
                count += 1
            else:
                ans += 1
                now = i
                count = 1
        else:
            ans += 1
            now = i
            count = 1
print(ans)

Measured memory_bytes: 13840
#include<iostream>
using namespace std;
int main(void){
   int m, f, b;
   cin >> m >> f >> b;
   if ( m >= b ){
       cout << 0 << endl;
   }
   else if ( m + f >= b ){
       cout << b - m << endl;
   } 
   else{
       cout << "NA" << endl;
   } 
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
ll dp[100100][13];

int main() {
    ll n,tmp1 = 0,tmp2 = 0,flg = 0;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<ll>());
    for (int i = 0; i < n; ++i) {
        if(a[i] == a[i+1] && flg == 0){
            tmp1 = a[i];
            i++;
            flg = 1;
        }else if(a[i] == a[i+1]){
            tmp2 = a[i];
            break;
        }
    }
    cout << tmp1*tmp2 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    cout << binary_search(v.begin(), v.end(), k) << endl;
  }
}


Measured memory_bytes: 3140
#include<cstdio>
#include<cmath>
int main(){
    double a,b;
    scanf("%lf %lf",&a,&b);
    if(a>b){
    	printf("GREATER");
	}
	else if(a<b){
		printf("LESS");
	}
	else {
		printf("EQUAL");
	}
    return 0 ;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
    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;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    System.out.print("#");
                }
                System.out.println("");
            }   
            System.out.println("");
        }
        sc.close();
    }
    
}


Measured memory_bytes: 34492
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,h;
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
}

Measured memory_bytes: 3656