akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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


int n;

int main() {

	cin >> n;

	n = n % 10;

	if (n == 0 || n == 1 || n == 6 || n == 8)cout << "pon" << endl;
	else if (n == 3)cout << "bon" << endl;
	else cout << "hon" << endl;

	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main() {
    string s;
    cin >> s;
    bool ans = false;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) ans = true;
    cout << (ans?"Yes":"No") << endl;
}

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

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

    long long n, m;   cin >> n >> m;

    for(int i = 0; i < m; i++) {
        long long x;    cin >> x;
        n = n - x;
    }

    if(n < 0) {
        cout << "-1\n";
        return 0;
    }

    cout << n << '\n';

    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  int n;cin>>n;
  long long a[n];
  for(int i = 0; n > i; i++){
    cin>>a[i];
  }
  long long ans = 0;
  for(int i = 0; n > i; i++){
    ans += a[i];
    ans -= (i+1);
  }
  cout << ans << endl;
}


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

using namespace std;

using ll = long long;

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

    string S;
    cin >> S;
    int odd_zero = 0;
    int even_zero = 0;
    for (int i = 0; i < S.length(); ++i) {
        odd_zero += i % 2 == 1 && S[i] == '0';
        even_zero += i % 2 == 0 && S[i] == '0';
    }
    int s_length = S.length();
    int odd_num = s_length / 2;
    int even_num = s_length - odd_num;
    // odd = 0
    int odd_res = odd_num - odd_zero + even_zero;
    // even = 0
    int even_res = even_num - even_zero + odd_zero;


    cout << min(odd_res, even_res) << '\n';

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <vector>

int main(void)
{
    int x, a, b;
    std::cin >> x >> a >> b;
    x -= a;
    x -= (x/b)*b;
    std::cout << x << std::endl;
    return 0;
}


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

const ll mod = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    map<int, ll> mp;
    rep(i, N) {
        cin >> A[i];
        ll tmp = A[i];
        ll b = 0;
        while (tmp > 0) {
            if (tmp & 1) mp[b]++;
            else mp[b];
            b++;
            tmp /= 2LL;
        }
    }

    // for (auto & tmp : mp) {
    //     cout << tmp.first << ", " << tmp.second << endl;
    // }

    ll ans = 0;

    ll sz = N-1;
    rep(i, sz) {
        ll b = 1;
        for (auto & tmp : mp) {
            if ((A[i] >> tmp.first) & 1) {
                ans += (N - tmp.second) * b;
                tmp.second--;
            }
            else {
                ans += tmp.second * b;
            }
            ans %= mod;
            b *= 2LL;
            b%= mod;
        }
        N--;
    }

    cout << ans << endl;
}


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

int main(){
  int n; cin>>n;
  vector<int> a(n),b(n),c(n-1);
  for(int i=0; i<n; i++){
    cin>>a.at(i);
  }
  for(int i=0; i<n; i++){
    cin>>b.at(i);
  }
  for(int i=0; i<n-1; i++){
    cin>>c.at(i);
  }
  int s=0,pre=-5;
  for(int i=0; i<n; i++){
    //printf("%d %d\n",a[i],pre);
    s+=b[a[i]-1];
    if(a[i]==pre+1) s+=c[pre-1];
    pre=a[i];
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fir first
#define sec second
using namespace std;
int x[100010],y[100010],noans[410];
bitset<410> z,b[410];
int read()
{
	int x=0,flag=1;char c=getchar();
	while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();}
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
	return x*flag;
}
int main()
{
	int n=read(),m=read();
	for(int i=1;i<=m;i++) x[i]=read(),y[i]=read();
	for(int i=1;i<=n;i++)
	{
		z.reset();
		z[i]=1;
		for(int j=m;j>=1;j--)
		{
			int ss=x[j],tt=y[j];
			if(z[ss]&&z[tt]) {noans[i]=1;break;}
			if(!z[ss]&&!z[tt]) continue;
			z[ss]=z[tt]=1;
		}
		b[i]=z;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(!noans[i]&&!noans[j]) if(!(b[i]&b[j]).count()) ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define MAX_N 20

int n;
int a[MAX_N], b[MAX_N], c[MAX_N]; //入力用

void solve()
{
    int pre = -1;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += b[a[i] - 1];
        if (a[i] - 1 == pre)
        {
            ans += c[a[i] - 2];
        }

        pre = a[i];
    }

    cout << ans << endl;
}

int main()
{
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n - 1; i++)
    {
        cin >> c[i];
    }

    solve();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
    int cnt[26]={0};
    char s;
    int i=0;
    while(scanf("%c", &s)!=EOF){
        if(s>='A'&& s<='Z'){
            s+=32;
        }
        if(s>='a'&&s<='z')
        cnt[s-97]++;
    }
    for(int i=0; i<26; i++){
        printf("%c : %d\n", i+97, cnt[i]);
    }
}


Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b;i++)
    {
        if(i%k==0)
        {
            cout << "OK";
            goto lable;
        }    
    }
    cout << "NG";
    lable:
        return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    string s, t;
    cin >> s >> t;
    
    int ans = 0;
    rep(i,3) {
        if(s[i]==t[i]) { ans++; }
    }
    cout << ans << endl;
    return 0;
} /*atcoder*/



Measured memory_bytes: 3608
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  vll cs(n - 1), ss(n - 1), fs(n - 1);
  rep(i, n-1) cin >> cs[i] >> ss[i] >> fs[i];

  rep(i, n-1){
    ll t = ss[i] + cs[i];
    repLRE(j, i+1, n-2){
      ll k = (t - ss[j] + fs[j] - 1)/fs[j];
      if(k < 0) k = 0;
      t = ss[j] + k*fs[j] + cs[j];
    }
    cout << t << endl;
  }
  cout << 0 << endl;

  return 0;
}


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

int main()
{
    int n;
    long long ans=0;
    long long cnt[5]={0,0,0,0,0};
    char s[11];
    cin >> n;

    for(int i=0;i<n;i++){
        cin >> s;
        if(s[0]=='M'){
            cnt[0]++;
        }else if(s[0]=='A'){
            cnt[1]++;
        }else if(s[0]=='R'){
            cnt[2]++;
        }else if(s[0]=='C'){
            cnt[3]++;
        }else if(s[0]=='H'){
            cnt[4]++;
        }
    }
    
    for(int i=0;i<5;i++){
        for(int j=0;j<i;j++){
            for(int k=0;k<j;k++){
                ans+=cnt[i]*cnt[j]*cnt[k];
            }
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 0; --i)
#define repBX(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

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

int main() {
    int A,B;
    cin >> A >> B;
    cout << lcm(A,B) << endl;
    
    return 0;
}

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

int main ()
{
  int N,sum;
  cin >> N;
  
  for(int i = 0;i < N;i++){
    int l1,l2;
    cin >> l1 >> l2;
    sum += l2 -l1 + 1;
  }
  cout << sum << endl;
}

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

int main()
{
  int n; cin >> n;
  int ans=0, num=0,i;
  for(i=0; i<(int)(1e6+1e5); ++i){
    num=(num*10)+7;
    if(num%n==0){
      ++ans;
      break;
    }
    else{
      num=num%n;
      ++ans;
    }
  }
  if(i!=1e6+1e5) cout << ans << endl;
  else cout << -1 << endl;
}


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

void swap(char *a,char *b){
    char t = *a;
    *a = *b;
    *b = t;
}
int main() {
    int n,i,j,k;
    vector<char> bk[9];
    cin>>n;
    string bs(n,'A'),sn(n,'0');
    for (i=0;i<n;i++) {
        cin>>bs[i]>>sn[i];
        bk[sn[i]-'0'-1].push_back(bs[i]);
    }
    string ss(bs);
    k=0;
    for (i=0;i<9;i++) {
        for(j=0;j<bk[i].size();j++,k++) {
            bs[k]=bk[i][j];
            cout<<(k==0?"":" ")<<bs[k]<<i+1;
        }
    }
    cout<<"\nStable\n";
    for (i=0;i<n-1;i++) {
        k=i;
        for (j=i;j<n;j++)if(sn[j]<sn[k])k=j;
        if(i!=k){swap(sn[i],sn[k]);swap(ss[i],ss[k]);}
        cout<<ss[i]<<sn[i]<<" ";
    }
    cout<<ss[n-1]<<sn[n-1]<<endl;
    cout<<(ss==bs?"Stable":"Not stable")<<endl;
    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

#include <iostream>
using i64 = long long;
template<i64 M> struct modint { i64 a;
  constexpr modint(const i64 x = 0): a((x%M+M)%M){}
  constexpr i64 value() const { return a; }
  constexpr modint inv() const { return this->pow(M-2); }
  constexpr modint pow(i64 r) const {
    modint ans(1); modint aa = *this;
    while(r) { if(r & 1) ans *= aa; aa *= aa; r >>= 1; }
    return ans;
  }
  constexpr modint& operator=(const i64 r) { a = (r % M + M) % M; return *this; }
  constexpr modint& operator+=(const modint r) { a += r.a; if(a >= M) a -= M; return *this; }
  constexpr modint& operator-=(const modint r) { a -= r.a; if(a < 0) a += M; return *this; }
  constexpr modint& operator*=(const modint r) { a = a * r.a % M; return *this; }
  constexpr modint& operator/=(const modint r) { (*this) *= r.inv(); return *this; }
  constexpr modint operator+(const modint r) const { return modint(*this) += r; }
  constexpr modint operator-(const modint r) const { return modint(*this) -= r; }
  constexpr modint operator*(const modint r) const { return modint(*this) *= r; }
  constexpr modint operator/(const modint r) const { return modint(*this) /= r; }
  constexpr bool operator!=(const modint r) const { return this->value() != r.value(); }
};

template<const i64 M> std::ostream& operator<<(std::ostream& os, const modint<M>& m) { os << m.value(); return os; }

using fp = modint<998244353>;

int main() {
  string S;
  cin >> S;
  i64 N = S.size();
  auto dp = ndvec(N * 2 + 1, N * 2 + 1, fp(0));
  dp[0][0] = fp(1);
  i64 rsum = 0;
  rep(i,0,N * 2) {
    i64 R = 0;
    if(i < N)
      R = (int)(S[i] - '0');
    rsum += R;
    i64 n = std::min(N * 2, (i + 1) * 2);
    rep(j,0,N * 2 + 1) {
      i64 r = rsum - j;
      i64 b = n - rsum - (i - j);
      if(b < 0 || r < 0) continue;
      if(r > 0) {
        dp[i + 1][j + 1] += dp[i][j];
      }
      if(b > 0) {
        dp[i + 1][j] += dp[i][j];
      }
    }
  }
  cout << dp[N * 2][rsum] << endl;
}


Measured memory_bytes: 128380
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
Node root;

void insert(int);
void preorder(Node);
void inorder(Node);
Node Search(Node,int);

int main(){
  int n, i, k;
  char I[10];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", I);
    if (I[0]=='i'){
      scanf("%d", &k);
      insert(k);
    } else if(I[0]=='f'){
        scanf("%d", &k);
        Node s = Search(root, k);
        if ( s != NIL ) printf("yes\n");
        else printf("no\n");
    } else if(I[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
 
  return 0;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL){
    y=x;
    if(z->key < x->key)
      x=x->left;
    else
      x=x->right;
  }
  z->parent=y;
    
 
  if (y == NIL)
    root=z;
  else if (z->key < y->key)
    y->left=z;
  else
    y->right=z;
}

void inorder(Node tree){
  if( tree != NIL){
    inorder(tree->left);
    printf(" %d",tree->key);
    inorder( tree->right);
  }
}

void preorder(Node tree){
  if( tree != NIL){
    printf(" %d",tree->key);
    preorder(tree->left);
    preorder(tree->right);
  }
}

Node Search(Node tree,int k){
  if(tree==NIL || k==tree->key){
    return tree;
  }
  if(k<tree->key){
    return Search(tree->left,k);
  }
  else return Search(tree->right,k);
}

Measured memory_bytes: 19364
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> cnts(N+1, 0);
    rep(i, 0, N)
    {
        cnts[i+1] = cnts[i];
        if (S[i] == 'R') ++cnts[i+1];
        // printf("%d %d %d %c\n", i, cnts[i], cnts[i+1], S[i]);
    }

    int num_red = cnts[N];
    int ans = N;
    rep(num, 0, num_red+1)
    {
        int now = 0;
        // remove
        now += num_red - num;
        // swap
        now += num_red - cnts[num];

        //printf("%d %d\n", num, now);
        
        // update
        ans = min(ans, now);
    }

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



Measured memory_bytes: 4448
A,B,C,D = map(int,input().split())
#高橋体力A 高橋攻撃B
#青木体力C 青木攻撃D
result = "No"
turn = "t"
while 1:
  if turn == "t":
    C -= B
    turn = "a"
    if C <= 0:
      result = "Yes"
      break
  elif turn == "a":
    A -= D
    turn = "t"
    if A <= 0:
      result = "No"
      break
print(result)

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

typedef long long ll;
typedef long double ld;

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

int main(){

    ll N;

    cin >> N;

    cout << "ABC" << N << endl;

    return 0;
}

Measured memory_bytes: 256
N,H,D=map(int,input().split())
mod=10**9+7
table=[1]
num=0
for i in range(1,N+1):
    table.append(table[-1]*i%mod)
    num=(num+table[-1])%mod
dp=[0]*(H+1)
d_sum=[0]*(H+1)
for i in range(1,D+1):
    dp[i]=table[N]
for i in range(1,H+1):
    dp[i]=(dp[i]+(d_sum[i-1]-d_sum[max(0,i-D-1)])*num)%mod
    d_sum[i]=(dp[i]+d_sum[i-1])%mod
print(dp[H])

Measured memory_bytes: 88088
import statistics
import math

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

A_list_min = 10**9+1
A_list_sum = 0
for i in range(N):
    A_list[i] = A_list[i] - (i+1)

A_medi = int(statistics.median(A_list))
ans = 0
for i in range(N):
    ans += abs(A_list[i] - A_medi)
print(ans)

Measured memory_bytes: 109236
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;


int main(){
    string s1,s2;
    while(cin>>s1,s1!="."){
        cin>>s2;
        int c1=0,c2=0;
        int n1=s1.size(),n2=s2.size();
        bool flag=false;
        int ans=0,cnt=0;
        while(1){
            if(!flag&&s1[c1]!=s2[c2]){
                ans=1;
                break;
            }
            if(s1[c1]=='\"'){
                ++c1,++c2;
                while(1){
                    if(s1[c1]!=s2[c2]){
                        ++cnt;
                        while(s1[c1]!='\"') ++c1;
                        while(s2[c2]!='\"') ++c2;
                        break;
                    }
                    else if(s1[c1]=='\"') break;
                    ++c1,++c2;
                }
            }
            ++c1,++c2;
            if(c1==n1||c2==n2){
                if(c1!=n1||c2!=n2) ans=1;
                break;
            }
        }
        if(ans==1||cnt>1) cout<<"DIFFERENT"<<endl;
        else if(cnt==1) cout<<"CLOSE"<<endl;
        else cout<<"IDENTICAL"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,C;
  cin>>n>>C;
  int d[C][C];
  int c[n][n];
  rep(i,0,C){
    rep(j,0,C){
      cin>>d[i][j];
    }
  }
  rep(i,0,n){
    rep(j,0,n){
      cin>>c[i][j];
    }
  }
  int x[C],y[C],z[C];
  rep(i,0,C){
    x[i]=0;
    y[i]=0;
    z[i]=0;
  }
  rep(i,0,n){
    rep(j,0,n){
      if((i+j)%3==0){
        x[c[i][j]-1]++;
      }
      else if((i+j)%3==1){
        y[c[i][j]-1]++;
      }
      else{
        z[c[i][j]-1]++;
      }
    }
  }
  int p[C];
  rep(i,0,C){
    int cur=0;
    rep(j,0,C){
      cur+=x[j]*d[j][i];
    }
    p[i]=cur;
  }
  int q[C];
  rep(i,0,C){
    int cur=0;
    rep(j,0,C){
      cur+=y[j]*d[j][i];
    }
    q[i]=cur;
  }
  int r[C];
  rep(i,0,C){
    int cur=0;
    rep(j,0,C){
      cur+=z[j]*d[j][i];
    }
    r[i]=cur;
  }
  int ans=3e8;
  rep(i,0,C){
    rep(j,0,C){
      rep(k,0,C){
        if(i!=j && j!=k && k!=i){
          ans=min(ans,p[i]+q[j]+r[k]);
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>> G(N * 3);
	for (auto i = 0; i < M; ++i)
	{
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		G[u].push_back(v + N);
		G[u + N].push_back(v + 2 * N);
		G[u + 2 * N].push_back(v);
	}
	int S, T;
	cin >> S >> T;
	--S;
	--T;

	queue<pair<int, int>> q;
	q.push(make_pair(S, 0));
	vector<int> dp(N * 3, -1);
	dp[S] = 0;
	while (!q.empty())
	{
		auto p = q.front();
		q.pop();
		for (auto v : G[p.first])
		{
			if (dp[v] >= 0)
			{
				continue;
			}

			dp[v] = p.second + 1;
			q.push(make_pair(v, p.second + 1));
		}
	}

	if (dp[T] >= 0)
	{
		dp[T] /= 3;
	}
	cout << dp[T] << endl;

	return 0;
}

Measured memory_bytes: 17792
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
using namespace std;
int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> p(1e5+10,0),waa(1e5,0);
    ll ac=0,wa=0;
    rep(i,0,m){
        char buf[2];
        int num;
        cin>>num>>buf;
        if(!p[num]){
            if(!strcmp(buf,"WA"))waa[num]++;
            else{ 
                ac++;
                wa+=waa[num];
                p[num]=1;
            }
        }
    }
    cout<<ac<<" "<<wa<<endl;
}

Measured memory_bytes: 1792
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val l = sc.nextInt()
    val r = sc.nextInt()
    val d = sc.nextInt()
    println(r / d - (l - 1) / d)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 34404
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	int idx = -1;
	rep(i,n){
		int a;
		cin >> a;
		if(a == 1) idx = i+1;
	}
	int ans = (n - 1 + k - 1 - 1) / (k - 1);
	chmax(ans, 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3504
// template version 1.13
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i, n) {
    cin>>a[i];
  }
  sort(all(a));
  dump(a);

  int ans = 0;
  rep(i, n){
    rep(j, i+1, n-1){
      auto k = posl(a, a[i]+a[j]);
      dump(i,j,k);
      ans += max(0LL, k-j-1);
    }
  }
  cout << ans << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
X=[]
X.append(abs(A[0]))
for I in range(N-1):
	X.append(abs(A[I]-A[I+1]))
X.append(abs(A[N-1]))
SUM=sum(X)
for K in range(N):
	if K==0:
		print(SUM+abs(A[K+1])-X[0]-X[1])
	elif K==(N-1):
		print(SUM+abs(A[K-1])-X[N-1]-X[N])
	else:
		print(SUM+abs(A[K-1]-A[K+1])-X[K]-X[K+1])

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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    vector<long long> p1(N, 0), p2(N, 0);
    for (int i = 0; i < N - 1; i++) {
        if (i % 2 == 0) {
            p1[i]--;
            p1[i + 1]++;
        } else {
            p1[i]++;
            p1[i + 1]--;
        }
    }
    for (int i = 0; i < N - 1; i++) {
        if (i % 2 == 0) {
            p2[i]++;
            p2[i + 1]--;
        } else {
            p2[i]--;
            p2[i + 1]++;
        }
    }
    sort(p1.begin(), p1.end());
    sort(p2.begin(), p2.end());
    long long sum1 = 0, sum2 = 0;
    for (int i = 0; i < N; i++) {
        sum1 += p1[i] * A[i];
        sum2 += p2[i] * A[i];
    }
    cout << max(sum1, sum2) << endl;
}

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

int main(){

    int a,b,t;
    while (1){
        cin >> a >> b;
        if (a==0){
            if(b==0){
                break;
            }
        }
        if(a>b){
            t=a;
            a=b;
            b=t;
        }
        cout << a << " " << b << endl;
    }
    return 0;
}






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

int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  for (auto &e : w) {
    cin >> e;
  }
  bool r = true;
  for (int i = 0; i < n - 1; i++) {
    if (w[i].back() != w[i + 1].front()) {
      r = false;
    }
  }
  map<string, int> m;
  for (auto e : w) {
    m[e]++;
    if (m[e] > 1) {
      r = false;
    }
  }
  cout << (r ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define fr(i,x,y) for(int i=x;i<y;i++)
#define f(n) for(int i=0;i<n;i++)
#define ff(m) for(int j=0;j<m;j++)
#define F(x) for(auto it:x)
#define in insert
#define pb push_back
#define pi pair<int,int>
#define si second
#define fi first
#define show_(x) cerr<<"-> "<<#x<<endl;F(x){cerr<<it<<" ";}cout<<endl;
#define show(x) cerr<<#x<<"-> "<<x<<endl;
//#define start_routine cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int begtime = clock();
//#define end_routine int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0;
#define FILEIO freopen("F:\\inout\\input.txt", "r", stdin); freopen("F:\\inout\\output.txt", "w", stdout);
using namespace std;
void print(int a[],int n){f(n){cout<<a[i]<<" ";}cout<<endl;}
int m(int x){return x%1000000007;} 
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int p(int a,int b){if(b==0)return 1;int t=p(a,b/2); if(b%2==0)return t*t; else return a*t*t; } 
//strlen(s.c_str());  set <int, greater<int>> s; numeric_limits<double>::max()
//---------------------------------------------------------------------------------------------------------------------------------------------
 int t[100000];


signed main(){
	//FILEIO
	//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	if(k==1){
		cout<<0<<endl;
		return 0;
	}
	cout<<n-k<<endl;

	

	
	
	






	return 0;
}



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

int main(){
  ll N,Y,x,y,z;
  cin>>N>>Y;
  for(int i=0;i*10000<=Y;i++){
    for(int j=0;i*10000+j*5000<=Y;j++){
      if((Y-i*10000-j*5000)%1000==0&&i+j+(Y-i*10000-j*5000)/1000==N&&(Y-i*10000-j*5000)/1000>=0){
        cout<<i<<" "<<j<<" "<<(Y-i*10000-j*5000)/1000<<endl;
        return 0;
      }
    }
  }
  cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
map<int,int>ret;
vector<pii>e;
signed main(){
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	for(int i=0LL,x;i<n;i++){
		cin>>x;
		ret[x]=i;
		e.pb(mp(x,i));
	}
	sort(e.rbegin(),e.rend());
	int x=e.back().F;
	vector<int>sz(n,1LL);
	vector<int>dp(n,0LL);
	vector<pii>ans;
	for(auto c:e){
		if(c.F!=x){
			if(sz[c.S]*2LL>=n)return puts("-1"),0;
			int p=c.F-(n-2LL*sz[c.S]);
			if(!ret.count(p))return puts("-1"),0;
			int pa=ret[p];
			dp[pa]+=dp[c.S]+sz[c.S];
			sz[pa]+=sz[c.S];
			ans.pb(mp(c.S+1LL,pa+1LL));
		}
	}
	if(dp[e.back().S]!=x)return puts("-1"),0;
	for(auto c:ans)cout<<c.F<<' '<<c.S<<endl;
	return 0;
}


Measured memory_bytes: 12656
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef std::pair<int, int> par;
inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 100005;
std::vector<par> G[maxn];
bool a[maxn], vis[maxn];
par edge[maxn];
bool ans[maxn];

void dfs(int u) {
	vis[u] = true;
	for(par p : G[u])
		if(not vis[p.first]) {
			dfs(p.first);
			if(a[p.first]) {
				a[u] ^= 1;
				a[p.first] ^= 1;
				ans[p.second] ^= 1;
			}
		}
}

int main() {
	int n = input(), m = input();
	for(int i = 1; i <= m; i ++) {
		int u = input(), v = input();
		G[u].push_back(par(v, i));
		G[v].push_back(par(u, i));
		edge[i] = par(u, v);
		a[u] ^= 1;
	}
	dfs(1);
	if(a[1])
		puts("-1");
	else {
		for(int i = 1; i <= m; i ++) {
			if(ans[i]) std::swap(edge[i].first, edge[i].second);
			printf("%d %d\n", edge[i].first, edge[i].second);
		}
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#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, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, k, c;
  cin>>n>>k>>c;
  string s;
  cin>>s;
  vi cnd;
  int cur;
  REP(i, n){
    if(s[i]=='o'){
      cnd.push_back(i);
      cur=i+c+1;
      break;
    }
  }
  int cnt=0;
  while(cur<n){
    while(cur<n && s[cur]=='x'){
      ++cur;
    }
    if(cur<n){
      cnd.push_back(cur);
      cur+=c+1;
      ++cnt;
      if(cnt>=k){
        break;
      }
    }
  }
  vi cndd;
  FORR(i, 0, n){
    if(s[i]=='o'){
      cndd.push_back(i);
      cur=i-(c+1);
      break;
    }
  }
  cnt=0;
  while(cur>=0){
    while(cur>=0 && s[cur]=='x'){
      --cur;
    }
    if(cur>=0){
      cndd.push_back(cur);
      // DEBUG(cur);
      cur-=c+1;
      ++cnt;
    }
  }
  // DEBUG_VEC(cnd);
  // DEBUG_VEC(cndd);
  REP(i, k){
    if(cnd[i]==cndd[k-1-i]){
      cout<<cnd[i]+1<<'\n';
    }
  }
  return 0;
}


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

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

fn keta_sum(i:u32) -> u32 {
    let s: &str = &format!("{}", i); 
    s.chars().map(|c|c as u32 - 48).sum()
}

fn main() {
    let vec : Vec<u32> = (0..3).map(|_| read()).collect();
    let ans : u32 = (1..vec[0] + 1).filter(|i| keta_sum(*i) >= vec[1] && keta_sum(*i) <= vec[2]).sum();
    println!("{}", ans);
}


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

const double eps = 1e-9;
bool same(double a, double b) { return abs(a - b) < eps; }

struct P {
    double x, y;
    P() : x(0), y(0) {}
    P(double x, double y) : x(x), y(y) {}
    P operator + (P b) { return P(x + b.x, y + b.y); }
    P operator - (P b) { return P(x - b.x, y - b.y); }
    P operator * (double b) { return P(x * b, y * b); }
    P operator / (double b) { return P(x / b, y / b); }
    double operator * (P b) { return x * b.x + y * b.y; }
    double operator ^ (P b) { return x * b.y - y * b.x; }
    double abs() { return hypot(x, y); }
    P unit() { return *this / abs(); }
    P spin(double o) {
        double c = cos(o), s = sin(o);
        return P(c * x - s * y, s * x + c * y);
    }
};

struct L {
    // ax + by + c = 0
    double a, b, c, o;
    P pa, pb;
    L() : a(0), b(0), c(0), o(0), pa(), pb() {}
    L(P pa, P pb) : a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb), o(atan2(-a, b)), pa(pa), pb(pb) {}
    P project(P p) { return pa + (pb - pa).unit() * ((pb - pa) * (p - pa) / (pb - pa).abs()); }
    P reflect(P p) { return p + (project(p) - p) * 2; }
    double get_ratio(P p) { return (p - pa) * (pb - pa) / ((pb - pa).abs() * (pb - pa).abs()); }
};

struct C {
    P c;
    double r;
    C() : r(0) {}
    C(P c, double r) : c(c), r(r) {}
};

bool parallel(L x, L y) { return same(x.a * y.b, x.b * y.a); }

P intersect(L x, L y) { return P(-x.b * y.c + x.c * y.b, x.a * y.c - x.c * y.a) / (-x.a * y.b + x.b * y.a); }

#define sq(x) ((x) * (x))
vector<P> intersect(C a, C b) {
    if (a.r > b.r) swap(a, b);
    double d = (a.c - b.c).abs();
    vector<P> ps;
    if (same(a.r + b.r, d)) ps.push_back(a.c + (b.c - a.c).unit() * a.r);
    else if (a.r + b.r > d && d + a.r >= b.r) {
        double o = acos((sq(a.r) + sq(d) - sq(b.r)) / (2 * a.r * d));
        P i = (b.c - a.c).unit();
        ps.push_back(a.c + i.spin(o) * a.r);
        ps.push_back(a.c + i.spin(-o) * a.r);
    }
    return ps;
}

int main() {
    C c[2];
    for (int i = 0; i < 2; ++i) cin >> c[i].c.x >> c[i].c.y >> c[i].r;
    vector<P> ps = intersect(c[0], c[1]);
    if (ps.size() == 1u) ps.push_back(ps[0]);
    if (ps[1].x < ps[0].x || (same(ps[0].x, ps[1].x) && ps[1].y < ps[0].y)) swap(ps[0], ps[1]);
    cout << fixed << setprecision(10) << ps[0].x << " " << ps[0].y << " " << ps[1].x << " " << ps[1].y << endl;
}



Measured memory_bytes: 3536
# coding: utf-8
# Here your code !
H,W=map(int,input().rstrip().split())
panel=[]
for i in range(H):
    panel.append([x for x in input().rstrip()])
    
#print(panel,flush=True)

def countBomb(y, x):
    cnt=0
    vec=[
        (0,-1),
        (1,-1),
        (1,0),
        (1,1),
        (0,1),
        (-1,1),
        (-1,0),
        (-1,-1)
    ]
    
    for tpl in vec:
        tmpX=x+int(tpl[0])
        tmpY=y+int(tpl[1])
        if(tmpX<0 or tmpY<0 or tmpX>=W or tmpY>=H):
            continue
        if(panel[tmpY][tmpX]=="#"):
            cnt+=1
    return cnt
            

result=[]
for i in range(H):
    row=[]
    for j in range(W):
        puts="#"
        if(panel[i][j]=="."):
            puts=countBomb(i,j)
        row.append(str(puts))
    #result.append(row)
    print("".join(row),flush=True)


Measured memory_bytes: 3064
// finish date: 2018/09/4
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N, K;
    cin >> N >> K;
    vi minus;
    vi plus;
    rep(i, N) {
        int x;
        cin >> x;
        if (x == 0) K--;
        if (x > 0) plus.push_back(x);
        else minus.push_back(-x);
    }
    reverse(minus.begin(), minus.end());
    if (K == 0) {
        cout << 0 << endl;
        return 0;
    }
    int mi = INT_MAX;
    rep(i, minus.size()) {
        if (i == K - 1) {
            mi = min(mi, minus[i]);
            break;
        }
        if (0 <= K - (i + 1) - 1 && K - (i + 1) - 1 < plus.size()) {
            mi = min(mi, minus[i] * 2 + plus[K - (i + 1) - 1]);
        }
    }

    rep(i, plus.size()) {
        if (i == K - 1) {
            mi = min(mi, plus[i]);
            break;
        }
        if (0 <= K - (i + 1) - 1 && K - (i + 1) - 1 < minus.size()) {
            mi = min(mi, plus[i] * 2 + minus[K - (i + 1) - 1]);
        }
    }

    cout << mi << endl;


    return 0;
}



Measured memory_bytes: 1020
#include<iostream>
#include<string>
#include<map>
#include<set>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s;
int n,flag,x,p;
char c;
map<char,int>m;
int bnf1();
int get_A(){
  int res=0;
  if(s[p]=='[')p++,res=bnf1(),p++;
  else res=m[s[p++]];
  return res;
}
int bnf1(){
  int res=get_A();
  while(s[p]=='-'){
    int t=p++;
    int x=get_A();
    if(x&&res)flag++;
    if(!x&&!res)flag++;
    res=max(res,x)-1;
  }
  return res;
}
int main(){
  cin>>s;
  set<char>st;
  r(i,s.size())if(isalpha(s[i]))st.insert(s[i]);
  n=st.size();
  r(i,n){
    cin>>c>>x;
    m[c]=x;
  }
  if(bnf1()!=0)flag++;
  cout<<(flag?"No":"Yes")<<endl;
}

Measured memory_bytes: 3208
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-

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

for i in range(0, N):
    A[i] -= i

A.sort()

if len(A) % 2 == 0:
    bi = int(N / 2 - 1)
else:
    bi = int((N - 1) / 2)

#print("A:{}".format(A))
#print("bi:{}".format(bi))
#print("A[bi]:{}".format(A[bi]))

print(sum(map(lambda x: abs(x - A[bi]), A)))

Measured memory_bytes: 26128
# frozen_string_literal: true

$factors = Array.new
def factrize(n)
  (2..Math.sqrt(n)).each do |d|
    ex = 0
    while n % d == 0
      ex += 1
      n /= d
    end
    $factors << [d,ex]
  end
  if n != 1
    $factors << [n,1]
  end
end

n, p = gets.split.map(&:to_i)
ans = 1
factrize(p)
$factors.each do |factor|
  (1..factor[1] / n).each do
    ans *= factor[0]
  end
end

puts ans


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int main2() {
  int A, B, C; cin >> A >> B >> C;
  cout << min(C, B/A) << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    rep(i,N){
        cin >> A[i] >> B[i];
    }
    ll ans;
    sort(all(A));
    sort(all(B));
    if (N % 2 == 0){
        ll min_ans = A[N / 2] + A[N / 2 - 1];
        ll max_ans = B[N / 2] + B[N / 2 - 1];
        ans = max_ans - min_ans + 1;
    }
    else{
        ll min_ans = A[N / 2];
        ll max_ans = B[N / 2];
        ans = max_ans - min_ans + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6444
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

const int MAX = 500;
const int INF = 1e9;

int main(){
  int n,m;

  while(cin >> n >> m, n | m){
    map<string,int> mp;
    int dist[MAX+1][MAX+1];
    string a,b,start,goal,via;
    int c,d;

    for(int i = 0 ; i <= n ; i++){
      for(int j = 0 ; j <= n ; j++){
	dist[i][j] = INF;
      }
    }

    cin >> start >> via >> goal;

    int s = 1;
    for(int i = 0 ; i < m ; i++){
      cin >> a >> b >> c >> d;

      if(!mp[a]){
	mp[a] = s++;
      }
      if(!mp[b]){ 
	mp[b] = s++;
      }

      dist[mp[a]][mp[b]] = dist[mp[b]][mp[a]] = c / 40 + d;
    }
  
    for(int k = 1 ; k <= n ; k++){
      for(int i = 1 ; i <= n ; i++){
	for(int j = 1 ; j <= n ; j++){
	  dist[i][j] = min(dist[i][j] ,dist[i][k] + dist[k][j]);
	}
      }
    }

    cout << dist[mp[start]][mp[via]] + dist[mp[via]][mp[goal]] << endl;
  }

  return 0;
}

Measured memory_bytes: 2252
#include <iostream>
#include <string>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

int main()
{
    string X;
    cin >> X;
    int S = 0;
    int T = 0;
    long long sum = 0;
    REP(i,X.size()){
        if(X[i]=='S'){
            S++;
        }else if(X[i]=='T'){
            if(S>0){
                S--;
                sum++;
            }else{
                T++;
            }
        }
    }
    sum = S+T;
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back

void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}




struct UnionFind
{

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

  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }

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

  bool unite(int x, int y) {

    x = find(x);
    y = find(y);

    if (x == y) return false;

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

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

    return true;
  }

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

int n,m;
vector<vector<int>> v;

signed main(){
  cin>>n>>m;
  v.resize(m+1);
  rep(i,n){
    int k;
    cin>>k;
    rep(j,k){
      int l;
      cin>>l;
      v[l].EB(i);
    }
  }

  UnionFind uf(n);

  rep(i,m+1){
    FOR(j,1,v[i].size()){
      uf.unite(v[i][j-1],v[i][j]);
    }
  }

  if(uf.size(0)==n){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }

}


Measured memory_bytes: 4608