akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const long double pi = acos(-1.0);

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

  int n; cin >> n;
  vector<ll> a(n);
  bool zero = 0;
  rep(i, n) {
    cin >> a[i];
    if(a[i] == 0) {
      zero = 1;
    }
  }

  if(zero) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  ll bad = (ll)1e18;
  rep(i, n) {
    if(ans > (ll)1e9 && a[i] > (ll)1e9) {
      cout << -1 << endl;
      return 0;
    }

    ans *= a[i];
    if(ans > bad) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3992
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 233333;
int f,r,n,bel[N];Pii q[N<<3];
multiset<int>e[N];map<int,int>Map[N];
void del(int u, int v){
	if(u>v)swap(u,v);Map[u][v]--;
	e[u].erase(e[u].find(v));e[v].erase(e[v].find(u));
}
void add(int u, int v){
	if(u>v)swap(u,v);Map[u][v]++;if(Map[u][v]>=2)q[r++]=Pii(u,v);
	e[u].insert(v);e[v].insert(u);
}
int find(int x){return bel[x]==x?x:bel[x]=find(bel[x]);}
int main() {
	read(n);
	rep(i,1,n)bel[i]=i;
	rep(i,1,n-1+n-1){
		int u,v;read(u);read(v);add(u,v);
	}
	rep(t,1,n-1){
		int x,y;
		while(1){
			if(f==r){puts("NO");return 0;}
			x=q[f].fi,y=q[f].se;f++;
			x=find(x);y=find(y);
			if(x!=y)break;
		}
	//	printf("merge %d %d\n",x,y);
		if(SZ(e[x])>SZ(e[y]))swap(x,y);//x-->y
		bel[x]=y;
		Vi rec;
		for(multiset<int>::iterator it=e[x].begin();it!=e[x].end();it++)rec.pb(*it);
		rep(i,0,SZ(rec)-1){
			del(x,rec[i]);if(rec[i]!=y)add(y,rec[i]);
		}
		
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 55040
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n, count = 0;
    cin >> n;
    int h[n];

    for(int i=0; i<n; i++){
	cin >> h[i];	
    }

    for(int i=0; i<n; ){
	if(h[i]>0){
	    count++;
	    for(int j=i; j<n; j++){
		if(h[j]==0)
		    break;		
		h[j]--;
	    }
	}else
	    i++;
    }
    cout << count << "\n";
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
signed main() {
  	cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);
    LL N, H;
    cin >> N >> H;
    vector<LL> a(N), b(N);
    for(int i=0; i<N; i++) cin >> a[i] >> b[i];

    // 振り最強剣
    LL a_max = *max_element(all(a));
    // 強いものから投げる
    sort(all(b));
    reverse(all(b));
    LL ans = 0;
    for(int i=0; i<N; i++){
        if(a_max < b[i]){
            H -= b[i];
            ans++;
            // 投げで倒した
            if(H <= 0) break;
        }
    }
    // 剣を振りまくって倒す
    if(H > 0) ans += (H + (a_max-1)) / a_max;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

struct query{
    int s,t,x;
};

int main(){
    int n,q;
    cin >> n >> q;
    vector<query> que(n);
    rep(i,n) cin >> que[i].s >> que[i].t >> que[i].x;
    map<int,int> ans;
    set<int> st;
    rep(i,q){
        int d;
        cin >> d;
        ans[d] = -1;
        st.insert(d);
    }

    sort(que.begin(),que.end(),[](const query &l,const query &r){
        return l.x < r.x;
    });

    rep(i,n){
        int a = que[i].s - que[i].x;
        int b = que[i].t - que[i].x;
        auto it = st.lower_bound(a);
        
        if(*it >= b) continue;
        while(it != st.end()){
            ans[*it] = que[i].x;
            it = st.erase(it);
            if(it == st.end()) break;
            if((*it) >= b) break;
        }

    }

    for(auto p:ans) cout << p.second << endl; 

    return 0;
}

Measured memory_bytes: 23040
def print_format(N,input_list,count):
    for i in range(N):
        if i != N-1:
            print(input_list[i],end=" ")
        else:
            print(input_list[i])
    print(count)

def selection_sort(N,input_list):
    swap_count = 0
    for i in range(N):
        minj = i
        for j in range(i,N):
            if input_list[j] < input_list[minj]:
                minj = j
        if i != minj:
            swap_count += 1
        input_list[i],input_list[minj] = input_list[minj],input_list[i]
    return input_list,swap_count

def main():
    N = int(input())
    input_list = [int(i) for i in input().split()]
    input_list,count = selection_sort(N,input_list)
    print_format(N,input_list,count)

if __name__ == "__main__":
    main()


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

int main() {
int r;
cin >> r;
if(r<1200)cout << "ABC" << endl;
else if(r<2800)cout << "ARC" << endl;
else cout << "AGC" << endl;
}
  


Measured memory_bytes: 256
from sys import stdin
from heapq import heappop, heappush
manhattan = tuple([[abs((i % 4) - (j % 4)) + abs((i // 4) - (j // 4)) for j in range(16)] for i in range(16)])
movables = ((1, 4), (0, 2, 5), (1, 3, 6), (2, 7), (0, 5, 8), (1, 4, 6, 9), (2, 5, 7, 10), (3, 6, 11),
            (4, 9, 12), (5, 8, 10, 13), (6, 9, 11, 14), (7, 10, 15), (8, 13), (9, 12, 14), (10, 13, 15), (11, 14))
swap_mul = tuple([[(1 << mf) - (1 << mt) for mt in range(0, 64, 4)] for mf in range(0, 64, 4)])
destination = 0xfedcba9876543210
i = 0
board_init = 0
blank_init = 0
for _ in range(4):
    for n in map(int, stdin.readline().split()):
        if n:
            n -= 1
        else:
            n = 15
            blank_init = i
        board_init += n * 16 ** i
        i += 1
estimation_init = sum(manhattan[i][((board_init >> (4 * i)) & 15)] for i in range(16) if i != blank_init)
queue = [(estimation_init, board_init, blank_init)]
visited = set()
while True:
    estimation, board, blank = heappop(queue)
    if board in visited:
        continue
    elif board == destination:
        print(estimation)
        break
    visited.add(board)
    for new_blank in movables[blank]:
        num = (board >> (4 * new_blank)) & 15
        new_board = board + swap_mul[new_blank][blank] * (15 - num)
        if new_board in visited:
            continue
        new_estimation = estimation + 1 - manhattan[new_blank][num] + manhattan[blank][num]
        if new_estimation > 45:
            continue
        heappush(queue, (new_estimation, new_board, new_blank))

Measured memory_bytes: 163364
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Mon Feb 10 22:50:14 JST 2020
 **/

using pii = pair<Int, Int>;
signed main() {
    Int n, D, A; cin >> n >> D >> A;
    vector<pii> ps(n);
    REP(i, n) cin >> ps[i].first >> ps[i].second;
    sort(ps.begin(), ps.end());
    vector<Int> num(n);
    Int ptr = 0;
    Int ans = 0, cur = 0;
    REP(i, n) {
        while (ps[ptr].first + 2 * D < ps[i].first) {
            cur -= num[ptr] * A;
            ptr++;
        }
        Int rem = ps[i].second - cur;
        if (rem < 0) continue;
        num[i] = (rem + A - 1) / A;
        ans += num[i];
        cur += A * num[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<climits>
#include<string>
#include"math.h"
#include"string.h"

using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    if(strncmp(s.c_str(),t.c_str(),s.length())!=0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

int main(){

string str,p;
string order,temp;
int q,a,b;
cin>>str>>q; 


for(int l=0;l<q;l++){
    cin>>order>>a>>b;
if(order=="replace"){
    cin>>p;
    int j=0;
    for(int i=a;i<=b;i++){
str[i]=p[j];
j++;
    }
}else if(order=="reverse"){
    temp=str;
    int k=b;
     for(int i=a;i<=b;i++){
str[i]=temp[k];
k--;
    }
    
}else if(order=="print"){
    for(int i=a;i<=b;i++){
cout<<str[i];
    }
cout<<endl;

}

}



    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
ll N;ld p[3001];ld dp[3001][3001];
int main(){
      cin>>N;for(ll i=1;i<=N;i++)cin>>p[i];
      dp[0][0] = 1;
      for(ll i=1;i<=N;i++){
            for(ll j=0;j<=i;j++){
                  if(j==0)dp[i][j] = dp[i-1][j]*(1.0-p[i]);
                  else if(i==j)dp[i][j] = dp[i-1][j-1]*p[i];
                  else if(i!=j)dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1.0-p[i]);
            }
      }
      ld ans=0;
      for(ll i=N,j=0;i>j;i--,j++)ans += dp[N][i];
      cout<<setprecision(12);
      cout<<ans<<endl;
      return 0;
}


Measured memory_bytes: 139136
n,a,b=map(int,input().split())

c=10**9+7

nca=1
ncb=1

for i in range(a):
    nca*=(n-i)*pow(i+1,c-2,c)
    nca%=c

for i in range(b):
    ncb*=(n-i)*pow(i+1,c-2,c)
    ncb%=c

ans=pow(2,n,c)-1-(nca+ncb)

ans%=c

print(ans)

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

//input
int N;
double p[3030];

//dp table
double dp[3010][3010] = {0.0};

int main() {
    cin >> N;

    for (int i = 0; i < N; ++i) cin >> p[i];

    dp[0][0] = 1.0;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= i + 1; ++j) {
            if (j - 1 >= 0) {
                dp[i+1][j] += dp[i][j-1] * p[i];
            }
            dp[i+1][j] += dp[i][j] * (1 - p[i]);
        }
    }

    double ans = 0.0;

    for(int i = N / 2 + 1; i <= N; i++){
        ans += dp[N][i];
    }
    cout << setprecision(12) <<ans << endl;
    return 0;
}

Measured memory_bytes: 69120
#include<bits/stdc++.h>
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<string> vs;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<pair<string, ll> > vsi;
typedef set<ll> si;
typedef map<ll, ll> mii;
typedef map<string, ll> msi;
typedef tuple<ll, ll, ll> ti;
 
 
vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
 
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
 
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
 
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
 
 
#define pb push_back
#define mk make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define mod 1000000007
#define ff first
#define ss second
 
 
//Loops
#define REP(i, b) for(ll i=0; i<(ll)(b); i++)
#define F(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define FD(i, a, b) for(ll i=(ll)(a); i>=(ll)(b); i--)
 
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define RTIME(start, end) ((double)(end-start)/(double)CLOCKS_PER_SEC)
#define D(a) cout<<a<<endl
#define MAX 1000007
//#define INF 1e18
 
const ll nmax=1000*1007;
    

struct edge
{
    ll a, b, cost;
    edge(ll x, ll y, ll z):a(x), b(y), cost(z) {};
};
 
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);   
 
}
 

int main ()
{
    fastio()

    ll n;
    ld ans=0;
    cin>>n;
    vi v(n);
    REP(i, n)
        cin>>v[i];
    sort(all(v));
    ans=v[0];
    F(i, 1, n-1)
    {
        ans=(ans+(ld)v[i])/((ld)2);
    }

    cout<<fixed<<setprecision(10)<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define loop(i, a, n) for(ll i = (a); i < (n); i++)
#define dd(x) cout << #x << " : " << x << endl
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

ll get_goal(ll start, ll a[], const ll n){
    ll goal = start;
    ll cnt = 0;
    while(cnt < n){
        goal = a[goal];
        cnt++;
    }
    return goal;
}

P find_loop(ll a[], const ll n){
    ll vis[n];
    memset(vis, -1, sizeof(vis));
    ll now = 0;
    P info = {-1, -1};
    ll cnt = 0;
    while(cnt < n+1){
        if(vis[now] > -1) {
            info.first = now;
            info.second = cnt - vis[now];
            // dd(now); dd(cnt); dd(vis[now]);
            break;
        } else {
            vis[now] = cnt;
            cnt++;
        }
        now = a[now];
    }
    return info;
}

int main(){
    ll n; ll k; cin >> n >> k;
    ll a[n]; rep(i, n) {
        ll tmp; cin >> tmp;
        a[i] = --tmp;
    }

    P info = find_loop(a, n);
    ll ans = 0;
    ll now = 0;
    ll cnt = 0;
    bool flag = false;
    while(true){
        if(now == info.first) break;
        else if(cnt == k) {
            flag = true;
            break;
        }
        cnt++;
        now = a[now];
    }
    if(flag) ans = now;
    else {
        k -= cnt;
        ll true_k = k%info.second;
        // dd(cnt);
        // dd(true_k); dd(info.second); dd(info.first);
        ans = get_goal(now, a, true_k);
    }
    cout << ++ans << endl;


    return 0;
}

Measured memory_bytes: 6712
if __name__ == '__main__':
    S = str(input())
    Bases = ['A', 'T', 'G', 'C']
    len_max = 0
    len_start = 0
    for i, s in enumerate(S):
        if s not in Bases:
            len_max = max(len_max, i - len_start)
            len_start = i+1
    len_max = max(len_max, i - len_start+1)
    
    print(len_max)

Measured memory_bytes: 3060
// 12/07/2020  @ 19:54:17
// *****************************************************************
// *****************************************************************
#include <bits/stdc++.h>
// *****************************************************************
// *****************************************************************
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#define fr(i,n) for(llu i=0;i<n;i++)
#define fl(j,a,b) for(llu j=a;j<=b;j++)
#define Pi 3.1415926535897932384626
#define mod 1e9+7
#define MID(a,b) ((a + b) >> 1)
#define MAX(a,b) ((a) > (b) ? (a): (b))
#define MIN(a,b) ((a) < (b) ? (a) :(b))
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define printer(a, n) fr(i,n) cout << a[i] << " ";
// *****************************************************************
// *****************************************************************
typedef long long unsigned int llu;
typedef long long int ll;
// *****************************************************************
// *****************************************************************
using namespace std;
// *****************************************************************
// *****************************************************************

                   // Dream it. Wish it. Do it.

                         // tannatsri //

              // Without tact you can learn nothing.

// *****************************************************************
// *****************************************************************
bool rev(ll a, ll b) {
    return a > b;
}
// *****************************************************************
void solution() {
	long double n;
	cin >> n ;
	cout << 2.000 * 3.1415926535897932384626* (n * 1.0);
}
// *****************************************************************
int main() {
    IOS;
    // #ifndef ONLINE_JUDGE
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/input.txt", "r", stdin);
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/output.txt", "w", stdout);
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/error.txt", "w", stderr);
    // #endif
    // *****************************************************************
    // *****************************************************************
    int t = 1;
    // cin >> t;
    while(t--) {

       solution();
       cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n;
llint a[100005];
bool used[200005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint ans = a[1]-1, mx = 1;
	for(int i = 2; i <= n; i++){
		if(a[i] <= mx) continue;
		if(a[i] == mx+1){
			mx++;
			continue;
		}
		ans += a[i]/(mx+1);
		if(a[i] % (mx+1) == 0) ans--;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int n; cin >> n;
  vector<string> s(n);
  rep(i, n) {
    cin >> s.at(i);
  }

  int str[n][26];
  rep(i, n) {
    rep(j, 26) {
      str[i][j] = 0;
    }
  }

  rep(i, n) {
    for(char c : s.at(i)) {
      str[i][c - 'a']++;
    }
  }

  vector<int> ans(26);
  rep(i, 26) {
    ans.at(i) = INT_MAX;
    rep(j, n) {
      ans.at(i) = min(ans.at(i), str[j][i]);
    }
  }

  rep(i, 26) {
    while (ans.at(i) > 0) {
      cout << (char)('a' + i);
      ans.at(i)--;
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,n;
int main(){
	cin>>a>>b;
	if(b==100)n=1000;
	if(b>=10&&b<100)n=100;
	if(b<10)n=10;
	a=a*n+b;
	for(int i=1;i*i<=a;i++)if(i*i==a){cout<<"Yes"<<endl;return 0;}
	cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	vector<int> ans;

	while(true){
		int n, k;
		cin >> n >> k;

		if(n == 0 && k == 0) break;

		vector<int> input;
		rep(i, n){
			int a;
			cin >> a;
			input.push_back(a);
		}

		vector<int> cumu;
		cumu.push_back(0);

		rep(i, n){
			cumu.push_back(cumu[i] + input[i]);
		}

		int sumMax = 0;
		rep(i, n){
			if(n < i + k) break;

			if(sumMax < cumu[i + k] - cumu[i]) sumMax = cumu[i + k] - cumu[i];
		}

		ans.push_back(sumMax);
	}

	rep(i, ans.size()){
		cout << ans[i] << endl;
	}

	return 0;
}


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

int main(){
  string S;
  cin>>S;
  int count=0;
  
  for(int i=0;i<S.size();i++){
    count+=S.at(i)-'0';
  }
  
  if(stoi(S)%count==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
# AOJ 1074: Popularity Estimation
# Python3 2018.7.10 bal4u

while True:
	n = int(input())
	if n == 0: break
	f, tbl = [0]*31, []
	for i in range(n):
		a = input().split()
		nm = a.pop(0)
		m = int(a.pop(0))
		d = list(map(int, a))
		tbl.append([0, nm, d])
		for i in d: f[i] += 1
	for i in range(n):
		for j in tbl[i][2]: tbl[i][0] += n-f[j]+1
	tbl.sort(key=lambda x:(x[0],x[1]))
	print(tbl[0][0], tbl[0][1])



Measured memory_bytes: 5624
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    vector<int> dp(n);
    int ans = -1;
    for (int i = 0; i < n; ++i) {
        ans--;
        if(!v[i]) ans = INF<int>;
        else if(v[i] < 0){
            ans = min(ans, -v[i]);
        }else {
            dp[i] = max(dp[i], min(v[i], ans));
        }
    }
    ans = -1;
    for (int i = n-1; i >= 0; --i) {
        ans--;
        if(!v[i]) ans = INF<int>;
        else if(v[i] < 0){
            ans = min(ans, -v[i]);
        }else {
            dp[i] = max(dp[i], min(v[i], ans));
        }

    }
    cout << accumulate(dp.begin(),dp.end(), 0) << "\n";
    return 0;
}


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

int main() {
  int N, K, x;
  int sum = 0;
  cin >> N >> K;
  
  for (int i = 0; i<N; i++) {
    cin >> x;
    if (x <= K-x)
      sum += 2*x;
    else
      sum += 2*(K-x);
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
ABCD = list(map(int, input()))


def D2NC(D: int, N: int) -> list:
    res = []
    while D > 0:
        res.insert(0, D % N)
        D //= N
    if not res:
        res.append(0)
    res = [str(i) for i in res]
    return res


for i in range(2**3):
    pattern = ''.join(D2NC(i, 2)).zfill(3)
    ans = ABCD[0]
    idx = 0
    op = []
    for j in pattern:
        if j == '0':
            ans += ABCD[idx+1]
            op.append('+')
        else:
            ans -= ABCD[idx+1]
            op.append('-')
        idx += 1
    if ans == 7:
        break

A, B, C, D = ABCD
op_1, op_2, op_3 = op
print('{}{}{}{}{}{}{}=7'.format(A, op_1, B, op_2, C, op_3, D))


Measured memory_bytes: 3064
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n;
    pair<ll,ll> ab[200010];
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        ll t,d;
        std::cin >> t>>d;
        ab[i] = {d,t};
    }
    ll now = 0;
    sort(ab,ab+n);
    for (int i = 0; i < n; i++) {
        if( now+ab[i].second <= ab[i].first ){
            now+= ab[i].second;
        }else{
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
    
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int dp[2002002]={};
int main(){
    fast_io
    
    int W, a, b;
    cin>>W>>a>>b;
    int ans;
    if(a+W<b) ans=b-(a+W);
    else if(b+W<a) ans=a-(b+W);
    else ans=0;
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    
    long long N,A,B;
    cin >> N >> A >> B;
    
    if(A%2!=B%2)cout << min(A-1,N-B)+1+(B-A-1)/2 <<endl;
    else cout << abs(A-B)/2 <<endl;
}
    
    



Measured memory_bytes: 256
#include <iostream>

const int N = 5000 + 7;

int n;
int a[N], b[N];
int xa[3], xb[3];
int ans;

int abs(int x) {
	return x < 0 ? -x : x;
}
void calc(int x, int y) {
	if (x < 0 || y < 0) return;
	int cur = 0;
	for (int i = x, j = y; i < n || j < n; ) {
		if (i < n && a[i] == -1) { ++i; continue; }
		if (j < n && b[j] == -1) { ++j; continue; }
		cur += abs(i - j), i += i < n, j += j < n;
	}
	for (int i = x - 1, j = y - 1; i > 0 || j > 0; ) {
		if (i > 0 && a[i] == -1) { --i; continue; }
		if (j > 0 && b[j] == -1) { --j; continue; }
		cur += abs(i - j), i -= i > 0, j -= j > 0;
	}
	ans = std::min(ans, cur);
}

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%1d", a + i);
	for (int i = 1; i <= n; ++i) scanf("%1d", b + i);
	for (int i = 1; i <= n; ++i)
		ans += abs(a[i] - b[i]);
	if (ans && n > 2) ans = 1 << 29;
	for (int i = 1; i < n; ++i)
		a[i] = a[i] == a[i + 1] ? -1 : a[i],
		b[i] = b[i] == b[i + 1] ? -1 : b[i];
	xa[0] = xa[1] = xb[0] = xb[1] = -1;
	for (int i = n; i; --i) {
		if (a[i] != -1) xa[a[i]] = i;
		if (b[i] != -1) xb[b[i]] = i;
	}
	for (int i = 1; i < n; ++i) {
		if (a[i] != -1) calc(i, xb[a[i]]);
		if (b[i] != -1) calc(xa[b[i]], i);
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int n,u=1;
  cin>>n;
  int c=n,n_d=0;
  while(c>0){
    n_d++;
    c=c/10;
  }
  int sum=0,k=1;
  for(int i=1;i<=n_d-1;i++){
    if(i%2==1){
      sum=sum+(9*k);
    }
    k=k*10;
  }
  if(n_d%2==1){
    for(int i=1;i<=n_d-1;i++)
      u=u*10;
    sum=sum+n-u+1;
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
   

  int main(){      
    lint h,w;
    cin>>h>>w;
    lint c[10][10];
    rep(i,10){
        rep(j,10){
            cin>>c[i][j];
        }
    }
    rep(k,10){
        rep(i,10){
            rep(j,10){
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    lint ans=0;
    rep(i,h*w){
            lint x;
            cin>>x;
            if(x==-1)continue;
            ans+=c[x][1];
    }
    cout<<ans<<endl;
  }
          
  

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



int main(){
     int a,b,c;
     cin >> a >>b >>c;
     int k;
     cin >> k;
     vector<int> s(3);
     s[0] =a , s[1] =b, s[2]=c;
     sort(s.begin(),s.end());
     rep(i,k){
         s[2]=s[2]*2;
     }
     int count =0;
     rep(i,3) count += s[i];
     cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
int main()
{
  int n,a,b;
  string str,ch,p;
  char c;
  cin>>str;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>ch;
    if(ch=="replace"){
      cin>>a>>b>>p;
      for(int j=a,k=0;j<=b;j++,k++)str[j]=p[k];
    }
    if(ch=="reverse"){
      cin>>a>>b;
      for(int j=a,k=b;j<(a+b+1)/2;j++,k--){
    swap(str[j],str[k]);
      }
    }
    if(ch=="print"){
      cin>>a>>b;
      for(int j=a;j<b+1;j++)cout<<str[j];
      cout<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3224
#include <stdio.h>
 
int main(){
    int n;
    scanf("%d",&n);
    int min=1001,max=-1,t;
    while(n--){
        scanf("%d",&t);
        if(t<min) min=t;
        if(t>max) max=t;
    }
    printf("%d\n",max-min);
    return 0;
}

Measured memory_bytes: 760
# bitDP(集合を数に変換して状態(=添字)として持つようなDPのこと)
# dp[i][S]=(男性はi人目までで、既にペアになった女性の集合がSであるような場合の数)
# 「既にペアになった女性の集合がS」なら「bitpopcount(S)人目までをチェックした」ってことになるから、iを状態として持つ必要は無いことがわかる
import sys
input = sys.stdin.readline
mod=10**9+7
def main():
    n=int(input())
    a=[list(map(int,input().split())) for i in range(n)]
    dp=[0]*(1<<n)
    dp[0]=1
    for i in range(1,1<<n):
        k=bin(i).count("1")
        for j in range(n):
            if i>>j&1 and a[k-1][j]:
                dp[i]+=dp[i^(1<<j)]
        dp[i]%=mod
    print(dp[(1<<n)-1])
main()

Measured memory_bytes: 57452
import math

# 標準入力
A,B,H,M=map(int,input().split())

# 角度の差が出る
A_RAD = float((H*60+M)/720*2*math.pi)
B_RAD = float(M/60*2*math.pi)
AB_RAD = A_RAD - B_RAD

C = math.sqrt(A**2+B**2-2*A*B*math.cos(AB_RAD))

print(C)


Measured memory_bytes: 9492
while True:
  H,M=map(int,input().split())
  if H == 0 and M == 0:
    break
  else:
    for i in range(H):
      if i == 0 or i == H - 1:
        print('#'*M)
      else:
        print('#'+'.'*(M-2)+'#')
    print('')

Measured memory_bytes: 7580
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

static const int INF = 10010010;

int main(){

  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> HP(100, INF);

  REP(i,n) cin >> x[i];

  for(int p = 1; p <= 100; ++p){
    HP[p] = 0;
    REP(i,n){
      HP[p] += (x[i] - p)*(x[i] - p);
    }
  }

  sort(ALL(HP));

  cout << HP[0] << endl;
  return 0;
}

Measured memory_bytes: 3592
#!/usr/bin/env python3
import sys

def solve(N: int, A: "List[int]"):
    max_a = max(A)
    arr = [0] * (max_a + 1)
    for a in A:
        arr[a] += 1

    counter = 0
    for x in range(1,max_a+1):
        if arr[x] == 1:
            counter += 1
        if arr[x]:
            for j in range(x*2,max_a+1,x):
                arr[j] = 0
    print(counter)

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 102144
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>

#define int long long

using namespace std;

void Main()
{
	int A, B, C;
	cin >> A >> B >> C;
	cout << max(0LL, C - (A - B)) << endl;
}
 
int32_t main()
{
	Main();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
const ll maxn=4e2+5;
ll n,a[maxn],dp[maxn][maxn],s[maxn];
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    rep(i,1,n+1) cin>>a[i];
    rep(i,1,n+1) s[i]=a[i]+s[i-1];
    memset(dp, 0x3f, sizeof dp);
    rep(i,1,n+1) dp[i][i]=0;
    per(i,1,n+1)
        rep(j,i+1,n+1)
            rep(k,i,j)
                dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]+s[j]-s[i-1]);
    cout<<dp[1][n]<<"\n";
}


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

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

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

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




#define int long long
#define rng(i,l,r) for(size_t i=(l);i<(r);++i)
#define rep(i,n) rng(i,0,n)
#define gnr(i,l,r) for(size_t i=(r)-1;i>=(l);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()   //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend()//...,3,2,1

using namespace std;
//using ll = long long;


const int MOD = 1000000007;
const int INF = 1e18;

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

const double pi = acos(-1);



template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


using Graph = vector<vector<int>>;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//*max_element(ALL(vector))
//count(ALL(vector),num) -> n




void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

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

    int x; cin >> x;
    
    int ans = 0;
    int now = 100;
    while(now<x){
        now *= 1.01;
        ans++;
    }
    
    cout << ans << endl;
    
    
    
    
}



signed main() {
    solve();
    return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define pii pair<int, int>

const int N = 17;
int n, A[N];
std::vector<std::pii> vec[N];
bool is[N];

int get(int x) {
	int ans = 0;
	while (x) {
		ans++;
		x &= (x - 1);
	}
	return ans;
}

bool check() {
	for (int i = 0; i < n; i++) if (is[i]) {
		for (int j = 1; j <= A[i]; j++) {
			if (vec[i][j].second == 1 && !is[vec[i][j].first]) return false;
			if (vec[i][j].second == 0 && is[vec[i][j].first]) return false;
		}
	}
	return true;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", A + i);
		vec[i].resize(A[i] + 1);
		for (int j = 1; j <= A[i]; j++) {
			scanf("%d%d", &vec[i][j].first, &vec[i][j].second);
			vec[i][j].first--;
		}
	}
	int ans = 0;
	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < n; j++) {
			if (i >> j & 1) is[j] = 1;
			else is[j] = 0;
		}
		if (check()) ans = std::max(ans, get(i));
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
std::vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
ll n,r,ans=0;
std::vector<int> h;
int main(){
  cin >> n;
  h.resize(n);
  for (size_t i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (size_t l = 0; l < n; l++) {
    while (h[l] != 0) {
      for (r = l+1; r < n; r++)if(h[r] == 0)break;
      for (size_t a = l; a < r; a++)h[a]--;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

X, Y, Z = i_l()

X, Y = Y, X
X, Z = Z, X

print(X, Y, Z)

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

import sys

def main():
    N = int(input())
    A = list(map(int, input().split()))
    dic_Lg = {}
    dic_Lw = {}
    for i in range(N):
        x = i - A[i]
        if x in dic_Lg:
            dic_Lg[x]+=1
        else:
            dic_Lg[x]=1
        y = i + A[i]
        if y in dic_Lw:
            dic_Lw[y]+=1
        else:
            dic_Lw[y]=1
    LP = list(dic_Lw.keys()) + list(dic_Lg.keys())
    LP = set(LP)
    ret = 0
    for i in LP:
        if i in dic_Lg and i in dic_Lw:
            ret += dic_Lg[i] * dic_Lw[i]
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 85616
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int findsumofDigits(int n){
        int sum = 0;
        while(n >0){
            sum += n%10;
            n /= 10;
        }
        return sum;
    }

int main()
{
    long n,ans;
    cin >> n;
    ans = 0;
    std::vector<long> vec(3*n);
    for(int i = 0; i < 3*n; i++)
    {
        cin >> vec[i];
    }

    sort(vec.begin(),vec.end(),greater<int>());

    
    for(int i = 0 ; 1 + 2*i < 2*n ; i++)
    {
        ans += vec[1 + 2*i];
    }
    
    cout << ans << endl;
    

}



Measured memory_bytes: 2560
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<numeric>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a)   a.begin(),a.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
    //
    ModInt operator++(int) {
        auto t = *this;
        *this += 1;
        return t;
    }

    ModInt operator--(int) {
        auto t = *this;
        *this -= 1;
        return t;
    }
    ModInt operator<<(const int n){
        return ModInt(*this)*ModInt(2).pow(n);
    }
    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void d(){
    ll N; cin >> N;
    auto A = v<>(N,0);
    rep(i,N) cin >> A[i];
    auto dp = v<>(N,0);
    rep(i,N){
        dp[0]+=A[i]*pow(-1,i%2);
    }
    dp[0]/=2;
    dp[N-1] = A[N-1]-dp[0];
    rep(i,N-2)dp[i+1]=A[i]-dp[i];
    rep(i,N) cout << 2*dp[i] << " ";
}
int main(){
    d();
    return 0;
}

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

const int maxn = 2e5 + 5;
int a[maxn];

int main()
{
	int n;	cin >> n;
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i];
		a[i] -= i;
	}
	sort(a + 1, a + n + 1);
	int b = a[n / 2 + 1];
	long long ans = 0;
	for(int i = 1; i <= n; i ++)
		ans += abs(a[i] - b);
	cout << ans << endl;
}

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

int n, fir[1 << 18], sec[1 << 18];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < 1 << n; i++) {
        scanf("%d", &fir[i]);
    }
    auto upd = [&](int pos, int val) {
        if (val > fir[pos]) sec[pos] = fir[pos], fir[pos] = val;
        else if (val > sec[pos]) sec[pos] = val;
    };
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 1 << n; j++) if (!(j >> i & 1)) {
            upd(j | (1 << i), fir[j]), upd(j | (1 << i), sec[j]);
        }
    }
    int lst = 0;
    for (int i = 1; i < 1 << n; i++) {
        lst = max(lst, fir[i] + sec[i]);
        printf("%d\n", lst);
    }
    return 0;
}

Measured memory_bytes: 5120
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>


//Hang in there!

using namespace std;


int main() {
	double N;
	cin >> N;
	int ans = 0;
	while (N > 1) {
		N = ceil(N / 3);
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;

	set<string> s;
	rep(i, 0, N) {
		string S; cin >> S;
		s.insert(S);
	}
	cout << s.size() << endl;
}







Measured memory_bytes: 19204