akhauriyash/Code-Regression huggingface dataset:
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
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; }
template<class T> inline T int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif


int dp[2001];

int solve(int num){
	if(dp[num] != -1) return dp[num];
	if(num == 0) return 1;
	if(num < 3) return 0;
	int sum = 0;
	rep(i, num-2){
		sum = (sum + solve(num - i - 3) ) % MOD;
	}
	return dp[num] = sum;
}

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	memr(dp, -1);
	int S; cin >> S;

	cout << solve(S) << endl;

	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
const int MAX = 10000000;
const int MOD = 1000000007;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll comb(ll n,int a){
    ll num = 1;
    for(int i = 0;i < a;i++){
        num *= (n - (ll)i);
        num %= MOD;
    }

    return (num * finv[a]) % MOD;
}

ll pow2_mod(ll n){
    ll ans = 1;
    if(n == 0)return 1;
    else if(n % 2 == 0){
        ll t = pow2_mod(n/2);
        return t * t % MOD;
    }
    return 2LL * pow2_mod(n-1);
}

int main(){
    COMinit();
    ll n;
    cin >> n;
    int a,b;
    cin >> a >> b;

    ll all_com = (pow2_mod(n) - 1 + MOD) % MOD;
    ll ans = (all_com - comb(n,a) - comb(n,b) + 2 * MOD) % MOD;

    cout << ans << endl;
}

Measured memory_bytes: 234752
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef long long ll;
const ll INF = 1e18L + 1;

int main()
{
  int n, m;
  map<int, int> mp;
  cin >> n >> m;
  rep(i, m)
  {
    int s, c;
    cin >> s >> c;
    if (mp.find(s) != mp.end() && mp.find(s)->second != c)
    {
      cout << -1 << endl;
      return 0;
    }
    else
      mp[s] = c;
  }

  int ans = 0;
  for (auto it = mp.begin(); it != mp.end(); it++)
  {
    if ((n != 1 && it->first == 1 && it->second == 0))
    {
      cout << -1 << endl;
      return 0;
    }
    ans += it->second * pow(10, n - it->first);
    // ans *= pow(10, n - it->first);
  }

  if (ans < pow(10, n - 1))
  {
    if (n != 1)
      ans += pow(10, n - 1);
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}




void test_case() {

    int n,k;
    cin>>n>>k;

    int ans = 0;
    while (n)
    {
        ans++;
        n=n/k;
    }

    cout<<ans<<endl;
    






}


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

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


    int t = 1;
    //cin >> t;
    while(t--)
    {   
        test_case();
    }
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N;  cin >> N;
    map<ll,ll> count;
    ll ans = 0;
    for(int i = 0 ; i <= 100000 ; i++)  count[i] = 0;
    for(int i = 0 ; i < N ; i++){
      int a;  cin >> a;
      count[a] += 1;
      ans += a;
    }

    int Q;  cin >> Q;
    for(int i = 0 ; i < Q ; i++){
      int B, C;  cin >> B >> C;
      ans = ans - B*count[B] + C*count[B];
      count[C] += count[B];
      count[B] = 0;

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

Measured memory_bytes: 9936
/*
* author: pavveu
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int,int>;
using graph = vector<vi>;

#define FOR(name__, upper__) for (int name__ = 0; name__ < (upper__); ++name__)
#define all(x) begin(x), end(x)
#define mp make_pair
#define mt make_tuple

template<class T>
void initialize_matrix(vector<vector<T>>& matrix, int rows, int cols, T value) {
	assert(matrix.empty());
	FOR (row, rows) 
		matrix.emplace_back(cols, value);
}

void dfs(graph& adj, int u, vi& vis) {
	vis[u] = 1;
	for (int v : adj[u]) {
		if ( !vis[v] ) 
			dfs(adj, v, vis);
	}	
}

void go() {
	int V,E;
	cin >> V >> E;

	graph adj(V);
	FOR(e, E) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].emplace_back(v);
		adj[v].emplace_back(u);
	}

	vi vis(V, 0);
	int cc = 0;
	FOR(u, V) {
		if ( !vis[u] ) {
			dfs(adj, u,vis);
			cc++;
		}
	}
	cout << cc - 1 << endl;
}

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

	go();

	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<ll> l(n);
    rep(i, n) cin >> l[i];
    int ans = 0;
    for (int i = 0; i < n-2; i++) {
        for (int j = i+1; j < n-1; j++) {
            if (l[i] == l[j]) continue;
            for (int k = j+1; k < n; k++) {
                if (l[i] == l[k]) continue;
                if (l[j] == l[k]) continue;
                ll maxEdge = 0;
                maxEdge = max(l[i], l[j]);
                maxEdge = max(maxEdge, l[k]);
                if ((l[i]+l[j]+l[k]) > 2*maxEdge) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt();
            var N = line[0];
            var K = line[1]-1;
            var x = consoleReader.SplitInt();

            if (K == 0)
            {
                return x.Min(Math.Abs);
            }

            var min = int.MaxValue;
            for (int i = 0; i < N - K; i++)
            {
                if (x[i + K] <= 0)
                {
                    min = Math.Min(min, -x[i]);
                }
                else if (x[i] >= 0)
                {
                    min = Math.Min(min, x[i + K]);
                    break;
                }
                else
                {
                    min = Math.Min(min, x[i + K] - x[i] + Math.Min(x[i + K], -x[i]));
                }
            }
            return min;
        }

        public const int mod = 1000000007;
        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc()); static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

    #region Console
    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int() => int.Parse(String()); public long Long() => long.Parse(String()); public ulong ULong() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt() => String().Split().Select(int.Parse).ToArray(); public long[] SplitLong() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitULong() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt(int count) { for (int i = 0; i < count; i++) yield return Int(); } public IEnumerable<long> RepeatLong(int count) { for (int i = 0; i < count; i++) yield return Long(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt(int count) { for (int i = 0; i < count; i++) yield return SplitInt(); } }
    #endregion
}

Measured memory_bytes: 21472
ri = lambda S: [int(v) for v in S.split()]

S = [ri(input()) for _ in range(3)]
N = int(input())
D = set()
O = set()

def mark(A, v):
    for i in range(3):
        for j in range(3):
            if A[i][j] != 0 and A[i][j] == v:
                A[i][j] = 0
                if (i, j) in [(0, 0), (1, 1), (2,2)]:
                    D.add((i,j))
                if (i, j) in [(0, 2), (1, 1), (2, 0)]:
                    O.add((i, j))

for _ in range(N):
    b = int(input())
    mark(S, b)

R = [sum(r) for r in S]
C = [sum(r) for r in zip(*S)]



check = len(D) == 3 or len(O) == 3 or any(v == 0 for v in R) or any(v == 0 for v in C)

print("Yes" if check else "No")


Measured memory_bytes: 9136
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
//typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define P pair<int,int>

int main() {
	int INF = 1000000000;
	int V, E, start;
	cin >> V >> E >> start;
	vector<vector<P>>G(V);
	rep(i, E) {
		int s, t, d;
		cin >> s >> t >> d;
		G[s].push_back(mp(t, d));
	}
	vector<int>dist(V, INF);//startからの距離を入れる配列。INF(未訪問)で初期化
	dist[start] = 0;
	priority_queue<P, vector<P>, greater<P>>que;//少ない値を優先するプライオリティキューを宣言
	que.push(mp(dist[start], start));

	while (!que.empty()) {
		P p = que.top();
		int v = p.second;
		que.pop();
		if (dist[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			P e = G[v][i];
			int u = e.first, cst = e.second;
			if (dist[u] > dist[v] + cst) {
				dist[u] = dist[v] + cst;
				que.push(mp(dist[u], u));
			}
		}
	}
	rep(i, V) {
		if (dist[i] == INF) {
			cout << "INF" << endl;
		}
		else {
			cout << dist[i] << endl;
		}
	}
}


Measured memory_bytes: 12964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    ll K;
    cin >> K;
    ll X = 7;
    for (int i = 1; i <= 10000000; i++) {
        if (X % K == 0) {
            cout << i << endl;
            return 0;
        }
        X = (X*10+7)%K;
    }
    puts("-1");
}

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



void Main() {
    // input
    u_int32_t N;
    cin >> N;
    
    vector<u_int32_t> nums(N);
    for (u_int32_t i = 0; i < N; i++) {
        cin >> nums[i];        
    }
    
    sort(nums.begin(), nums.end());
    for (u_int32_t i = 0; i < N - 1; i++) {
        if (nums[i] == nums[i+1]) {
            cout << "NO" << endl;
            return;
        }
    }

    cout << "YES" << endl;
    return;
}

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


Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
int main(){
    string d[3];
    cin>>d[0]>>d[1]>>d[2];
    int n=0;
    while(1){
        int t=n;
        if(d[n].size()==0)break;
        t=d[n][0]-'a';
        d[n].erase(d[n].begin());
        n=t;
    }
    cout<<(char)('A'+n)<<endl;
    return 0;
}

Measured memory_bytes: 764
def check(arr):
    for i in arr:
        if(i % 2 ==0):
            if(i % 3!=0 and i % 5!=0):
                return "DENIED"
    return "APPROVED"

n=int(input())
arr=list(map(int,input().strip().split()))[:n]
k=check(arr)
print(k)

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

int main() {
  string s; cin >> s;
  int n = s.length();
  int ans = n-1;
  for (char c = 'a'; c <= 'z'; c++) {
    	int res = 0;
  		for (int i = 0; i < n; i++) {
        	int j = i;
          	while (j<n && s[j] != c) j++;
          	res = max(res,j-i);
        }
    	ans = min(ans,res);
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main(){

    long long int n;

    cin >>n;

    long long int l=n/15;
    long long int m=n%15;

    long long int a[15]={1+15*l,2+15*l,0,4+15*l,0,0,7+15*l,8+15*l,0,0,11+15*l,0,13+15*l,14+15*l,0};

    long long int s=0;

    for(int i=0;i<m;i++)s+=a[i];


    cout << 60*l*l+s <<endl;


}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=100000;
long long INF=1000000000000000000;
int main()
{
  int n,i;
  long long res=1,a[N_MAX];
  double m=INF;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a[i];
    if(a[i]>0)
      m/=a[i];
  }
  sort(a,a+n);
  if(a[0]==0){
    res=0;
  }else if(m<0.2){
    res=-1;
  }else{
    for(i=0;i<n;i++)
      res*=a[i];
    if(res>INF)
      res=-1;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll n;
    cin >> n;
    ll x[n];
    rp(i, 0, n) cin >> x[i];
    ll xx[n];
    rp(i, 0, n) xx[i] = x[i];
    sort(xx, xx + n);
    ll le = xx[n / 2 - 1], ri = xx[n / 2];
    rp(i, 0, n)
    {
        if (x[i] < ri)
        {
            ce(ri);
        }
        else
        {
            ce(le);
        }
    }
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> A(N);
    rep (i, N) {
        cin >> A[i];
    }

    ll sum = 0;
    ll ans = 0;
    rep (i, N) {
        if (A[i] != 0) {
            sum += A[i];
        } else {
            ans += sum/2;
            sum = 0;
        }
    }

    if (sum) {
        ans += sum/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (h == 0 && w == 0) break;
            for (int j = 0; j < h; j++) {
                for (int i = 0; i < w; i++) {
                    System.out.print("#");

                }
                System.out.println();
            }
            System.out.println();
            
        }
    }
}



Measured memory_bytes: 35520
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<s.length();i++)
        if(s[i]==t[i])ans++;
    cout<<ans;
    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 all(x) (x).begin(), (x).end()

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

    // start
    string s;
    cin >> s;
    cout << (s <= "2019/04/30" ? "Heisei" : "TBD") << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
N, X = map(int, input().split())
m_list = [int(input()) for i in range(N)]

min_sum = 0
for i in m_list:
    min_sum += i

min = m_list[0]
for i in m_list:
    if i < min:
        min = i

print(N + (X - min_sum)//min)

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

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

    int n, m;
    cin >> n >> m;

    vector<int> a(n), b(n), c(n);
    int r = n;

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

        int k = a[i] - b[a[i]]++;
        if (k >= 0) r -= c[k]++ == 0;
    }
    

    for (int j = 0; j < m; j++) {
        int x, y, k;
        cin >> x >> y;
        x--; y--;

        k = y - b[y]++;
        if (k >= 0) r -= c[k]++ == 0;

        k = a[x] - --b[a[x]];
        if (k >= 0) r += --c[k] == 0;

        a[x] = y;

        cout << r << '\n';
    }

    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int stones[101];
int steps[101];

int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	int pos = 0;
	for (int i = 0; i < N; ++i) {
		int stone;
		scanf("%d", &stone);
		if (i == 0) {
			steps[pos] = 0;
			stones[pos] = stone;
		}
		else {
			int m = 1000000001;
			for (int j = 1; j <= min(K, i); j++) {
				int tmp = abs(stone - stones[(pos - j + K) % K]) + steps[(pos - j + K) % K];
				m = min(m, tmp);
			}
			steps[pos] = m;
			stones[pos] = stone;
		}
		pos = (pos + 1) % K;
	}

	printf("%d\n", steps[(pos - 1 + K) % K]);
	//system("pause");
	return 0;
}


Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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(int argc, char const *argv[]) {
  string s; cin >> s;
  if(s=="ABC") puts("ARC");
  else puts("ABC");
  return 0;
}


Measured memory_bytes: 3604
#!/usr/bin/env python3
import sys
import numpy as np

def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    grid = np.zeros((H,W))
    for i in range(N):
        if a[i] == 1:
            grid[:,:x[i]] = 1
        elif a[i] == 2:
            grid[:,x[i]:] = 1
        elif a[i] == 3:
            grid[:y[i],:] = 1
        elif a[i] == 4:
            grid[y[i]:,:] = 1
    print(np.count_nonzero(grid==0))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    a = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12528
#include <iostream>

using namespace std;

int main() {
    long long x;
    cin >> x;

    long long r = x % 11;
    x /= 11;
    long long ans;

    if (r == 0) {
        ans = x * 2;
    } else if (r <= 6) {
        ans = x * 2 + 1;
    } else {
        ans = x * 2 + 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
object Main extends App {
    val list = readLine.split(" ").map{_.toInt}.toList
    def loop(restList: List[Int], acc: List[Int]): Unit = {
      restList match {
        case Nil => println("YES")
        case head :: tail if head == 7 => {
          if(acc.contains(7)) println("NO") else loop(tail, acc :+ head)
        }
        case head :: tail if head == 5 => {
          if(acc.count(x => x == 5) < 2 ) loop(tail, acc :+ head) else println("NO")
        }
        case _ => println("NO")
      }
    }
    loop(list, List.empty)
}

Measured memory_bytes: 27332
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  long long x;
  cin >> x;

  long long count = (x / (5 + 6)) * 2;
  if (x % (5 + 6) == 0) {}
  else if (x % (5 + 6) <= 6) count++;
  else count += 2;

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

string s;
bool f;
string func = "(),RL";
typedef pair<string, bool> psb;

string max_(string a, string b)
{

	if (a.size() > b.size()) return a;
	else if (a.size() < b.size()) return b;
	else return max(a, b);
}

pair<string, bool> solve(int l, int r)
{
	string tmp = s.substr(l, r - l);
	bool ff = true;
	REP(i, func.size())
	{
		if (tmp.find(func[i]) != string::npos) ff = false;
	}
	if (ff)
	{
		string res;
		if (tmp[0] == '0'&& tmp.size() > 1) return psb(res, false);
		FOR(i, l, r)
		{
			if (s[i] == '?') res.push_back('9');
			else res.push_back(s[i]);
		}
		return psb(res, true);
	}
	if  (r-l >= 6 &&
		(s[l] != 'R' || s[l] != 'L' || s[l] != '?') &&
		(s[l+1] == '(' || s[l+1] == '?') &&
		(s[r-1] == ')' || s[r-1] == '?'))
	{
		string res;
		FOR(i, l + 3, r - 2)
		{
			if (s[i] != ','&&s[i] != '?') continue;
			psb lhs = solve(l + 2, i);
			psb rhs = solve(i + 1, r - 1);
			if (lhs.second&&rhs.second)
			{
				string L = lhs.first, R = rhs.first;
				if (s[l] == 'R') res = max_(res, R);
				if (s[l] == 'L') res = max_(res, L);
				if (s[l] == '?')
				{
					res = max_(res, max_(R, L));
				}
			}
		}
		if (res == "") return psb(res, false);
		else return psb(res, true);
	}
	else return psb("", false);
}

int main()
{
	cin >> s;
	f = true;
	psb ans = solve(0, s.size());
	if (!ans.second) puts("invalid");
	else cout << ans.first << endl;
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vint a(N);
  rep(i, N) cin >> a[i];
  sort(all(a));
  cout << a[N-1]-a[0] << endl;

  return 0;
}


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

#define PI 3.14159265359
#define INF 1000000009
#define LINF 1000000000000000009
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

int dx[4] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1};
using namespace std; 

int main(void)
{
    string s;
    cin >> s;
    int n = s.size();

    v_int a(n+1);
    irep(i, n) {
        if(s[i] == '<') {
            a[i+1] = max(a[i+1], a[i]+1);    
        }
    }
    
    irep(i, n) {
        if(s[n-i-1] == '>') {
            a[n-i-1] = max(a[n-i-1], a[n-i]+1);    
        }
    }

    ll ans = 0;
    irep(i, n+1) {
        //cout << a[i] << endl;
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}
/** tcoder **/


Measured memory_bytes: 2820
ss = gets.chomp.split("").map(&:to_i)
k = gets.chomp.to_i
count = 0
ss.each do |s|
  if s == 1
    count += 1
  else
    break
  end
end

if count >= k
  puts 1
else
  ss.delete(1)
  puts ss[0]
end

Measured memory_bytes: 1788
//////////////////////////
/*      _        ____   */
/*  U  /"\  u U /"___|  */
/*   \/ _ \/  \| | u    */
/*   / ___ \   | |/__   */
/*  /_/   \_\   \____|  */
/*   \\    >>  _// \\   */
/*  (__)  (__)(__)(__)  */
/*  Compro by NULL_CT©  */
//////////////////////////
/*STL Libs*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

/*Boost to boost compile time*/
#include <boost/multiprecision/cpp_int.hpp>

#define REP(I, LIM) for (long I = 0; I < LIM; I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;
using bint = boost::multiprecision::cpp_int;

static constexpr int MOD = 10000007;
static constexpr long INF = LONG_MAX;

vector<long> divisor(long n) {
  vector<long> head, tail;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      head.push_back(i);
      if (i * i != n)
        tail.push_back(n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return (head);
}

//--------------------------------

void execute() {
  int n;
  cin>>n;
  if( 30 <= n){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

//--------------------------------

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

  execute();

  return (0);
}


Measured memory_bytes: 3140
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
const int N = 1e5+10;
typedef long long LL;
int a[N];

int main()
{
    memset(a,0,sizeof(a));
    int maxt=0, x;
    int n;
    scanf("%d", &n);
    for(int i=0;i<n;i++)
    {
        scanf("%d", &x);
        a[x]++;
        maxt=max(maxt,a[x]);
        a[x+1]++;
        maxt=max(maxt,a[x+1]);
        a[x-1]++;
        maxt=max(maxt,a[x-1]);
    }
    printf("%d\n",maxt);
    return 0;
}





Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define drep(i,a,b) for (int i = (a); i >= (b); --i)
#define grep(i,u) for (int i = head[u],v = e[i].v; i; v = e[i = e[i].nxt].v)
#define il inline
#define LL long long
#define ULL unsigned LL
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
il LL read() {
	LL res = 0,f = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') f = -f; ch = getchar();}
	while (isdigit(ch)) {res = res*10+ch-'0'; ch = getchar();} return res*f;
}
namespace qiqi {
	const int N = 1e5+5,INF = 0x3f3f3f3f; int n,ecnt,head[N],dis[N][3],a[N],m,d[N];
	struct Edge {int v,nxt;} e[N<<1]; il void add(int u,int v) {e[++ecnt] = (Edge){v,head[u]}; head[u] = ecnt;}
	int find(int u,int fa,int c) {int mx = u,x; grep(i,u) if (v != fa) {dis[v][c] = dis[u][c]+1; x = find(v,u,c); if (dis[x][c] > dis[mx][c]) mx = x;} return mx;}
	void dfs(int u,int fa) {int x = dis[u][1]+dis[u][2]; a[++m] = u; grep(i,u) if (v != fa && x == dis[v][1]+dis[v][2]) {dfs(v,u); return;}}
	void main() {
		n = read(); rep(i,2,n) {int u = read(),v = read(); add(u,v); add(v,u);} dfs(find(find(find(1,0,0),0,1),0,2),0);
		int x = dis[a[1]][1]+dis[a[1]][2],y; rep(u,1,n) {if ((y = dis[u][1]+dis[u][2]) > x+2) {puts("-1"); return;} if (y > x) grep(i,u) ++d[v];}
		rep(i,1,m/2) {x = a[i]; y = a[m-i+1]; if (d[x] != d[y]) {if (d[x] > d[y]) reverse(a+1,a+m+1); break;}}
		x = 1; rep(j,1,m) {y = x+d[a[j]]-1; rep(i,x,y) printf("%d ",i+1); printf("%d ",x); x = y+2;}
	}
}
int main() {
	qiqi::main(); return 0;
}

Measured memory_bytes: 14988
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
using namespace std;

typedef long long ll;
vector<vector<pair<int, ll>>> path(100005);
ll depth[100005];

void dfs(int v, int p, ll d){
    depth[v] = d;
    for(int i = 0; i < path[v].size(); i++){
        if(path[v][i].first == p) continue;
        dfs(path[v][i].first, v, path[v][i].second+d);
    }
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        int u, v;
        ll w;
        cin >> u >> v >> w;
        pair<int, ll> p = make_pair(v, w);;
        path[u].push_back(p);
        p.first = u;
        path[v].push_back(p);
    }
    dfs(1, -1, 0);
    
    for(int i = 1; i <= N; i++){
        if(depth[i]%2 == 0){
            cout << "1" << endl;
        } else cout << "0" << endl;
    }
}

Measured memory_bytes: 10240
package main

import (
	"fmt"
	"sort"
)

func main() {
	L := make([]int, 3)
	fmt.Scan(&L[0], &L[1], &L[2])

	sort.Ints(L)
	ans := L[0] + L[1] + L[2]*10

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
main(){
  std::string s;
  std::cin>>s;
  for(int i=0;i<4;++i)std::cout<<s[i];
  std::cout<<" ";
  for(int i=4;i<s.size();++i)std::cout<<s[i];
  std::cout<<std::endl;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  auto f = [](int i) {
    string s = to_string(i);
    for (int i = 0; i < s.size(); i++) {
      if (s[i] != s[s.size() - 1 - i]) return false;
    }
    return true;
  };
  int ans = 0;
  for (int i = a; i <= b; i++) if (f(i)) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string b;
  int n;
  cin>>b>>n;
  string s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  int ans=0;
  for(int i=0;i<n;i++){
    s[i]=s[i]+s[i];
    ans+=(int)s[i].find(b)!=-1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3200
#include"stdio.h"
#include"string.h"
int main()
{
	int len,min,i,j,num;
	char a[300000];
	int left[300000];
	while(scanf("%d",&len)!=EOF)
	{
	    getchar();
		for(i=0;i<len;i++)
			scanf("%c",&a[i]);
		num=0;
		memset(left,0,sizeof(left));
		for(i=0;i<len-1;i++)
        {
			if(a[i]=='W')
				num++;
            left[i+1]=num;
        }
		num=0;
		for(j=len-1;j>0;j--)
        {
			if(a[j]=='E')
			    num++;
            left[j-1]+=num;
        }
		min=left[0];
		for(i=0;i<len;i++)
			if(left[i]<min)
				min=left[i];
		printf("%d\n",min);
	}
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, s, N) for(ll i{N - 1}; i > s - 1; i--)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  ll N, M;
  cin >> N >> M;
  vector<P> AB(N);
  for(auto&& i : AB){
    cin >> i.first >> i.second;
  }
  ll ans{}, ko{};
  sort(AB.begin(), AB.end());
  rep(tenme, 0, N){
    rep(kome, 0, AB.at(tenme).second){
      ans += AB.at(tenme).first;
      ko++;
      if(ko == M) break;
    }
  if(ko == M) break;
  }
  cout << ans << rt;
}

Measured memory_bytes: 1792
#include <stdio.h>
int n,k,i,j,p,num[5040],c[4],card[10],ans;
void set(int x){
    int i,j;
    if (x==k) {
        for (i=0; i<k; i++) {
            num[p]=num[p]*10;
            if (card[c[i]]>=10) {
                num[p]=num[p]*10;
            }
            num[p]+=card[c[i]];
        }
        p++;
        return;
    }
    for (i=0; i<n; i++) {
        int flag=1;
        for (j=0; j<x; j++) {
            if (c[j]==i) {
                flag=0;
                break;
            }
        }
        if (flag) {
            c[x]=i;
            set(x+1);
        }
    }
    return;
}
int main(){
    while (1) {
        scanf("%d%d",&n,&k);
        if (n==0&&k==0) {
            return 0;
        }
        for (i=0; i<n; i++) {
            scanf("%d",&card[i]);
        }
        for (i=0; i<5040; i++) {
            num[i]=0;
        }
        p=0;
        set(0);
        ans=0;
        k=p;
        while (k>0) {
            for (i=0; i<p; i++) {
                if (num[i]!=-1) {
                    ans++;
                    k--;
                    for (j=i+1; j<p; j++) {
                        if (num[i]==num[j]) {
                            k--;
                            num[j]=-1;
                        }
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 620
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

int main() {
    long long n;

    std::cin >> n;

    long long upper = 10000000000, lower = 0;

    while (upper - lower > 1) {
        long long mid = (upper + lower) / 2;
        long long sum_score = mid * (mid + 1) / 2;
        if (sum_score > n) {
            upper = mid;
        } else {
            lower = mid;
        }
    }

    if (upper * (upper - 1) / 2 == n) {
        upper--;
    }
    
    std::vector<long long> ans_set;
    long long sum = 0;
    for (long long i = upper; i > 0; i--) {
        if (sum + i <= n) {
            sum += i;
            ans_set.push_back(i);
        }
    }

    for (int i = 0; i < ans_set.size(); i++) {
        std::cout << ans_set[i] << std::endl;
    }
    
    return 0;
}

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

using namespace std;
typedef long long ll;

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

int main()
{
    string s, t;
    cin >> s >> t;

    cout << t << s << '\n';
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

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

    ll ans = MOD;
    for(int i = 1; i < 101;i++){
        ll sum = 0;
        for(int l = 0; l < n;l++){
            sum += (x[l]-i)*(x[l]-i);
        }
        ans = min(sum,ans);

    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(c) { for (auto it = c.begin(); it != c.end(); ++it) cout << it->first << "->" << it->second << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    map<int, LL> Ycount;  //! Y (= i+A[i]) to count
    map<int, LL> Zcount;  //! Z ()= i-A[i]) to count
    set<int> X;

    rep(i, N) {
        int Y = A[i]+i;
        int Z = i-A[i];
        ++Ycount[Y];
        ++Zcount[Z];
        X.insert(Y);
    }

    LL ans = 0;
    for (auto x: X) {
        ans += Ycount[x] * Zcount[x];
    }

    cout << ans << endl;

    return 0;
}


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

long int cal(long int S,int N){
    long int sum=0;
    if(N==0) return 0;
    for(int i=0;i<N;i++){
        long int d=1,e=1;
        for(int j=0;j<i;j++){
            d*=10;
            if(j>=1) e*=2;
        }
        sum+=((S-S%d)/d*e);
        sum+=cal(S%d,i);
        }
    return sum;
    }
    
    

int main(){

  long int S,T;
    int M=0;
    cin>>S;
    T=S;
    for(int i=0;T!=0;i++){
        T/=10;
        M++;
    }
    cout<<cal(S,M)<<endl;
}


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

int n;

int main() {
	cin>>n;
	int a[n], b[n+1];
	for (int i=0; i<n; i++) {
		cin>>a[i];
		b[a[i]]=i+1;
	}
	cout<<b[1];
	for (int i=2; i<n+1; i++) {
		cout<<" "<<b[i];
	}
	cout<<endl;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,Q,K;
  cin>>N;
  vector<vector<pair<int,int>>> A(N);
  for(int i=1;i<N;i++){
    int a,b,c;
    cin>>a>>b>>c;
    A[a-1].push_back({b-1,c});
    A[b-1].push_back({a-1,c});
  }
  cin>>Q>>K;
  vector<int> B(N,-1);
  queue<int> q;
  B[K-1]=0;
  q.push(K-1);
  while(!q.empty()){
    int I=q.front();
    q.pop();
    for(pair<int,int> p:A[I])
      if(B[p.first]==-1){
        B[p.first]=B[I]+p.second;
        q.push(p.first);
      }
  }
  while(Q--){
    int x,y;
    cin>>x>>y;
    cout<<B[x-1]+B[y-1]<<endl;
  }
}

Measured memory_bytes: 11876
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int h, w, m;
    cin >> h >> w >> m;

    vector<int> hi(m), wi(m);
    for (int i = 0; i < m; i++) {
        cin >> hi[i] >> wi[i];
    }

    vector<vector<int>> hw(h, vector<int>(0));
    for (int i = 0; i < m; i++) {
        hw[hi[i] - 1].push_back(wi[i] - 1);
    }

    for (int i = 0; i < h; i++) {
        sort(hw[i].begin(), hw[i].end());
    }

    vector<pair<int, int>> wh(w, make_pair(0, 0));
    for (int i = 0; i < m; i++) {
        wh[wi[i] - 1].first++;
    }

    for (int i = 0; i < w; i++) {
        wh[i].second = i;
    }

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

    int res = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w && wh[0].first - wh[j].first <= 1; j++) {
            vector<int>::iterator k = lower_bound(hw[i].begin(), hw[i].end(), wh[j].second);
            if (k == hw[i].end() || *k != wh[j].second) {
                res = max(res, static_cast<int>(hw[i].size()) + wh[j].first);
                break;
            } else {
                res = max(res, static_cast<int>(hw[i].size()) + wh[j].first - 1);
            }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 24388
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  vector<long long int>H(N);
  for(int i=0;i<N;i++){
    cin>>H.at(i);
    }
  sort(H.begin(),H.end());
  long long int ans = 1000000000;
    for(int i=0;i<N-K+1;i++){
      if(H.at(i+K-1)-H.at(i)<ans){
        ans = H.at(i+K-1)-H.at(i);
      }
    }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
import numpy as np
n = int(input())
a_rows = []
a_rows.append(list(map(int, input().split())))
a_rows.append(list(map(int, input().split())))

a_arr = np.array(a_rows)
sum_list = []
for i in range(n):
    summ  = sum(a_arr[0, :i+1])
    summ += sum(a_arr[1, i:])
    sum_list.append(summ)
print(max(sum_list))

Measured memory_bytes: 12492
/*
*/
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<map>
using namespace std;
typedef long long Int;
typedef pair<Int,Int> P;

#define INF (1LL<<60)

vector<Int> edge[108000];
Int dist[108000];
bool zombie[108000];
bool danger[108000];
Int pcost,qcost;
Int n,m,k,s,x,a,b;

void dijkstra(Int start){
	priority_queue<P/*要素の型はpair<Int,Int>*/,vector<P>/*内部コンテナ(vecctor)*/,greater<P>/*昇順*/ > pq;
	//dist配列をすべてINFにする。
	fill(dist,dist+108000,INF);
	
	//出発する街(1)の宿泊費を0にする。
	dist[start]=0;
	//pq.pushにfirstに0円secondにスタート町の場所を代入する
	pq.push(P(0,start));
	
	//移動できる道がなくなるまで繰り返す
	while(!pq.empty()){
		//tmpに指標となる街の宿泊費と場所を示す
		P tmp=pq.top();pq.pop();
		//fromに町の場所を入れる
		Int from=tmp.second;
		//d=そこまでの宿泊費を入れる
		Int d=tmp.first;
		//もし、dist[指し示す場所]がd以下の値がもう既に入っているなら
		if(dist[from]<d)continue;
		//指し示す町から続く街を調べる
		for(Int i=0;i<edge[from].size();i++)
		{
			//toに移動できる街の番号を代入する
			Int to=edge[from][i];
			//移動した先がゾンビ!!の場合やり直す
			if(zombie[to])continue;
			//危険でない町の宿泊費をcostにいれる
			Int cost=pcost;
			//危険な街の場合高級旅館料金にする
			if(danger[to])cost=qcost;
			//目的地の場合お金払わない
			if(to==n)cost=0;
			//
			if(dist[to]>dist[from]+cost){
				dist[to]=dist[from]+cost;
				pq.push(P(dist[to],to));
			}
		}
	}
}

bool done[108000];
vector<Int>  edges[108000];

int main(){
	/*
	n=町の数
	m=道路の数
	k=支配されている町の数
	s=危険な街になる道路の本数
	*/
	cin>>n>>m>>k>>s;
	/*
	pcost=危険でない町の宿泊費
	qcost=危険な街の宿泊費
	*/
	cin>>pcost>>qcost;
	
	/*
	longlong型のqueueを定義する
	*/
	queue<Int> q;
	
	/*
	x=ゾンビに支配されている町の番号
	*/
	for(Int i=0;i<k;i++){
		cin>>x;
		//支配されている町を1とする
		zombie[x]=true;
		//qにゾンビの町を入れる
		q.push(x);
	}
	
	for(Int i=0;i<m;i++){
		/*
		町aと町bをつなぐ道路
		*/
		cin>>a>>b;
		
		//aの末尾にbの町を入れる
		edge[a].push_back(b);
		//bの末尾にaの町を入れる
		edge[b].push_back(a);
	}
	//危険になる道路の本数回繰り返す
	for(Int i=0;i<=s;i++){
		//qが空になり次第終了
		if(q.empty())break;
		//ゾンビの町からi+1マス目の道路を全て調べる
		for(Int j=q.size()-1;j>=0;j--){
			//危険またはゾンビの町からを取り出しfromに入れる
			Int from=q.front();q.pop();
			//指した町がもう既に危険な街である場合はforに戻る
			if(danger[from])continue;
			//fromの町を危険な街に認定する
			danger[from]=true;
			//kの町から続く町を次の周回の時に始める値とする。
			for(Int k=0;k<edge[from].size();k++){
				q.push(edge[from][k]);
			}
		}
	}
	//
	dijkstra(1);
	
	cout<<dist[n]<<endl;
	
	return 0;
}



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

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int a[3] = {0};
    for (int x, i = 0; i < n; ++i) {
        scanf("%d", &x);
        int cnt = 0;
        while (x % 2 == 0) {
            ++ cnt;
            x /= 2;
        }
        if (cnt > 2)
            cnt = 2;
        ++ a[cnt];
    }
    if (a[1] == 0)
        return 0 * puts(a[0] <= a[2] + 1 ? "Yes" : "No");
    puts(a[0] <= a[2] ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
s, c = [], []
for _ in range(m):
    _s, _c = map(int, input().split())
    s.append(_s-1)
    c.append(_c)

for i in range(1000):
    *t, = map(int, list(str(i)))

    if len(t) != n:
        continue

    ok = True
    for j in range(m):
        if t[s[j]] != c[j]:
            ok = False
            break
    if ok:
        print(i)
        quit()

print(-1)


Measured memory_bytes: 3064