akhauriyash/Code-Regression huggingface dataset:
use std::io::Read;
use std::io::{stdout, BufWriter, Write};

fn main() {
    let mut buf = String::new();

    // stdinから全てbufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    // 読み込んだ文字列をスペースで分解する
    let mut iter = buf.split_whitespace();

    // about r
    let r: usize = iter.next().unwrap().parse().unwrap();
    // about D
    let d: usize = iter.next().unwrap().parse().unwrap();
    // about x_2000
    let x_2000: usize = iter.next().unwrap().parse().unwrap();

    let mut x_ans: Vec<usize> = Vec::with_capacity(11);
    x_ans.push(x_2000);
    
    for i in 1..11 {
        let x: usize = r * x_ans[i - 1] - d;
        x_ans.push(x);
    }

    // 出力
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    for i in 1..11 {
        writeln!(out, "{}", x_ans[i]).unwrap();
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
long long dp[102][100002] ;
long long w[100001] ;
long long v[100001] ;
long long  n , a ;
int main(){
    cin >> n >> a ;
    for ( int i = 1 ; i <= n ; i++ ){
        cin >> w[i] >> v[i] ;
    }
    dp[1][0] = 0 ;
    for ( int j = 1 ; j <= n ; j++ ){
        for ( int k = 0 ; k <= a ; k++ ){
            if ( k >= w[j] ){
                dp[j][k] = max( dp[j-1][k-w[j]] + v[j] , dp[j-1][k] ) ;
            }
            else
                dp[j][k] = dp[j-1][k] ;
        //    cout<< dp[j][k] <<" ";
        }
        //cout<<"\n";
    }
    cout << dp[n][a] ;
    return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

char G[105][105];
bool check[105][105];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w; cin>>h>>w;
  rep(i,h) rep(j,w) cin>>G[i][j];
  rep(i,h){
    bool flg=true;
    rep(j,w){
      if(G[i][j]=='#') flg=false;
    }
    if(flg){
      rep(j,w) check[i][j]=true;
    }
  }
  rep(i,w){
    bool flg=true;
    rep(j,h){
      if(G[j][i]=='#') flg=false;
    }
    if(flg){
      rep(j,h) check[j][i]=true;
    }
  }
  rep(i,h){
    bool flg=false;
    rep(j,w){
      if(check[i][j]) continue;
      flg=true;
      cout<<G[i][j];
    }
    if(flg) cout<<endl;
  }
}


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

using namespace std;

int main(){

 int n,mini=INT_MAX,maxi=INT_MIN,cost = INT_MAX;
 cin>>n;

 int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    mini= min(mini,a[i]);
    maxi = max(maxi,a[i]);
  }


   for(int i=mini;i<=maxi;i++)
  {
     int sum =0;
     for(int j =0;j<n;j++)
     sum += (a[j] - i) * (a[j] - i);

     if(sum < cost) cost = sum;
   }

   cout<<cost<<endl;

return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}

			var X = inputArray[0];

			var primeList = new List<long>();

			long ans = 0;
			long i = 2;
			while (true) {

				if (checkPrime(i,primeList)) {
					if(i >= X) {
						ans = i;
						break;
					}
					primeList.Add(i);
				}

				i++;
			}

			//答えの出力
			Console.WriteLine(ans);

		}

		/// <summary>
		/// 素数かどうか判定する
		/// </summary>
		/// <param name="i"></param>
		/// <param name="primeList">i以下の素数のリスト</param>
		/// <returns></returns>
		private static bool checkPrime(long i,IEnumerable<long> primeList) {


			foreach (var prime in primeList) {
				if (i % prime == 0) {
					return false;
				}
			}
			return true;

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 15456
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

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

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BHarshadNumber solver = new BHarshadNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class BHarshadNumber {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

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

            out.println(n % sum == 0 ? "Yes" : "No");
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}

//a,b x
int main(){
	//rep1(i,50) pw2[i]=2*pw2[i-1];
	//rep1(i,18) pw10[i]=10*pw10[i-1];
	ll K,X; cin>>K>>X;
	for(int i=max(X-K+1,-1000000ll);i<=min(1000000ll,X+K-1);i++){
		cout<<i<<" ";
	}
		
}

Measured memory_bytes: 256
from math import sqrt
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
ans = 0


def dist(p1, p2):
    return sqrt(abs(p1[0]-p2[0])**2 + abs(p1[1]-p2[1])**2)


for i in range(N):
    for j in range(i, N):
        ans += dist(L[i], L[j])

print(ans*2/N)


Measured memory_bytes: 38384
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Array as A

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  bs <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  cs <- A.listArray (1, pred n) . map unsafeSignedDecimal . T.words <$> T.getLine :: IO (A.Array Int Int)
  let
    is = fst . foldl step ([], Nothing) $ as
    step (is, Just i) a | a == succ i = (i : is, Just a)
                        | otherwise = (is, Just a)
    step _ a = ([], Just a)
  print $ sum bs + sum (map (cs A.!) is)

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
s = input()
mod = 10 ** 9 + 7
#dp[k] -> 13で割ったあまりがkのパターン数
dp = [0] * 13
dp[0] = 1
mul = 1

for c in s[::-1]:
  #次の状態
  nextDP = [0] * 13
  if c == "?":
    for k in range(10):
      for j in range(13):
        nextDP[(k * mul + j)%13] += dp[j]
        nextDP[(k * mul + j)%13] %= mod
      
  else:
    k = int(c)
    for j in range(13):
        nextDP[(k * mul + j)%13] += dp[j]
        nextDP[(k * mul + j)%13] %= mod

  mul *= 10
  mul %= 13
  dp = nextDP

print(dp[5])


Measured memory_bytes: 43500
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL INF=300000000;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}

int main(){
    int n;
    cin>>n;
    int a[50][26]={};
    string s[50];
    for(int i=0;i<n;++i){
        cin>>s[i];
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<s[i].size();++j){
            a[i][s[i][j]-'a']++;
        }
    }
    string ans;
    for(int i=0;i<26;++i){
        int mi=10101010;
        for(int j=0;j<n;j++){
            mi=min(mi,a[j][i]);
        }
        for(int k=0;k<mi;++k){
            ans.push_back(i+'a');
        }
    }
    cout<<ans<<endl;
}

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

int main()
{
	
	int n,k;
	cin >> n >> k;
	vector<double> p(n+1);
	for(int i = 0;i<n;i++)
	{
		double x;cin >> x;
		x = x*(x+1)/2/x;
		p[i+1] = p[i]+x;
	}
	double ans = 0;
	for(int i = 0;i<n-k+1;i++)
	{
		ans = max(ans,p[i+k]-p[i]);
	}
	printf("%.10lf",ans);
	return 0;
}


Measured memory_bytes: 1920
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul
from decimal import Decimal

mod = 998244353
INF = 10 ** 13
sys.setrecursionlimit(2147483647)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

n = I()
A = LI()
ret = 1
flg = 0
for a in A:
    if a == 0:
        print(0)
        exit()
    if flg == 0:
        ret *= a
        if ret > 10 ** 18:
            flg = 1

if flg:
    print(-1)
else:
    print(ret)

Measured memory_bytes: 94548
#include <iostream>
#include "map"
#include "vector"
#include "set"
#include "algorithm"
#include "queue"

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


#define first x
#define second y


const int N = 1e5+5, inf = 1e9;


using namespace std;

void solve();
void bfs();
void dfs();
void bin_search();
int gcd(int a,int b);
ll gcd(ll a,ll b);



int main() {

    int n,i,j;
    cin>>n;
    int a[n+1];

    int st = -1;
    for(i=1;i<=n;i++) {
        cin>>a[i];
        if ( a[i] == 1 ) st = i;
    }

    if( st == -1 ){
        cout<<-1;
        return 0;
    }
    int res = 1;

    for(i=st+1;i<=n;i++){
        if( a[i] == a[st] + 1 ){
            st = i;
            res++;
        }
    }


    cout<<n - res;


    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int a,b,c;
    while (scanf("%d %d %d",&a,&b,&c)!=EOF) {
        if (a==b) {
            if (a==c)
                printf("No\n");
            else
                printf("Yes\n");
        }
        else {
            if (a==c||b==c)
                printf("Yes\n");
            else
                printf("No\n");
        }

    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;

const int MOD = (int)1e9 + 7;

int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	puts(max(a, max(b, c)) * 2 == a + b + c ? "Yes" : "No");
	return 0;
}


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(min(A,B) < C && C < max(A,B)) {
  cout << "Yes"<< endl;
  }
  else{
  cout << "No"<< endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a;i<=b;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair < int, int> 
#define pal pair < ll, ll> 
#define vi vector <int> 
#define vl vector < ll > 
#define vpai vector < pii > 

const int mod = 1e9+7;
const int INF = INT_MAX;
const int sze = 3005;

void solve() {
    int a;
    cin>>a;
    cout<<(a+a*a+a*a*a)<<endl;
}

int main() {
    IOS;

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

  return 0;
}

Measured memory_bytes: 3652
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.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        System.out.println(Math.PI*R*2);
    }

    public static void main(String[] args) {
        new Main();
    }
}


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

int main() {
    ll N, M;
    cin >> N >> M;

    if (N * 2 >= M) cout << M / 2 << endl;
    else cout << N + (M-2*N)/4 << endl;
}



Measured memory_bytes: 256
n, m = map(int, input().split())

edge = [[0] * n for _ in range(n)]
for _ in range(m):
   a, b = map(int, input().split())
   a -= 1
   b -= 1
   edge[a][b] = 1
   edge[b][a] = 1

def dfs(v):
   visited[v] = 1
   for k in range(n):
      if (edge[v][k] == 0):
         continue
      if (visited[k] == 1):
         continue
      dfs(k)


ans = 0
for i in range(n):
   for j in range(i+1, n):
      if (edge[i][j] == 1):
         edge[i][j] = 0
         edge[j][i] = 0
         # dfs
         visited = [0 for _ in range(n)]
         dfs(0)
         if (sum(visited) < n):
            ans += 1
         edge[i][j] = 1
         edge[j][i] = 1
print(ans)


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

bool cards[1000000]; 

int main(){
	int n,k;
	while(~scanf("%d %d",&n,&k)){
		if(n==0 && k==0) break;
		
		memset(cards,0,sizeof(cards));

		bool hasWhite = false;
		for(int i=0;i<k;i++){
			int num;
			scanf("%d",&num);
			cards[num] = true;
			if(num == 0) hasWhite = true;
		}

		if(hasWhite){
			int suc = 0;
			for(int i=1;i<=n;i++){
				int tmp = 0;
				bool mistake = false;
				for(int j=i;j<=n;j++){
					if(cards[j]){
						tmp++;
						suc = max(tmp,suc);
					}
					else{
						if(!mistake){
							mistake = true;
							tmp++;
							suc = max(tmp,suc);
							continue;
						}
						break;
					}
				}
			}

			printf("%d\n",suc);
		}
		else{
			int suc = 0;
			for(int i=1;i<=n;i++){
				int tmp = 0;
				for(int j=i;j<=n;j++){
					if(cards[j]){
						tmp++;
						suc = max(tmp,suc);
					}
					else{
						i=++j;
						break;
					}
				}
			}

			printf("%d\n",suc);
		}
	}
}

Measured memory_bytes: 2172
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
    a, b, w = lr()
    graph[a].append((b, w&1))
    graph[b].append((a, w&1))

color = [None] * (N+1)
color[1] = 0
root = 1
parent = [0] * (N+1)
stack = [(root, 0)]
while stack:
    cur, c = stack.pop()
    for next, weight in graph[cur]:
        if next == parent[cur]:
            continue
        parent[next] = cur
        color[next] = c^weight
        stack.append((next, color[next]))

print(*color[1:], sep='\n')


Measured memory_bytes: 41668
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include<algorithm>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility> 
using namespace std;

using ll = long long;
const int limit = 100010;
using edge = struct { int to; ll cost; };
vector<edge> tree[limit];
ll depth[limit];

//現在の頂点,親の頂点,頂点からの距離
void dfs(int v, int p, ll d) {
	depth[v] = d;
	for (auto &e : tree[v]) {
		if (e.to == p)continue;
		dfs(e.to, v, d + e.cost);
	}
}




int main()
{
	int n;
	cin >> n;

	for (int i = 0; i < n - 1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		tree[a].push_back({b,c});
		tree[b].push_back({a,c});
	}
	
	int q, k;
	cin >> q >> k;
	k--;

	dfs(k, -1, 0);

	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		cout << depth[x] + depth[y] << endl;
	}





	return 0;
}



Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
long long n, m, l, q;
vector< vector<long long> > dst;
vector< vector<int> > near, dst2;
int main(void){
    cin >> n >> m >> l;
    dst.assign(n, vector<long long>());
    near.assign(n, vector<int>());
    dst2.assign(n, vector<int>());
    for(int i=0;i<n;i++){
        dst[i].assign(n, 1e16);
        dst2[i].assign(n, 1e4);
    }
    for(int i=0;i<m;i++){
        int a, b, c;
        cin >> a >> b >> c;
        if(c > l)continue;
        a--;
        b--;
        dst[a][b] = dst[b][a] = c;
    }

    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dst[i][j] = min(dst[i][j], dst[i][k]+dst[k][j]);
            }
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(dst[i][j] <= l){
                near[i].push_back(j);
                dst2[i][j] = 1;
            }
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dst2[i][j] = min(dst2[i][j], dst2[i][k]+dst2[k][j]);
            }
        }
    }
    cin >> q;
    for(int i=0;i<q;i++){
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        if(dst2[s][t] == 1e4){
            puts("-1");
            continue;
        }
        cout << dst2[s][t] -1 << endl;
        
    }

}


Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main(){
  char ch[6];
  for(int i=0;i<6;i++){
    cin>>ch[i];
  }
  if(ch[3]==ch[2] && ch[5]==ch[4]){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ll n,k;
cin>>n>>k;
ll a=1;
ll ans=0;
while(a<n)
{
a*=k;
ans++;
}
if(a==n)
{
cout<<ans+1;
}
else
{
cout<<ans;
}
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;

	public static void Main(string[] args)
	{
		var s = Console.ReadLine();
		
		Console.WriteLine(s.Substring(0, s.Length - 8));
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 11092
#include <stdio.h>

int main(void){
	char s[100000];

	if(scanf("%s", s)<0) return -1;
	int i;
	for (i = 0; s[i] != '\0'; i++)
	{
		if (i % 2 == 0){
			printf("%c", s[i]);

		}
		
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


int main(){
    int n;
    cin >> n;
    cout  << 3*n*n << endl;



    return 0;
}

Measured memory_bytes: 888
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    int n;
    cin >> n;

    long long l[86] = {0};
    l[0] = 2;
    l[1] = 1;
    for (int i = 1; i <= n; i++) {
        if (i > 1)
            l[i] = l[i - 1] + l[i - 2];
    }

    cout << l[n] << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque

def bfs():
    global q, t
    while q:
        a = q.popleft()
        for i in [-1, 1]:
            if 0 <= a + i < h:
                if t[a + i] == -1:
                    q.append(a + i)
                    t[a + i] = t[a]
    return

def solve():
    global ans
    for i in range(h):
        for j in range(w):
            ans[i][j] = ans[t[i]][j]
    for i in range(h):
        print(" ".join(map(str, ans[i])))
    return

h, w, k = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = [[0] * w for _ in range(h)]
t = [-1] * h
x = 1
q = deque()
for i in range(h):
    cnt = 0
    for j in range(w):
        ans[i][j] = x
        if s[i][j] == "#":
            cnt += 1
            if cnt >= 2:
                x += 1
            ans[i][j] = x
    if cnt > 0:
        x += 1
        t[i] = i
        q.append(i)
bfs()
solve()

Measured memory_bytes: 13564
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, k = map(int, sys.stdin.readline().split())
    if n % k == 0:
        print(0)
    elif n < k:
        print(min(abs(n - k), n))
    else:
        a = n // k
        f, s = (a + 1) * k, a * k
        print(min(abs(f-n), abs(s-n)))


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


Measured memory_bytes: 38256
import java.util.*;

public class Main {
    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main();
    }

    public Main() {
        new B().doIt();
    }
    class B {
    	String str = "";
    	String dfs(int a,int b,int cnt){
    		if(a % b == 0)str = b+" "+cnt;
    		else dfs(b,a % b,cnt + 1);
    		return str;
    	}
        void doIt(){
        	while(true){
        		int a = sc.nextInt();
        		int b = sc.nextInt();
        		if(a + b == 0)break;
        		if(a > b)System.out.println(dfs(a,b,1));
        		else System.out.println(dfs(b,a,1));
        	}
        }
    }
}

Measured memory_bytes: 34072
n = int(input())
a = list(map(int, input().split())) 
b = list(map(int, input().split())) 
ans = 0

for i in range(n) :
  if b[i] > a[i] :
    if a[i+1] >= (b[i]-a[i]) :
      a[i+1] = a[i+1] - (b[i]-a[i])
      ans += b[i]
    else :
      ans += a[i] + a[i+1]
      a[i+1] = 0
  else :
    ans += b[i]
    
print(ans)

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

A, B, C, X, Y = list(map(int, input().split()))

cost = int(1e10)
for num_ac in range(0, int(1e5) + 1):
    num_A = max(0, X - num_ac)
    num_B = max(0, Y - num_ac)
    c = 2 * C * num_ac + A * num_A + B * num_B
    cost = min(c, cost)
print(cost)

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

int main(){
  int n;
  cin >> n;
  int b[n-1];
  for(int i=0;i<n-1;i++){
    cin >> b[i];
  }
  if(n==2)
    cout << 2*b[0] << endl;
  else{
  int cnt = b[0]+b[n-2];
  for(int i=0;i<n-2;i++)
    cnt += min(b[i],b[i+1]);
  cout << cnt << endl;
  }
}

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

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 n, k;
    cin >> n >> k;
    vector<int> p(n);
    vector<double> e(n);
    rep(i, n) {
        cin >> p[i];
        e[i] = (p[i]+1)/2.0;
    }
    double ans = 0.0, tmp = 0.0;

    vector<double> s(n+1);
    s[0] = 0.0;
    for(int i = 1; i <= n; i++) {
        s[i] = s[i-1] + e[i-1];        
    }
    rep(i, n-k+1) {
        chmax(ans, s[i+k]-s[i]);
    }
    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
const int maxn=6005;
const int mod=998244353;
int n,kk;
int fac[maxn],inv[maxn],inv_s[maxn],pw[maxn];
int C(int x,int y){
  if(x<y||x<0)return 0;
  return 1LL*fac[x]*inv_s[y]%mod*inv_s[x-y]%mod;
}
int main(){
  //freopen("aa.in","r",stdin);
  fac[0]=1;
  for(int i=1;i<maxn;i++)fac[i]=1LL*fac[i-1]*i%mod;
  inv[0]=inv[1]=1;
  for(int i=2;i<maxn;i++)inv[i]=mod-1LL*mod/i*inv[mod%i]%mod;
  inv_s[0]=1;
  for(int i=1;i<maxn;i++)inv_s[i]=1LL*inv_s[i-1]*inv[i]%mod;
  pw[0]=1;
  for(int i=1;i<maxn;i++)pw[i]=2LL*pw[i-1]%mod;
  scanf("%d%d",&kk,&n);
  for(int s=2;s<=2*kk;s++){
    int t=0;
    int f=0;
    int o=(s%2==0);
    for(int i=1;i<s-i;i++){
      if(s-i<=kk)t++;
    }
    //printf("init %d %d %d\n",s,t,o);
    for(int i=0;i<=t;i++){
      int coef=1LL*C(t,i)*pw[i]%mod;
      for(int j=0;j<=o;j++){
        f=(f+1LL*coef*C(n+kk-2*t-o-1-j,i+kk-2*t-o-1))%mod;
      }
    }
    printf("%d\n",f);
  }
  return 0;
}

Measured memory_bytes: 384
#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<int> a(n);
   rep(i,n) cin>>a[i];
   vector<int> tmp(n);
   rep(i,n) tmp[i]=a[i];
   sort(tmp.begin(),tmp.end());
   rep(i,n){
      if(a[i]==tmp[n-1]) cout<<tmp[n-2]<<endl;
      else cout<<tmp[n-1]<<endl;
   }
   return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    string s;
    cin>>s;
    int num[3]={0};
    rep(i,s.size()) num[s[i]-'a']++;
    sort(num,num+3);
    if(num[2]-num[0]<=1) cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 512
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

ll arr[2000];
vector<ll> ans;
int main() {
	cin >> N >> A >> B;
	rep(i, N) {
		cin >> arr[i];
	}
	if (N < 2) cout << abs(B - arr[0]);
	else cout << max(abs(B - arr[N - 1]), abs(arr[N - 1] - arr[N - 2]));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  ll mod = pow(10, 9) + 7;
  cin >> N >> M;
  ll a[M];
  ll dp[N + 2]{};
  dp[0] = 1;
  for (int i = 0; i < M; i++) {
    cin >> a[i];
    dp[a[i]] = -1;
  }
  for (int i = 0; i < N; i++) {
    if (dp[i] == -1) continue;
    if (dp[i + 1] != -1) {
      dp[i + 1] += dp[i];
      dp[i + 1] %= mod;
    }
    if (dp[i + 2] != -1) {
      dp[i + 2] += dp[i];
      dp[i + 2] %= mod;
    }
  }
  cout << dp[N] << "\n";
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
  int h, w;
  scanf("%d %d", &h, &w);
  
  int c[10][10];
  for(int i = 0; i < 10; ++i) for(int j = 0; j < 10; ++j) scanf("%d", &c[i][j]);
  
  for(int k = 0; k < 10; ++k) for(int i = 0; i < 10; ++i) for(int j = 0; j < 10; ++j)
    c[i][j] = c[i][j] < c[i][k] + c[k][j] ? c[i][j] : c[i][k] + c[k][j];
  
  int mp = 0;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      int a;
      scanf("%d", &a);
      
      if(a != -1) mp += c[a][1];
    }
  }
  
  printf("%d", mp);
  
  return 0;
}

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll n,c;
ll h[202020];
ll deq[202020];
ll dp[202020];

ll f(ll j,ll i){
    return -2*h[j]*h[i]+dp[j]+h[j]*h[j]+c;
}
ll check(ll f1,ll f2,ll f3){
    ll a1=-2*h[f1];ll b1=dp[f1]+h[f1]*h[f1]+c;
    ll a2=-2*h[f2];ll b2=dp[f2]+h[f2]*h[f2]+c;
    ll a3=-2*h[f3];ll b3=dp[f3]+h[f3]*h[f3]+c;
    return (a2-a1)*(b3-b2)>=(b2-b1)*(a3-a2);
}

void solve(){
    cin>>n>>c;
    REP(i,n) cin>>h[i];
    int s=0,t=1;
    deq[0]=0;
    dp[0]=0;
    
    for(ll i=1;i<n;i++){
        while(s+1<t && f(deq[s],i)>=f(deq[s+1],i)) s++;
        dp[i]=h[i]*h[i]+f(deq[s],i);

        //直線を追加
        while(s+1<t && check(deq[t-2],deq[t-1],i)) t--; 
        deq[t]=i;
        t++;
    }
    cout<<dp[n-1]<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	stack<int>S1;
	stack<pair<int,int> >S2;
	char ch;
	int sum=0;
    for(int i=0;cin>>ch;i++)
    {
    	if(ch=='\\')S1.push(i);
    	else if(ch=='/'&&S1.size()>0)
    	{
    		int j=S1.top();S1.pop();
    		sum+=i-j;
    		int a=i-j;
    		while(S2.size()>0&&S2.top().first>j)
    		{
    			a+=S2.top().second;S2.pop();
    		}
    		S2.push(make_pair(j,a));
    	}
    }
    vector<int>ans;
    while(S2.size()>0){ans.push_back(S2.top().second);S2.pop();}
    reverse(ans.begin(),ans.end());
    cout<<sum<<endl;
    cout<<ans.size();
    for(int i=0;i<ans.size();i++)
    {
    	cout<<" ";
    	cout<<ans[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3216
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
long long n,m,i,j,ch[100005][2],cur,cnt=1;
string s;
long long dfs(long long x,long long dep)
{
	//if (!dep) return 0;
	long long ans=0,i;
	if (ch[x][0]+ch[x][1]!=0&&ch[x][0]*ch[x][1]==0) ans=(dep&(-dep));
	for (i=0;i<=1;i++) if (ch[x][i]) ans^=dfs(ch[x][i],dep-1);
	return ans;
}
int main()
{
	cin>>n>>m;
	for (i=1;i<=n;i++)
	{
		cur=1;
		cin>>s;
		for (j=0;j<s.size();j++)
		{
			if (!ch[cur][s[j]-'0']) ch[cur][s[j]-'0']=++cnt;
			cur=ch[cur][s[j]-'0'];
		}
	}
	if (dfs(1,m)) cout<<"Alice"; else cout<<"Bob";
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  ll n,k;
  cin >> n >> k;
  vector<pair<ll,ll>> vec(n);
  ll minsum = 0;
  rep(i,n){
    cin >> t1;
    vec[i].first = abs(t1);
    if(t1 >= 0){
      vec[i].second = 1;
    }else{
      vec[i].second = 0;
      minsum++;
    }
  }
  sort(all(vec),greater<pair<ll,ll>>());
  ll sum = 0;
  ll ans = 1;
  if(minsum == n){
    if(k % 2 == 0){
      rep(i,k){
        ans *= vec[i].first;
        ans %= mod;
      }
    }else{
      REP(i,n-k,n){
        ans *= vec[i].first;
        ans %= mod;
      }
      ans = (ans * -1 + mod) % mod;
    }
  }else{
    rep(i,k){
      ans *= vec[i].first;
      ans %= mod;
      if(vec[i].second == 0){
        sum++;
      }
    }
    if(sum % 2 != 0){
      ans = (-ans + mod) % mod;
      ll piv1 = -1;
      rep_rev(i,k){
        if(vec[i].second == 0){
          piv1 = i;
          break;
        }
      }
      ll piv2 = -1;
      REP(i,k,n){
        if(vec[i].second == 1){
          piv2 = i;
          break;
        }
      }


      ll piv3 = -1;
      rep_rev(i,k){
        if(vec[i].second == 1){
          piv3 = i;
          break;
        }
      }
      ll piv4 = -1;
      REP(i,k,n){
        if(vec[i].second == 0){
          piv4 = i;
          break;
        }
      }
      if(piv1 != -1 && piv2 != -1 && piv3 != -1 && piv4 != -1){
        if(vec[piv1].first * vec[piv4].first >= vec[piv2].first * vec[piv3].first){
          piv1 = -1;
        }else{
          piv3 = -1;
        }
      }
      if(piv1 != -1 && piv2 != -1){
        ll tans = vec[piv2].first;
        rep(i,k){
          if(i != piv1){
            tans *= vec[i].first;
            tans %= mod;
          }
        }
        ans = tans;
      }else if(piv3 != -1 && piv4 != -1){
        ll tans;
        tans = vec[piv4].first;
        rep(i,k){
          if(i != piv3){
            tans *= vec[i].first;
            tans %= mod;
          }
        }
        ans = tans;
      }
    }
  }



  cout << ans << endl;
}


Measured memory_bytes: 6428
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
 
#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pf(a) printf("%d\n",a);
#define pfl(a) printf("%lld\n",a);
#define TEST int test; cin >> test;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647
 
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);
 
ll power(ll x, unsigned long long y)
{
    ll res = 1;     // Initialize result
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x);
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}
map<ll,ll>mp;
void solve()
{
    int n;
    ll x,ans = 0;
    cin >> n ;
    ll a[n+1];
    for(int i = 1; i <= n ; i++)
    {
        cin >> a[i];
        mp[i+a[i]]++;
    }
    for(int i = 1; i <= n ; i++)
    {
        if(mp.count(i-a[i]))
            ans += mp[i - a[i]];
    }
    cout << ans << endl;
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //TEST
    solve();
    return 0;
}

Measured memory_bytes: 17612
n = gets.to_i
array = gets.split(" ").map{|k|k.to_i}
cnt = 0
for i in 0..(n-1) do
    minh = i
    for h in i..(n-1) do
        if array[minh] > array[h]
            minh = h
        end
    end
        if array[i] != array[minh]
            k = array[i]
            array[i] = array[minh]
            array[minh] = k
            cnt += 1
        end
end

puts array.join(" ")
puts cnt


Measured memory_bytes: 6876
#include<bits/stdc++.h>
#include<random>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

vector<bool> used(100010,false);
vector<vector<ll>> g;
vector<ll> pa(100010);
vector<ll> dpt(100010);
P edg;
set<ll> s;
void dfs(ll pos, ll par, ll d) {
	used[pos] = true;
	pa[pos] = par;
	dpt[pos] = d;
	REP(i,g[pos].size()) {
		if(g[pos][i] == par) continue;
		if(used[g[pos][i]]) {
			edg.first = pos;
			edg.second = g[pos][i];
		} else {
			dfs(g[pos][i],pos, d + 1);
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	cin >> N;
	g.resize(N);
	REP(i,N) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(0,-1,0);
	if(dpt[edg.first] < dpt[edg.second]) swap(edg.first,edg.second);
	ll p1=edg.first,p2=edg.second;
	s.insert(p1);s.insert(p2);
	while(dpt[p1] > dpt[p2]) {
		s.insert(p1);
		p1=pa[p1];
	}
	while(p1 != p2) {
		s.insert(p1);
		p1=pa[p1];
		s.insert(p2);
		p2=pa[p2];
	}
	s.insert(p1);
	ll Q;
	cin >> Q;
	REP(i,Q) {
		ll a,b;
		cin>>a>>b;
		a--;
		b--;
		if(s.count(a)&&s.count(b)) cout<<2<<endl;
		else cout<<1<<endl;
	}
	return 0;
}




Measured memory_bytes: 19220
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int a = 0;
		
		if((K % 2) == 0) {
			a = (K / 2) * (K / 2);
		} else {
			int b = (K - 1) / 2;
			a = (b + 1) * b;
		}
		System.out.println(a);
	}
}


Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadLineLongInt();
            var money = 100d;
            var year = 0;

            while(money < n) {
                money = Math.Floor(money*0.01) + money;
                year++;
            }

            Console.WriteLine(year);
            ReadLine();
        }

        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static long ReadLineLongInt() => long.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int n, x = 0;
    cin >> n;
    rep(i, n){
        int a; cin >> a;
        x ^= a;
    }

    Judge(!x);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

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

const int MAXH = 50, MAXW = 50;

char semi[MAXW + 2][MAXH + 2];
int dp[MAXW + 2][MAXH + 2];

int main()
{
    int h, w; cin >> h >> w;
    rep(j,h)rep(i,w) cin >> semi[i][j];
    
    rep(j, h - 1) dp[0][j + 1] = dp[0][j] + semi[0][j + 1] - '0';
    rep(i, w - 1) dp[i + 1][0] = dp[i][0] + semi[i + 1][0] - '0';

    rep(j, h)rep(i,w) dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j]) + semi[i + 1][j + 1] - '0';

    cout << dp[w - 1][h - 1] << endl;

    return 0;
}

Measured memory_bytes: 1176