akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void sort(int n,int score[n]){
  int i,j;
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(score[j-1]<score[j]){
        int d=score[j-1];
        score[j-1]=score[j];
        score[j]=d;
      }
    }
  }
}
int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(){
  int n,k,a;
  long int sum=0;
  int i;
  int x,y,z=0;
  int xi,yi,zi;
  int tmp,tmp2,tmp3;
  scanf("%d %d",&n,&k);
  int buf[n];
  for(i=0;i<n;i++){
    scanf("%d",&a);
    buf[i]=a;
    /*if(z<=a){
      tmp=z;
      tmp2=y;
      tmp3=x;
      z=a;y=tmp;x=tmp2;
      tmp=zi;
      tmp2=yi;
      tmp3=xi;
      z=i;y=zi;x=yi;
    }else if(y<=a){
      tmp2=y;
      tmp3=x;
      y=a;x=tmp2;
      tmp2=yi;
      tmp3=xi;
      y=i;x=yi;
    }else if(x<=a){
      x=a;
      xi=i;
    }
    */
  }
  qsort(buf, sizeof(buf) / sizeof(*buf), sizeof(*buf), desc);
  if(n<=k){
    printf("%ld\n",sum);
  }else{
    for(i=k;i<n;i++){
      sum+=buf[i];
    }
    printf("%ld\n",sum);
  }
  return 0;
}


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
 
int main(void){
    long A, B;
    cin >> A >> B;
  	long ans = 0;
  	if(B<=A){
      	if(B == 1){ans = 0;}else{ans = 1;} 
    }else if(B == 1){
		ans = 0;      
	}else{
      	long i = 0;
      	bool flag = true;
    	while(flag){
          	i++;
        	if(i*(A-1)+A >= B)flag = false;
        }
      	ans = 1 + i;
    }
  	cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, size):
        self.table = [None] * size

    def find(self, x):
        if self.table[x] == None:
            return x
        else:
            # compression of the path
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    
    def union(self, parent, child):
        p_root = self.find(parent)
        c_root = self.find(child)
        if p_root != c_root:
            self.table[c_root] = p_root
        
def solve():
    import sys
    input_lines = sys.stdin.readlines()
    while True:
        N, Q = map(int, input_lines[0].split())
        if N == 0:
            break
        
        parent = [0, 1] + list(map(int, input_lines[1:N]))
        
        unmarked = [True] * (N + 1)
        unmarked[1] = False
        operation = []
        for o in input_lines[N:N+Q]:
            mq, v = o.split()
            v = int(v)
            if mq == 'M':
                if unmarked[v]:
                    unmarked[v] = False
                    operation.append((mq, v))
            else:
                operation.append((mq, v))
        
        uf = UnionFind(N + 1)
        for v, p in enumerate(parent[2:], start=2):
            if unmarked[v]:
                uf.union(p, v)
        
        ans = 0
        for mq, v in reversed(operation):
            if mq == 'M':
                uf.union(parent[v], v)
            else:
                ans += uf.find(v)
        
        print(ans)
        
        del input_lines[:N+Q]

solve()


Measured memory_bytes: 89856
#include <iostream>
#include <string>

int main()
{
  std::string numCount = "";
  int limit = 0;
  int ableToGo = 0;
  int result = 0;
  int beforeNumber = 0;
  std::cin >> numCount;
  limit = std::stoi(numCount);
  std::cin >> numCount;
  beforeNumber = std::stoi(numCount);
  for(int i = 1; i < limit; ++i)
  {
    std::cin >> numCount;
    if(beforeNumber < std::stoi(numCount))
    {
      if(result < ableToGo) result = ableToGo;
      ableToGo = 0;
    }
    else
    {
      ++ableToGo;
    }
    beforeNumber = std::stoi(numCount);
  }
  if(result < ableToGo) result = ableToGo;
  std::cout << result << std::endl;
  return 0;
}

Measured memory_bytes: 256
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(x) begin(x),end(x)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const int inf = 2e9+9;
const int mod = 1e9+7;
ll n,sum;
int main(){
    fast,cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum += __gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3648
s = input()

res = 0
for i in range(2**(len(s)-1)):
    pos = 0
    for j in range(len(s)-1):
        if (i >> j) & 1:
            res += int(s[pos:j+1])
            pos = j + 1
    res += int(s[pos:])

print(res)


Measured memory_bytes: 9116
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using pii = pair<int,int>;
using ll = long long;
#define INF 0x3f3f3f3f

int N;
int K;

int x[100010];

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

    cin >> N >> K;
    rep(i, N) {
        cin >> x[i];
    }

    int l = 0;
    int r = K-1;

    int minv = INF;

    for (; r < N; ++l, ++r) {
        int sum = 0;

        int a = abs(x[l]);
        int b = abs(x[r]);

        if ((x[l] < 0) == (x[r] < 0)) {
            sum = max(a,b);
        }
        else {
            sum = min(a,b) + a + b;
        }

        minv = min(minv, sum);
    }

    outl(minv);


    return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
int n,a[10005],b[10005],cnt1,cnt2;
int main()
{
	while(~scanf("%d",&n))
	{
		LL suma = 0;
		for(int i = 1;i <= n;++i)
		{
			scanf("%d",&a[i]);
			suma += 1ll * a[i];
		}
		
		LL sumb = 0;
		for(int i = 1;i <= n;++i)
		{
			scanf("%d",&b[i]);
			sumb += 1ll * b[i];
		}	
		
		LL stp = sumb - suma;
		if (stp < 0)
		{
			printf("No");
			continue;
		}
		
		LL cnta = 0, cntb = 0;
		for (int i = 1; i <= n; i++)
		{
			if (a[i] == b[i]) continue;
			int d = b[i] - a[i];
			if (a[i] < b[i])
			{
				if (d & 1)
				{
					cnta += (d + 1) / 2;
					cntb++;
				}
				else
					cnta += d / 2;
			}
			if (a[i] > b[i])
			{
				d = -d;
				cntb += d;
			}
			
			if (cnta > stp || cntb > stp) break;
		}
		
		if (cnta > stp || cntb > stp) printf("No");
		else printf("Yes");
	}
	return 0;
}

Measured memory_bytes: 384
n = int( input() )
arr = list( map( int , input().strip().split(" ") ) )

dp = [ 0 for i in range(n) ]

for i in range(1,n):

    #one jump
    cost1 = abs(arr[i] - arr[i-1]) + dp[i-1] 
    cost2 = cost1 + 2
    # two jump
    if i != 1:
        cost2 = abs(arr[i] - arr[i-2]) + dp[i-2]

    dp[i] = min( cost1  ,cost2 )

print(dp[n-1])

Measured memory_bytes: 13928
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while(true){
		c -= b;
		if(c <= 0){
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if(a <= 0){
			cout << "No" << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3548
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    e = sorted([LI()[::-1] for _ in range(m)])
    r = 0
    c = -2
    for b,a in e:
        if a > c:
            r += 1
            c = b - 0.5
    return r


print(main())


Measured memory_bytes: 23396
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline int read()
{
	register int c=getchar(),f=1,k=0;
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	return k*f;
}
const int maxn=2*(1000000)+100;
char s[maxn],ss[maxn],sss[maxn];
int len;
int main()
{
	scanf("%s",s+1);
	int N=0;
	for (register int i=1;i<=len;i++)if (s[i]!='x')ss[++N]=s[i],sss[++N]=s[i];
	for (register int i=1;i<=N;i++)if (ss[i]!=sss[N-i+1])return puts("-1"),0;
	len=strlen(s+1);
	int l=1;
	int r=len;
	int ans=0;
	while (l<r)
	{
		if (s[l]!=s[r])
		{
			if (s[l]=='x')ans++,l++;else if (s[r]=='x')ans++,r--;
			else
			{printf("-1\n");return 0;
			}
		}
		else l++,r--;
	}
	printf("%d\n",ans);
} 


Measured memory_bytes: 2304
#include<stdio.h>

int main(){
  int h,w,n,sum=0,cnt=0;
  scanf("%d%d%d",&h,&w,&n);
  while(n>sum){
    if(h>w){
      sum+=h;
      w--;
    }else{
      sum+=w;
      h--;
    }
    cnt++;
  }
  printf("%d",cnt);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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;
}
int main() {
  cout << fixed << setprecision(10);
  ll n;
  cin >> n;
  ll ans = 0;
  ll tmp = n;
  if(n==1){
    cout << 0 << endl;
    return 0;
  }
  for(ll i=2; i*i<=tmp; i++){
    ll count = 0;
    while(n%i==0){
        n/=i;
        count++;
    }
    for(ll k=0; k<=tmp; k++){
      if(k*(k+1)/2==count){
        ans+=k;
        break;
      }else if(k*(k+1)/2>count){
        if(count-k*(k+1)/2<=k)
        ans+=k-1;
        break;
      }
    }

  }
  if(n!=1){
    ans+=1; 
  }
  cout << ans << endl;
}


Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <vector>
#include <sstream>

void manipStack(std::vector<int> &v, char op) {
    int temp1, temp2;
    temp2 = v.back();
    v.pop_back();
    temp1 = v.back();
    v.pop_back();
    switch (op) {
        case '+':
            v.push_back(temp1 + temp2);
            break;
        case '-':
            v.push_back(temp1 - temp2);
            break;
        case '*':
            v.push_back(temp1 * temp2);
            break;
        default:
            break;
    }
}

int main() {
    std::string str;
    std::vector<int> str_sp;
    
    // input
    std::getline(std::cin, str);
    std::istringstream iss(str);
    
    // calculation
    while(getline(iss, str, ' ')) {
        if (str == "+") {
            manipStack(str_sp, '+');
        } else if (str == "-") {
            manipStack(str_sp, '-');
        } else if (str == "*") {
            manipStack(str_sp, '*');
        } else {
            str_sp.push_back(std::stoi(str));
        }
    }
    
    std::cout << str_sp.back() << std::endl;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const int maxn = 5e5 + 50;
typedef pair<int, int> P;

int arr[maxn];
int a, b, c, d, e, f, g;
void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=0; i<t; i++)
	{
		solve();
	}
	return 0;
}

// type below

void solve()
{
	cin >> a;
	while(a)
	{
		if(a % 10 == 7)
		{
			cout << "Yes";
			return;
		}
		a /= 10;
	}
	cout << "No";
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
using namespace std;
typedef long long ll;

int main() {
	IOS;
	string s;
	int A, B[3];
	cin >> s;
	A = stoi(s.substr(0, 1));
	for (int i = 0; i < 3; i++) B[i] = stoi(s.substr(i + 1, 1));	
	int ans;
	for (int i = 0; i < (1 << 3); i++) {
		int sum = A;
		for (int j = 0; j < 3; j++) {
			if (i &(1 << j))sum += B[j];
			else sum -= B[j];
		}	
		if (sum == 7)ans = i;
	}
	string unko = s.substr(0, 1);
	for (int i = 0; i < 3; i++) {
		if (ans & (1 << i))unko.push_back('+');
		else unko.push_back('-');
		unko.push_back(s[i+1]);
	}
	unko = unko + "=7";
	cout << unko << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,x,y,m=0;
	cin>>n>>k>>x>>y;
	if(n>k)
	{
		m=x*k+(n-k)*y;
	}
	else m=n*x;
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import *

N = int(input())
xy = [tuple(map(int, input().split())) for _ in range(N)]

if N==1:
    print(1)
    exit()
    
cnt = defaultdict(int)

for i in range(N):
    for j in range(N):
        if i==j:
            continue
        
        cnt[(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])] += 1

M = max(list(cnt.values()))
print(N-M)

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

int checkEqual(int i, int n, int *A, int M) {
  if (A[i] == M) {
    return 1;
  }
  else {
    if (i == n - 1) {
      return 0;
    }
    else {
      int ans1 = checkEqual(i + 1, n, A, M - A[i]);
      int ans2 = checkEqual(i + 1, n, A, M);

      return ans1 || ans2;
    }
  }
}

int main()
{
  int n;
  cin >> n;
  int *A = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int M;
    cin >> M;

    int ans = checkEqual(0, n, A, M);
    if (ans) {
      cout << "yes" << endl;
    }
    else {
      cout << "no" << endl;
    }
  }

  return 0;
}


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

int main(void){
	char c[2];
	cin >> c;
	if(c[0]=='a' || c[0]=='i'||c[0]=='e'||c[0]=='u'||c[0]=='o'){
		cout << "vowel";
	}else{
		cout << "consonant";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s, t, ans; int dp[3001][3001];
int main(){
    cin >> s >> t;
    for(int i=1; i<=s.size(); i++){
        for(int j=1; j<=t.size(); j++){
            if(s[i-1] == t[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    for(int i=s.size(), j=t.size(); i!=0 && j!=0; ){
        if(dp[i][j] == dp[i-1][j]) i--;
        else if(dp[i][j] == dp[i][j-1]) j--;
        else { ans.push_back(s[i-1]); i--; j--; }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 35456
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vi black(N), white(N);
  if (S[0] == '0') {
    black[0] = 0;
    white[0] = 1;
  } else {
    black[0] = 1;
    white[0] = 0;
  }
  for (int i = 1; i < N; i++) {
    if (S[i] == '1') {
      white[i] = black[i-1];
      black[i] = white[i-1] + 1;
    } else {
      white[i] = black[i-1] + 1;
      black[i] = white[i-1];
    }
  }
  cout << min(black[N-1], white[N-1]) << endl;
  return 0;
}


Measured memory_bytes: 1280
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String s = scan.next();
		
		if(s.charAt(0) >= 'A' && s.charAt(0) <= 'Z') {
			System.out.println("A");
		}else {
			System.out.println("a");
		}
		
		
	}
}
 


Measured memory_bytes: 35772
S = list(map(int, input().split()))
X = S[0];
K = S[1];
D = S[2];
if (K % 2) == 1:
	X1 = X - D
else:
	X1 = X
L1 = X1 % (2*D)
L2 = L1 - 2*D
ans = 1000000000000000000
if abs(X - L1) < K * D:
	ans = min(ans, L1)
if abs(X - L2) < K * D:
	ans = min(ans, -L2)
ans = min(ans, abs(X - K*D))
ans = min(ans, abs(X + K*D))
print(ans)

Measured memory_bytes: 9072
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, x = inpl()
A = inpl()

min_cost_s = 0
tmp = INF
for i in range(N):
    if A[i] < tmp:
        min_cost_s = i
        tmp = A[i]

A = A[min_cost_s:] + A[:min_cost_s]
B = [A[i] for i in range(N)]

ans = INF
for shift in range(N):
    for i in range(N):
        if i - shift >= 0:
            B[i] = min(B[i], A[i - shift])
    # print(B)

    ans = min(ans, shift * x + sum(B))

print(ans)


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    lint A, B, N;
    cin >> A >> B >> N;

    auto compute = [&](lint x) {
        return A * x / B - A * (x/B);
    };

    // for_(x,1,N+1) cerr << "#" << x << " " << compute(x) << endl;

    lint x = min(B - 1, N);
    cout << compute(x) << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
    int n, m;
    string u, t;
    set<string> u_set;
    bool is_opened = false;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> u;
        u_set.insert(u);
    }
    cin >> m;
    for (int i=0; i<m; i++) {
        cin >> t;
        if (u_set.find(t) != u_set.end()) {
            if (is_opened) {
                cout << "Closed by " << t << endl;
                is_opened = false;
            }
            else {
                cout << "Opened by " << t << endl;
                is_opened = true;
            }
        }
        else {
            cout << "Unknown " << t << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1232
n,q,*abpx=map(int,open(0).read().split())
edge=[[] for i in range(n)]
for a,b in zip(abpx[:-2*q:2],abpx[1:-2*q:2]):
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

base_score = [0]*n
for p,x in zip(abpx[-2*q::2],abpx[-2*q+1::2]):
    base_score[p-1] += x
    
score=[0]*n
check=[0]*n
update_n=[0]
check[0] = 1
while update_n:
    current_n = update_n.pop()
    score[current_n] = base_score[current_n]
    for next_n in edge[current_n]:
        if check[next_n]:
            continue
        else:
            check[next_n] = 1
            base_score[next_n] += base_score[current_n]
            update_n += next_n,

print(*score)

Measured memory_bytes: 94956
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<cassert>
#include<sstream>
#include<complex>
#include<cstdio>
#include<climits>
#include<cstdlib>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<ctime>
#include<cctype>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS) 
#define MAX 5010
using namespace std;
/*
dp[今どこの切断可能な点をみているのか][自分のとったお菓子の数][１つ前の切断可能な点を切断したかしないか（0->切断していない,1->切断した）] := その時の最小コスト

切断する -> 切断した場所のお菓子を自分のものとする
 */
int dp[2][MAX][2];

/*
cost[0]とcost[N]は端の部分
 */
int cost[MAX*2];
int N;


int main()
{
  cin >> N;
  REP(i,1,N)cin >> cost[i];
  rep(i,2)rep(j,MAX)rep(k,2)dp[i][j][k] = inf;
  dp[0][0][0] = 0;

  rep(i,N+1)
    {
      rep(j,min((int)(N/2),i)+1)
	{
	  dp[(i+1)&1][j][0]   = min(dp[i&1][j][0],dp[i&1][j][1]);
	  dp[(i+1)&1][j+1][1] = min(dp[i&1][j][0]+cost[i]+cost[i+1],dp[i&1][j][1]-cost[i]+cost[i+1]);
	}
    }
  cout << min(dp[N%2][N/2][0],dp[N%2][N/2][1]) << endl;
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

vector<vector<int>> get_graph(int n, vector<P> &edges) {
    vector<vector<int>> graph(n);
    for (P &p:edges) graph[p.first].push_back(p.second);
    return graph;
}

vector<double> solve(int n, vector<P> &edges) {
    auto g = get_graph(n, edges);

    vector<double> dp(n, 0);
    for (int i = n - 2; i >= 0; i--) {
        double now = 0;
        for (int to : g[i]) {
            now += dp[to];
        }
        now /= g[i].size();
        now += 1;
        dp[i] = now;
    }
    return dp;
}

int get_max_e(vector<int> &tos, vector<double> &dp) {
    if (tos.size() == 1) return -1;
    double ma = 0;
    for (int to : tos) cmax(ma, dp[to]);
    for (int to : tos) if (dp[to] == ma) return to;
    __throw_runtime_error("konaide");
}

vector<P> filter_edge(vector<P> edges, P p) {
    auto it = find(edges.begin(), edges.end(), p);
    assert(it != edges.end());
    edges.erase(it);
    return edges;
}

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

    vector<P> edges(m);
    for (P &p:edges) cin >> p.first >> p.second, p.first--, p.second--;

    vector<vector<int>> graph = get_graph(n, edges);

    vector<double> plain = solve(n, edges);

    double ans = plain[0];

    rep(i, n - 2) {
        int max_e = get_max_e(graph[i], plain);
        if (max_e == -1) continue;
        vector<P> edge_ignore = filter_edge(edges, P(i, max_e));
        assert(edge_ignore.size() + 1 == edges.size());
        double now = solve(n, edge_ignore)[0];
        cmin(ans, now);
    }
    cout << setprecision(20) << ans << endl;

}

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

using namespace std;

int main() { 

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int n, d;
	cin >> n >> d;

	vector<vector<int>> a(n, vector<int>(d));
	
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < d; j++) {
			cin >> a[i][j]; 
		}
	}

	int ans = 0;

	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			int sum = 0;
			for(int k = 0; k < d; k++) {
				sum += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
			}
			if(sqrt(sum) == int(sqrt(sum))) ans++;
		}
	}

	cout << ans;

	return 0; 
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ld long double
#define pi 3.1415926535897932384626433832795028841971693993
#define MOD 998244353
#define sec setprecision
using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n,ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return pow(x * x % m, n / 2, m);
	else
		return x * pow(x, n - 1, m) % m;
}
ll pow(ll x, ll n) {
	if (n == 0)
		return 1;
	else if (x == 1)return(1);
	else if (n % 2 == 0)
		return pow(x * x , (n / 2));
	else
		return x * pow(x, n - 1);
}
int ketasuu(ll h) {
	if (h < 0)return(-(ketasuu(-h)));
	else if (h < 10)return(1);
	else return(1 + ketasuu(h / 10));
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long com(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if ((a - b) % 2 == 0) {
		cout << (b-a) / 2 << endl;
	}
	else {
		cout << min(a - 1, n - b) + 1 + (b - a - 1) / 2 << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,min,l=0;
	cin>>n;
	min=n;
	for(int i=2;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			min=n/i;
		}
	}
	while(min!=0)
	{
		min/=10;
		l++;
	}
	cout<<l<<endl;
	return 0;
}

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

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

using namespace std;

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

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

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

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

  ll h, w;
  cin >> h >> w;
  vvll dist(10, vll(10));
  rep(i, 10) rep(j, 10) cin >> dist[i][j];

  rep(k, 10) rep(i, 10) rep(j, 10) chmin(dist[i][j], dist[i][k] + dist[k][j]);

  ll ans = 0;
  rep(i, h) {
    rep(j, w) {
      ll a;
      cin >> a;
      if (a == -1) continue;
      ans += dist[a][1];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3592
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split(' ')))
q = tuple(map(int, input().split(' ')))

x = [i for i in range(1,n+1)]
ls = list(permutations(x))
i = 0
for per in ls:
    if per == p:
        a = i
    if per == q:
        b = i
    i += 1

print(abs(a-b))


Measured memory_bytes: 13796
n, x = map(int, input().split())
l = list(map(int, input().split()))

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

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
const int INF=1001001001;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int n;
    cin >> n;
    int d[n];
    rep(i,n){
        cin >> d[i];
    }
    ll ans = 0;
    rep(i, n - 1)
    {
        rep2(j,i+1,n){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

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

  int n, x; cin >> n >> x;
  vll s(n);
  for(int i=0;i<n;++i) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  vvll dp(n+1, vll(x+1, 0));
  for(int i=0;i<=x;++i) {
    dp[0][i] = i;
  }
  for(int i=0;i<n;++i) {
    for(int j=0;j<=x;++j) {
      dp[i+1][j] += dp[i][j%s[i]];
      dp[i+1][j] %= MOD;
      dp[i+1][j] += dp[i][j] * i % MOD;
      dp[i+1][j] %= MOD;
    }
  }
  cout << dp[n][x] << endl;

}


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

using matrix = vector<vector<long long>>;

const int mod = 1000000007;

int N;
long long K;
matrix A;

matrix mul(matrix &a, matrix &b) {
    matrix res(N, vector<long long>(N, 0));
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            for(int k = 0; k < N; k++)
                (res[i][j] += a[i][k] * b[k][j]) %= mod;
    return res;
}

matrix pow(matrix m, long long k) {
    matrix res(N, vector<long long>(N, 0));
    for(int i = 0; i < N; i++)
        res[i][i] = 1; // 単位行列にする

    while(k > 0) {
        if(k & 1) res = mul(res, m);
        m = mul(m, m);
        k >>= 1;
    }
    return res;
}

int main() {
    cin >> N >> K;
    A.assign(N, vector<long long>(N));
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            cin >> A[i][j];

    A = pow(A, K);

    long long res = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            res += A[i][j];
            if(res >= mod) res -= mod;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	int a, b,c,k;
	int ans;
	cin >> a >> b >> c >> k;
	if (a >= b && a >= c){
		ans = a*pow(2, k) + b + c;
	}
	else if (b >= a&&b >= c){
		ans = a + b*pow(2, k) + c;
	}
	else{
		ans = a + b + c*pow(2, k);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()!!.toInt()

    val counter = mutableMapOf<Long, Long>()
    val list = readLine()!!.split(' ').map {
        val index = it.toLong()
        counter[index] = (counter[index] ?: 0) + 1
        return@map index
    }

    val calc = counter.map { it.value * (it.value - 1) / 2 }.sum()
    list.forEach { value ->
        println(calc - (counter[value]!! - 1))
    }
}

Measured memory_bytes: 112424
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Magatro
{
    
    static void Main()
    {
        int[] a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int cnt = 1;
        if (a[1] != a[0])
        {
            cnt++;
        }
        if (a[2] != a[1] && a[2] != a[0])
        {
            cnt++;
        }
        Console.WriteLine(cnt);
    }
   
}




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

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    for(int i=1; i<n; i++){
        string x = s.substr(0, n-i);
        string y = s.substr(n-i, i);
        int al_x[26]={0};
        int al_y[26]={0};
        for(int j=0; j<x.length(); j++) al_x[x.at(j)-'a']++;
        for(int j=0; j<y.length(); j++) al_y[y.at(j)-'a']++;
        int count =0;
        for(int j=0; j<26; j++){
            if(al_x[j]>0 && al_y[j]>0) count++;
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
a, b, c, d = map(int, ','.join(input()).split(','))

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = 0
            lists = []
            if i % 2 == 0:
                ans = a + b
                lists.append('+')
            else:
                ans = a - b
                lists.append('-')
            if j % 2 == 0:
                ans += c
                lists.append('+')
            else:
                ans -= c
                lists.append('-')
            if k % 2 == 0:
                lists.append('+')
                ans += d
            else:
                ans -= d
                lists.append('-')
            if ans == 7:
                print(str(a) + lists[0] + str(b) + lists[1] + str(c) + lists[2] + str(d) + '=7')
                exit()

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

int main() {
    int N;
    cin >> N;
    
  
    if (N == 1||N == 2||N == 3||N == 4||N == 5||N == 6||N == 7||N == 8||N == 9||N == 10||N == 12||N == 14||N == 15||N == 16||N == 18||N == 20||N == 21||N == 24||N == 25||N == 27||N == 28||N == 30||N == 32||N == 35||N == 36||N == 40||N == 42||N == 45||N == 48||N == 49||N == 54||N == 56||N == 63||N == 72||N == 81||N == 64) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int i=0;
	int a[5]={0};
	scanf("%d %d %d %d %d",a,a+1,a+2,a+3,a+4);
	for(i=0;i<5;i++)
    {
	    if(a[i]==0)printf("%d",i+1);
    }
}

Measured memory_bytes: 1736
import java.util.*;

public class Main {

    static int[][] g;
    static int n;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        g = buildGraph(sc, n, n-1);
        long[] di = dijkstra(n, g, 0);
        long max = 0;
        int idx = 0;
        for (int i = 0; i < n; i++) {
            if(max < di[i]){
                max = di[i];
                idx = i;
            }
        }
        di = dijkstra(n, g, idx);
        max = 0;
        idx = 0;
        for (int i = 0; i < n; i++) {
            if(max < di[i]){
                max = di[i];
                idx = i;
            }
        }
        max++;
        System.out.println((max % 3 == 0 || max % 3 == 1) ? "First" : "Second");
        sc.close();
    }

    public static long[] dijkstra(int n, int[][] graph, int s) {
        // {sからの最短距離, 頂点}
        PriorityQueue<long[]> pq =
                new PriorityQueue<long[]>((x, y) -> Long.compare(x[0], y[0]));
        long[] d = new long[n]; // sからの最短距離
        Arrays.fill(d, Long.MAX_VALUE);
        d[s] = 0;
        pq.add(new long[]{0, s});
        while(!pq.isEmpty()){
            long[] a = pq.poll();
            int v = (int)a[1];
            if(d[v] < a[0]) continue;
            for (int g: graph[v]) {
                int to = g;
                int cost = 1;
                if(d[to] > d[v] + cost){
                    d[to] = d[v] + cost;
                    pq.add(new long[]{d[to], to});
                }
            }
        }

        return d;
    }

    public static int[][] buildGraph(Scanner sc, int n, int m){
        int[][] graph = new int[n][];
        int[][] edges = new int[m][2];
        int[] deg = new int[n];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() -1;
            int b = sc.nextInt() -1;
            edges[i][0] = a;
            edges[i][1] = b;
            deg[a]++;
            deg[b]++;
        }
        for (int i = 0; i < n; i++) {
            graph[i] = new int[deg[i]];
        }
        for (int i = 0; i < m; i++) {
            int a = edges[i][0];
            int b = edges[i][1];
            graph[a][--deg[a]] = b;
            graph[b][--deg[b]] = a;
        }

        return graph;
    }

}


Measured memory_bytes: 134800
#include <bits/stdc++.h>
using namespace std;
// for(int i = 0;i < num; i++){}
int main() {
    //
  
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
    int num;
    int cnt = 0;
  scanf("%d", &num);
    //cin >> num;

    for (int i = 1; i <= num; i++) {
        cnt = 0;
        for (int x = 1; x <= sqrt(i); x++) {
            if (x*x + x > i) break;
            for (int y = 1; y <= sqrt(i); y++) {
                if (x*x + y*y + x * y + x + y> i) break;
                for (int z = 1; z <= sqrt(i); z++) {
                    if (x*x + y*y + z*z + x * y + y * z + z * x > i) break;
                    if (x*x + y*y + z*z + x * y + y * z + z * x == i) cnt++;
                }
            }
        }
printf("%d\n", cnt);
        //cout << cnt << endl;
    }
    //
}


Measured memory_bytes: 3828
#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
template<class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    int k, x;
    while(~scanf("%d %d", &k, &x)) {
        for(int i = x - k + 1; i <= x + k - 1; ++i) {
            if(i != x - k + 1) printf(" ");
            printf("%d", i);
        }
        printf("\n");
    }
    return 0;
}

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define pb push_back
#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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 int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

int main()
{
    string s; cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          163577857
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

 typedef tree<pii, null_type, less<pii>, rb_tree_tag,  
            tree_order_statistics_node_update>  odst; 


void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   
    #endif
}



void solve()
{
 int n;
 cin >> n ;
 int a[n+1];

 forf(i,1,n+1) cin >> a[i];

 map<int,int>mp;
 
 int an =0;
 for(int i=1;i<=n;i++)
 {
   an += mp[i-a[i]];
   mp[a[i]+i]++;
 }

 cout<<an<<endl;
 
 



}

int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

 }

Measured memory_bytes: 27828
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N ;
  int P = 0; 
  
  for (int i = 0;i < N; i++) {
   
   int l_i,r_i;
     
    cin >> l_i >> r_i;
    
   P  += r_i - l_i + 1;
  }
  cout << P << endl;
}

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

int main(){
	int n;
	while (cin >> n) {
		if (n == 0) { break; }
		int x, y, a[15][15] = {};
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j <= n; j++) {
				if (j == n) {
					a[i][n] = sum;
					continue;
				}
				cin >> a[i][j];
				sum += a[i][j];
			}
		}
		for (int i = 0; i<n; i++) {
			for (int j = 0; j <= n; j++) {
				a[n][j] += a[i][j];
			}
		}
		for (int i = 0; i<=n; i++) {
			for (int j = 0; j <= n; j++) {
				int k;
				if (a[i][j] != 0) {
					k = log10(a[i][j]);
					k = 4 - k;
				}
				else{
					k = 4;
				}
				for(int z = 0; z < k; z++){
					cout << " ";
				}
				cout << a[i][j];
			}

			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3344
#include<bits/stdc++.h>          
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)	make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

vector<int> a(100500);
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin >> n >> k;
	int minv = INF;
	int pnt = 0;
	reps(i,n){
		cin >> a[i];
		if(a[i] == 1) pnt = i;
	}
	int cnt = 0;
	cnt = (n + k - 1) / k;
	cout << ((n - 1) + (k - 1) - 1)/ (k - 1) << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

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

}
int main(){
  
  ll N;
  cin>>N;
  
  vector<string>S(N);
  
  rep(i,N){
    cin>>S[i];
    }
  sort(all(S));
   
    ll ans=1;
  string now=S[0];
  rep(i,S.size()){
    if(i!=0){
      if(S[i]!=now){
ans++;
        now=S[i];
      }
    }
  }
  cout<<ans<<endl;
  

    }

Measured memory_bytes: 9596
#include <iostream>
#include <limits.h>
using namespace std;
int mod(int n)
{
	if(n>=0) return n;
	return -1*n;
}
int cost(int n, int h[],int i)
{
	if(i == n-1) return 0;
	if(i == n-2) return mod(h[n-1]-h[n-2]);
	return min(mod(h[i]-h[i+1])+cost(n,h,i+1),mod(h[i]-h[i+2])+cost(n,h,i+2));
}

int cost2(int n, int h[])
{
	int a[n],i;
	for(i=0;i<n;i++)
	    a[i] = INT_MAX;
	if(n==1) return 0;
	if(n==2) return mod(h[0]-h[1]);
	a[n-1] = 0;
	a[n-2] = mod(h[n-1]-h[n-2]);
	for(i=n-3;i>=0;i--)
		a[i] = min(mod(h[i]-h[i+1])+a[i+1],mod(h[i]-h[i+2])+a[i+2]);
	return a[0];
}

int main()
{
	int n;
	cin >> n;
	int i,h[n];
	for(i=0;i<n;i++)
		cin >> h[i];
	cout << cost2(n,h);
	return 0;
}

Measured memory_bytes: 1024
from heapq import heapify, heappush, heappop

n, m = map(int, input().split())
a = list(map(int, input().split()))

q = [-ai for ai in a]
heapify(q)

for i in range(m):
    v = heappop(q)
    v = -(abs(v) // 2)
    heappush(q, v)

print(-sum(q))

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	cout << (m1 != m2 ? "1" : "0") << endl;
	return 0;
}


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


int main(){
  string S;
  char now = 'a';
  cin >> S;

  sort(S.begin(),S.end());

  for(size_t i = 0; i < S.size(); i++){
    if(now == S[i]){
      now++;
    }else if(now < S[i]){
      cout << now << endl;
      return 0;
    }
  }

  if(now <= 'z'){
    cout << now << endl;
    return 0;
  }
  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void) {

	long long int money = 100;

	long long int targetValue = 0;

	scanf("%lld%*c", &targetValue);

	int year = 0;

	while (targetValue > money)
	{
		money = money+money/100;

		year++;

	}

	printf("%d\n", year);

	return 0;
}

Measured memory_bytes: 1732
package main

import (
  "fmt"
)

func main() {
  var s string
  fmt.Scanf("%s", &s)
  str := []rune("CODEFESTIVAL2016")
  
  ans := 0
  for i, v := range s {
    if v != str[i] {
      ans++
    }
  }
  fmt.Printf("%d\n", ans)
}

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

using namespace std;

int n, m;
vector<int> v;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < m-1; ++i) {
        v[i] = v[i+1] - v[i];
    }
    v.pop_back();
    sort(v.begin(), v.end());
    while (--n && v.size()) {
        v.pop_back();
    }
    int ans = 0;
    for (int i = 0; i < (int) v.size(); ++i) {
        ans += v[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include<stdio.h>

int main()
{
    int N, a, b;

    scanf("%d", &N);

    if(N == 1){
        printf("Hello World\n");
    }
    else{
        scanf("%d %d", &a, &b);

        printf("%d\n", a+b);
    }


    return 0;
}


Measured memory_bytes: 128