akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#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)

using ll = long long;
#define INF 1e9

ll N;
ll K;
vector<ll> A, F, cost;
ll maxx = 0;

bool isOK(ll x){
  ll cnt = 0;
  REP(i, N){
    if(cost[i] > x){
      ll diff = cost[i] - x;
      if(diff > 0){
        cnt += diff/F[i] +(diff%F[i] ? 1 : 0);
      }
    }
  }
  return cnt <= K;
}

ll binary_search(){
  ll left = -1, right = maxx;
  while(right - left > 1){
    ll mid = left + (right-left)/2;
    if(isOK(mid)) right = mid;
    else left = mid;
  }
  return right;
}

int main(){
  cin >> N >> K;
  A.resize(N), F.resize(N), cost.resize(N);
  REP(i, N){
    cin >> A[i];
  }
  REP(i, N){
    cin >> F[i];
  }
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<ll>());
  REP(i, N){
    cost[i] = A[i]*F[i];
    maxx = max(maxx, cost[i]);
  }
  cout << binary_search() << endl;



  
  return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  int r = 0;
  rep(i,n) if(s[i] == 'R') r++;
  int ans = 0;
  rep(i,r) if(s[i] == 'W') ans++;
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
struct UnionFind {
    vector<int> A;
    UnionFind(int n) : A(n, -1) {}
    int find(int x) {
        if (A[x] < 0) return x;
        return A[x] = find(A[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (A[x] > A[y]) swap(x, y);
        A[x] += A[y];
        A[y] = x;
    }
};
int main() {
    int N, M; cin >> N >> M;
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--, b--;
        uf.unite(a, b);
    }
    int maxsize = 0;
    for (int i = 0; i < N; i++) {
        int t = uf.find(i);
        maxsize = max(maxsize, -uf.A[t]);
    }
    cout << maxsize << endl;
    return 0;
}

Measured memory_bytes: 3988
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FORE(x,xs) for (auto &x : xs)
const int MAX = 1e5+10;

int N;
int A[MAX];
vi edge[MAX];
int parent[MAX];

void makeTree(int n, int p) {
    parent[n] = p;
    FORE (v, edge[n]) {
        if (v == p) continue;
        makeTree(v, n);
    }
}

ll dfs(int n) {
    ll s = 0, mx = 0;
    if (edge[n].size() == 1) return A[n];
    FORE (e, edge[n]) {
        if (parent[e] != n) continue;
        ll m = dfs(e);
        mx = max(mx, m);
        if (m == -1) return -1;
        s += m;
    }
    ll r = 2 * A[n] - s;
    if (r < 0 || r > A[n] || s - mx < (s-r)/2) r = -1;
    return r;
}

int main() {
    cin >> N;
    REP (i, N) cin >> A[i];
    REP (i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    if (N == 2) {
        string ans = (A[0] == A[1]) ? "YES" : "NO";
        cout << ans << endl;
        return 0;
    }

    int root = 0;
    REP (i, N) {
        if (edge[i].size() >= 2) { root = i; break; }
    }

    makeTree(root, -1);
    string ans = "NO";
    if (dfs(root) == 0) ans = "YES";
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int s, w;
  cin >> s >> w;
  if(w >= s) cout << "un";
  cout << "safe\n"; 
  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,k,r,s,p,cnt=0;
  cin>>n>>k>>r>>s>>p;
  string t;
  cin>>t;
  int arr[n+k];
  memset(arr,0,sizeof arr);
  for(long long int i=0;i<n;i++){
    if(!arr[i]){
    
      arr[i]=1;
      if(t[i]=='r') cnt+=p;
      else if(t[i]=='p') cnt+=s;
      else if(t[i]=='s') cnt+=r;
      if(i+k<n) {
        
        if(t[i]==t[i+k]) {arr[i+k]=1;} 
        
       }
    }
        
      
  }
  cout<<cnt;
}
    
    
    
      
       
    

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define forn(i,a,b) for(long long i=a;i<=b;i++)
#define fork(i,a,b,k) for(long long i=a;i<=b;i+=k)
int n;
double p[3000],dp[3005][3005];
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>p[i];
	dp[0][0]=1.0;
	for(int i=1;i<=n;i++){
		dp[i][0]=dp[i-1][0]*(1-p[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i>=j)dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
		}
	}
	double ans=0.0;
	for(int i=(n+1)/2;i<=n;i++)ans+=dp[n][i];
	cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 69120
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
string s[55];int t[55];
int main()
{
	int n;cin>>n;
	rep(i,n) cin>>s[i]>>t[i];
	string x;cin>>x;
	rep(i,n){
		if(s[i]==x){
			int out=0;
			REP(j,i+1,n) out+=t[j];
			cout<<out<<endl;
		}
	}
}


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

int main() {
  int y, m, d;
  char c1, c2;
  cin >> y >> c1 >> m >> c2 >> d;
  cout << (m < 5 ? "Heisei" : "TBD") << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int main()
{
    int n;
    ll k;
    cin >> n >>  k;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }

    vector<int> to;
    to.push_back(0);
    rep(i,n){
        int now = to.back();
        to.push_back(a[now]);


    }
    int visited[n+1];
    rep(i,n)visited[i] = 0;
    int s,end;
    rep(i,n){
        if(visited[to[i]]){
            end = i;
            break;
        }
        visited[to[i]] = 1;
    }
    rep(i,n){
        if(to[i] == to[end]){
            s = i;
            break;
        }
    }
    int len = end - s;

    if(k <=s ){
        cout << to[k]+1 << endl;
        return 0;
    }
    k-=s;
    cout << to[k%len+s]+1 << endl;
    
    return 0;
}

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

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

  vector<int> buka(n, 0);
  for (int i = 1; i < n; ++i) buka[a[i]]++;
  rep(i, n) cout << buka[i] << endl;
  return 0;
}

Measured memory_bytes: 4824
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  for(int i=0;i<n;i++)
    cin>>b.at(i);
  int64_t p=0;
  int64_t m=0;
  for(int i=0;i<n;i++){
    if(b.at(i)-a.at(i)>0)
      p+=(b.at(i)-a.at(i))/2;
    else
      m+=a.at(i)-b.at(i);
  }
  cout<<(p>=m?"Yes":"No")<<endl;
}

Measured memory_bytes: 3660
package main

import (
	"fmt"
)

func main() {
	var a,b int
	fmt.Scanf("%d %d", &a, &b)
	res := a - 2*b
	if (res < 0)  {
		fmt.Printf("%d\n", 0)
	} else {
		fmt.Printf("%d\n", res)
	}
}

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

string convert( string trg ){
    sort(trg.begin(), trg.end());
    int a = 0, b = 0, mul = 1;
    for(string::iterator it = trg.begin(); it != trg.end(); it++){
        int n = (*it)-'0';
        a += n * mul;
        b += n * 1000 / mul;
        mul *= 10;
    }
    a = a-b;
    char tmp[8] = {a/1000+'0', a/100%10+'0', a/10%10+'0', a%10+'0'};
    string res(tmp);
    return res;
}

int main(){
    string ss;
    string FIN("0000"), GOAL("6174");
    while( cin >> ss ){
        if( ss == FIN ) break;
        if( ss[0] == ss[1] && ss[1] == ss[2] && ss[2] == ss[3] ){
            cout << "NA" << endl;
            continue;
        }
        int c = 0;
        while( c < 10 && ss!=GOAL ){
            c++;
            ss = convert(ss);
        }
        cout << c << endl;

    }
    return 0;
}

Measured memory_bytes: 1212
/* ex 3_3
  kt125 */

#include<stdio.h>

int main(void){
  int n, k;
  scanf("%d %d", &n, &k);
  
  int q, count = 0;
  while(1){
    q = n / k;
    if (n/k == 0){
      count++;
      break;
    }
    n = q;
    count ++;
  }
  printf("%d", count);
}
    

Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = 1;
		int b = 0;
		int c = 0;
		for(int i=1; i<=31; i++){
			for(int j=2; j<10; j++){
			a = 1;
				for(int k=0; k<j; k++){
					a *= i;
				}
			if(a<=x && a>b)b=a;
			}
		if(c<b)c=b;
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N;
  cin >> N;
  ll ans = 1e18;
  for(ll i=1;i*i<=N;i++){
    if(N%i==0){
      ll x = i;
      ll y = N/i;
      ll d = (x-1)+(y-1);
      ans = min(ans, d);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
L = len(S)
Q = 10**9 + 7
anum = [ 0 for _ in range(L+1)]
#bnum = [ 0 for _ in range(L+1)]
cnum = [ 0 for _ in range(L+1)]
hnum = [ 0 for _ in range(L+1)]
for i in range(1,L+1):
    if S[i-1] == 'A':
        anum[i] = anum[i-1] + 1
#        bnum[i] = bnum[i-1]
        cnum[i] = cnum[i-1]
        hnum[i] = hnum[i-1]
    elif S[i-1] == 'B':
        anum[i] = anum[i-1]
#        bnum[i] = bnum[i-1] + 1
        cnum[i] = cnum[i-1]
        hnum[i] = hnum[i-1]
    elif S[i-1] == 'C':
        anum[i] = anum[i-1]
#        bnum[i] = bnum[i-1]
        cnum[i] = cnum[i-1] + 1
        hnum[i] = hnum[i-1]
    else:
        anum[i] = anum[i-1]
#        bnum[i] = bnum[i-1]
        cnum[i] = cnum[i-1]
        hnum[i] = hnum[i-1] + 1

ans = 0
czen = cnum[L]
hzen = hnum[L] 
for i in range(1,L+1):
    if S[i-1] == 'B' or S[i-1] == '?':
#        A = ((anum[i-1]*(3**hnum[i-1]))%Q + (hnum[i-1]*(3**(hnum[i-1]-1)))%Q)%Q
#        C = (((czen - cnum[i])*(3**(hzen - hnum[i])))%Q + ((hzen - hnum[i])*(3**(hzen - hnum[i]-1)))%Q)%
        A = ((anum[i-1]*pow(3,hnum[i-1],Q))%Q + (hnum[i-1]*pow(3,max(0,hnum[i-1]-1),Q))%Q)%Q
        C = (((czen - cnum[i])*pow(3,hzen - hnum[i],Q))%Q + ((hzen - hnum[i])*pow(3,max(0,hzen - hnum[i]-1),Q))%Q)%Q
        K = (A*C)%Q
        ans = (ans + K)%Q
print(int(ans))

Measured memory_bytes: 48560
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

N = input()

lst = []
m = {}

for i in range(N):
    x, y, w = map(int, raw_input().split())
    m[(x, y)] = w
    lst.append((x - 1, y - 1))
    lst.append((x - 1, y))
    lst.append((x, y - 1))
    lst.append((x, y))

ans = 0

for p in lst:
    x = p[0]
    y = p[1]
    S = 0
    if (x, y) in m:
        S += m[(x, y)]
    if (x + 1, y) in m:
        S += m[(x + 1, y)]
    if (x, y + 1) in m:
        S += m[(x, y + 1)]
    if (x + 1, y + 1) in m:
        S += m[(x + 1, y + 1)]
    ans = max(ans, S)

print str(ans) + " / 1"


Measured memory_bytes: 69756
#include <iostream>
using namespace std;
int main() {
	int n, k,s[100] = {0};
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		int d;
		cin >> d;
		for (int j = 0; j < d; j++) {
			int a;
			cin >> a;
			if (s[a-1] == 0) {
				s[a-1] = 1;
			}
		}
	}
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 0) { 
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    # 標準入力を取得
    N, M = list(map(int, input().split()))
    k, s = [], []
    for m in range(M):
        l = list(map(int, input().split()))
        k_m, s_m = l[0], l[1:]
        k.append(k_m)
        s.append(s_m)
    p = list(map(int, input().split()))

    return N, M, k, s, p


def lights_on(M: int, s: list, p: list, switches: int) -> bool:
    """
    電球がすべて点灯しているかどうかを確認する.

    Args:\n
        M (int): 電球の数
        s (list): 電球に対応するスイッチ
        p (list): スイッチと電球の点灯の関係
        switches (int): スイッチの状態

    Returns:\n
        bool: 電球がすべて点灯していれば真、そうでなければ偽
    """
    result = True
    for m in range(M):
        switch_on_count = 0
        for s_m_km in s[m]:
            if switches & (1 << (s_m_km - 1)):
                switch_on_count += 1
        if switch_on_count % 2 != p[m]:
            result = False

    return result


def main(N: int, M: int, s: list, p: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): スイッチの数
        M (int): 電球の数
        s (list): 電球に対応するスイッチ
        p (list): スイッチと電球の点灯の関係
    """
    # 求解処理
    ans = 0
    for switches in range(1 << N):
        if lights_on(M, s, p, switches):
            ans += 1

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, M, k, s, p = get_input()

    # メイン処理
    main(N, M, s, p)


Measured memory_bytes: 9292
N = int(input())
march = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(N):
    S = input()
    if S[0] == 'M':
        march['M'] += 1
    elif S[0] == 'A':
        march['A'] += 1
    elif S[0] == 'R':
        march['R'] += 1
    elif S[0] == 'C':
        march['C'] += 1
    elif S[0] == 'H':
        march['H'] += 1
ans = 0
ans += march['M']*march['A']*march['R']
ans += march['M']*march['A']*march['C']
ans += march['M']*march['A']*march['H']
ans += march['M']*march['R']*march['C']
ans += march['M']*march['R']*march['H']
ans += march['M']*march['C']*march['H']
ans += march['A']*march['R']*march['C']
ans += march['A']*march['R']*march['H']
ans += march['A']*march['C']*march['H']
ans += march['R']*march['C']*march['H']

print(ans)


Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, l;
	cin >> n >> l;
	int mm = 1e8;
	int sum =  0;
	for (int i = 1; i <= n; i++) {
		if (abs(mm) > abs(l + i - 1)) {
			mm = l + i - 1;
		}
		sum += l + i - 1;
	}
	cout << sum - mm << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

void print_a(VI v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    char ch;
    cin>>ch;
    if(ch >= 'A' && ch <= 'Z') cout<<"A\n";
    else cout<<"a\n";

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n) cin>>a[i];
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n) cin>>a[i];
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3640
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		long l = Long.parseLong(sc.get());
		StringBuilder sb = new StringBuilder();

		while (l > 0){
			var l1 = (l - 1) % 26;
			sb.append((char) (l1 + 'a'));
			l--;
			l /= 26;
		}

		System.out.println(sb.reverse().toString());
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}


int main()
{
    int n,l;
    cin >> n >> l;
    vector<string> v;
    for (size_t i = 0; i < n; i++)
    {
        string s;
        cin>>s;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    string ans="";
    for (size_t i = 0; i < v.size(); i++)
    {
        ans += v[i];
    }
    cout << ans << endl;

    return 0;
}

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]


N = int(input())
A = list(map(int, input().split()))

C = [0]*(2*10**5+1)

for i in A:
    C[i] += 1

ans = sum(i*(i-1)//2 for i in C)

for i in A:
    print(ans-C[i]+1)

Measured memory_bytes: 104112
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		String [] inArray = in.split(" ");
		int [] ansArray = new int[3];
		int a = Integer.parseInt(inArray[0]);
		int b = Integer.parseInt(inArray[1]);
		int c = Integer.parseInt(inArray[2]);

		ansArray[0] = a + b;
		ansArray[1] = b + c;
		ansArray[2] = a + c;


		int ans = ansArray[0];

		for (int i = 0 ; i < ansArray.length; i++) {
			if (ans > ansArray[i]){
				ans = ansArray[i];
			}
		}

		System.out.println(ans);
		sc.close();
	}



}


Measured memory_bytes: 20820
N = int(input())

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

tmplist = [A,B,C,D,E]
max_time_list = []
for x in tmplist:
    dim = N/x
    max_time_list.append(int(dim)+1 if int(dim)!=dim else int(dim))

print(max(max_time_list)+4)


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N = d_in()

aranged_list = [0] * N
for i in range(N):
    idx = d_in()
    aranged_list[idx-1] = i

ans, count = 0, 0
temp = -1
for i in aranged_list:
    if i > temp:
        count += 1
        temp = i
    else:
        ans = max(ans, count)
        count = 1
        temp = i
ans = max(ans, count)

print(N - ans)

Measured memory_bytes: 10960
//invincible M15
//IIT-(ISM)Dhanbad
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pi  3.141592653589793238462643383279
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define high_functioning_sociopath  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const unsigned int M = 1000000007;
/*------------------------------------- THE GAME IS ON ---------------------------------------------*/
ll dp[105][100005];
ll knapsack(vector<pair<ll,ll>>&v , ll n, ll w)
{
       if(n==0 || w==0)return 0;
       if(dp[n][w]!=-1)return dp[n][w];
       if(v[n-1].ff <= w)
       {
              return dp[n][w]=max((v[n-1].ss + knapsack(v, n-1, w-v[n-1].ff)),knapsack(v, n-1,w));
       }
       else
       {
              return dp[n][w]=knapsack(v, n-1 , w);
       }
}
void solve()
{
       ll n,w;
       cin>>n>>w;
       vector<pair<ll,ll>>v;
       for(int i=0;i<n;i++)
       {
              ll x,y;
              cin>>x>>y;
              v.pb({x,y});
       }
       memset(dp,-1,sizeof(dp));
       cout<<knapsack(v,n,w)<<endl;
       
}
int32_t main()
{
   high_functioning_sociopath
   ll t=1;
   //cin>>t;
   while(t--)
   {
      solve();
   }
}

Measured memory_bytes: 85656
#include<stdio.h>
int main(){
    
    int S;
    int h, m, s;
    scanf("%d", &S);
    
    h = S / 3600;
    m = ( S % 3600) / 60;
    s = S % 60;
    
    printf("%d:%d:%d\n", h, m, s);
    
    return 0;
}


Measured memory_bytes: 2112
/*  ex3_3
    pptenshi  */

#include<stdio.h>

int main(void) {
    int n, k;
    int digits = 0;  // 桁数

    // input
    scanf("%d %d", &n, &k);

    //caluculate digits
    while (n > 0) {
        n /= k;
        digits++;
    }

    //output
    printf("%d", digits);

    return 0;
}

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

int main(){
    int N;
    int answer = 0;
    cin >> N;
    vector<int> A(N),B(N),C(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for(int i = 0; i < N; i++){
        cin >> B.at(i);
    }
    for(int i = 0; i < N-1; i++){
        cin >> C.at(i);
    }
    for(int i = 0; i<N; i++){
        answer += B.at(i);
        if ((i < N-1) && (A.at(i) == A.at(i+1) -1)){
            answer += C.at(A.at(i)-1);
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int a,b;
    cin>>a>>b;
    a+=b;
    if(a%2)cout<<"IMPOSSIBLE"<<endl;
    else cout<<a/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

constexpr int N = 3;
int c[10][10];

int main(){
    rep(i,N) rep(j,N) cin >> c[i][j];

    int a[4];
    int b[4];

    for(int t=-200;t<=200;t++){
        a[0] = t;
        b[0] = c[0][0]-a[0];
        b[1] = c[0][1]-a[0];
        b[2] = c[0][2]-a[0];

        bool ok = true;
        a[1] = c[1][0] - b[0];
        a[2] = c[2][0] - b[0];

        rep(i,N) rep(j,N){
            if(a[i] + b[j] == c[i][j]) continue;
            else{
                ok = false;
                break;
            }
        }
        if(ok){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

struct Data {
  int r, l, k;
};
int main() {
  string S;
  cin >> S;
  int n = S.length();
  vector<Data> d(n);
  for (int i = 0; i < n; i++) {
    if (S[i] == 'R') {
      d[i].k = 0;
    } else {
      d[i].k = 1;
    }
  }
  d[0].r = 0;
  for (int i = 1; i < n; i++) {
    if (S[i] == 'R') {
      d[i].r = i;
    } else {
      d[i].r = d[i - 1].r;
    }
  }
  d[n - 1].l = n - 1;
  for (int i = n - 2; i >= 0; i--) {
    if (S[i] == 'L') {
      d[i].l = i;
    } else {
      d[i].l = d[i + 1].l;
    }
  }
  int cnt[n]{};
  for (int i = 0; i < n; i++) {
    int g;
    if (d[i].k == 0) {
      g = d[i].l - i;
      if (g % 2 == 0) {
        cnt[d[i].l]++;
      } else {
        cnt[d[i].l - 1]++;
      }
    } else {
      g = i - d[i].r;
      if (g % 2 == 0) {
        cnt[d[i].r]++;
      } else {
        cnt[d[i].r + 1]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      cout << cnt[i] << "\n";
    } else {
      cout << cnt[i] << " ";
    }
  }
  return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>

using namespace std;
using ll = long long int;


int main(void) {
	int tmp;
	string ret;
	cin >> tmp;
	int l = tmp / 100;
	int r = tmp - l * 100;

	if (0 <= l && l <= 99) {
		if (1 <= r && r <= 12) {
			if (1 <= l && l <= 12)
				ret = "AMBIGUOUS";
			else
				ret = "YYMM";
		}
		else if (13 <= r && r <= 99) {
			if (1 <= l && l <= 12)
				ret = "MMYY";
			else 
				ret = "NA";
		}
		else {
			if (1 <= l && l <= 12)
				ret = "MMYY";
			else
				ret = "NA";
		}
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
#define CoutV(vec)        \
    for (auto v : vec)    \
    {                     \
        cout << v << " "; \
    }                     \
    cout << endl;
#define CoutVV(vecvec)      \
    for (auto vec : vecvec) \
        CoutV(vec);

using ll = long long;
using P = pair<int, int>;
#define INF 10000000;

ll MOD = 1e9 + 7;

int main()
{

    string s, t;
    cin >> s >> t;
    vector<int> start(26, -1), goal(26, -1);

    REP(i, s.size())
    {
        int a = s[i] - 'a';
        int b = t[i] - 'a';

        if (start[a] != -1 || goal[b] != -1)
        {
            if (start[a] != b || goal[b] != a)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            start[a] = b;
            goal[b] = a;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 776
S = input()
T = input()

moves = [[None for i in range(len(T)+1)] for j in range(len(S)+1)]
dp = [[0 for i in range(len(T)+1)] for j in range(len(S)+1)]

# dp[i][j] = longest substring of S[:i] and T[:j]

for i in range(1,len(S)+1):
    for j in range(1,len(T)+1):
        sc = S[i-1]
        tc = T[j-1]

        c = 0

        if dp[i-1][j] > dp[i][j]:
            dp[i][j] = dp[i-1][j]
            c = 1
        if dp[i][j-1] > dp[i][j]:
            dp[i][j] = dp[i][j-1]
            c = 2
        if sc == tc and 1 + dp[i-1][j-1] > dp[i][j]:
            dp[i][j] = 1 + dp[i-1][j-1]
            c = 3
        moves[i][j] = c

s = ""

cur = [len(S), len(T)]
while cur != [0, 0]:
    
    move = moves[cur[0]][cur[1]]
    if move == 3:
        s += S[cur[0]-1]
        cur[0] -= 1
        cur[1] -= 1
    elif move == 2:
        cur[1] -= 1
    elif move == 1:
        cur[0] -= 1
    else:
        break


print(s[::-1])


Measured memory_bytes: 192008
fun main(args: Array<String>) {
    val sb = StringBuilder( readLine()!! )
    val w = listOf("dream","dreamer","erase","eraser")
 
    while (sb.isNotEmpty()){
        val erase = w.find { sb.endsWith(it) }
        if(erase==null){
            println("NO")
            return
        }else{
            sb.delete(sb.length-erase.length , sb.length)
        }
    }
    println("YES")
}

Measured memory_bytes: 39080
N,M,X = map(int,input().split())
li =[]
aa = []
for i in range(N):
    la = list(map(int,input().split()))
    li.append(la)
for i in range(2**N):
    lm = [0]*M
    c = 0
    #print(bin(i))
    for j in range(N):
        if  i & (1<<j):
            lm = [lm[a]+li[j][a+1] for a in range(M)]
            c += li[j][0]
            #print(lm)
    #print(lm)
    if all([i>=X for i in lm]):
        #print("a")
        aa.append(c)
if aa == []:
    print("-1")
else:
    print(min(aa))


Measured memory_bytes: 74436
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  int X, Y;
  cin >> S >> X >> Y;
  int N = S.size();
  int initPos = S.find('T');
  if (initPos == (int)string::npos) {

    if (X == N)
      print("Yes");
    else {
      print("No");
    }

    return 0;
  } else {
    // DEBUG(S);
    // DEBUG(initPos);
    X -= initPos;
    int dtype = 0; // xtype
    vec< vec< int > > xyLis(2, vec< int >());
    int cnt = 0;
    S.pb('T');
    int xyLisSum[2] = {0, 0};
    FOR(i, initPos, (int)S.size()) {
      if (S[i] == 'T') {
        if (cnt != 0) {
          xyLis[dtype].pb(cnt);
          xyLisSum[dtype] += cnt;
          cnt = 0;
        }
        dtype++;
        dtype %= 2;
      } else {
        cnt++;
      }
    }
    //
    int sx = xyLisSum[0] - X;
    int sy = xyLisSum[1] - Y;

    if (sx % 2 == 0 && sy % 2 == 0 && sx >= 0 && sy >= 0) {
      sx /= 2;
      sy /= 2;
      // DEBUG(sx);
      // DEBUG(sy);
      // PRINTALL(xyLis[0]);
      // PRINTALL(xyLis[1]);

      vec< bool > flgX(sx + 1, false);
      flgX[sx] = true;
      FORA(e, xyLis[0]) {
        REPS(i, sx) {
          if (flgX[i] && i - e >= 0) {

            flgX[i - e] = true;
          }
        }
      }

      vec< bool > flgY(sy + 1, false);
      flgY[sy] = true;
      FORA(e, xyLis[1]) {
        REPS(i, sy) {
          if (flgY[i] && i - e >= 0) {

            flgY[i - e] = true;
          }
        }
      }

      if (flgX[0] && flgY[0]) {
        print("Yes");
      } else {
        print("No");
      }
    } else {
      print("No");
    }
    return 0;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
    ll k; cin >> k;
    queue<ll> que;
    vector<ll> lun;
    for(ll i=1; i<10; ++i){que.push(i); lun.push_back(i);}
    while(!que.empty()){
        ll v = que.front(); que.pop();
        ll d = v * 10 + (v%10);
        if(d%10==0){
            for(ll i=0; i<=1; ++i){
                que.push(d+i);
                lun.push_back(d+i);
            }
        }else if(d%10==9){
            for(ll i=-1; i<=0; ++i){
                que.push(d+i);
                lun.push_back(d+i);
            }
        }else{
            for(ll i=-1; i<=1; ++i){
                que.push(d+i);
                lun.push_back(d+i);
            }
        }
        if(lun.size()>=k){break;}
    }
    cout << lun[k-1] << endl;
    return 0;
}   


Measured memory_bytes: 4632
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
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;
}

// べき乗
ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  ll A,B,V,W,T;
  cin >> A >> V >> B >> W >> T;
  if ((V-W)*T >= abs(A-B)) {
    cout << "YES";
  }
  else cout << "NO";
  cout << endl;
}


Measured memory_bytes: 3480
# coding: utf-8

n = int(input())
dp = [0,1]

for i in range(2,n+1):
    Q = []
    Q.append(1+dp[i-1])
    
    p6 = 1
    while i >= 6**p6:
        Q.append(1+dp[i-6**p6])
        p6 += 1

    p9 = 1
    while i >= 9**p9:
        Q.append(1+dp[i-9**p9])
        p9 += 1
    
    dp.append(min(Q))

print(dp[n])

Measured memory_bytes: 46428
fun main(arg: Array<String>) {
    val (N, Y) = listOfInt()
    val M = IntArray(3)
    for (i in 0 .. N)
        for (j in 0 .. N) {
            val k = N - i - j
            if (k < 0) break
            val t = i * 10000 + j * 5000 + k * 1000
            if (t == Y) return println("$i $j $k")
        }
    println("-1 -1 -1")
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 37764
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	int N, L;
	cin >> N >> L;
	vector<string> S(N);
	rep(i, N) cin >> S[i];
	sort(ALL(S));

	rep(i, N) cout << S[i];
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int have_odd(const uint64_t A, const uint64_t B, const uint64_t C) {
    return ((A&1)||(B&1)||(C&1)) ? 1 : 0;
}

int main(void)
{
    uint64_t A, B, C;
    int64_t ans = 0;
    scanf("%lu %lu %lu", &A, &B, &C);
    while (!have_odd(A,B,C)) {
        uint64_t tmpA, tmpB, tmpC;
        tmpA = (B+C)/2;
        tmpB = (C+A)/2;
        tmpC = (A+B)/2;
        A = tmpA;
        B = tmpB;
        C = tmpC;
        ans++;
        if (A == B && B == C) {
            ans = -1;
            break;
        }
    }
    printf("%" PRId64 "\n", ans);
    return 0;
}


Measured memory_bytes: 128
from collections import deque

def main():
    N,C = map(int, input().split())
    x = [0 for _ in range(N)]
    v = [0 for _ in range(N)]
    for i in range(N):
        x[i],v[i] = map(int, input().split())

    a = [0 for _ in range(N)]
    amax = 0
    b = [0 for _ in range(N)]
    bmax = 0
    cal1 = []
    cal2 = []
    for i in range(N):
        if i == 0:
            cal1.append(v[i]-x[i])
            cal2.append(v[-i-1]-(C-x[-i-1]))
            if amax < cal1[-1]:
                amax = cal1[-1]
            if bmax < cal2[-1]:
                bmax = cal2[-1]
        else:
            cal1.append(cal1[-1]+v[i]-abs(x[i]-x[i-1]))
            cal2.append(cal2[-1]+v[-i-1]-abs(x[-i-1]-x[-i]))
            if amax < cal1[-1]:
                amax = cal1[-1]
            if bmax < cal2[-1]:
                bmax = cal2[-1]
        a[i] = max([amax, cal1[-1]])
        b[i] = max([bmax, cal2[-1]])
    c = [0 for _ in range(N-1)]
    d = [0 for _ in range(N-1)]
    if c==[]:
        c.append(0)
        d.append(0)
    for i in range(N-1):
        c[i] = a[i] + b[-i-2] - x[i]
        d[i] = b[i] + a[-i-2] - (C-x[-i-1])
    return max([amax,bmax,max(c),max(d)])

if __name__ == '__main__':
    print(main())



Measured memory_bytes: 29924
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){
    
    int N,K,H[1000000];
    long long ans =0;
    cin >> N >> K;

    if(K>=N){
        cout << 0 << endl;
        return 0;
    }

    for(int i=0;i<N;i++){
        cin >> H[i];
    }

    sort(H,H+N,greater<int>());

    for(int i=K;i<N;i++)
    {
        ans += H[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 2944
from collections import defaultdict as dd
n = int(input())
counter = dd(int)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            ans = x**2 + y**2 + z**2 + x*y + y*z + z*x
            counter[ans] += 1

for num in range(1, n+1):
    print(counter[num])


Measured memory_bytes: 72788
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX_N = 2000;
int a[MAX_N], n, x;
int f[MAX_N][MAX_N];
int main() {
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long ans = 1e18;
	//スライムiを入手するのに必要なコストを考える　j回変色させたときの最小がf[i][j]
	for (int i = 0; i < n; i++) {
		f[i][0] = a[i];
		for (int j = 1; j < n; j++) {
			f[i][j] = min(f[i][j - 1], a[(i - j + n) %n]);
		}
	}
	//変色させる回数をiとする
	for (int i = 0; i < n; i++) {
		long long cur = (long long)x*i;
		for (int j = 0; j < n; j++) {
			cur += f[j][i];
		}
		ans = min(ans, cur);
	}

	cout << ans << endl;



	


	return 0;
}


Measured memory_bytes: 15872
#include<stdio.h>
int main()
{
    int n,i,j,m,s,t;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    t=0;
    for(i=0;i<n;i++){
        s=0;
        for(j=1;j<n;j++){
            if(j<=i){
                continue;
            }
            m=a[i]*a[j];
            s=s+m;
        }
        t=t+s;
    }
    printf("%d\n",t);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

	    switch(s) {
	    case "MON":
	    	System.out.println(6);
	    	break;
	    case "TUE":
	    	System.out.println(5);
	    	break;
	    case "WED":
	    	System.out.println(4);
	    	break;

	    case "THU":
	    	System.out.println(3);
	    	break;

	    case "FRI":
	    	System.out.println(2);
	    	break;

	    case "SAT":
	    	System.out.println(1);
	    	break;

	    case "SUN":
	    	System.out.println(7);
	    	break;

	  }
	}

}

Measured memory_bytes: 19924
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>
#include <cassert>
#include <climits>

using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const i64 INFL = (1LL<<62);
const i64 MOD = 1000000007;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> i64 mod_pow(i64 a, i64 n, T mod) { mod=(i64)mod; i64 res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }
void print() { std::cout << std::endl; }
template <typename T, typename... A> void print(const T& first, const A&... rest) { cout << sizeof...(rest) << endl; std::cout << first; if (sizeof...(rest)) std::cout << " "; print(rest...); }
template <typename... A> void print(const A&... rest) { print(rest...); }
template <typename A> void print(const std::vector<A>& v) { std::for_each(v.begin(), v.end(), [](A x) { std::cout << x << " "; }); std::cout << std::endl; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> node(n, 0);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    node[a-1]++;
    node[b-1]++;
  }
  rep(i, n){
    if(node[i] & 1){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;


  return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];

    int lmax = 1000;
    vector<int> a(lmax+1,0);
    for(int li : l) a[li]++;
    vector<int> b(lmax+1,0);
    int bi = 0;
    rep(i,lmax+1){
        bi += a[i];
        b[i] = bi;
    }

    int64_t ans = 0;
    for(int i = 1; i <= lmax; i++){
        for(int j = i; j <= lmax; j++){
            int64_t ai = a[i];
            int64_t aj = a[j];
            int64_t bj = b[j];
            int64_t bk = b[min(lmax,i+j-1)];
            if(i == j){
                ans += ai*(ai-1)*(ai-2)/6;
                ans += ai*(ai-1)/2*(bk-bj);
            }
            else{
                ans += ai*aj*(aj-1)/2;
                ans += ai*aj*(bk-bj);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 100100;
int n;
int a[maxn][3];
int dp[maxn][3];

int dfs(const int i, const int j)
{
    if (i == 0)
        return a[i][j];
    int& ans = dp[i][j];
    if (-1 == ans) {
        ans = 0;
        FOR(d,0,3) if (d != j) {
            int result = dfs(i-1, d) + a[i][j];
            ans = max(ans,result);
        }
    }
    return ans;
}
    
int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);
    while (cin >> n) {
        memset(dp,-1,sizeof(dp));
        FOR(i,0,n) FOR(j,0,3){
            cin >> a[i][j];
        }
        int ans=0;
        FOR(k,0,3) {
            ans= max(ans,dfs(n-1,k));
        }
        cout << ans << endl;
    }
    
}


Measured memory_bytes: 8832