akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>

using namespace std;

const int X = 1e5;

typedef set<int> si;
typedef vector<int> vi;
typedef pair<int, int> pii;

int fi(int f[], int x) {
    return f[x] == x ? x : (f[x] = fi(f, f[x]));
}

int main() {
    int n;
    cin >> n;
    vi vx[X];
    pii yx[n];
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        vx[x].push_back(y);
        yx[i] = {y, x};
    }
    sort(yx, yx+n);

    int f[X];
    for (int i = 0; i < X; i++) {
        f[i] = i;
    }

    for (int i = 1; i < n; i++) {
        if (yx[i].first == yx[i-1].first) {
            f[fi(f, yx[i].second)] = f[fi(f, yx[i-1].second)];
        }
    }

    si s[X];
    int cnt[X];
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < X; i++) {
        cnt[fi(f, i)]++;
        for (int j : vx[i]) {
            s[fi(f, i)].insert(j);
        }
    }

    long long ans = 0;
    for (int i = 0; i < X; i++) {
        ans += cnt[i] * s[i].size();
    }

    cout << ans - n << endl;

    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 2e5 + 10;
int rk[maxn] , ans[maxn];
int n;
int a[maxn];

bool cmp(int x , int y){
	return a[x] < a[y];
}

int main(){
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> a[i];
	for(int i = 1 ; i <= n ; ++ i)
		rk[i] = i;
	sort(rk + 1 , rk + n + 1 , cmp);
	for(int i = 1 ; i <= n / 2 ; ++ i)
		ans[rk[i]] = a[rk[n / 2 + 1]];
	for(int i = n / 2 + 1 ; i <= n ; ++ i)
		ans[rk[i]] = a[rk[n / 2]];
	for(int i = 1 ; i <= n ; ++ i)
		cout << ans[i] << endl; 
	return 0;
}

Measured memory_bytes: 4608
#include<iostream>
#include<string>
using namespace std;
int N_MAX = 50;
int main()
{
  int n,i,res=0;
  int t[N_MAX];
  string x;
  string s[N_MAX];
  cin >> n;
  for(i=0;i<n;i++){
    cin >> s[i] >> t[i];
    res+=t[i];
  }
  cin >> x;
  for(i=0;i<n;i++){
    res-=t[i];
    if(s[i]==x) break;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
from sys import stdin
N = int(stdin.readline().rstrip())
A = list(map(int, stdin.readline().rstrip().split()))

result = 1
if 0 in A:
    print(0)
    exit()

for i in A:
    result = result * i
        
    if result > 10**18:
        print(-1)
        exit()
print(result)

Measured memory_bytes: 21776
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7;
int main(void)
{
  int N,A[200000],cusum=0,total=0;
  if(!scanf("%d",&N))return -1;
  rep(i,N){if(!scanf("%d",&A[i]))return -1;cusum=(1l*cusum+A[i])%MOD;}
  rep(i,N){cusum-=A[i];if(cusum<0){cusum+=MOD;}total=(1l*total+1l*A[i]*cusum%MOD)%MOD;}
  return printf("%d\n",total),0;
}

Measured memory_bytes: 2508
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
int read();

int n, k;
int res[200005], vis[200005];
vector<int> e[200005], dis[200005];
void add(int f, int t) { e[f].push_back(t), e[t].push_back(f); }
bool check(int x, int y) { return x - y == 1 || y - x == 1; }

int main() {
    n = read();
    for (int i = 1, u, v; i < n; ++i) u = read(), v = read(), add(u, v);
    k = read();
    int mn = 100000000;
    for (int i = 1, u; i <= k; ++i)
        u = read(), mn = min(res[u] = read(), mn), vis[u] = 1;
    for (int i = 1; i <= n; ++i)
        if (vis[i]) dis[res[i] - mn].push_back(i);
    for (int i = 0; i < n; ++i)
        for (int j = dis[i].size() - 1, u; j >= 0; --j)
            for (int t = e[u = dis[i][j]].size() - 1, v; t >= 0; --t)
                if (!vis[v = e[u][t]])
                    res[v] = res[u] + 1, dis[i + 1].push_back(v), vis[v] = 1;
    for (int u = 1; u <= n; ++u)
        for (int i = e[u].size() - 1, v; i >= 0; --i)
            if (!check(res[u], res[e[u][i]])) return puts("No"), 0;
    puts("Yes");
    for (int u = 1; u <= n; ++u) printf("%d\n", res[u]);
    return 0;
}

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}


Measured memory_bytes: 17408
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		int c = a;
		int d = a;
		int[] b = new int[10];
		int i = 0;
		while (a != 0) {
			b[i] = a % 10;
			a = c / 10;
			c = a;
			i = i + 1;
		}
		int n = 0;
		for (int j = 0; j < 10; j++) {
			n = n + b[j];
		}
		String e = (d % n == 0) ? "Yes" : "No";
		System.out.println(e);
	}
}

Measured memory_bytes: 22100
#hps = (1..100).to_a
hps = []
gets.to_i.times {
	hps.push gets.to_i
}
hps.sort! {|a,b|b<=>a}
sum = 1
hps.each_with_index{|n,idx|
	sum += [0,n-(idx/4)].max
}
p sum

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


int main() {
int K;
cin >> K;
  string S;
  cin >> S;
  if(S.size() <= K) cout << S << endl;
  else{
  for(int i=0; i<K;i++){
  cout << S.at(i);
  }
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

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

int gcd(int a, int b) {
		if(a == 0) return b;
		return gcd(b%a, a);
}

int main() {
	ll k, sum = 0;
	cin >> k;
	
	for(int a = 1; a <= k; a++) {
		for(int b = 1; b <= k; b++) {
			int temp = gcd(a,b);
			for(int c = 1; c <= k; c++) sum += gcd(temp,c);
		}
	}
	
	cout << sum << endl;
  
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <math.h>
using namespace std;

int prime(double m){
    int i;
    if(int(m)%2==0)return 0;    
    for(i=3;i<=sqrt(m);i+=2)if(int(m)%i==0)return 0;
    return 1;
}

int main(){
    int i,n,sum=0;
    double m;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>m;
        if(m==2||prime(m)==1)sum++;
        
    }
    cout<<sum<<endl;
    return 0;
}

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

#define inf 1e9
struct item
{
    int wt;
    int val;
};

long long solve(vector<item> ar, int n, int W)
{
    long long dp[n+1][W+1];
    for(int w=0;w<=W;w++)
    {
        dp[1][w] =0;
    }
    dp[1][ar[1].wt] = ar[1].val;
    for(int i=2;i<=n;i++)
    {
        for(int w=0;w<=W;w++)
        {
            dp[i][w] = dp[i-1][w];
            if(ar[i].wt>w)
                continue;
            dp[i][w] = max(dp[i][w],ar[i].val+dp[i-1][w-ar[i].wt]);
        }

    }
    return *max_element(dp[n],dp[n]+W+1);
}

int main()
{
    int n,w;
    cin>>n>>w;
    vector<item> ar(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>> ar[i].wt>>ar[i].val;
    }
    cout<<solve(ar,n,w);
}


Measured memory_bytes: 81752
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
#include <iomanip>
using namespace std;

int main(){
    int h,w; cin >> h >> w;
    vector<string> a(h+1);
    for ( int i = 1 ; i <= h ; i++ ){
       cin >> a[i];
    }
    for ( int i = 0 ; i <= h+1 ; i++ ){
        if ( i == 0 || i == h+1 ){
            for ( int j = 0 ; j <= w+1 ; j++){ cout << '#';}
        }
        else cout << '#' << a[i] << '#';

        cout << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;


int main(){
	while(1){
		int n,r,p,c;
		cin>>n>>r;
		if(n==0)break;
		int ans=0;
		vl s(110),t(110);
		rep(i,1,n+1)s[i]=n-i+1;
		rep(i,0,r){
			cin>>p>>c;
			t=s;
			rep(j,1,p+c+1){
				if(j<=c)s[j]=t[p+j-1];
				else if(j>c&&j<p+c)s[j]=t[j-c];
			}
		}
		print(s[1]);
	}
	return 0;
}


Measured memory_bytes: 3152
#include <iostream>
using namespace std;
int main(void){
    int n[31]={}, who;
    for(int i=1; i<=28; i++){
        cin >> who;
        n[who]=1;
    }
    
    for(int i=1; i<=30; i++){
        if(n[i]==0){
            cout << i << endl;
        }
    }
    return 0;
}



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

int main() {
 
 int A,B;
  cin >> A >> B ;
  int x=0 ;
  
  while(A<=B) {
    if((A/10000 == A%10) && (A%10000/1000 == A%100/10)){
      x++ ;
    }
    
    A++ ;
      
  }
  
  cout << x << endl;
  
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
S = input()

# それぞれ必要な数を確認
lneed = cnt = 0
for s in S:
    if s == ')':
        cnt += 1
        lneed = max(lneed, cnt)
    else:
        cnt -= 1
rneed = cnt = 0
for s in S[::-1]:
    if s == '(':
        cnt += 1
        rneed = max(rneed, cnt)
    else:
        cnt -= 1

# 辞書順最小なので、(は全部左に、)は全部右に付ける
ans = ('(' * lneed) + S + (')' * rneed)
print(ans)


Measured memory_bytes: 3064
# 2106~
# 10^2 より大きい部分と，10^2より小さい部分に分ける
A,B=input().split()
A = int(A)
B = float(B)
if A < 10**2:
    print(int(A*B))
    exit()
Ag = int(A/(10**2))
Bg = round(B*(10**2))
ABg = Ag*Bg
Al = A - Ag*(10**2)
Abl = int(Al*B)
print(ABg+Abl)





Measured memory_bytes: 9184
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = np.array(rl())
count = 3 ** N
even_num = A[A%2 == 0].size
answer = count - 2 ** even_num
print(answer)
#32

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    string s;
    cin>>s;


    long long sum=0;
    rep(i,s.size()){
        sum+=(long long )(s[i]-'0');
    }
    if(sum%9==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;

}
/*


*/


Measured memory_bytes: 3728
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
	int N,M;
	scanf("%d %d", &N, &M);
	
	int count = 0;
	
	if(N > 1){
		count += N * (N-1) / 2;
	}
	if(M > 1){
		count += M * (M-1) / 2;
	}
	
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <iomanip>
#include <functional>
#include <stack>
#include <numeric>
#define PI 3.1415926535
#define FOR(i,n) for (int i=0; i<(n) ;i++)
#define INF 114514810

using namespace std;

int n, m, l, t, a[100][100] = { 0 }, b[100][100] = { 0 };
long long int c = 0;
int main(){
	cin >> n >> m >> l;
	FOR(i, n)
		FOR(j, m)
		cin >> a[i][j];
	FOR(i, m)
		FOR(j, l)
		cin >> b[i][j];
	FOR(i, n){
		FOR(j, l){
			FOR(k, m){
				c += a[i][k] * b[k][j];
			}
		if (j != l - 1) cout << c << " ";
		else cout << c;
		c = 0;
		}
	cout << endl;
	}
}

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

int N;
int h[200009];
int a[200009];

// BIT (1-indexed)
long long bit[200009];

void update(int a, long long k) {
    for(; a <= N; a += a & -a)
        bit[a] = max(bit[a], k);
}

long long query(int a) {
    long long res = 0;
    for(; a > 0; a -= a & -a)
        res = max(res, bit[a]);
    return res;
}

int main() {
    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> h[i];
    for(int i = 0; i < N; i++)
        cin >> a[i];

    for(int i = 0; i < N; i++)
        update(h[i], query(h[i]) + a[i]);

    cout << query(N) << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

#define keta setprecision(15) //15桁表示



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

	ll a, b, k;
	cin >> a >> b >> k;
	ll tmp = a;
	a -= min(a, k);
	k -= tmp;
	if (k > 0)
	{
		b -= min(b, k);
	}

	cout << a<<" " << b << endl;;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

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

int r;
cin >> r;
fin(r*r);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
n,m,x=map(int,input().split())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
s=[]
a=[0]*(m+1)
s.append(a)
for i in range(n):
  newl=[]
  for j in s:
    new=[j[k]+l[i][k] for k in range(m+1)]
    newl.append(new)
  s.extend(newl)
ans=float('inf')
for i in s:
  for j in range(m):
    if i[j+1]<x:break
  else:
    ans=min(ans,i[0])
if ans==float('inf'):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 11512
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
 ll n,a,b;
 cin >> n >> a >> b;
 ll c = a + b;
 ll ans = a * (n/c);//a+bのなかにnがある＊それまでのaの個数
 ans += min(n%c,a);//最後のa+b中をnで区切ったとき，その余りがAより小さい(青区切り)とその数を出力，余りがAより大きい(赤区切り)とaを出力する
 cout << ans << endl;
 return 0;

}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]

ans = 0
for i in range(h):
    maze[i] = input()

import itertools
ans=0
count=0
for casei in itertools.product([0,1], repeat=h):
    for casej in itertools.product([0,1], repeat=w):
        for i in range(h):
            for j in range(w):
                if maze[i][j]=='#' and casei[i]==0 and casej[j]==0:
                    count+=1
        if count == k:
            ans+=1
        count=0

print(ans)



Measured memory_bytes: 68508
from itertools import permutations
from math import factorial
def myAnswer(N:int, XY:list) -> int:
   l = [i for i in range(N)]
   number = factorial(N)
   ans = 0
   for i in permutations(l):
      i = list(i)
      pre = i.pop(0)
      for n in i:
         ans += ((XY[n][0] - XY[pre][0])**2 + (XY[n][1] - XY[pre][1])**2)**0.5
         pre = n
   return ans/number


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   XY = []
   for _ in range(N):
      XY.append(list(map(int,input().split())))
   print(myAnswer(N,XY[:]))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3316
def parent(i):
    return(i // 2)

def left(i):
    return(i * 2)

def right(i):
    return(i * 2 + 1)

def maxHeapify(i):
    l = left(i)
    r = right(i)
    largest = 0
    
    if l <= H and A_list[l] > A_list[i]:
        largest = l
    else:
        largest = i
        
    if r <= H and A_list[r] > A_list[largest]:
        largest = r
    
    if largest != i:
        tmp_val = A_list[largest]
        A_list[largest] = A_list[i]
        A_list[i] = tmp_val
        maxHeapify(largest)

H = int(input())
A_list = list(map(int, input().split()))
A_list.insert(0, 0)
for i in range(H // 2, 0, -1):
    # print(i)
    # print(A_list)
    maxHeapify(i)
for i in range(1, H+1):
    print(" ", A_list[i], sep="", end="")
print("")


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

#define MAX(a , b) (a > b? a : b)
#define MIN(a , b) (a < b? a : b)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

const double pi = 2.0*acos(0.0);

int coin[] = {500,100,50,10,5,1};

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

    ll n;
    cin >> n;
    if (n==0)
    {
        cout << 0 << endl;
    }
    else if (n%500==0)
    {
        cout << n*2 << endl;
    }
    else
    {
        ll dot = n / 500;
        ll sum = dot * 1000;
        ll MOD = n % 500;
        ll ans = MOD / 5;
        ans = ans * 5;
        sum = sum + ans;
        cout << sum << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int m,f,r;
    while(true){
        scanf("%d%d%d",&m, &f, &r);
        if(m==-1 && f==-1 && r==-1)break;
        if(m==-1 || f==-1 || m+f<30)cout<<'F'<<endl;
        else if(m+f>=80) cout<<'A'<<endl;
        else if(m+f>=65) cout<<'B'<<endl;
        else if(m+f>=50) cout<<'C'<< endl;
        else if(m+f>=30) 
        {
            if(r>=50)cout<<'C'<<endl;
            else cout<<'D'<<endl;
        }
    }
}


Measured memory_bytes: 3228
#include <stdio.h>
int main()
{
    int N;
    scanf("%d",&N);
    
    for(int i = 0; i <= 25; i++){
        for(int j=0;j<=15;j++){
            if(N==4*i+7*j){
                printf("Yes");
                goto LABEL;
            }
            if(i==25){
            printf("No");
            goto LABEL;
        }
        }
    }
    LABEL:
    
    return 0;
}


Measured memory_bytes: 128
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] line1 = br.readLine().split(" ");
    int a = Integer.parseInt(line1[0]);
    int b = Integer.parseInt(line1[1]);
    int m = Integer.parseInt(line1[2]);
    
    int mina = Integer.MAX_VALUE;
    int minb = Integer.MAX_VALUE;
    
    String[] as = br.readLine().split(" ");
    int[] asint = new int[a];
    for (int i=0; i<a; i++){
      asint[i] = Integer.parseInt(as[i]);
      if(mina>asint[i]){
        mina = asint[i];
      }
    }
    String[] bs = br.readLine().split(" ");
    int[] bsint = new int[b];
    for (int i=0; i<b; i++){
      bsint[i] = Integer.parseInt(bs[i]);
      if (minb>bsint[i]){
        minb = bsint[i];
      }
    }
    int minsum = mina + minb;
    String[] data;
    int x;
    int y;
    int c;
    int temp;
    
    for (int i=0; i<m; i++){
      data = br.readLine().split(" ");
      x = Integer.parseInt(data[0]);
      y = Integer.parseInt(data[1]);
      c = Integer.parseInt(data[2]);
      temp = asint[x-1] + bsint[y-1] - c;
      if (temp < minsum){
        minsum = temp;
      }
    }
    System.out.println(minsum);
  }
}

Measured memory_bytes: 62480
k=int(input())
li=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(li[k-1])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int n,a,b;
   string s;
   cin >> n >> a >> b;
   cout << min(b,a*n) << endl;
   return 0;
}


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

int main() {
	char S[50];
	int N,i,count=0;

	scanf("%d", &N);
	scanf("%s", S);

	for (i = 0; i < N; i++) {
		if (S[i] == 'A'&&S[i + 1] == 'B'&&S[i + 2] == 'C')count++;
	}
	printf("%d\n", count);

	return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  bool ans = true;
  
  for(int i=0; i<N; i++) cin >> A.at(i);
  for(int i=0; i<N; i++) {
    if(A.at(i)%2==0) {
      if(A.at(i)%3!=0 && A.at(i)%5!=0)
        ans = false;
       }
  }
  if(ans==false) cout <<"DENIED" << endl;
  else cout << "APPROVED" << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
       int n;
       cin >> n;
    int a,b,c;
    int a0,b0,c0,a1,b1,c1;
    cin >> a0 >>b0 >> c0;
    for(int i=1;i<n;i++){
        cin >> a >>b >>c;
        a1=max(b0,c0)+a;
        b1=max(a0,c0)+b;
        c1=max(a0,b0)+c;
        a0=a1;b0=b1;c0=c1;
    }
    cout << max(a0,max(b0,c0));


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll, ll> pii;
const int maxn = 2e6 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const ll mod = 1000000007;
ll fact[maxn], inv[maxn];
ll power(ll a, int x) {
	ll ans = 1;
	while (x) {
		if (x & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		x >>= 1;
	}
	return ans;
}
void init() {
	fact[0] = 1ll;
	for (int i = 1; i < maxn; i++) {
		fact[i] = fact[i - 1] * i %mod;
	}
	inv[maxn - 1] = power(fact[maxn - 1], mod - 2);
	for (int i = maxn - 2; i >= 0; i--) {
		inv[i] = inv[i + 1] * (i + 1) % mod;
	}
}
ll f(int i, int j) {
	return fact[i + j] * inv[i] % mod*inv[j] % mod;
}
ll cal(int i, int j) {
	ll res = 0;
	for (int k = 1; k <= i + 1; k++)
		res = (res + f(k, j)) % mod;
	return res;
}
int r1, c1, r2, c2;
int main() {
	cin >> r1 >> c1 >> r2 >> c2;
	init();
	ll ans = (cal(r2, c2) + cal(r1 - 1, c1 - 1)) % mod;
	ans = (ans - cal(r1 - 1, c2) + mod - cal(r2, c1 - 1) + mod) % mod;
	cout << ans << endl;
	return 0;
};

Measured memory_bytes: 31488
#include <iostream>
#include <vector>
#include <algorithm> //sort,二分探査など
#include <atcoder/all>
//#include<bitset>
//#include<cmath>//pow,logなど
//#include<deque>
//#include<functional>
//#include<iterator>
//#include<map>
//#include<numeric>//gcd,lcm
//#include<queue>
//#include<set>
//#include<stack>
//#include<string>
//#include<utility>//pair

//QCFium法
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

//浮動小数点処理高速化
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace atcoder;
using i64 = int64_t;
using f80 = __float80;
using u64 = uint_fast64_t;

constexpr i64 INF = 1010000000000000017LL;
constexpr u64 MOD = 1000000007LL;
constexpr f80 PI = 3.14159265358979323846;

#define _overload3(_1, _2, _3, name, ...) name
#define repi(i, start, end) for (int i = (int)(start); i < (int)(end); ++i)
#define _rep(i, n) repi(i, 0, n)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(i, start, end) for (int i = (int)(start); i > (int)(end); --i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()

#define v(T) vector<T>
#define vv(T) v(v(T))
#define vvv(T) v(v(v(T)))
typedef v(int) vi;

#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
  rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
  for (T &in : v)
    is >> in;
  return is;
}

//sort(rng(P),[](const vi &a, const vi &b){return a[1]<b[1];});

void Main()
{
  int T;
  cin >> T;

  rep(i, T)
  {
    int N, M, A, B;
    cin >> N >> M >> A >> B;
    cout << floor_sum(N, M, A, B) << "\n";
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 3676
#include <iostream>
#define A int
#define B main
#define C ()
#define D {
#define E ;
#define F std::
#define G cin
#define H >>
#define I cout
#define J <<
#define K *
#define L endl
#define M return 0
#define N }

A B C D A a E F G H a E F I J a K a K a J F L E M E N



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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

struct Node {
    Node *parent, *left, *right;
    int key;

    Node() : parent(nullptr), left(nullptr), right(nullptr), key(2000000001) {}
    Node(Node* p, Node* l, Node* r, int k) : parent(p), left(l), right(r), key(k) {}

    void insert(int k) {
        if (key == 2000000001) { key = k; }
        else if (k <= key) {
            if (left != nullptr) { left->insert(k); }
            else { left = new Node(this, nullptr, nullptr, k); }
        } else {
            if (right != nullptr) { right->insert(k); }
            else { right = new Node(this, nullptr, nullptr, k); }
        }
    }
    bool find(int k) {
        if (k == key) { return true; }
        if (k < key && left != nullptr) { return left->find(k); }
        if (k > key && right != nullptr) { return right->find(k); }
        return false;
    }
};

void in_print(Node* node) {
    if (node->left != nullptr) { in_print(node->left); }
    cout << " " << node->key;
    if (node->right != nullptr) { in_print(node->right); }
}

void pre_print(Node* node) {
    cout << " " << node->key;
    if (node->left != nullptr) { pre_print(node->left); }
    if (node->right != nullptr) { pre_print(node->right); }
}

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

    Node* tree = new Node();

    rep(i, 0, n) {
        char s[20];
        scanf("%s", s);

        if (s[0] == 'i') {
            int x;
            cin >> x;
            tree->insert(x);
        } else if (s[0] == 'f') {
            int x;
            cin >> x;
            cout << (tree->find(x) ? "yes" : "no") << endl;
        } else {
            in_print(tree);
            cout << endl;
            pre_print(tree);
            cout << endl;
        }
    }
}


Measured memory_bytes: 21884
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int n, l[2010];

int main() {
    cin >> n;
    rep(i, n) cin >> l[i];
    sort(l, l+n);

    ll ans = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] + l[j] <= l[k]) break;
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
int M[99][99];
main(n,i,x,y){
	for(;scanf("%d",&n),n;){
		memset(M,0,sizeof(M));
		x=n/2,y=n/2+1,M[x][y]=1;
		for(i=2;i<=n*n;i++){
			x=(x+1)%n,y=(y+1)%n;
			for(;M[x][y];y=(y+1)%n)x=(x+n-1)%n;
			M[x][y]=i;
		}
		for(y=0;y<n;y++,puts(""))
			for(x=0;x<n;x++)printf("%4d",M[x][y]);
	}
exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

vector<vector<int>> G;
vector<int> colors;

bool dfs(int v, int color = 0) {
  colors[v] = color;

  for(auto u : G[v]) {
    if (colors[u] != -1) {
      if (colors[u] == color) return false;
      continue;
    }
    if(!dfs(u, 1 - color)) return false;
  }
  return true;
}

int main() {
  ll n, m;
  cin >> n >> m;
  colors.assign(n, -1);
  G.resize(n);

  for(int i = 0; i < m; ++i) {
    int a , b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  bool bipartite = true;
  if(!dfs(0)) bipartite = false;

  if (bipartite) {
    ll w = 0, b = 0;
    for(int i = 0; i < n; ++i) {
      b += colors[i];
    }
    w = n - b;
    cout << w*b-m << endl;
  } else {
    cout << n*(n-1)/2-m << endl;
  }
  return 0;
}

Measured memory_bytes: 6528
#coding:utf-8

N,Q=map(int, raw_input().split())
S=raw_input()
P=[0]*(N+1)
for i in range(N):
    if i==0:
        P[0]=0
        continue
    if S[i-1:i+1]=="AC":
        P[i]=P[i-1]+1
    else:
        P[i]=P[i-1]
for _ in range(Q):
    l,r=map(int, raw_input().split())
    print(P[r-1]-P[l-1])

Measured memory_bytes: 8436
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int k = sc.nextInt();
      	int[] l = new int[n];
      	for(int i = 0; i < n; i++){
        	l[i] = sc.nextInt();
        }
      	Arrays.sort(l);
      	int sum = 0;
      	for(int i = n-1; i > n-k-1; i--){
        	sum += l[i];
        }
      	System.out.println(sum);
    }
}

Measured memory_bytes: 35756
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e5+10;
int n,m;

int fa[N];
inline int Find(int x){
	return fa[x]==x?x:fa[x]=Find(fa[x]);
}

int d[N];
vector<int>e[N];
vector<pa>ans;
inline void dfs(int u,int fa){
	for (auto v:e[u]) if (v!=fa){
		dfs(v,u);
	}
	if (u==1) return;
	if (d[u]) ans.ep(u,fa);
		else ans.ep(fa,u),d[fa]^=1;
}

int main(){
	n=read(),m=read();
	if (m&1) return puts("-1"),0;
	For(i,1,n) fa[i]=i;
	For(i,1,m){
		int x=read(),y=read();
		int a=Find(x),b=Find(y);
		if (a!=b) fa[a]=b,e[x].pb(y),e[y].pb(x);
			else ans.ep(x,y),d[x]^=1;
	}
	dfs(1,0);
	for (auto i:ans) printf("%d %d\n",i.fi,i.se);
}

Measured memory_bytes: 14408
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
S = input()

lovenum = 753
ans = 1000
for i in range(len(S)):
    if i+3>len(S):
        break
    X = int(S[i:i+3])
    num = abs(X-753)
    ans = min(ans,num)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
using namespace std;
//
const int inf=1e9+7;//0x3f
//
int main(){
	int N;
	int ret=0;
	cin>>N;
	for(int i=1;i<=N;i+=2){
		int num=i;
		int ans=1;
		int now=3;
		while(num>1){
			int cnt=0;
			while(num%now==0){
				num/=now;
				cnt++;
			}
			now+=2;
			ans*=(cnt+1);
		}
		if(ans==8){
			ret++;
		}
	}
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  vector<ll> h(N); rep(i,N) cin>>h[i];
  
  //dp
  vector<ll> table(N,INF);
  
  function<ll(ll)> dp=[&](ll i){
    if(i<=0) return 0LL;
    if(table[i]<INF) return table[i];
    
    ll ret=INF-1;
    chmin(ret,dp(i-1)+abs(h[i]-h[i-1]));
    if(i>1) chmin(ret,dp(i-2)+abs(h[i]-h[i-2]));
    
    return table[i]=ret;
  };
  
  cout<<dp(N-1)<<endl;
  
  return 0;
}

Measured memory_bytes: 12676
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i = 1; i < n+1; i++)
    {
      scanf("%d",&A[i]);
    }

  for(i = 0; i <= VMAX; i++)
    {
      C[i] = 0;
    }

  for(j = 1; j <= n; j++)
    {
      C[A[j]]++;
    }

  for(i = 1; i <= VMAX; i++)
    {
      C[i] += C[i-1];
    }

  for(j = n; j > 0; j--)
    {
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }

  for(i = 1; i < n; i++)
    {
      printf("%d ",B[i]);
    }
  
  printf("%d\n",B[n]);
 
  return 0;
}



Measured memory_bytes: 9636
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef long double db;
    typedef pair<int,int> pii;
    typedef vector<int> vi;
    #define de(x) cout << #x << "=" << x << endl
    #define rep(i,a,b) for(int i=a;i<(b);++i)
    #define all(x) (x).begin(),(x).end()
    #define sz(x) (int)(x).size()
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define lb(x) (x&-(x))
    const int N = 101010;

    int main(){
        map<int,int> m1;
        int n,tmp,cnt=0;
        cin>>n;
        for(int i=0;i<n;i++)
        {
        scanf("%d",&tmp);
        m1[tmp]++;
        }
        map<int,int>::iterator it;
        for(it=m1.begin();it!=m1.end();it++)
        {
            if(it->first!=it->second)
            {
                if(it->first < it->second)
                cnt+=it->second-it->first;
                else
                cnt+=it->second;
            }
        }
        cout<<cnt<<endl;
        return 0;
    }

Measured memory_bytes: 4736
#include <iostream>
using namespace std;
 
int main() {
	int yj[18] = {};
	for(int i = 0; i < 18; i++){
		 cin >> yj[i];
	}
	if(yj[5] < yj[2]) {
		yj[5] = yj[5] + 60;
		yj[4] = yj[4] - 1;
	}
	if(yj[4] < yj[1]) {
		yj[4] = yj[4] + 60;
		yj[3] = yj[3] - 1;
	}
	if(yj[11] < yj[8]) {
		yj[11] = yj[11] + 60;
		yj[10] = yj[10] - 1;
	}
	if(yj[10] < yj[7]) {
		yj[10] = yj[10] + 60;
		yj[9] = yj[9] - 1;
	}
	if(yj[17] < yj[14]) {
		yj[17] = yj[17] + 60;
		yj[16] = yj[16] - 1;
	}
	if(yj[16] < yj[13]) {
		yj[16] = yj[16] + 60;
		yj[15] = yj[15] - 1;
	}
	cout <<yj[3] - yj[0]<<" "<<yj[4] - yj[1]<<" "<<yj[5] - yj[2]<<endl;
	cout <<yj[9] - yj[6]<<" "<<yj[10] - yj[7]<<" "<<yj[11] - yj[8]<<endl;
	cout <<yj[15] - yj[12]<<" "<<yj[16] - yj[13]<<" "<<yj[17] - yj[14]<<endl;
 
	return 0;
}

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

int main(){
	ll n;
	cin >> n;
	if(n == 0){
		cout << 0 << endl;
		return 0;
	}
	string s = {};
	while(n != 0){
		if(n % (-2) == 0){
			s += '0';
		}else{
			n--;
			s += '1';
		}
		n /= (-2);
	}
	reverse(s.begin(),s.end());
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){ 
  double x, y, x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  double r;
  
  r = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
  printf("%lf\n",r);
  //cout << r << endl;

  return 0;
}  


Measured memory_bytes: 3288
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n+1,0);
  vector<ll> c(n+1,0);
  rep(i,n) { 
    ll num;
    cin >> num;
    a[i] = num;
    b[num]++;
  }
  ll cnt = 0;
  for(int i = 1; i <= n; ++i) {
    ll d = b[i];
    if(d > 0){
      b[i] = (d * (d-1)) / 2;
      c[i] = ((d-1) * (d-2)) / 2;
    }
    cnt += b[i];
   // cout << b[i] << " " << c[i] << endl;
  }
  //printf("%lld\n\n", cnt);
  rep(i,n) {
    ll ans = cnt - b[a[i]] + c[a[i]];
    cout << ans << endl;
  }

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  double b;
  double a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    b += 1/a[i];
  }
  cout << fixed << setprecision(6) << 1/b << endl;
}

Measured memory_bytes: 256
import math
def divisors(n, sort=True, reverse=False):
    sqn = math.sqrt(n)
    sqn_int = int(sqn)
    div_list = []
    if sqn == sqn_int:
        div_list.append(sqn_int)
        loop = range(1,sqn_int)
    else:
        loop = range(1,sqn_int + 1)
    for i in loop:
        if n % i == 0:
            div_list.append(i)
            div_list.append(n//i)
    if sort:
        div_list.sort(reverse=reverse)
    return div_list

inpl = lambda: list(map(int,input().split()))
N, K = inpl()
A = inpl()
S = sum(A)
div = divisors(S, reverse=True)
for d in div:
    mods = [ a % d for a in A ]
    mods.sort()
    Sm = sum(mods)
    h = Sm // d
    minK = min(d*(h+1) - sum(mods[N-h-1:]), sum(mods[:N-h]))
    if minK <= K:
        print(d)
        break

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> a(n), s(n + 1, 0);
  rep(i, n) cin >> a[i];
  rep(i, n) s[i + 1] = s[i] + a[i];
  rep(i, n - 1) {
    ll t1 = (s[n] - s[i + 1]);
    t1 %= MOD;
    ans += a[i] * t1;
    ans %= MOD;
  }

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

Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"

int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>n>>m>>k;
	m=m*k;
	if(m>=n)cout<<"Yes";
	else cout <<"No";
	
	

}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int a[N], dp[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n;
    cin>>n;
    f(i, n) cin>>a[i];
    dp[n - 1] = 0;
    for(int i = n - 2; i >= 0; i--) {
        if(a[i + 1] <= a[i]) dp[i] = dp[i + 1] + 1;
    }
    int ans = -1;
    f(i, n) ans = max(ans, dp[i]);
    cout<<ans;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int, int> pi;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MKP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

const int INF = 999999;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll MOD = 1000000007;

ll m, x = 0;
char N[10] = { 0 };
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	m = atoi(N);
	REP(i, 9) {
		char y[1];
		y[0] = N[i];
		x += atoi(y);
	}
	if (m%x) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll m=pow(10,9)+7;
int main(){
    int n;
    cin >> n;
    ll a[n];
    ll sum=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum+=a[i];
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        sum-=a[i];
        ans+=(sum%m*a[i]%m)%m;
    }
    cout << ans%m << endl;
}

Measured memory_bytes: 5180
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5;


int main(){
	int N;
	cin>>N;
	int a[MAX];
	rep(i,N)cin>>a[i];
	sort(a,a+N);
	
	int ans=0;
	if(N==1)ans=1;
	else{
		rep(i,N-1)if(a[i]==a[i+1])a[i]=a[i+1]=0;
		rep(i,N) if(a[i]!=0) ans++;
	}
	cout<<ans;
}

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

using namespace std;

const int MAXN = 1e5+2;
int N, M;
int Q;
vector<int> adj[MAXN];
int clr[MAXN]={0};
int v[MAXN],d[MAXN],c[MAXN];
int cvr[MAXN]={0}; //至今为止，访问过p的最大distance cover. 每次flood时会-1，所以distance比较小的时候就停止flood

void solve(){
	cin>>N>>M;
	for (int i=0;i<M;i++){
		int a0,b0;
		cin>>a0>>b0;
		adj[a0].push_back(b0);
		adj[b0].push_back(a0);
	}
	cin>>Q;
	for (int i=0;i<Q;i++){
		cin>>v[i]>>d[i]>>c[i];
	}
	for (int i=Q-1;i>=0;i--){
		deque<pair<int,int> > dq;
		dq.push_back({v[i],d[i]+1});
		while (!dq.empty()){
			int p = dq.front().first;
			int dis = dq.front().second;
			dq.pop_front();
			if (dis<=0){
				break;
			}
			if (cvr[p]>=dis){
				continue;
			}
			else{
				cvr[p]=dis;
			}
			if (clr[p]==0){
				clr[p] = c[i];
			}
			for (auto pn:adj[p]){
				dq.push_back({pn, dis-1});
			}
		}
	}

	for (int i=1;i<=N;i++){
		cout<<clr[i]<<endl;
	}
}

int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	std::ios::sync_with_stdio(false);

//	int TestCase;
//	cin>>TestCase;
//	for (int iTest=0;iTest<TestCase;iTest++){
		solve();
//	}
}


Measured memory_bytes: 8988
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;
struct edge {
	int from, to, cost;
};


int main() {
	int n; string s; cin >> s >> n;
	int sz = s.size();
	vector<string> sub;
	rep(i, sz) {
		string t = "";
		rep(j, min(n, sz - i)) {
			t += s[i+j];
			sub.push_back(t);
		}
	}
	sort(sub.begin(), sub.end());
	sz = sub.size();
	rep(i, sz-1) {
		if (sub[i] == sub[i + 1]) sub[i] = "zzzzzz";
	}
	sort(sub.begin(), sub.end());
	cout << sub[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1660
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n1 = Number(lines.shift());
  const arr1 = lines.shift().split(' ').map(Number);
  const n2 = Number(lines.shift());
  const arr2 = lines.shift().split(' ').map(Number);

  const solve = memoization(function(i, m) {
    if (m == 0) return true;
    if (i >= n1) return false;
    return solve(i + 1, m) || solve(i + 1, m - arr1[i]);
  });
  arr2.map(m => solve(0, m) ? 'yes' : 'no').forEach(res => console.log(res));
})();

function memoization(f) {
  const cache = {};
  return (...param) => {
    const c = cache[param];
    return typeof c === 'undefined' ? cache[param] = f(...param) : c;
  };
}



Measured memory_bytes: 24396
A, B, C, D = map(int, input().split())
def div_num(a, b, c):
    if (a%c)==0:
        return (b//c)-(a//c)+1
    else:
        return (b//c)-(a//c)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
XC = div_num(A, B, C)
XD = div_num(A, B, D)
XCD = div_num(A,B,int((C*D)/gcd(C,D)))
print(B-A+1-(XC+XD-XCD))

Measured memory_bytes: 3064