akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 1e18;
long long int N,K,l[100],sum=0;
pll key[1005];
string str[1234];
int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>K;
    for(long long int i = 0; i < N; i++){
        cin>>l[i];
    }
    sort(l,l+N,greater<long long int>());
    for(long long int i = 0; i < K; i++){
        sum+=l[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
   int a;
   int b;
   
	scanf("%d", &a);
	scanf("%d", &b);
	
   if (a < b)
   {
      printf("a < b\n");
   }
   if (a > b)
   {
      printf("a > b\n");
   }
   if (a == b)
   {
      printf("a == b\n");
   }
   
	return 0;
}

Measured memory_bytes: 580
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<int> d(n);
	for (auto &v : d) {
		cin >> v;
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (i == j) {
				continue;
			}
			ans += d[i] * d[j];
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define MAXN 1000002
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod=1e9+7;

void solve()
{
    int a,b;
    cin>>a>>b;
    if(b>=a)
    cout<<"unsafe";
    else
    cout<<"safe";
}

int main()
{
  fastio
  solve();
}


Measured memory_bytes: 3612
#include <iostream>

using namespace std;
char alpha(char x){
char a[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z'};
     x++;
     return x;
}

int main()
{
    char j;
    cin>>j;
    cout<< alpha(j);
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    string s,t;cin>>s>>t;
    int reg=INF;
    for(int i=0;i<s.size()-t.size();i++){
        int cnt=0;
        for(int j=0;j<t.size();j++){
            if(s[i+j] != t[j]) cnt++;
        }
        reg=min(cnt,reg);
    }

    int cnt=0;
    REP(i,t.size()){
        if(s[i] != t[i]) cnt++;
    }

    reg=min(cnt,reg);
    

    cout << reg << endl;
}

Measured memory_bytes: 3612
N,K=map(int, input().split())
ans=0
mod=10**9+7
for i in range(K,N+2):
    if i==K:
        MIN=sum(list(range(0,K)))%mod
        MAX=sum(list(range(N,N-K,-1)))%mod
    else:
        MIN+=(i-1)%mod
        MAX+=(N+1-i)%mod
    ans+=(MAX-MIN+1)%mod
    ans%=mod

print(ans)

Measured memory_bytes: 16624
#import
#import math
#import numpy as np
#= int(input())
#= input()
#= map(int, input().split())
#= [input(), input()]

s = input()
t = input()

sl = len(s)
tl = len(t)

dp = [[0] * (tl + 1) for _ in range(sl + 1)]

for i in range(1, sl + 1):
    for j in range(1, tl + 1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
        dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1])

res = ""
i = sl
j = tl  
while i > 0 and j > 0:
    if dp[i - 1][j] == dp[i][j]:
        i -= 1

    elif dp[i][j - 1] == dp[i][j]:
        j -= 1

    else:
        res = s[i - 1] + res
        i -= 1
        j -= 1

print(res)

Measured memory_bytes: 144500
#include<stdio.h>
int main(){
    int n,m;
    scanf("%d",&n);
    scanf("%d",&m);
    int k[n];
    int a[n][31];
    for(int i=0;i<n;i++){
        scanf("%d",&k[i]);
        for(int j=0;j<k[i];j++)
            scanf("%d",&a[i][j]);
    }
    int like[m];
    for(int i=0;i<=m;i++)
        like[i]=0;
    int ans=0;

    for(int i=0;i<n;i++){
        for(int j=0;j<k[i];j++)
            like[a[i][j]]++;
    }

    for(int i=0;i<=m;i++){
        if(like[i]==n)
            ans++;
    }        

    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
int binary_search_index(Int Y, vi &q){
    int left = 0, right = q.size() - 1;
    while (right >= left) {
        int mid = left + (right - left) / 2;
        if (q[mid] == Y) return mid;
        else if (q[mid] > Y) right = mid - 1;
        else if (q[mid] < Y) left = mid + 1;
    }
    return -1;
}


int main() {
    Int N,M;
    cin >> N >> M;
    vi L = vi(M);
    vi R = vi(M);
    rep(i,M){
        cin >> L[i] >> R[i];
    }
    int min_c = 1;
    int max_c = N;

    rep(i,M){
        if(L[i]>min_c){
            min_c = L[i];
        }
        if(R[i]<max_c){
            max_c = R[i];
        }
    }
    int ans = max(0,max_c-min_c+1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
# coding: utf-8

N, Q = map(int, input().split())
S = input()

num = [0] * (N+1)

for i in range(N):
    #if S[i]=='A' and S[i+1]=='C':
    if S[i:i+2] =='AC':
        num[i + 1] = num[i] + 1
    else:
        num[i + 1] = num[i]

        

for i in range(Q):
    l, r = map(int, input().split())
    print( num[r-1] - num[l-1] )


Measured memory_bytes: 6188
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        while(!input.equals("0")){
            int sum = 0;
            for(int i = 0; i < input.length(); i++){
                sum += input.charAt(i) - 48;
            }
            System.out.println(sum);
            input = sc.nextLine();
        }
    }
}



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

int main() {

  int A; cin >> A; // 冷蔵庫の種類数
  int B; cin >> B; // 電子レンジの種類数
  int M; cin >> M; // 割引券の種類数

  vector<int> a(A); // 冷蔵庫の値段
  rep(i,A){cin >> a.at(i);}
  vector<int> b(B); // 電子レンジの値段
  rep(i,B){cin >> b.at(i);}

  int x,y,c;  // 割引対象冷蔵庫番号・電子レンジ番号・割引額
  int min_val = 200000; // 最小購入価格
  int tmp_val = 200000; // 暫定購入価格

  if (debug) {
    cout << "A:" << A << endl;
    cout << "B:" << B << endl;
    cout << "M:" << M << endl;
  }

  // 割引券使用時の価格
  rep(i,M){
    cin >> x >> y >> c;  // 割引対象冷蔵庫番号・電子レンジ番号・割引額
    tmp_val = a.at(x-1) + b.at(y-1) - c;
    min_val = min(tmp_val,min_val);
    if (debug) {cout << tmp_val << ":" << min_val << endl;}
  }
  // 割引券非使用時の価格
  int min_valA = 100000; // 最小の冷蔵庫の価格
  int min_valB = 100000; // 最小の電子レンジの価格
  rep(i,A){
    if ( a.at(i) < min_valA ) { min_valA = a.at(i);}
  }
  rep(i,B){
    if ( b.at(i) < min_valB ) { min_valB = b.at(i);}
  }
  tmp_val = min_valA+min_valB;
  min_val = min(tmp_val,min_val);
  if (debug) {cout << tmp_val << ":" << min_valA << ":" << min_valB << endl;}

  cout << min_val << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1005],b[1005];
ll zyou(ll i,ll n){
	ll k=1;
	while(n>0){
		if(n&1) k=k*i;
		i=i*i;
		n>>=1;
	}
	return k;
}
int main(void){
    ll n,p; cin>>n>>p;
    ll ans=1;
    if(n==1){
		cout<<p<<endl; return 0;
	}
	if(n>=40){
		cout<<1<<endl;
		return 0;
	}
    for(ll i=2;zyou(i,n)<=p;i++){
		while(p%zyou(i,n)==0){
			ans=ans*i;
			p=p/zyou(i,n);
		}
	}
	cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int N=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int dp[1<<N], temp[1<<N];
bool bad[N+1][N+1][2];

inline void fix(int &x){
	if (x>=mod) x-=mod;
	if (x<0) x+=mod;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m>>k;
	n--;
	while (k--){
		cin>>a>>b>>x;
		bad[a-1][b-1][x^1]=1;
	}
	dp[0]=1;
	for (int i=0; i<m; i++){
		int x=(i&1);
		for (int j=0; j<n; j++){
			memset(temp, 0, sizeof(temp));
			for (int mask=0; mask<(1<<n); mask++){
				if (!bad[i][j][0] && ((mask>>j)&1)==0)
					fix(temp[mask]+=dp[mask]);
				if (!bad[i][j][1]){
					if (mask&(1<<j)) fix(temp[mask]+=dp[mask]);
					else{
						int msk=mask|(1<<j);
						int tmp=mask>>j<<j;
						if (tmp) msk^=tmp&-tmp;
						fix(temp[msk]+=dp[mask]);
					}
				}
			}
			memcpy(dp, temp, sizeof(dp));
		}
	}
	for (int mask=0; mask<(1<<n); mask++) fix(ans+=dp[mask]);
	cout<<ans<<"\n";
	
	return 0;
}


Measured memory_bytes: 11816
s = input().strip()
k = int(input())

found = False
# 最初の1でない数字がどこに現れるか
for i in range(len(s)):
    if s[i] != '1':
        found = True
        break

if found:
    if k <= i:
        print(1)
    else:
        print(s[i])
else:
    print(s[0])


Measured memory_bytes: 2940
import java.util.*;
import java.util.Map.Entry;
 
 
 
public class Main{
	
	public int num;
	public int vol;
 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 int N=sc.nextInt();
	 int[] A=new int[N+2];
	 A[0]=0;
	 A[N+1]=0;
	 long sum=0;
	 
	 for(int i=1;i<=N+1;i++) {
		 if(i<=N) {
			 A[i]=sc.nextInt();
		 }
		 sum+=Math.abs(A[i]-A[i-1]);
	 }
	 
	//System.out.println(sum);
	 for(int i=1;i<=N;i++) {
		
			System.out.println(sum+Math.abs(A[i+1]-A[i-1])-Math.abs(A[i]-A[i-1])-Math.abs(A[i+1]-A[i]));
		
	 }
 }
	
 
 
}


Measured memory_bytes: 68192
#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	string inf;
	for (int i : range(26))inf += string(1, 'a' + i);
	reverse(ALL(inf));
	string s;
	while (cin >> s) {
		if (s == inf) {
			cout << -1 << endl;
		}
		else {
			if (s.size() < 26) {
				set<char> x;
				for (auto &it : s)x.insert(it);
				for (int i : range(26))if (x.count('a' + i) == 0) {
					cout << s << string(1, 'a' + i) << endl;
					break;
				}
			}
			else {
				set<char> x;
				char last;
				while (s.size()) {
					last = s.back();
					s.pop_back();
					x.insert(last);
					if (s.back() < last)break;
				}
				last = s.back(); s.pop_back();
				cout << s << *x.upper_bound(last) << endl;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;
	if(W<x+r){
		cout << "No" << endl;
	}
	else if(0>x-r){
		cout << "No" << endl;
	}
	else if(H<y+r){
		cout << "No" << endl;
	}
	else if(0>y-r){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3112
#include<iostream>
using namespace std;
int main(){

while(1){
int m,f,r;
cin>>m>>f>>r;
if(m==-1 && f==-1 && r==-1)break;

if(m==-1 || f==-1){
cout<<"F"<<endl;
}else{
int q=m+f;
 if( q>=80 ){
  cout<<"A"<<endl;
 }else if( q>=65 && q<80 ){
  cout<<"B"<<endl;
 }else if( q>=50 && q<65 ){
  cout<<"C"<<endl;
 }else if( q>=30 && q<50 ){
  if(r>=50)cout<<"C"<<endl;
  if(r<50)cout<<"D"<<endl;
 }else if(q<30){
  cout<<"F"<<endl;
 }
}
}

}



Measured memory_bytes: 3100
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
A=set(a);B=set(b)
ans = 1
cnta = 0
cntb = 0
mod = 10**9+7
for num in range(n*m,0,-1):
    if num in A and num in B:
        cnta += 1
        cntb += 1
    elif num in A:
        ans *= cntb
        cnta += 1
    elif num in B:
        ans *= cnta
        cntb += 1
    else:
        ans *= (cnta*cntb - (n*m - num))%mod
    ans %= mod
print(ans)

Measured memory_bytes: 3316
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
#define oset tree<pi, null_type,greater<pi>, rb_tree_tag,tree_order_statistics_node_update>


int main()
{
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt << "\n";


    return 0;
}


Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  long long cnt[N];
  fill(cnt, cnt + N, 0);
  long long A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (i + A[i] < N) cnt[i + A[i]]++;
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    if (i - A[i] >= 0) ans += cnt[i - A[i]];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6744
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
bool isSquare(ll n) {
	ll d = (ll)sqrt(n) - 1;
	while (d * d < n) ++d;
	return d * d == n;
}

/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int N, D, X[10][10];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> D;
	rep(i, 0, N) rep(d, 0, D) cin >> X[i][d];

	int ans = 0;
	rep(i, 0, N) rep(j, i + 1, N) {
		int dd = 0;
		rep(d, 0, D) dd += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
		if (isSquare(dd)) ans++;
	}
	cout << ans << endl;
}







Measured memory_bytes: 256
fn solve(ps: Vec<usize>, k: usize) -> f64 {
    let n = ps.len();

    let mut sum = 0.0;
    let mut msum = 0.0;

    for i in 0..n {
        sum += (1.0 + ps[i] as f64) / 2.0;
        if i >= k {
            sum -= (1.0 + ps[i - k] as f64) / 2.0;
        }

        if msum < sum {
            msum = sum
        }
    }

    msum
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (n, k) = parse_line!(usize, usize);
    let ps = parse_vec!(usize);

    println!("{}", solve(ps, k));
}


Measured memory_bytes: 8444
import sys

sys.setrecursionlimit(100000)
input=lambda : sys.stdin.readline().rstrip('\n')

n,m=map(int,input().split())
g=[[]for i in range(n)]
s=set()
for i in range(m):
    a,b,c=map(int,input().split())
    g[a-1].append((c,b-1))
    g[b-1].append((c,a-1))
    if a>b:
        a,b=b,a
    s.add((a-1,b-1))

def dijkstra(g,st,s):
    from heapq import heappush, heappop, heapify
    inf=10**18
    dist=[inf for i in range(len(g))]
    visited=[False for i in range(len(g))]
    dist[st]=0
    que=[]
    heappush(que,(0,st,-1))
    while que:
        c,v,past=heappop(que)
        if visited[v]:
            continue
        visited[v]=True
        try:
            s.remove((v,past) if v<past else (past,v))
        except:
            pass
        for x in g[v]:
            tmp=x[0]+c
            if tmp<dist[x[1]] and not visited[x[1]]:
                dist[x[1]]=tmp
                heappush(que,(tmp,x[1],v))

for i in range(n):
    dijkstra(g,i,s)
print(len(s))


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

int main(){
  string x,y;
  int n;
  cin >> n;
  cin >> x >> y;
  string ans="";
  for(int i=0;i<n;i++){
    ans+=(char)x[i];
    ans+=(char)y[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <random>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define pi 3.141592653589793
#define prique priority_queue
constexpr auto mod=1000000007;
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int n){
    int cnt=0;
    for(int i=1;i<=sqrt(n);i++){
        if(n%1==0)cnt++;
    }
    if(cnt!=1) return false;
    else return n!=1;
}
struct UnionFind{
    vector<int> r;
    UnionFind(int N){
        r=vector<int>(N,-1);
    }
    int root(int x){
        if(r[x]<0) return x;
        return r[x]=root(r[x]);
    }
    bool unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(r[x]>r[y]) swap(x,y);
        r[x]+=r[y];
        r[y]=x;
        return true;
    }
    int size(int x){
        return -r[root(x)];
    }
};
vector<int> v;
int n,m,cnt=0,ans=0,aa[220000];
pair<int,int> pp[220000];
string s,ss[220000];
queue<int> que;
signed main(){
    cin>>s;
    if(s[s.size()-1]=='s'){
        cout<<s+"es";
    }else{
        cout<<s+'s';
    }
}

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

int main(void){
	string s[55][2];
	int ans[100],k,i,p,q;
	bool flag;
	cin >> q;
	for(p=0; p<q; p++){
		cin >> s[p][0];
		cin >> s[p][1];
		fill(ans,ans+100,0);
		if( s[p][0].length()>80 || s[p][1].length()>80 ){
			cout << "overflow" << endl;
			continue;
		}
		for(k=0; k<2; k++){
			reverse(s[p][k].begin(),s[p][k].end());
			for(i=(s[p][k].length()-1); i>=0; i--){
				ans[i] += (s[p][k][i] - '0');
			}
		}
		for(i=0; i<80; i++){
			ans[i+1] += (ans[i]/10);
			ans[i] %= 10;
		}
		flag = true;
		for(i=99; i>79; i--){
			if(ans[i] != 0){
				cout << "overflow" << endl;
				flag = false;
				break;
			}
		}
		if(!flag){
			continue;
		}
		flag = false;
		for(i=79; i>=0; i--){
			if(flag){
				cout << ans[i];
			}else if(ans[i]!=0){
				cout << ans[i];
				flag = true;
			}
		}
		if(!flag){
			cout << "0";
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

const int N = 1e5 + 5;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  long long ans = 0;
  for (int b = 1; b <= n; ++b) {
    for (int a = 0; a <= n; a += b) {
      int sisa = min(n-a+1, b);
      sisa -= min(sisa, k);
      ans += sisa;
    }
  }
  if (k == 0)
    ans = 1LL * n * n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		BigInteger a = new BigInteger(sc.next());
		BigInteger b = new BigInteger(sc.next());
		
		a = a.multiply(b);
		
		System.out.println(a);
	}

}



Measured memory_bytes: 26524
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static const long long MOD_NUM = 1000000007LL;

static void A_task();

int main()
{
	A_task();
	fflush(stdout);
	return 0;
}

static void A_task()
{
	int N;
	get1int(N);

	printf("%d\n", N * N * N);
}


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

using lint = int64_t;
const lint MOD = 1e9 + 7;

struct Node {
    bool visited;
    vector<int> tos;
    lint col;
};

void dfs(int pos, lint k, vector<Node>& nodes) {
    nodes[pos].visited = true;
    lint bro = 1;
    for (int nex: nodes[pos].tos) {
        if (nodes[nex].visited == true) bro++;
    }
    lint kp = k - bro;
    for (int nex: nodes[pos].tos) {
        if (nodes[nex].visited == false) {
            nodes[nex].col = kp;
            dfs(nex, k, nodes);
            kp--;
        }
    }
}

int main() {
    int n; lint k;
    cin >> n >> k;
    vector<Node> nodes(n);
    for (int i = 0; i < n; i++) {
        nodes[i].visited = false;
    }
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        nodes[a].tos.push_back(b);
        nodes[b].tos.push_back(a);
    }

    nodes[0].col = k;
    dfs(0, k, nodes);
    lint ans = 1;
    for (int i = 0; i < n; i++) {
        if (nodes[i].col <= 0) {
            ans = 0;
            break;
        } else {
            ans = (ans * nodes[i].col) % MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  int n, x;
  cin >> n >> x;
  ll dis = 0;
  int count = 1;
  REP(i, n) {
    int l;
    cin >> l;
    dis += l;
    if (dis <= x) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
	long long a,b,m,n,x,gcd,lcm;
	
	while(scanf("%lld %lld",&a,&b)==2)
	{
		m=a;
		n=b;
		while(1){
			if(!(x=m%n)){
				gcd=n;
				break;
			}
			m=n;
			n=x;
		}
		lcm=a*b/gcd;
		printf("%lld %lld\n",gcd,lcm);
	}
	return 0; 
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if((a==1 && b==2) || (a==2 && b==1)){printf("%d",3);}
    else if((a==1 && b==3) || (a==3 && b==1)){printf("%d",2);}
    else if((a==2 && b==3) || (a==3 && b==2)){printf("%d",1);}
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	h, w int
	s    []string
)

func calcLeft(c chan [][]int) {
	ls := make([][]int, h)
	for i := range ls {
		ls[i] = make([]int, w)
		for j := 0; j < w; j++ {
			if s[i][j] == '#' {
				ls[i][j] = 0
				continue
			}
			if j == 0 {
				ls[i][j] = 1
				continue
			}
			ls[i][j] = ls[i][j-1] + 1
		}
	}
	c <- ls
}

func calcRight(c chan [][]int) {
	rs := make([][]int, h)
	for i := range rs {
		rs[i] = make([]int, w)
		for j := w - 1; j >= 0; j-- {
			if s[i][j] == '#' {
				rs[i][j] = 0
				continue
			}
			if j == w-1 {
				rs[i][j] = 1
				continue
			}
			rs[i][j] = rs[i][j+1] + 1
		}
	}
	c <- rs
}

func calcTop(c chan [][]int) {
	ts := make([][]int, h)
	for i := range ts {
		ts[i] = make([]int, w)
	}
	for j := 0; j < w; j++ {
		for i := 0; i < h; i++ {
			if s[i][j] == '#' {
				ts[i][j] = 0
				continue
			}
			if i == 0 {
				ts[i][j] = 1
				continue
			}
			ts[i][j] = ts[i-1][j] + 1
		}
	}
	c <- ts
}

func calcDown(c chan [][]int) {
	ds := make([][]int, h)
	for i := range ds {
		ds[i] = make([]int, w)
	}
	for j := 0; j < w; j++ {
		for i := h - 1; i >= 0; i-- {
			if s[i][j] == '#' {
				ds[i][j] = 0
				continue
			}
			if i == h-1 {
				ds[i][j] = 1
				continue
			}
			ds[i][j] = ds[i+1][j] + 1
		}
	}
	c <- ds
}

func main() {
	fmt.Scan(&h, &w)

	sc := bufio.NewScanner(os.Stdin)
	s = make([]string, h)
	for i := range s {
		sc.Scan()
		s[i] = sc.Text()
	}

	c := make(chan [][]int)
	go calcLeft(c)
	go calcRight(c)
	go calcTop(c)
	go calcDown(c)
	xs1, xs2, xs3, xs4 := <-c, <-c, <-c, <-c

	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if v := xs1[i][j] + xs2[i][j] + xs3[i][j] + xs4[i][j] - 3; v > ans {
				ans = v
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 138272
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long n;
 cin>>n;
vector<long long>v;
     for(int i=0;;i++)
     {if (i*i<=n)
         {v.push_back(i*i);}
         else
         {
             break;
         }
     }
     cout<<v[v.size()-1];
     
     
     
     
     
 
}

Measured memory_bytes: 640
n, w = map(int,input().split())
weight = []
value = []
for i in range(n):
    x, y = map(int,input().split())
    weight.append(x)
    value.append(y)

dp = [[0]*(w+1) for i in range(n+1)]
# dp[i][sum_w] := i-1 番目までの品物から重さが sum_w を超えないように選んだときの、価値の総和の最大値
omosa = 0

for i in range(n):
    for omosa in range(w+1):
        if weight[i] <= omosa: #もし追加しても制限を超えないなら
            #i番目の商品を選ぶ場合
            dp[i+1][omosa] = max(dp[i+1][omosa], value[i] + dp[i][omosa-weight[i]])
        #i番目の商品を選ばない場合(これはいつでも起きる)
        dp[i+1][omosa] = max(dp[i+1][omosa], dp[i][omosa])

print(dp[n][w])

Measured memory_bytes: 120684
def calc():
  n=int(input())
  arr=[]
  check='abcdefghijklmnopqrstuvwxyz'
  while n!=0:
    n-=1
    arr.append(check[n%26])
    n//=26
  arr=arr[::-1]
  print(''.join(map(str,arr)))
  
calc()

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < N; ++i){
    if(A[i] > i){
      cout << -1 << endl;
      return 0;
    }
  }
  long long int ans = A.back();
  for(int i = N - 2; i >= 0; --i){
    if(A[i] == A[i+1] - 1) continue;
    if(A[i] < A[i+1] - 1){
      cout << -1 << endl;
      return 0;
    }
    ans += A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=1000000+5;
const ll inf=1e18;
const ll mod=1e9+7;

ll T[MX], lazy[MX], X[MX], H[MX];

void propagate(int p, int l, int h)
{
    T[p]+=(h-l+1)*lazy[p];
    if(l!=h)
    {
        lazy[2*p]+=lazy[p];
        lazy[2*p+1]+=lazy[p];
    }
    lazy[p]=0;
}
void up(int p, int l, int h, int x, int y, ll vl)
{
    if(lazy[p]!=0) propagate(p, l, h);
    if(x>h || y<l) return;
    if(l>=x && h<=y)
    {
        T[p]+=(h-l+1)*vl;
        if(l!=h)
        {
            lazy[2*p]+=vl;
            lazy[2*p+1]+=vl;
        }
        return;
    }
    int m=(l+h)/2;
    up(2*p, l, m, x, y, vl);
    up(2*p+1, m+1, h, x, y, vl);
    T[p]=T[2*p]+T[2*p+1];
}

long long Q(int p, int l, int h, int x, int y)
{
    if(x>h || y<l)   return 0;
    if(lazy[p]!=0)   propagate(p, l, h);
    if(l>=x && h<=y) return T[p];
    int m=(l+h)/2;
    return Q(2*p, l, m, x, y)+Q(2*p+1, m+1, h, x, y);
}

int main()
{
    FasterIO;

    ll tc, n, D, A;
    cin>>n>>D>>A;

    vector<ll>v; vector<pL>pa;
    for(int i=1; i<=n; i++)
    {
        cin>>X[i]>>H[i];
        pa.push_back({X[i], H[i]});
        v.push_back(X[i]);
    }
    v.push_back(1e18);
    sort(v.begin(), v.end());
    sort(pa.begin(), pa.end());
    for(int i=0; i<n;i++)
    {
        up(1, 1, n, i+1, i+1, pa[i].ss);
    }
    ll sm=0;
    for(int i=1; i<=n; i++)
    {
        ll h=Q(1, 1, n, i, i);
        if(h>0)
        {
            ll time=h/A+(h%A!=0);
            int lo=lower_bound(v.begin(), v.end(), pa[i-1].ff+2LL*D)-v.begin();

            if(v[lo]!=pa[i-1].ff+2LL*D) lo--;
            up(1, 1, n, i, min((ll)lo+1, n), -time*A);
            sm+=time;
        }
    }
    cout<<sm<<endl;
    return 0 ;
}


Measured memory_bytes: 25964
import java.util.Scanner;
/**
 * 解题方法 26 进制
 * k 进制每一位最大只有 k - 1，但是此道题目最大可以是 26，所以每次处理 N - 1
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long N = scanner.nextLong();
        String ans = "";
        while (N > 0) {
            N--;
            ans = (char)(N % 26 + 97) + ans;
            N /= 26;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 39160
from collections import deque

N, M = map(int, input().split())
edge = [[0 for i in range(N)] for i in range(N)]
edges = [(0,0) for i in range(M)]
ckd = [False for i in range(N)]
ans = 0


for i in range(M):
  a, b = map(int, input().split())
  edge[a-1][b-1] = 1
  edge[b-1][a-1] = 1
  edges[i] = (a-1, b-1)
  
for e in edges:
  edge[e[0]][e[1]] = 0
  edge[e[1]][e[0]] = 0
  
  q = deque()
  q.append(0)
  ckd = [False for i in range(N)]
  
  while q:
    r = q.popleft()
    for d in range(N):
      if edge[r][d] and not(ckd[d]):
        ckd[d] = True
        q.append(d)
        
  if not(all (c for c in ckd)):
    ans += 1
    
  edge[e[0]][e[1]] = 1
  edge[e[1]][e[0]] = 1
  
print(ans)

Measured memory_bytes: 40120
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#include <numeric>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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; cin >> N;
    vector<int>A(N+1);
    rep(i, N) {
        cin >> A[i];
    }
    ll ans = 0;
    sort(A.begin(), A.end(), greater<int>());
    A.insert(A.begin(), 0);
    REP(i, N / 2) {
        ans += 2*A[i];
        
   }
    if (N % 2 != 0) {
        ans += A[N / 2 + 1];
    }
    cout << ans-A[1] << endl;

   
}

        
 

    


    


    





















Measured memory_bytes: 4828
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    int a[n], b[n]; rep(i, n) cin >> a[i] >> b[i];
    int c[m], d[m]; rep(i, m) cin >> c[i] >> d[i];
    rep(i, n) {
        int ans = inf;
        int key = i;
        rep(j, m) {
            int tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (ans > tmp) {
                ans = tmp;
                key = j;
            }
        }
        cout << key + 1 << endl;
    }
    
    
}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.Array.IArray
import qualified Data.List as L
import Data.Char

type Table = Array (Int, Int) Char

main :: IO ()
main = do
  ss <- map split0 . lines <$> getContents
--  print ss
  mapM_ (putStrLn . toChar) ss
--  print table

toChar :: [String] -> String
toChar ss = map (\(i, j) ->
                   if i == 0 then ' '
                   else
                     if 2 <= i && j > 3 && i /= 7 && i /= 9
                     then toUpper (table ! (i, j-3))
                     else if (i == 7 || i == 9 ) && j > 4
                          then toUpper (table ! (i, j-4))
                          else (table ! (i, j)) ) ints
  where
    ints :: [(Int, Int)]
    ints =  concatMap (map (\ll ->
                              (read [head ll], length ll)) .
                       L.group) ss
               
split0 = split' (=='0')

split' :: (Char -> Bool) -> String -> [String]
split' p str = go str
  where
    go [] = []
    go ss = (if null ls then "0" else ls) : go (drop 1 rs)
      where
        (ls, rs) = break p ss

table :: Table
table = table' // zip (zip (repeat 1) [1..5]) "',.!?"
  where
    table' = accumArray (\_ c -> c) '1' ((1,1), (9, 5)) ns
    ns = zip [(i, j) |
               i <- [2..9],
               j <- [1..4],
               (i == 7 || i == 9) || (j /= 4)] ['a'..'z']

Measured memory_bytes: 4176
#include <bits/stdc++.h>  // ver2.2.6
#define int long long
 #define endl "\n"
 #define ALL(v) (v).begin(),(v).end()
 #define COUNT(a,i) upper_bound(ALL(a),i)-lower_bound(ALL(a),i)
 #define Vi vector<int>
 #define VVi vector<Vi>
 #define Vs vector<string>
 #define Pii pair<int,int>
 #define VPii vector<Pii>
 #define Tiii tuple<int,int,int>
 #define PQi priority_queue<int>
 #define PQir priority_queue<int,vector<int>,greater<int>>
 #define pb push_back
 #define mp make_pair
 #define mt make_tuple
 #define itos to_string
 #define stoi stoll
 #define FI first
 #define SE second
 #define cYES cout<<"YES"<<endl
 #define cNO cout<<"NO"<<endl
 #define cYes cout<<"Yes"<<endl
 #define cNo cout<<"No"<<endl
 #define cyes cout<<"yes"<<endl
 #define cno cout<<"no"<<endl
 #define _ <<' '<<
 #define sortr(v) sort(v,greater<>())
 #define rep(i,a,b) for(int i=a;i<b;i++)
 #define repeq(i,a,b) for(int i=a;i<=b;i++)
 #define repreq(i,a,b) for(int i=a;i>=b;i--)
 #define leng(n) (int)(log10(n)+1)
 #define dem(a,b) ((a+b-1)/(b))
 #define Vin(a) rep(iI,0,a.size())cin>>a[iI]
 #define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
 #define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
 #define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
 #define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
 #define VVerr(a) rep(iY,0,a.size()){Verr(a[iY]);}
 #define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
 #define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
 #define MAX LLONG_MAX
 #define MOD 1000000007  //  10^9 + 7
 using namespace std;



 int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
 int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
 void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮
 int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
 if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}

int comb(int n, int r){  //  nCr (MOD環境下)
  int a=1;for(int i=n;i>n-r;--i){a=a*i%MOD;}for(int i=1;
  i<r+1;++i){a=a*mypow(i,MOD-2,MOD)%MOD;}return a%MOD;}

Vi nCr(int n){
  cerr << n << endl;
  Vi a(n+1);
  a[0] = 1;
  repeq(i,1,n){
    a[i] = a[i-1]*(n+1-i)/(i);
  }
  return a;
}

signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,a,b,qw;
  cin >> n >> a >> b;
  
  vector<int> v(n);
  rep(i,0,n){
    cin >> qw;
    v.at(i) = qw;
  }
  sortr(ALL(v));
  int minn = v[a-1];
  
  double sum=0.0;
  int upper=0;
  rep(i,0,a){
    if(v[i] > minn) upper++;
    sum += v[i];
  }
  int ans = 0;
  cout<<sum/a<<endl;
  reverse(ALL(v));
  int minnct = COUNT(v,minn);
  
  Vi memo = nCr(minnct);
  
  Verr(memo);
  if(upper==0){
    repeq(i,a,b){
      if(i<=minnct) {
        ans += memo[i];
      }
    }
  }
  else{
    ans = memo[a-upper];
  }
  //cerr << minnct _ a _ upper << endl;
  cout<< ans <<endl;
  
  return 0;
}

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()

  cnt=0
  for j in range(-1,3):
    for b in range(-1,3):
      for c in range(-1,3):
        for d in range(-1,3):
          for e in range(-1,3):
            for f in range(-1,3):
              for g in range(-1,3):
                for h in range(-1,3):
                  for i in range(-1,3):
                    a=0

                    if i==0:
                      a+=3
                    elif i==1:
                      a+=5
                    elif i==2:
                      a+=7

                    if h==0:
                      a+=30
                    elif h==1:
                      a+=50
                    elif h==2:
                      a+=70

                    if g==0:
                      a+=300
                    elif g==1:
                      a+=500
                    elif g==2:
                      a+=700

                    if f==0:
                      a+=3000
                    elif f==1:
                      a+=5000
                    elif f==2:
                      a+=7000

                    if e==0:
                      a+=30000
                    elif e==1:
                      a+=50000
                    elif e==2:
                      a+=70000

                    if d==0:
                      a+=300000
                    elif d==1:
                      a+=500000
                    elif d==2:
                      a+=700000

                    if c==0:
                      a+=3000000
                    elif c==1:
                      a+=5000000
                    elif c==2:
                      a+=7000000

                    if b==0:
                      a+=30000000
                    elif b==1:
                      a+=50000000
                    elif b==2:
                      a+=70000000

                    if j==0:
                      a+=300000000
                    elif j==1:
                      a+=500000000
                    elif j==2:
                      a+=700000000

                    if a>n:
                      return cnt
                    else:
                      x=list(set(str(a)))
                      if x.count('0')>0:
                        continue
                      if len(x)==3:
                        cnt+=1
  
  return cnt

print(main())


Measured memory_bytes: 5420