akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <functional>
#define MOD 1000000007

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 (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

struct edge {
    int to;
    int cost;
};

typedef long long ll;
using namespace std;
using P = pair<int, int>;

bool compare_by_b(pair<int,pair<string,int>> a, pair<int,pair<string,int>> b) {
    if(a.second.first != b.second.first){
        return a.second.first < b.second.first;
    }else{
    return a.second.second > b.second.second;
    }
}

int ncr(int n, int r){
    return 0;
}

int main(void) {
    COMinit();
    
    int i=0,j=0,k=0;
    int n;
    vector<int> v;
    cin >> n >> k;
    ll ans=0;
    for(i=1;i<=k;i++){
        ans = COM(n-k+1,i);
        ans = ans * COM(k-1,i-1) % MOD;
        
        cout << ans << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 12160
#include<cstdio>
#include<iostream>

int main(){
    int k,a,b,c;

    scanf("%d",&k);
    scanf("%d",&a);
    scanf("%d",&b);

    if(a > b) {
        c = a%k;
        if(c <= a - b ) {
            printf("OK\n");
        } else {
            printf("NG\n");
        }
    } else {
        c = b%k;
        if(c <= b-a){
            printf("OK\n");
        } else {
            printf("NG\n");
        }

    }

    return 0;

}

Measured memory_bytes: 3688
// AOJ 0615 Cake 2
// 2018.2.27 bal4u

#include <stdio.h>

int n;
int a[2002];
long long memo[2002][2002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

long long calc(int l, int r, int s)
{
	int nl, nr;
	long long k, k2;

	if (memo[l][r]) return memo[l][r];
	if (l == r) {
		if (s) return memo[l][r] = 1;
		return memo[l][r] = a[l] + 1;
	}
	nl = l+1; if (nl == n) nl = 0;
	nr = r-1+n; if (nr >= n) nr -= n;
	if (s) {
		if (a[l] > a[r]) return memo[l][r] = calc(nl, r, 0);
		else             return memo[l][r] = calc(l, nr, 0);
	}
	k  = calc(nl, r, 1) + a[l];
	k2 = calc(l, nr, 1) + a[r];
	if (k2 > k) k = k2;
	return memo[l][r] = k;
}

int main()
{
	int i, i1, i2;
	long long k, ans;

	n = in();
	for (i = 0; i < n; i++) a[i] = in();
	a[n] = a[0];

	ans = 0;
	i1 = 1, i2 = n-1; for (i = 0; i < n; i++) {
		if (i1 == n) i1 = 0;
		if (i2 == n) i2 = 0;
		k = calc(i1, i2, 1) + a[i] - 1;
		if (k > ans) ans = k;
		i1++, i2++;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 33152
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

int main() {
  int a, b;
  std::cin >> a >> b;
  if (a + b == 15) std::cout << "+" << std::endl;
  else if (a * b == 15) std::cout << "*" << std::endl;
  else std::cout << "x" << std::endl;
  return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int n,s;

int f(int cur,int num,int sum){
	if(cur==10)return num==0 && sum==0;
	return f(cur+1,num,sum) + f(cur+1,num-1,sum-cur);
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>n>>s && (n||s)){
		cout<<f(0,n,s)<<endl;
	}
}

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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)

int32_t main(){
  	fast;
    int n; cin >> n;
    int ar[n];

    int minn = 1e18,sum=0,neg=0;

    for(int i=0;i<n;i++){
      cin >> ar[i];
      if(ar[i]<0) neg++;
      ar[i] = abs(ar[i]);
      minn = min(minn,ar[i]);
      sum+=ar[i];
    }

    if(neg%2==0) cout << sum;
    else cout << sum-2*minn;
    
    return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};


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

  ll n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ub = 1e9+2;
  int lb = 0;
  while(ub-lb>1){
    int mid = (ub+lb)/2;
    vector<int> b(n);
    rep(i,n){
      if(a[i]<mid) b[i] = 0;
      else b[i] = 1;
    }
    vector<int> sum(n+1);
    sum[0] = 0;
    rep(i,n) sum[i+1] = sum[i] + b[i];
    rep(i,n+1) sum[i] = sum[i]*2 - i + n;
    BinaryIndexedTree<int> bito(n*3+10);
    BinaryIndexedTree<int> bite(n*3+10);
    ll cnt = 0;
    rep(i,n+1){
      // cout << sum[i] << endl;
      if(i%2==0){
        cnt += bite.sum(sum[i]);
        cnt += bito.sum(max(0,sum[i]-1));
        bite.add(sum[i],1);
      }
      else{
        cnt += bite.sum(max(0,sum[i]-1));
        cnt += bito.sum(sum[i]);
        bito.add(sum[i],1);
      }
    }
    // cout << mid <<" " << cnt << endl;
    if(cnt>=(n*(n+1)/2+1)/2) lb = mid;
    else ub = mid;
  }
  cout << lb << endl;
   

  
  return 0;
    

}


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

int main() {
  int N, D, X[10][10];
  int num = 0;
  cin >> N >> D;
  for(int i=1; i<=N; i++) {
    for(int j=1; j<=D; j++)
      cin >> X[i][j];
  }
  for(int n=1; n<N; n++) {
    for(int i=n+1; i<=N; i++) {
      int a=0;
      for(int j=1; j<=D; j++) {
	a += (X[n][j]-X[i][j])*(X[n][j]-X[i][j]);
      }
      int temp = sqrt(a);
      if(temp*temp==a)
	num++;
    }
  }

  cout << num << endl;
  return 0;	
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<limits>
#include<iomanip>
using namespace std;





int main(){
    cout<<fixed<<setprecision(12);
    double d;
    cin>>d;
    double ans=d;
    int x=(int)ans;
    if(d*d-x*x<=1 && x>=1){ans=max(x*1.0+1,ans);}
    ans=max(pow(d*d/2,1.0/2)*2,ans);
    cout<<ans<<endl;
    
    return 0;
}




Measured memory_bytes: 3476
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }
    let modulo = 1_000_000_007;
    println!(
        "{}",
        a.iter()
            .fold(
                (a.iter().fold(0, |sum, ai| sum + ai), 0),
                |(rem, res), ai| (rem - ai, (res + (rem - ai) % modulo * ai) % modulo)
            )
            .1
    );
}


Measured memory_bytes: 5548
s = input()
def dfs(i, f, sum):
  if i == 3:
    if sum == 7:
      print(f + '=7')
      exit()
  else:
    dfs(i + 1, f + '-' + s[i + 1], sum - int(s[i + 1]))
    dfs(i + 1, f + '+' + s[i + 1], sum + int(s[i + 1]))

dfs(0, s[0], int(s[0]))

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

        using namespace std;

        #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        #define FOR(i,a,b) for(int i = (a); i < (b); i++)
        #define rep(i,n) FOR(i,0,n)
        #define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
        #define ITER(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
        #define FILL(a,value) memset(a, value, sizeof(a))

        #define SZ(a) (int)a.size()
        #define ALL(a) a.begin(),a.end()
        #define PB push_back
        #define MP make_pair
        #define in insert
        #define er erase
        #define fs first
        #define sc second


        typedef long long LL;
        typedef vector<int> VI;

        typedef vector<bool> VB;
        typedef vector<LL> VL;
        typedef pair<int,int> PII;
        typedef pair<LL,LL> PLL;
        typedef vector<PII> VPI;
        typedef vector<VL>VVL;
        typedef vector<VI>VVI;
        typedef vector<string>VS;

        typedef vector<vector<PII>> VVPI;
        typedef vector<vector<PLL>> VVPL;



        const double PI = acos(-1.0);
        const int INF = 1000 * 1000 * 1000 + 7;
        const LL LINF = INF * (LL)INF;

        const int MAX = 305;

        const int MAS = 1e5 + 10 ;
        const int MOD = 1000 * 1000 * 1000 + 7;
        const double EPS = 1e-8;



        int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            //  freopen("skateboard.in","r",stdin);
            //  freopen("skateboard.out","w",stdout);
            int n;
            cin >> n;
            VL h(n);
            int base = 1;
            while(base <= n)
            {
                base*=2;
            }
            VL tree(base * 2);
            rep(i,n)
            {
                cin >> h[i];
            }
            VL a(n);
            rep(i,n)
            {
                cin >> a[i] ;
            }
            vector<LL > dp(n + 1);
            rep(i,n)
            {

                LL x =h[i] + base;
                LL best = 0;
                while(x > 1)
                {
                    if(x%2 == 1)
                    {
                        best =max(best,tree[x-1]);
                    }
                    x/=2;
                }
              //  return 0;
                dp[h[i]] = best +a[i];
                for(int j = base + h[i]; j >=1;j/=2)
                {

                    tree[j] = max(tree[j],dp[h[i]]);
                }
             }
            LL ans = 0;
            for(int i = 0; i <=n;i++)
            {
                ans = max(ans,dp[i]);
            }
            cout << ans << endl;
        }

Measured memory_bytes: 9088
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

def calculate(N,M,arr):
    ret = 0

    j = 0

    res = []

    # 1,2,3,4,5
    #         ↑
    # 4,3,2,1

    # M = 4
    # range(1,5) => 1,2,3,4

    for i in range(1,M+1):
        # i = 1,2,3
        # 比如M=4的话，第三天(最多1天),第二天(最多2天),第一天(最多3天)

        # 记下来循环打工信息资源,以j为标记
        # j为资源编号
        # arr[j][0]为该编号资源的天数


        # 候补的资源，满足所有天数，因为是满足后续的天数来算的

        while (j < N) and (arr[j][0] <= i):

                heappush(res, -arr[j][1])
                j = j + 1 #j找到的话就往上顶一格，一共这一天，或者前一天寻找的时候以下一个资源天为开始

        if len(res) > 0:
            ret -= heappop(res)

    return ret


N,M = map(int,input().split())


# 后面的逻辑是基于前面的从小到大的排序的
list = [list(map(int,input().split())) for i in range(N)]

arr = sorted(list,key=lambda x:x[0])

result = calculate(N,M,arr)

print(result)



Measured memory_bytes: 32736
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  sort(ALL(a), greater<int>());
  ll ans = a[0];
  n -= 2;
  int ind = 1;
  REP(i,n){
    ans += a[ind];
    if(i%2==1) ind++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3988
n = int(input())
a = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
#一行で入力された数値をリストに
list=[0]*(n)

for i in range(n-1):
    list[a[i]-1] +=1

for i in range(n):
    print(list[i])


Measured memory_bytes: 32364
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define float long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define endl '\n'
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,x,t; cin>>n>>x>>t;
    int ans = t*((n+x-1)/x);
    cout<<ans<<endl;
}

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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()
#define sz(x) x.size()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

void solve()
{
    int n;
    cin>>n;
    ll ans=0,mx=0;
    for(int i=0;i<n;i++){
        ll el;cin>>el;
        if(i==0){
            mx=el;
            continue;
        }
        ans+=max(0LL,mx-el);
        mx=max(mx,el);
    }
    cout<<ans<<"\n";
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

def binarySearch(list, key):
    left = 0
    right = len(list)

    while left < right:
        mid = (left + right) // 2
        if key == list[mid]:
            return True
        elif key < list[mid]:
            right = mid
        else:
            left = mid + 1

    return False

ans = 0
for t in T:
    if binarySearch(S, t) == True:
        ans += 1
print(ans)



Measured memory_bytes: 16716
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
	ll a,b,c,k;
  	cin>>a>>b>>c>>k;
  
  	rep(i,k){
     	if(a>=b){
         	b*=2; 
        }else if(b>=c){
         	c*=2; 
        }
    }
  	
  	if(a<b && b<c) cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

int main()
{
	int a[1010];
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	int ans = 0;
	for (int i = 1; i <= m; i++)
		ans += a[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3240
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int MOD=1e+9+7;
int main(){
	string S;
	scan(S);
	int N=S.size();
	ll dp[100001][4]={};
	dp[N][3]=1;
	for(int i=N-1;i>=0;i--){
		for(int j=3;j>=0;j--){
			if(j==3){
				dp[i][j]=dp[i+1][j]*((S[i]=='?')*2+1);
				dp[i][j]%=MOD;
			}
			else{
				dp[i][j]=dp[i+1][j]*((S[i]=='?')*2+1)%MOD+dp[i+1][j+1]*(S[i]=='?'||S[i]=='A'+j)%MOD;
				dp[i][j]%=MOD;
			}
		}
	}
	prin(dp[0][0]);
	return 0;
}


Measured memory_bytes: 3584
h = gets.to_i
results = [h]
while h > 1
  results << h / 2
  h = h / 2
end
1.upto(results.size) do |i|
  if i == 1
    next
  else
    results[-i] = 2 * results[1-i] + 1
  end
end
puts results[0]

Measured memory_bytes: 1788
n = int(input())
a = list(map(int,input().split()))

even = {}
odd = {}
for i in range(n):
    if i%2 == 0:
        if a[i] not in even:
            even[a[i]] = 1
        else:
            even[a[i]] += 1
    else:
        if a[i] not in odd:
            odd[a[i]] = 1
        else:
            odd[a[i]] += 1

sorted_even = sorted(even.items(), reverse=True, key=lambda x:x[1])
sorted_odd = sorted(odd.items(), reverse=True, key=lambda x:x[1])

if sorted_even[0][0] != sorted_odd[0][0]:
    print(n - sorted_even[0][1] - sorted_odd[0][1])
elif sorted_even[0][1] == sorted_odd[0][1]:#最頻値とその出現回数が等しい
    if len(sorted_even) == 1 and len(sorted_odd) == 1:
        print(n//2)
    elif len(sorted_even) == 1:
        print(n - sorted_even[0][1] - sorted_odd[1][1])
    elif len(sorted_odd) == 1:
        print(n - sorted_even[1][1] - sorted_odd[0][1])
    elif sorted_even[1][1] > sorted_odd[1][1]:
        print(n - sorted_even[1][1] - sorted_odd[0][1])
    elif sorted_even[1][1] < sorted_odd[1][1]:
        print(n - sorted_even[0][1] - sorted_odd[1][1])
    else:
        print(n - sorted_even[0][1] - sorted_odd[1][1])#2番目の最頻値とその出現回数も等しい
elif sorted_even[0][1] > sorted_odd[0][1]:
    print(n - sorted_even[0][1] - sorted_odd[1][1])
else:
    print(n - sorted_even[1][1] - sorted_odd[0][1])

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

int main() {
  int n;
  string s;

  cin >> n >> s;

  if(n%2 != 0){
    cout << "No";
    return 0;
  }

  rep(i,n/2){
    if(s.at(i) != s.at(n/2+i)){
      cout << "No";
      return 0;
    }

  }

  cout << "Yes";
}


Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int a, b;
	cin >> a >> b;

	if (a <= b)
	{
		cout << a;
	}
	else
	{
		cout << a - 1;
	}

	return 0;
}


Measured memory_bytes: 3608
n = int(input())
s = input()

ans = 0
for i in range(1000):
  pin = '{:03d}'.format(i)
  p1 = s.find(pin[0])
  if p1>=0:    
    p2 = s[p1+1:].find(pin[1])     
    if p2>=0:
      p3 = s[p1+p2+2:].find(pin[2])      
      if p3>=0:
        ans+=1        
    
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){
    
    int r,g,b,n;
    int ans=0;
    cin >> r>>g>>b>>n;
    
    for(int i=0;r*i<=n;i++){
        for(int j=0;g*j<=n;j++){
            if(n-r*i-g*j>=0&&(n-r*i-g*j)%b==0)ans++;
        }
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fir first
#define sec second
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 307;
inline void add(int &x, int y) {x += y; if (x >= mod) x -= mod;}
vector<pii>vec[MAXN];
int dp[MAXN][MAXN][MAXN];
int main()
{
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 1, l, r, c; i <= m; i++)
    {
        scanf("%d%d%d", &l, &r, &c);
        vec[r].emplace_back(l, c);
    }
    dp[1][0][0] = 3;
    for (int i = 1; i <= n; i++)
    {
        for (pii t : vec[i])
        {
            int l = t.fir, c = t.sec;
            for (int j = 0; j < i; j++)
                for (int k = 0; k <= j; k++)
                {
                    if (j == k && j) continue;
                    if (c == 1)
                        if (!(j < l && k < l)) dp[i][j][k] = 0;
                    if (c == 2) 
                        if ((j >= l && k >= l) || (j < l && k < l)) dp[i][j][k] = 0;  
                    if (c == 3)
                        if (!(j >= l && k >= l)) dp[i][j][k] = 0;
                }
        }
        for (int j = 0; j < i; j++)
            for (int k = 0; k <= j; k++)
            {
                if (j == k && j) continue;
                add(dp[i + 1][j][k], dp[i][j][k]);
                add(dp[i + 1][i][j], dp[i][j][k]);
                add(dp[i + 1][i][k], dp[i][j][k]);
            }
    }
    int ans = 0;
    for (int j = 0; j < n; j++)
        for (int k = 0; k <= j; k++)
        {
            if (j == k && j) continue;
            else add(ans, dp[n][j][k]);
        }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 110848
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N;
    cin >> N;
    V<PLL> xy(N);
    for(ll i = 0; i < N; i++) {
        ll x, y;
        cin >> x >> y;
        xy[i] = PLL(x, y);
    }

    map<PLL, ll> cnt;
    for(ll i = 0; i < N; i++) {
        for(ll j = i + 1; j < N; j++) {
            ll xi, yi;
            ll xj, yj;
            tie(xi, yi) = xy[i];
            tie(xj, yj) = xy[j];
            ll dx = xi - xj;
            ll dy = yi - yj;
            if(dx == 0 && dy == 0) continue;
            if(dx < 0) {
                dx *= -1;
                dy *= -1;
            }
            if(dx == 0) dy = abs(dy);
            cnt[PLL(dx, dy)]++;
        }
    }

    ll ans = N;
    for(const auto &ele : cnt) {
        ll num = ele.second;
        chmin(ans, N - num);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
N = int(input())
a = list(map(int, input().split()))

a_i = max(a)
a2 = sorted(a, key = lambda x: abs(2 * x - a_i))

a_j = float('inf')
j = 0
while a_j >= a_i:
    a_j = a2[j]
    j += 1

print(a_i, a_j)

Measured memory_bytes: 14060
#include <stdio.h>
#include <stdlib.h>

int main(void) {

  int d;
  scanf("%d", &d);
  long c[26];
  for (int i = 0; i < 26; i++) {
    scanf("%ld", &c[i]);
  }
  long s[d][26];
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      scanf("%ld", &s[i][j]);
    }
  }
  int contest;
  for (int i = 0; i < d; i++) {
    contest = rand()%26+1;
    printf("%d\n", contest);
  }

  return 0;
}

Measured memory_bytes: 1796
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String s = scanner.nextLine();
			StringBuilder sb = new StringBuilder();
			s.chars().forEach(c -> {
				switch (c) {
				case '0':
				case '1':
					sb.append((char) c);
					break;
				case 'B':
					if (sb.length() > 0) {
						sb.deleteCharAt(sb.length() - 1);
					}
					break;
				default:
					break;
				}
			});
			System.out.println(sb.toString());
		}
	}
}


Measured memory_bytes: 26704
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 1e6 + 10 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 1e9 + 7 ;
const double eps = 1e-7 ;
template <class T> void read(T &a)
{
	int f = 1 ; a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	a *= f;
}

ll n, ans;

ll a[maxn], b[maxn], sum;

signed main()
{
	scanf("%lld", &n);
	rep(i, 1, n) scanf("%lld", &a[i]);
	sort(a + 1, a + n + 1);
	rep(i, 1, n) if(a[i] < 0) sum ++;
	if(sum == 0)
	{
		ans -= a[1];
		rep(i, 2, n) ans += a[i];
		printf("%lld\n", ans);
		rep(i, 2, n - 1) printf("%lld %lld\n", a[1], a[i]), a[1] -= a[i];
		printf("%lld %lld\n", a[n], a[1]);
		return 0;
	}
	if(sum == n)
	{
		ans += a[n];
		rep(i, 1, n - 1) ans -= a[i];
		printf("%lld\n", ans);
		per(i, n, 2) printf("%lld %lld\n", a[i], a[i - 1]), a[i - 1] = a[i] - a[i - 1];
		return 0;
	}
	rep(i, 1, n) ans += abs(a[i]);
	printf("%lld\n", ans);
	rep(i, 2, n)
	{
		if(a[i] >= 0) break;
		printf("%lld %lld\n", a[n], a[i]);
		a[n] -= a[i];
	}
	per(i, n - 1, 1)
	{
		if(a[i] < 0) break;
		printf("%lld %lld\n", a[1], a[i]);
		a[1] -= a[i];
	}
	printf("%lld %lld\n", a[n], a[1]);
	return 0;
}


Measured memory_bytes: 6016
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i,x,y) for(int i=((int)x);i<=((int)y);i++)
#define Dep(i,y,x) for(int i=((int)y);i>=((int)x);i--)
#define Rep(i,x) for (int y,i=head[x];i;i=E[i].nxt)
using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;

int rd() {
	char c=getchar(); int t=0,f=1;
	while (!isdigit(c)) f=(c=='-')?-1:1,c=getchar();
	while (isdigit(c)) t=t*10+c-48,c=getchar(); return t*f;
}
void wt(int x) {
	if (x<0) putchar('-'),wt(-x);
	else { if (x>9) wt(x/10); putchar(x%10+48); }
}

const int N=1e6+5;
const int mod=1e9+7;

int n,m,fa[N];

struct Info {
	int x,y,id;
}E[N],P[N];

bool cmpx(Info A,Info B) { return A.x==B.x?A.y<B.y:A.x<B.x; }
bool cmpy(Info A,Info B) { return A.y==B.y?A.x<B.x:A.y<B.y; }
bool cmpid(Info A,Info B) { return A.id<B.id; }

int getf(int x) {
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}

ll kruskal() {
	ll ans=0;
	sort(E+1,E+m+1,cmpid);
	For (i,1,n) fa[i]=i;
	For (i,1,m) {
		int x=getf(E[i].x),y=getf(E[i].y);
		if (x!=y) {
			fa[x]=y;
			ans+=E[i].id;
		}
	}
	return ans;
}

int dis(Info  A,Info B) {
	return min(abs(A.x-B.x),abs(A.y-B.y));
}

int main() {
	n=rd();
	For (i,1,n) P[i]=(Info){rd(),rd(),i};
	sort(P+1,P+n+1,cmpx);
	For (i,2,n) E[++m]=(Info){P[i-1].id,P[i].id,dis(P[i-1],P[i])};
	sort(P+1,P+n+1,cmpy);
	For (i,2,n) E[++m]=(Info){P[i-1].id,P[i].id,dis(P[i-1],P[i])};
	
	printf("%lld\n",kruskal());
}





Measured memory_bytes: 7552
r, c = (int(x) for x in raw_input().split())
g = [raw_input() for _ in xrange(r)]
pts = [(i, j) for i in xrange(r) for j in xrange(c) if g[i][j] == '#']
good_pts = [(i,j) for (i,j) in pts if (i+1,j) in pts or (i-1,j) in pts or (i,j-1) in pts or (i,j+1) in pts]
print "Yes" if len(pts) == len(good_pts) else "No"


Measured memory_bytes: 2948
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#define   FOR(i,n) for(int i=0;i<n;i++)

using namespace std;
int int_sort(const void*a,const void *b) {
    return *(  int *) b - *(int *) a;
    //qsort(b, a, sizeof(long long int), int_sort);
}

int main() {

    int out=700;
    char s[100];
    cin>>s;
    FOR(i,3){
       if(s[i]=='o')
           out+=100;
    }
    cout<<out;
    return 0;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

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

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt" , "r" , stdin);
// 	freopen("output.txt" , "w" , stdout);
// #endif

	string s;
	cin >> s;
	int a, b, f = 0;
	vector<int>v[26];
	for (int i = 0; i < s.length(); i++)
	{
		v[s[i] - 97].push_back(i + 1);
	}
	for (int i = 0; i < 26; i++)
	{
		if (v[i].size() > 0)
		{
			int p = v[i][0], c = v[i][0], count = 0;
			for (int j = 0; j < v[i].size(); j++)
			{

				if (v[i][j] - c <= 2)
				{
					c = v[i][j];
					count++;
				}
				if (count > (c - p + 1) / 2 && ((c - p + 1) >= 2))
				{
					f = 1;
					a = p;
					b = c;
					break;
				}
				else
				{
					p = v[i][j];
					c = v[i][j];
					count = 1;
				}

			}
			if (f)
				break;
		}
	}
	if (!f)
		cout << -1 << " " << -1 << endl;
	else
		cout << a << " " << b << endl;



}


Measured memory_bytes: 1104
n,m=map(int,input().split())
h=list(map(int,input().split()))
hs=[0]*n
ans=0
for i in range(m):
    a,b=map(int,input().split())
    if hs[a-1] < h[b-1]:
        hs[a-1] = h[b-1]
    if hs[b-1] < h[a-1]:
        hs[b-1] = h[a-1]
for ind,i in enumerate(hs):
    if h[ind] > i:
        ans+=1
print(ans)

Measured memory_bytes: 20104
/*
  ->->->->->-> Vora Mahammadasim <-<-<-<-<-<-
*/
#include<bits/stdc++.h>
#define int  long long
#define Mod 10000007
using namespace std;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    map<int,int>m;
    for(int i=0;i<c;i++){
        int x;
        cin>>x;
        x--;
        m[x]++;
    }
    vector<int>ans(a,b);
    for(int i=0;i<a;i++){
        ans[i] -= c;
    }
    for(int i=0;i<a;i++){
            ans[i] += m[i];
    }
    for(int i=0;i<a;i++){
        if(ans[i]<=0) cout<<"No\n";
        else cout<<"Yes\n";
    }
}


Measured memory_bytes: 7680
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 1e6 + 10;
int fact[MAXN],inv_fact[MAXN];
const int MOD = 1e9 + 7;
int n,dp[MAXN],sol[MAXN],subsum[MAXN]; 
vector<int> graph[MAXN];

int power(int x,int y){
    int res = 1;
    while(y){
        if(y&1) res = (res*x)%MOD;
        x = (x*x)%MOD;
        y >>= 1;
    }
    return res;
}

void precompute(){
    fact[0] = 1;
    FOR(i,1,MAXN-1) fact[i] = (fact[i-1]*i)%MOD;
    FOR(i,0,MAXN-1) inv_fact[i] = power(fact[i],MOD-2);
}

void dfs(int u,int p){
    subsum[u] = 1;
    dp[u] = 1;

    for(int v:graph[u]){
        if(v == p) continue;
        dfs(v,u);
        subsum[u] += subsum[v];
        int from_v = (dp[v]*inv_fact[subsum[v]])%MOD;
        dp[u] = (dp[u]*from_v)%MOD;
    }

    dp[u] = (dp[u]*fact[subsum[u]-1])%MOD;
}

void root_change_dfs(int u,int p){
    if(p == 0) sol[u] = dp[u];

    for(int v:graph[u]){
        if(v == p) continue;
        int temp = (sol[u]*inv_fact[n-1])%MOD;
        temp = (temp*fact[n-subsum[v]-1])%MOD;
        temp = (temp*power(dp[v],MOD-2))%MOD;
        temp = (temp*fact[subsum[v]])%MOD;
        sol[v] = (dp[v]*inv_fact[subsum[v]-1])%MOD;
        sol[v] = (sol[v]*fact[n-1])%MOD;
        sol[v] = (sol[v]*temp)%MOD;
        sol[v] = (sol[v]*inv_fact[n-subsum[v]])%MOD;
        root_change_dfs(v,u);
    }
}

void solve(){
    precompute();
    cin>>n;

    FOR(i,1,n-1){
        int u,v; cin>>u>>v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1,0);
    root_change_dfs(1,0);
    FOR(i,1,n) cout<<sol[i]<<endl;
}

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}



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

namespace ConsoleApplication67
{
    class Program
    {
        static int Sin(int a, int b, int c)
        {
            int d = (a - 1) / 3 * 590+ (a-1)%3*195;
            if(a%3!=0)
            d += (b-1) / 2 * 39 + (b-1) % 2 * 20 + c;
            if (a % 3 == 0)
                d += (b - 1) * 20 + c;
            return d;
        }
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            for (int b = 0; b < a; b++)
            {
                int[] me = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int c = Sin(me[0], me[1], me[2]);
                int d = Sin(1000, 1, 1);
                Console.WriteLine(d-c);
            }
        }
    }
}

Measured memory_bytes: 9616
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long lint;
lint N,A,B;
const int MAX_N = 100010;
lint a[MAX_N];

lint getCnt(lint x,lint y){
	return x/y + (x%y>0);
}

bool chk(lint x){
	lint cnt = 0;
	for(int i=0;i<N;i++){
		cnt += getCnt(max(0ll,a[i]-B*x),(A-B));
	}
	return cnt <= x;
}

int main(){
	scanf("%lld%lld%lld",&N,&A,&B);
	for(int i=0;i<N;i++){
		scanf("%lld",&a[i]);
	}

	lint lo = 0, hi = 1e9, mid;
	while(lo+1 < hi){
		mid = (lo+hi)/2;
		if(chk(mid)){
			hi = mid;
		}else{
			lo = mid;
		}
	}
	printf("%lld\n",hi);
	return 0;
}

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

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

  int temp = N, sum = 0;
  while(temp >= 10){
    sum = sum + temp % 10;
    temp = temp / 10;
  }

  if (N % (sum+temp) == 0){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }

}


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

int main(){
  int N,rN,x,y,z,s,i;
  int* ct;
  cin >> N;
  ct = new int[N+1];
  for(i=0;i<=N;i++)
    ct[i] = 0;
  rN = sqrt(N);
  for(x=1;x<=rN;x++)
    for(y=1;y<=rN;y++)
      for(z=1;z<=rN;z++){
        s = x*x + y*y +z*z + x*y + y*z + z*x;
        if (s<=N)
          ct[s]++;
      }
  for(i=1;i<=N;i++)
    cout << ct[i] << endl;

  return 0;
}

Measured memory_bytes: 3492
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

l = [i+1 for i in range(N)]
i = 0
p = 0
q = 0

for v in itertools.permutations(l, N):
    if(P == list(v)):
        p = i
    if(Q == list(v)):
        q = i
    i += 1

print(abs(p - q))


Measured memory_bytes: 3064
x=list(map(int,input().split()))
y=list(map(int,input().split()))
import copy
z=copy.deepcopy(y)
for i in range(x[1]):
    z[i]=abs(y[i]-x[0])
    

def main(x,y,z):
    t=0
    if 0 not in z:
        print(x[0])
        t=1
    num=1
    while True:
        if t==1:
            break
        if z.count(num)!=2:
            if x[0]-num not in y:
                print(str(x[0]-num))
                break
            else:
                print(str(x[0]+num))
                break
        num+=1
            
            
main(x,y,z)

Measured memory_bytes: 9292
#include <cstdio>
#include <cmath>

using namespace std;

int isPrime(int a) {
    int boundaly = 2;
    if (a < boundaly) return false;
    if (a == boundaly) return true;
    if (a % 2 == 0) return false;

    double sqNum = sqrt(a);
    for (int i = 3; i <= sqNum; i += boundaly) {
        if (a % i == 0) return false;
    }

    return true;
}

int main() {
    int n, input;
    int ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &input);
        if (isPrime(input)) ans++;
    }

    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 2740
#include<stdio.h>
int main()
{
    int a,b,c,i;
    while(scanf("%d%d%d",&a,&b,&c)==3)
    {
        for(i=1;i<=10;i++)
        {
            c=a*c-b;
            printf("%d\n",c);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#define MOD 1000000007
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int N;
ll ans;

int main() {
    cin >> N;
    map<ll, int> value_index;
    for (int i = 1; i <= N; i++) {
        ll x; cin >> x;
        value_index[x] = i;
    }
    multiset<int> index{0, 0, N+1, N+1};
    ans = 0;
    for (auto itr = value_index.rbegin(); itr != value_index.rend(); itr++) {
        int a, b, c, d;
        int i = itr->second;
        ll value = itr->first;
        auto x = index.upper_bound(i);
        c = *x;
        d = *(++x);
        b = *(----x);
        a = *(--x);
        ans += ((b-a) * (c-i) + (i-b) * (d-c)) * value;
        index.insert(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
import java.lang.Math;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String S = scanner.nextLine();

        final char[] order1 = { '0', '1' };
        final char[] order2 = { '1', '0' };

        int count1 = 0;
        int count2 = 0;

        final int n = S.length();
        for (int i = 0; i < n; i++) {
            int c = S.charAt(i);
            int c1 = order1[i % 2];
            int c2 = order2[i % 2];
            if (c1 != c) {
                count1++;
            }
            if (c2 != c) {
                count2++;
            }
        }

        System.out.println(Math.min(count1, count2));
    }
}


Measured memory_bytes: 28216
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b){
	return a>b;
}
int main()
{
 int n,k,i,x;
 
 cin>>n>>k;
 
 int a[2000000+5]={0};
 
 for(i=1;i<=n;i++){
 cin>>x;
 a[x]++;
 }
 sort(a+1,a+2000000+1,cmp);
 
 int s=0;
 
 for(i=k+1;i<=2000000;i++)s+=a[i];
 cout<<s;
 return 0; 
}

Measured memory_bytes: 8064
#include <stdio.h>
#include <string.h>
#include <ctype.h>

// 文字列strに対して以下の命令に沿って操作する
// ・print a b: strのaからb文字目を出力
// ・reverse a b: strのaからb文字目までを逆順変換
// ・replace a b p: strのaからb文字目までをpに置換

int main() {
    char szInputStr[1000];  // 入力文字列
    char szOp[10];          // 命令
    int iNumOfOP;           // 命令数
    int iCount;             // カウント変数
    int iCount2;            // カウント変数2
    int iCount3;            // カウント変数3
    int iArgA;              // 命令の引数a
    int iArgB;              // 命令の引数b
    char szArgP[1000];      // 命令の引数p
    char chSwapTmp;         // 逆順スワップ時のテンポラリ

    // In: 文字列str, 命令数
    scanf("%s", szInputStr);
    scanf("%d", &iNumOfOP);

    for (iCount = 0; iCount < iNumOfOP; iCount++) {
        // In: OP
        scanf("%s", szOp);
        // In: Arg a b
        scanf("%d %d", &iArgA, &iArgB);
        // opによって処理を変える
        if (strcmp(szOp, "print") == 0) {    // op: print
            // iArgAからiArgBまでを出力
            for (iCount2 = iArgA; iCount2 <= iArgB; iCount2++) {
                printf("%c", szInputStr[iCount2]);
            }
            printf("\n");
        }
        else if (strcmp(szOp, "replace") == 0) {    // op: replace
            // In: Arg p
            scanf("%s", szArgP);
            // iArgAからiArgBまでを置換
            for (iCount2 = iArgA, iCount3 = 0; iCount2 <= iArgB; iCount2++, iCount3++) {
                szInputStr[iCount2] = szArgP[iCount3];
            }
        }
        else if (strcmp(szOp, "reverse") == 0) {    // op: reverse
            // iArgAからiArgBまでを逆順変換
            while (iArgA < iArgB) {
                chSwapTmp = szInputStr[iArgA];
                szInputStr[iArgA] = szInputStr[iArgB];
                szInputStr[iArgB] = chSwapTmp;
                iArgA++;
                iArgB--;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2104
x = int(input())

m = 0
b = 1
p = 2
ls = []

if x in (1,2,3):
    print(1)
else:
    while b <= x:
        p = 2
        while p <= x:
            if  b**p <= x:
                # print(f"{b}**{p}={b**p}")
                ls.append(b**p)
                p += 1
            else:
                # print(f"break{b}**{p}={b**p}, m{m}")
                break
        b += 1
    print(max(ls))



Measured memory_bytes: 3316
import sys

x, y = map(int, input().split())

crane_feet = x * 2

if crane_feet == y:
  print('Yes')
  sys.exit()
elif y - crane_feet < 0:
  print('No')
  sys.exit()

diff = y - crane_feet
for i in range(1, diff+1):
  crane_feet -= 2
  if crane_feet < 0:
    break
  
  if crane_feet + i*4 == y:
    print('Yes')
    sys.exit()

print('No')

Measured memory_bytes: 61868
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <utility>
#include <queue>
#define ull unsigned long long
#define ll long long
#define mod 998244353
using namespace std;

int main()
{
    int a, b, c;
    cin>>a>>b>>c;

    cout<<c-min(a-b, c)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;


int gcd(int a, int b){
  int n1 = a, n2 = b;
  if(n1 < n2) swap(n1, n2);
  int r = n1 % n2;
  while(r){
    n1 = n2;
    n2 = r;
    r = n1 % n2;
  }
  return n2;
}

int main(){
  int N,X;
  cin >> N >> X;
  vector<int> x(N);
  for(int i = 0; i < N; i++){
    cin >> x[i];
    x[i] -= X;
  } 

  int g = abs(x[0]);
  for(int i = 0; i < N; ++i){
    g = gcd(g, abs(x[i]));
  }
  cout << g << endl;
}


Measured memory_bytes: 640
program a
implicit none
character(4) s
character(1) i, j
integer n
read*, s
 do n=1, 3
 i=s(n:n)
 j=s(n+1:n+1)
 if (i.eq.j) then
 print*, "Bad"
 return
 end if
 end do
print*, "Good"
end program

Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static double pi=3.14285714;
    public static void process()throws IOException
    {
      int r=ni();
      pn(2*pi*r);
    }

 static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

    //  oj = System.getProperty("ONLINE_JUDGE") != null;
        if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        
         //int t=ni();
        // while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static String nn()throws IOException{return sc.next();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
    
    
    

    


Measured memory_bytes: 33160
n, m = map(int, input().split())
loads = [list(map(int, input().split())) for _ in range(m)]
ans = [0] * (n + 1)
for i in range(m):
    for j in loads[i]:
        ans[j] += 1
for out in range(1, n + 1):
    print(ans[out])


Measured memory_bytes: 9172