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

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    for (int i = 0; i < N; i++) cin >> X[i];
    int answer = pow(10, 9);
    sort(X.begin(), X.end());
    for (int i = X[0]; i <= X[N - 1]; i++) {
        int now = 0;
        for (int j = 0; j < N; j++) {
            now += pow(i - X[j], 2);
        }
        answer = min(answer, now);
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int X = sc.nextInt();
    int t = sc.nextInt();

      if (X >= t){
        System.out.println(X - t) ;
      }
      else {
      System.out.println(0) ;
      }
  }
}


Measured memory_bytes: 21844
/*

@author hasankamal

*/

#include <iostream>
#include <vector>
using namespace std;

typedef vector<int> vi;
typedef long long int ll;

ll absol(ll x){
	return x < 0 ? -1 * x : x;
}

int main(){

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

	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans;
	if(k % 2 == 0)
		ans = a - b;
	else
		ans = b - a;

	if(absol(ans) > ((ll)1e18) ){
		cout << "Unfair";
		return 0;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
inline int Add(int x,int y){
    return (x+=y)>=mod?x-mod:x;
}
inline int Sub(int x,int y){
    return (x-=y)>=0?x:x+mod;
}
inline int Mul(int x,int y){
    return 1ll*x*y%mod;
}
int n,x,y,z;
int dp[1<<17],newdp[1<<17];
bool ok[1<<17];
bool check(int n){
    vector<int> v;
    int c=0;
    while(n){
        c++;
        if(n&1){
            v.push_back(c);
            c=0;
        }
        n>>=1;
    }
    int o=z;
    int sum=0;
    for(int i=0;i<v.size();i++){
        sum+=v[i];
        if(sum==o){
            if(o==z)o+=y;
            else if(o==y+z)o+=x;
            else o=-1;
        }
    }
    if(o==-1)return false;
    return true;
}
int main(){
    scanf("%d%d%d%d",&n,&x,&y,&z);
    int m=x+y+z;
    for(int i=0;i<(1<<m);i++)ok[i]=check(i);
    //for(int i=0;i<(1<<m);i++)cout<<i<<' '<<ok[i]<<endl;
    dp[0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<m);j++)newdp[j]=0;
        for(int j=0;j<(1<<m);j++){
            if(dp[j]==0)continue;
            for(int k=1;k<=10;k++){
                int x=(j<<k|(1<<(k-1)))%(1<<m);
                if(ok[x])newdp[x]=Add(newdp[x],dp[j]);
            }
        }
        for(int j=0;j<(1<<m);j++)dp[j]=newdp[j];
    }
    int ans=1;
    for(int i=1;i<=n;i++)ans=Mul(ans,10);
    for(int i=0;i<(1<<m);i++)ans=Sub(ans,dp[i]);
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 1408
/*
  AtCoder Beginner Contest 088
  A - Infinite Coins
*/

#include<iostream>
using namespace std;

int N, A;

int main() {
  scanf("%d%d", &N, &A);
  if (N % 500 <= A) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

ll a;
str t;

int main() {
    fast;
    cin>>t;
    a = t.size();
    vec<int> nl(a,-1),  pr(a, -1);
    int c = -1;
    for(int q=0; q<a; q++){
        if(t[q]=='R') c = q;
        else pr[q] = c;
    }
    c = -1;
    for(int q=a-1; q>=0; q--){
        if(t[q]=='L') c = q;
        else nl[q] = c;
    }
    vec<int> o(a);
    for(int q=0; q<a; q++){
        if(t[q]=='R') o[nl[q]-(nl[q]-q)%2]++;
        else o[pr[q]+(q-pr[q])%2]++;
    }
    for(int i : o) cout<<i<<" ";
}

Measured memory_bytes: 1872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int a = in(),b = in(),c = in();
    cout << (a+b+c == 2 * a||a+b+c == 2 * b||a+b+c == 2 * c ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ss = Integer.parseInt(s);
        int p = ss / 100;
        int b = ss % 100;
        if(p == 0&&b==0){
            System.out.println("NA");
        }
        else if(p > 0 && p < 13 && b > 0 && b < 13){
            System.out.println("AMBIGUOUS");
        }else if(b > 0 && b < 13){
            System.out.println("YYMM");
        }else if(p > 0 && p < 13){
            System.out.println("MMYY");
        }else{
            System.out.println("NA");
        }
    }
}

Measured memory_bytes: 21716
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		System.out.println((a - b) % 2 == 0 ? "Alice" : "Borys");
	}
}

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

vector<int>graph[1005] , rgraph[1005];

bool vis[1005];
vector<int>order;
int comp[1005];
int cp = 0;

void dfs1(int u)
{
	vis[u] = true;
	for(int i = 0; i < graph[u].size(); i++)
	{
		int v = graph[u][i];
		if(!vis[v])
			dfs1(v);
	}
	order.push_back(u);
}


void dfs2(int u)
{
	vis[u] = true;
	comp[u] = cp;
	for(int i = 0; i < rgraph[u].size(); i++)
	{
		int v = rgraph[u][i];
		if(!vis[v])
			dfs2(v);
	}
}

void dfs(int u)
{
	vis[u] = 1;
	for(int i = 0; i < graph[u].size(); i++)
	{
		if(!vis[graph[u][i]])
			dfs(graph[u][i]);
	}
}
map<pair<int,int>, bool>ans;
vector<pair<int,int> >e;

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 0 ; i < m ; i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		graph[u].push_back(v);
		rgraph[v].push_back(u);
		e.push_back({u,v});
		ans[e.back()] = 0;
	}
	for(int i = 1 ; i <= n; i++)
	{
		if(!vis[i])
			dfs1(i);
	}
	memset(vis,0,sizeof(vis));
	reverse(order.begin(),order.end());

	for(int i = 0 ; i < order.size(); i++)
	{
		int v = order[i];
		if(!vis[v])
		{
			dfs2(v);
			cp++;
		}
	}
	memset(vis,0,sizeof(vis));

	for(int i = 1; i <= n; i++)
	{
		memset(vis,0,sizeof(vis));
		
		vis[i] = 1;
		//cout << i << ": ";
		for(int j = 0 ; j < graph[i].size(); j++)
		{
			int v = graph[i][j];
			if(vis[v])
			{
			//	cout <<  v<< "  ";
				ans[{i,v}] = 1;
			}
			dfs(v);
		}
		//cout << endl;

		reverse(graph[i].begin(),graph[i].end());

		memset(vis,0,sizeof(vis));

		vis[i] = 1;
		
		for(int j = 0 ; j < graph[i].size(); j++)
		{
			int v = graph[i][j];
			if(vis[v])
			{
			//	cout <<  v<< " ** ";
				ans[{i,v}] = 1;
			}
			dfs(v);
		}
		//cout << endl;
	}
	//cout << cp << endl;
	for(int i = 0; i < e.size(); i++)
	{
		if(comp[e[i].first] != comp[e[i].second])
			ans[e[i]] ^= 1;
		if(ans[e[i]])
			puts("same");
		else
			puts("diff");
	}
	return 0;
}


Measured memory_bytes: 19312
# -*- coding: utf-8 -*-

import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    token = lines[0].split(" ")
    n = int(token[0])
    a = [int(i) for i in lines[1].split(" ")]
    b = [int(i) for i in lines[2].split(" ")]

    return (n, a, b)


def solve(n, a, b):
    
    result = 0
    for i in range(n):
        
        if a[i] >= b[i]:
            c = b[i]
            e = 0
            a[i] = a[i] - c
        else:
            c = a[i]
            d = b[i] - c
            a[i] = 0
            if a[i+1] >= d:
                e = d
                a[i+1] = a[i+1] - d
            else:
                e = a[i+1]
                a[i+1] = 0
        
        result = result + (c+e)

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))


if __name__ == '__main__':

    main()


Measured memory_bytes: 20288
#include <bits/stdc++.h>
using namespace std;
 
#define INPUT freopen("input.txt", "r", stdin);
 
#define ll long long
#define ld long double
 
int main()
{
    //INPUT;
 
    ld n, x, t;
    cin >> n >> x >> t;
 
    ld tm = ceil(n / x);
 
    ll ans = tm * t;
 
    cout << ans << endl;
}

Measured memory_bytes: 3704
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,y) for(int i=(x);i<=(y);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
	int n = 0;
	cin >> n;
	long long count = 0, rating = 0;
	set<string> s;
	for (int i = 0; i < n; i++) {
		cin >> rating;
		if (rating >= 1 && rating <= 399)
			s.insert("grey");
		else if (rating >= 400 && rating <= 799)
			s.insert("brown");
		else if (rating >= 800 && rating <= 1199)
			s.insert("green");
		else if (rating >= 1200 && rating <= 1599)
			s.insert("cyan");
		else if (rating >= 1600 && rating <= 1999)
			s.insert("blue");
		else if (rating >= 2000 && rating <= 2399)
			s.insert("yellow");
		else if (rating >= 2400 && rating <= 2799)
			s.insert("orange");
		else if (rating >= 2800 && rating <= 3199)
			s.insert("red");
		else
			count++;
	}
	if (s.size() > 0)
		cout << s.size() << " " << (long long) s.size() + count << endl;
	else if (count > 0)
		cout << 1 << " " << count << endl;
    return 0;
}


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

int main()
{
     long long int a,b,c,s=0;
     cin>>a>>b;
     s=(a+b)/2;
     if(abs(a-s)==abs(b-s))cout<<s<<endl;
     else
        cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
    //static List<string> str = new List<string>();
	static void Main(string[] args)
	{
		// 入力フェーズ
		int N = Int32.Parse(Console.ReadLine()); // 足場の数
		string[] stone = Console.ReadLine().Split(' '); // 足場の高さ

		List<int> height = new List<int>();
		for(int i=0; i<N; i++){
			height.Add(Int32.Parse(stone[i]));
		}
//Console.WriteLine(height.Count + "");
		long[] dp = new long[N+1];

		dp[0] = 0; // 0番目まで到達するコスト = 0
		dp[1] = 0; // 1番目まで到達するコスト = 0
		dp[2] = Math.Abs(height[0] - height[1]); // 2番目まで到達するコスト
//Console.WriteLine(dp[2] + "");
		for(int i=3; i<=N; i++)
		{
			//long a = dp[i-1] + Math.Abs(height[i-2] - height[i-1]);
			//long b = dp[i-2] + Math.Abs(height[i-3] - height[i-1]);
			//Console.WriteLine(a + " " + b);
			// i+1番目まで到達する最小のコストは・・・
			dp[i] = Math.Min(
						dp[i-1] + Math.Abs(height[i-2] - height[i-1]) // i番目→i+1番目
						, dp[i-2] + Math.Abs(height[i-3] - height[i-1]) // i-1番目→i+1番目
			);
		}
		Console.WriteLine(dp[N] + "");


    }

}


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

int main()
{
    int A, B;
    string S, T, U, all;
    getline(cin, all);
    S = all.substr(0, all.find(" "));
    T = all.substr((all.find(" ")+1));
    cin >> A >> B;
    cin.ignore();
    getline(cin,U);
    if (U == S)
        A = A - 1;
    if (U == T)
        B = B - 1;

    cout << A << " " << B;
    return 0;
}



Measured memory_bytes: 3596
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

char f[12][6];
bool checked[12][6];
int dx[4] = {0,-1,0,1};
int dy[4] = {1,0,-1,0};

int checkfrom(int i, int j){
    pair<int,int> tmp;
    deque<pair<int,int> > q;
    vector<pair<int,int> > modi;
    int cnt = 0,nx,ny;
    char color = f[i][j];

    q.push_back(make_pair(i,j));
    checked[i][j] = true;
    while(!q.empty()){
        tmp = q.front();
        q.pop_front();
        modi.push_back(tmp);
        cnt++;
        for(int i=0;i<4;i++){
            nx = tmp.first + dx[i];
            ny = tmp.second + dy[i];
            if(0 <= nx && nx < 12 &&
               0 <= ny && ny < 6 &&
               !checked[nx][ny] &&
               f[nx][ny] == color){
                q.push_back(make_pair(nx,ny));
                checked[nx][ny] = true;
            }
        }
    }
    if(cnt >= 4){
        for(int i=0;i<modi.size();i++){
            f[modi[i].first][modi[i].second] = '.';
            for(int j=0;j<4;j++){
                if(f[modi[i].first + dx[j]][modi[i].second + dy[j]] == 'O'){
                    f[modi[i].first + dx[j]][modi[i].second + dy[j]] = '.';
                }
            }
        }
    }
    return cnt;
}

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



    for(int x=0;x<n;x++){
        memset(f, 0, sizeof(f));

        for(int i=0;i<12;i++){
            for(int j=0;j<6;j++){
                scanf(" %c", &f[i][j]);
            }
        }
        int max_deleted = 0;
        int res = 0,tx,ty;
        while(1){
            max_deleted = 0;
            memset(checked, false, sizeof(checked));
            for(int i=11;i>=0;i--){
                for(int j=0;j<6;j++){
                    if(f[i][j] != '.' && f[i][j] != 'O' && !checked[i][j]){
                        max_deleted = max(checkfrom(i, j), max_deleted);
                    }
                }
            }
            for(int i=0;i<6;i++){
                int base = 11;
                for(int j=11;j>=0;j--){
                    if(f[j][i] != '.'){
                        f[base][i] = f[j][i];
                        base--;
                    }
                }
                while(base >= 0){
                    f[base][i] = '.';
                    base--;
                }
            }
            
            if(max_deleted < 4) break;
            res++;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

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

int keta(int a)
{
	int keta=1;
	while (a >= 10)
	{
		a = a/10;
		keta++;
	}

	return keta;
}

int main(void)
{
	int ans = 0;
	int n;
	cin >> n;

	for (int i = n; i> 0; i--)
	{
		if (keta(i) % 2 != 0) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
A, B, C = list(input().split())
ans = max(
    int(A) + int(B + C),
    int(A) + int(C + B),
    int(B) + int(A + C),
    int(B) + int(C + A),
    int(C) + int(A + B),
    int(C) + int(B + A))
print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define lo first
#define hi second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define debug
#define TRACE(x)

using namespace std;
using pii = pair<int, int>;

typedef long long llint;

const int MAXN = 100010;

int n, a[MAXN];
vector<int> e[MAXN], w[MAXN];
bool ok;

llint dfs(int x, int dad) {
  llint sum = 0, maks = 0;
  for (int y : e[x])
    if (dad != y) {
      llint tmp = dfs(y, x);
      maks = max(maks, tmp);
      sum += tmp;
    }

  llint up = 0;
  
  if ((int)e[x].size() == 1 && dad != -1)
    up = a[x];
  else if ((int)e[x].size() > 1)
    up = 2 * a[x] - sum;
  
  maks = max(maks, up);
  sum += up;
  
  if (up < 0)
    ok = false;
  if ((int)e[x].size() > 1) {
    if (sum % 2)
      ok = false;
    if (maks > sum - maks)
      ok = false;
  }

  TRACE(x+1 _ up _ sum _ maks _ ok);
  
  return up;
}

int main(void) {
  ok = true;
  scanf("%d",&n);
  REP(i, n) scanf("%d",&a[i]);
  REP(i, n - 1) {
    int u, v;
    scanf("%d %d",&u,&v);
    --u;
    --v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  REP(i, n) w[i].resize(e[i].size());

  if (n == 2) {
    ok = (a[0] == a[1]);
  }
  
  REP(x, n)
    if (e[x].size() >= 2) {
      if (dfs(x, -1) != 0)
	ok = false;
      break;
    }

  printf(ok ? "YES\n" : "NO\n");
  
  return 0;
}


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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e&1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) { return 0; }
    if (n == r || r == 0) { return 1; }
    r = min(r, n-r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n-i+1))/(i); 
    }
    return ans;
}

ll nCr(tuple<ll,ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n+k-1, k);
}

template<typename T>
void print(T v) {
    cout << v << " ";
}

template<typename T>
void print(vector<T> v) {
    for (auto &i : v) {
        print(i);
    }
    cout << endl;
}

void solve() {
    ll n;
    cin >> n;
    vector<ll> A(n);
    for (auto &i : A) {
        cin >> i;
    }

    map<ll, ll> L, R;
    for (int i = 0; i < n; ++i) {
        L[i-A[i]]++;
        R[i+A[i]]++;
    }
    ll ans = 0;
    map<ll, bool> marked;
    for (auto &i : L) {
        if (!marked[i.first]){
            ans += L[i.first]  * R[i.first];
        }
        marked[i.first] = true;
    }
    for (auto &i : R) {
        if (!marked[i.first]){
            ans += L[i.first]  * R[i.first];
        }
        marked[i.first] = true;
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

Measured memory_bytes: 72836
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  rep(i, n) {
    cout << "Case " << i + 1 << ':' << endl;
    int x;
    cin >> x;
    rep(j, 10) {
      stringstream ss;
      ss << setfill('0') << setw(8) << x * x;
      string s;
      ss >> s;
      ss.clear();
      ss << s.substr(2, 4);
      ss >> x;
      cout << x << endl;
    }
  }
}

Measured memory_bytes: 2992
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
best = ''
for ti in t:
    if ti == 's':
        best += 'r'
    elif ti == 'p':
        best += 's'
    else:
        best += 'p'
lis = [[] for _ in range(k)]
# print(lis)
final_st = ''
for bi,b in enumerate(best):
    lis[bi%k].append(b)
for each_lis in lis:
    each_st = ''
    for e_i,e_lis in enumerate(each_lis):
        if e_i == len(each_lis) - 1:
            if e_i == 0:
                each_st += each_lis[e_i]
            else:
                if each_lis[e_i] != each_lis[e_i - 1]:
                    each_st += each_lis[e_i]
            break
        else:
            if each_lis[e_i] != each_lis[e_i + 1]:
                each_st += each_lis[e_i]
            else:
                each_st += each_lis[e_i]
                each_lis[e_i + 1] = 'x'
    #print(each_st)
    final_st += each_st
#print(lis)
#print(final_st)
final_sum = 0
for f in final_st:
    if f == 'r':
        final_sum += r
    elif f == 's':
        final_sum += s
    elif f == 'p':
        final_sum += p
print(final_sum)

Measured memory_bytes: 13656
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount _builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace __gnu_pbds;
using namespace std;
//typedef
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
//constants
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
// gcd of a and b
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
// distance between (a,b) and (c,d)
long double dis(long long a,long long b,long long c,long long d){return sqrt( ((a)-(c))*((a)-(c))+((b)-(d))*((b)-(d)) );}
// simple prime check
bool isprime(long long a){
if(a==2)return 1;
if(!(a&1))return 0;
for(ll i=3;i*i<=a;i+=2){
	if(a%i==0)return 0;
}
return 1;
}
// fast expo
long long mpow(long long base,long long exponent,long long modulus){
if(modulus==1)return 0;
long long result = 1;
base=base%modulus;
while(exponent){
		if(exponent%2 == 1)
			result=(result*base)%modulus;
		exponent=exponent>>1;
		base=(base*base)%modulus;
	}
return result;
}
// modular inverse
ll minv(ll a,ll mod){
	ll _gcd=gcd(a,mod);
	assert(_gcd==1);
	return mpow(a,mod-2,mod);
}

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

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

/*
void sieve(int N){
	for(int i=0;i<=N;i++){
		spf[i]=i;
	}
	for(int i=2;i*i<=N;i++){
		if(spf[i]==i){
			for(int j=i*i;j<=N;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
	return;
}
*/

/*
void nCr(ll n,ll k){
	ll i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=min(i,k);j++){

			if(j==0 or j==i)C[i][j]=1LL;
			else  C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}
	}
	return;
}
*/
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll a,b;
ll ans;
ll bits[55];
int main(){FAST;
cin>>a>>b;
ll p=2;
for(ll i=0;i<50;i++){
	ll divs=(b+1)/p;
	ll rem=(b+1)%p;
	ll del=min(rem,p/2);
	rem-=del;
	ll ones=divs*p/2+rem;
	bits[i]=ones;
	p*=2;
}
if(a){
	p=2;
	for(ll i=0;i<50;i++){
		ll divs=(a)/p;
		ll rem=(a)%p;
		ll del=min(rem,p/2);
		rem-=del;
		ll ones=divs*p/2+rem;
		bits[i]-=ones;
		p*=2;
	}	
}
for(ll i=0;i<50;i++){
	if(bits[i]&1){
		ans+=(1LL<<i);
	}
}
cout<<ans;
return 0;
}


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

using namespace std;

const int MAXN = 1E5;
bool isSheep[MAXN];
bool o[MAXN];
bool options[2] = {true, false};

bool isValid(int n)
{
    bool firstSheep = isSheep[0];
    for (int i = 1; i < n; i++)
    {
         if (isSheep[i] && o[i] || !isSheep[i] && !o[i])
         {
             isSheep[(i + 1) % n] = isSheep[i - 1];
         }
         else if (isSheep[i] && !o[i] || !isSheep[i] && o[i])
         {
             isSheep[(i + 1) % n] = !isSheep[i - 1];
         }
    }
    if (isSheep[0] != firstSheep)
        return false;
    if (firstSheep && o[0] || !firstSheep && !o[0])
    {
        return isSheep[n - 1] == isSheep[1];
    }
    else
    {
        return isSheep[n - 1] != isSheep[1];
    }
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        char c;
        cin >> c;
        o[i] = c == 'o';
    }
    bool valid = false;
    for (bool s1 : options)
    {
        for (bool s2 : options)
        {
            isSheep[0] = s1;
            isSheep[1] = s2;
            if (isValid(n))
            {
                valid = true;
                break;
            }
        }
        if (valid)
            break;
    }
    if (valid)
    {
        stringstream ss;
        for (int i = 0; i < n; i++)
        {
            if (isSheep[i])
                ss << "S";
            else
                ss << "W";
        }
        cout << ss.str() << endl;
    }
    else
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 768
fun main(args: Array<String>){
    val X = readLine()!!.toLong()
    var motohyaku:Double = 100.0
    var nensuu = 0

    while (X > motohyaku){
        motohyaku = Math.floor(motohyaku * 1.01)
        nensuu += 1
    }
    println(nensuu)
}

Measured memory_bytes: 34408
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int main() {
	int n; scanf("%d", &n);
	int Max = 0, sum = 0, a;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a);
		Max = max(Max, a);
		sum += a;
	}
	printf("%d\n", sum - Max / 2);
	return 0;
}

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

const int INF=1<<30;
const int MaxRC=1e3;
int dx[4]={ 0, 1, 0,-1};
int dy[4]={ 1, 0,-1, 0};

struct DATA{
	int x, y;
	DATA(int x=0,int y=0):x(x),y(y){}
} st, ed, now, nxt;

int main(){
	int R, C, K;
	while(scanf("%d %d %d\n",&R,&C,&K)!=EOF){
		scanf("%d %d %d %d\n",&st.x,&st.y,&ed.x,&ed.y);
		st.x--, st.y--, ed.x--, ed.y--;
		
		vector<vector<char>> mat(R, vector<char>(C));
		for(int i=0;i<R;i++,getchar())
			for(int j=0;j<C;j++)
				mat[i][j]=getchar();
		vector<vector<int>> step(R, vector<int>(C,INF));
		queue<DATA> Q;
		Q.push(DATA(st.x,st.y));
		step[st.x][st.y]=0;
		while(Q.empty()==0){
			now=Q.front(); Q.pop();
			if(now.x==ed.x and now.y==ed.y) break;
			for(int i=0;i<4;i++)
				for(int k=1;k<=K;k++){
					nxt=DATA(now.x+k*dx[i],now.y+k*dy[i]);
					if(nxt.x==-1 or nxt.x==R or nxt.y==-1 or nxt.y==C or mat[nxt.x][nxt.y]=='@' or step[nxt.x][nxt.y]<=step[now.x][now.y])
						break;
					else if(step[nxt.x][nxt.y]>step[now.x][now.y]+1){
						step[nxt.x][nxt.y]=step[now.x][now.y]+1;
						Q.push(nxt);
					}
				}
		}
		printf("%d\n",(step[ed.x][ed.y]==INF)? -1: step[ed.x][ed.y]);
		
	}
}




Measured memory_bytes: 12040
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  cin >> N;
  if (N & 1) {
    cout << 0 << endl;
    return;
  }
  int ans = 0;
  int waru = 10;

  rep(i, 1, 50) {
    ans += N / waru;
    waru *= 5;
  }
  cout << ans << endl;

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

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		while(0 < 1) {
			int num1 = sc.nextInt();
			String str = sc.next();
			int num2 = sc.nextInt();
			switch(str.charAt(0)) {
			case '+':
				System.out.println(num1 + num2);
				break;
			case '-':
				System.out.println(num1 - num2);
				break;
			case '*':
				System.out.println(num1 * num2);
				break;
			case '/':
				System.out.println(num1 / num2);
				break;
			default:
				break;
		}
		if(str.charAt(0) == '?') break;
		}
		sc.close();
	}	
}


Measured memory_bytes: 26316
#include <stdio.h>
#include <math.h>


main()
{
int h,w;
while(1){
	scanf("%d %d",&h,&w);
	if((h|w)==0)break;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			printf("%c",(j+i)%2?'.':'#');
		}
		printf("\n");
	}
	printf("\n");
}
}


Measured memory_bytes: 2048
#include<stdio.h>
#define ll long long
ll llgcd(ll a, ll b){return b == 0 ? a : llgcd(b, a % b);}
ll lllcm(ll a, ll b){return a / llgcd(a, b) * b;}
int main(){
    long long a, b, n, ans = 0;
    scanf("%lld%lld%lld",&a,&b,&n);
    if(n < b)
        ans = n;
    else 
        ans = b - 1;
    ans *= a;
    ans /= b;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
using namespace std ;
#define rep(i,n) for(int i=0;i<n;i++)
#define maxn 200005
#define int long long
int dp[maxn];
void solve(){
    int n ;
    cin >> n ;
    int arr[n];
    rep(i,n){
        cin >> arr[i] ;
    }
    dp[0] = 0 ;
    dp[1] = abs(arr[1]-arr[0]) ;
    for(int i=2;i<n;i++){
        dp[i] = min(abs(arr[i]-arr[i-1])+dp[i-1],
                    abs(arr[i]-arr[i-2])+dp[i-2]);
    }
    cout << dp[n-1] ;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1 ;
    while(t--){solve();}
    return 0 ;
}


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

int main() {
	// your code goes here
	string s;
	cin >> s;
	int ans = 0, sm = 0;
	for(char ch : s) {
		
		if(ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T') {
			
			++sm;
			ans = max(ans, sm);
		}
		else {
			
			ans = max(ans, sm);
			sm = 0;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class prog{
  
  static bool judge(string input){
    bool judge = true;
    foreach(char i in input){
      if(i == '-') judge = false;
    }
    return judge;
  }
  
  static void Main(){
    int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
    string S = Console.ReadLine();
    int A = input[0];
    int B = input[1];
    
    if(judge(S.Substring(0,A))&&S.Substring(A,1) == "-"&&judge(S.Substring(A+1))) Console.WriteLine("Yes");
    else Console.WriteLine("No");
  }
}

Measured memory_bytes: 13268
s = gets.chomp.split('').map(&:to_i)
c1, c2 = 0, 0

s.each_with_index do |e, i|
  c1 += 1 if e == [0, 1][i % 2]
  c2 += 1 if e == [1, 0][i % 2]
end

puts [c1, c2].min


Measured memory_bytes: 10236
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.swing.text.Segment;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(Scanner sc = new Scanner(System.in)){
			System.out.println(sc.next().contains("9") ? "Yes" : "No");
		}
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
		
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 23124
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::{HashMap,BTreeMap};
use std::cmp::{max,min};
fn main(){
    input!{
        a:u64,
        b:u64,
    }
    let c = gcd(a, b);
    let mut primes = vec![];
    let mut sub = c;
    for prime in 2.. {
        if prime * prime > sub {
            break;
        }
        if sub % prime == 0 {
            primes.push(prime);
            while sub % prime == 0 {
                sub /= prime;
            }
        }
    }
    if sub > 1 {
        primes.push(sub);
    }
    println!("{}",primes.len() + 1);
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}

fn gcd(x: u64, y: u64) -> u64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

Measured memory_bytes: 4352
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<bool>> a(h, vector<bool>(w, false));
    P s;
    rep(i, h){
        rep(j, w){
            char c;
            cin >> c;

            if(c == 'S'){
                s = {i, j};
                a[i][j] = true;
            }
            if(c == '.'){
                a[i][j] = true;
            }
        }
    }

    vector<vector<P>> d(h, vector<P>(w, {INF, INF}));
    vector<int> dir = {1, 0, -1, 0};
    queue<pair<P, P>> q;
    queue<pair<P, P>> qq;
    q.push({s, {0, 0}});
    while(not q.empty()){
        int x = q.front().first.first;
        int y = q.front().first.second;
        P dist = q.front().second;
        qq.push(q.front());
        q.pop();

        if(d[x][y] <= dist){
            continue;
        }
        d[x][y] = dist;

        if(dist.second == k){
            continue;
        }

        rep(i, 4){
            int nx = x + dir[i];
            int ny = y + dir[i^1];

            if(0 > nx || nx >= h || 0 > ny || ny >= w || not a[nx][ny]){
                continue;
            }

            if(d[nx][ny] <= dist){
                continue;
            }

            q.push({{nx, ny}, {0, dist.second + 1}});
        }
    }

    q = qq;

    while(not q.empty()){
        int x = q.front().first.first;
        int y = q.front().first.second;
        P dist = q.front().second;
        q.pop();

        if(dist.first == 0){
            dist = {1, 0};
        }

        if(d[x][y].first == 1 && d[x][y] <= dist){
            continue;
        }
        d[x][y] = dist;

        rep(i, 4){
            int nx = x + dir[i];
            int ny = y + dir[i^1];

            if(0 > nx || nx >= h || 0 > ny || ny >= w){
                continue;
            }
            if(d[nx][ny] <= dist){
                continue;
            }

            q.push({{nx, ny}, {1, dist.second + 1}});
        }
    }

    int ans = INF;
    rep(i, h){
        rep(j, w){
            if(i != 0 && i != h - 1 && j != 0 && j != w - 1){
                continue;
            }

            int tmp = d[i][j].first + (d[i][j].second + k - 1) / k;
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 87552
#include <iostream>
#include <map>
#include <list>
#include <numeric>
using namespace std;


int main()
{
	int n, m;
	while (cin >> n >> m, n + m)
	{
		int t[100];
		int h[100];
		for (int i = 0; i < n; i++) cin >> t[i];
		for (int i = 0; i < m; i++) cin >> h[i];
		int sumT = accumulate(t, t + n, 0);
		int sumH = accumulate(h, h + m, 0);

		list<pair<int, int>> a;

		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				if (sumT - t[i] + h[j] == sumH - h[j] + t[i])
				{
					a.push_back(pair<int, int>(t[i], h[j]));
				}
			}
		}

		pair<int, int> ans(999, 999);
		for (auto x : a)
		{
			if (ans.first + ans.second > x.first + x.second)
			{
				ans = x;
			}
		}
		if (a.empty()) 
			cout << -1 << endl;
		else
			cout << ans.first << " " << ans.second << endl;
	}

	return 0;
}

Measured memory_bytes: 3316
N = int(input())
K = int(input())
keta = len(str(N))

def kosu(p):
  if p == 1:
    answer = [9, 0, 0]
  elif p == 2:
    answer = [9, 81, 0]
  elif p == 3:
    answer = [9, 162, 729]
  else:
    k1 = 9
    k2 = (9 ** 2) * (p - 1)
    k3 = int((9 ** 3) * (p - 1) * (p - 2) / 2)
    answer = [k1, k2, k3]
  return answer

if keta == 1:
  if K == 1:
    print(N)
  else:
    print("0")
  quit()
  
ans = 0  
for i in range(1, keta):
  ans += kosu(i)[K - 1]

#print(ans)  
if K == 1:
  ans += int(str(N)[0])
elif K == 2:
  y = 0
  i = 1
  while y == 0:
    if int(str(N)[i]) != 0:
      y = i
      ans += int(str(N)[i]) + 9 * (keta -y - 1)
    i += 1
    if i == keta:
      y = keta
    
  #print(x)
  ans += (int(str(N)[0]) - 1) * 9 * (keta - 1)
  
else:
  if keta >= 3:
    ans += int((int(str(N)[0]) - 1) * (9 ** 2) * (keta - 1) * (keta - 2) / 2)
    #print(ans)
    x = 0
    i = 1
    while x <= 1:
      if int(str(N)[i]) != 0:
        x += 1
        if x == 1:
          ans += (int(str(N)[i]) - 1) * (9 * (keta - i - 1))
          if i <= keta - 3:
            ans += (9 ** 2) * (keta - i - 1) * (keta - i - 2) / 2
        else:# x = 2
          ans += int(str(N)[i]) + 9 * (keta - i - 1)
      i += 1
      if (i == keta - 1) and (x == 0):
        x = 2
      if i == keta:
        x = 2
        

print(int(ans))
    


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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int main() {
  int r;
  cin >> r;
  cout << r*r;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, m;
  cin >> n >> m;
  if (n-2*m > 0) {
    cout << n-2*m << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(x,b) ((x)>=0&&(x)<(b))
#define Y first
#define X second
#define INF 1 << 30

typedef pair<int, int> pii;
typedef queue<int> qi;
typedef pair<int, int> pi;

int board[51][51], Y, X;
int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};

pii nextp1(pii now, int i){
  pii next = now;
  next.Y += dy[i];
  next.X += dx[i];
  if(BW((next.Y), Y) && BW((next.X), X) && board[next.Y][next.X] == 0) return next;
  return now;
}

pii nextp2(pii now, int i){
  pii next = now;
  next.Y += -1 * dy[i];
  next.X += -1 * dx[i];
  if(BW(next.Y, Y) && BW(next.X, X) && board[next.Y][next.X] == 0) return next;
  return now;
}

pii nextp(pii now, int i, int d){
  pii next = now;
  next.Y += dy[i] * d;
  next.X += dx[i] * d;
  if(BW(next.Y, Y) && BW(next.X, X) && board[next.Y][next.X] == 0) return next;
  return now;
}
     
int main(){
  while(scanf("%d%d", &X,  &Y) && X+Y){
    int tx, ty, kx, ky;
    scanf("%d%d%d%d", &tx, &ty, &kx, &ky); tx--; ty--; kx--; ky--;
    rep(i, Y) rep(j, X) scanf("%d", &board[i][j]); 

    map<pair<pi,pi>, bool>m; // t k
    queue<pii>tq, kq;
    tq.push(make_pair(ty, tx));
    kq.push(make_pair(ky, kx));
    m[make_pair(make_pair(ty, tx), make_pair(ky, kx))] = 1;
    int res = 1;
    while(!tq.empty()){
      if(res >= 100) break;
      int qsize = (int)tq.size();
      rep(i, qsize){
	pii t = tq.front(); tq.pop();
	pii k = kq.front(); kq.pop();
	rep(j, 4){
	  pii nt = nextp(t, j, 1), nk = nextp(k, j, -1);
	  pair<pi, pi> next = make_pair(make_pair(nt.Y, nt.X), make_pair(nk.Y, nk.X));
	  if(m.count(next) == 1) continue;
	  if(nt == nk){
	    printf("%d\n", res);
	    goto end;
	  }
	  m[next] = 1;
	  tq.push(nt); kq.push(nk);
	}
      }
      res++;

    }
    puts("NA");
  end:;
  }
  return 0;
}

Measured memory_bytes: 12384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n; cin >> n;
  vi arr(n);
  rep(i,n) {
    cin >> arr[i];
    --arr[i];
  }

  int ans = 0;
  if (arr[n-1] == n-1) {
    ++ans;
    swap(arr[n-1], arr[n-2]);
  }
  rep(i,n-1) {
    if (arr[i] == i) {
      ++ans;
      ++i;
    }
  }

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


Measured memory_bytes: 640