akhauriyash/Code-Regression huggingface dataset:
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv
c = Combination(3000)

def H(n, r, mod=10**9+7):
    return c(n+r-1, r)


mod = 10**9+7
N, K = map(int, input().split())
B = K
R = N-K
for i in range(1, K+1):
    bn = i
    br = B-i
    rn = i+1
    rr = R-i+1
    if rr<0 or br<0:
        print(0)
    else:
        #print(i, bn, br, rn, rr)
        ans = H(bn, br) * H(rn, rr) % mod
        print(ans)


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

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

   if (n == m) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
}

Measured memory_bytes: 256
def main():
    s = input().replace('ST', '')
    cnts = 0
    cnt = 0
    for i in s:
        if i == 'S':
            cnts += 1
        elif cnts > 0:
            cnts -= 1
            cnt += 1
    print(len(s)-cnt*2)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3500
#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[100];
    char s1 = 'L';
    char s2 = 'R';
    int count = 0;
    scanf("%s", str);
    int len = strlen(str);
    for (int i = 0; i < len; i++)
    {
        char s3 = str[i];
        if (i % 2 == 0)
        {
            if (s3 == s1)
            {
                puts("No");
                break;
            }
        }
        else
        {
            if (s3 == s2)
            {
                puts("No");
                break;
            }
        }
        count++;
    }
    if (count == len)
        puts("Yes");
    return 0;
}


Measured memory_bytes: 128
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
struct point
{
	int x,y;
}a[110],b[110];
int n;
bool used[110];
bool cmp1(point x,point y)
{
	if (x.y==y.y)
	{
		return x.x<y.x;
	}
	else
	{
		return x.y>y.y;
	}
}
bool cmp2(point x,point y)
{
	if (x.x==y.x)
	{
		return x.y>y.y;
	}
	else
	{
		return x.x<y.x;
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		scanf("%d%d",&a[i].x,&a[i].y);
	}
	for (int i=0;i<n;i++)
	{
		scanf("%d%d",&b[i].x,&b[i].y);
	}
	sort(a,a+n,cmp1);
	sort(b,b+n,cmp2);
	int ans=0;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<n;j++)
		{
			if (used[j])
			{
				continue;
			}
			if (a[j].y<b[i].y && a[j].x<b[i].x)
			{
				used[j]=true;
				ans++;
				break;
			}
		}
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define NODE_MAX (2000000)

struct node {
        int key;
        int parent;
        int left;
        int right;
};

void
max_heapify(struct node A[], int i, int heap_size)
{
        int largest = i;
        int left = A[i].left;
        int right = A[i].right;
        int key;

        if (A[left].key <= A[i].key && A[right].key <= A[i].key)
                largest = i;
        else if (right <= heap_size && A[left].key <= A[right].key)
                largest = right;
        else if (left <= heap_size)
                largest = left;

        if (largest != i) {
                key = A[i].key;
                A[i].key = A[largest].key;
                A[largest].key = key;
                max_heapify(A, largest, heap_size);
        }

}

int
main(void)
{
        int heap_size;
        struct node key[NODE_MAX];
        int i;

        scanf("%d", &heap_size);

        for (i = 1; i <= heap_size; i++)
                scanf("%d", &key[i].key);

        for (i = 1; i <= heap_size; i++) {
                key[i].parent = i / 2;
                key[i].left = i * 2;
                key[i].right = i * 2 + 1;
        }

        for (i = heap_size; 0 < i; i--)
                max_heapify(key, i, heap_size);

        for (i = 1; i <= heap_size; i++)
                printf(" %d", key[i].key);
        printf("\n");

        return 0;
}



Measured memory_bytes: 9536
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	string s; cin >> s;
	string ans="";
	rep(i,s.size()) {
		if(s[i]=='1') ans=ans+'1';
		else if(s[i]=='0') ans=ans+'0';
		else if(s[i]=='B') {
			if(ans.size()!=0) ans=ans.substr(0,ans.size()-1);
			else {}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3580
#import sys
#print(sys.maxsize)
N,X,M=map(int,input().split())
#table=list(range(M))
#for i in range(M):
 #   table[i]=((table[i]%M)**2)%M
#print(table[471])
start=X%M
rset=set()
rireki=list()
rset.add(start)
rireki.append(start)
ss=0
for j in range(1,M+1):
    start=(start**2)%M
    if start in rset:
        ss=rireki.index(start)
        break
    else:
        rireki.append(start)
        rset.add(start)
nn=len(rireki)
rep=(N-ss)//(nn-ss)
nokori=N-ss-rep*(nn-ss)
loop=rireki[ss:]
#print(nn)
#print(rep)
#print(sum(loop))
#print(ss)
#print(nokori+rep*(nn-ss)+ss)
if 0 in rireki:
    goukei=sum(rireki)
else:
    goukei=rep*sum(loop)+sum(rireki[:ss])+sum(loop[:nokori])
print(goukei)

Measured memory_bytes: 13532
// g++ -std=gnu++1y -O2 xxx.cpp

#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() {
    ll N,K; cin>>N>>K;

    cout << min(N%K,abs(N%K-K)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
#define N 2006
typedef long long ll;


int main(){
    char c;
    cin>>c;
    if(c>='A'&&c<='Z')
        cout<<"A";
    else if(c>='a'&&c<='z')
        cout<<"a";
    return 0;
}


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

using namespace std;

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

	int K, X;
	cin >> K >> X;

	if (K * 500 >= X)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var N, A, B, C, D int
	var S string
	fmt.Scan(&N, &A, &B, &C, &D, &S)

	// AとCの間、またはBとDの間に岩が２つ連続で並んでいるゾーンがある->No
	if strings.Contains(S[A-1:C], "##") || strings.Contains(S[B-1:D], "##") {
		fmt.Println("No")
		return
	}

	// C > D の時、Bの1つ前からDの1つ後までの間に平地が3つ連続で並んでいるゾーンがない->No
	if C > D && !strings.Contains(S[B-2:D+1], "...") {
		fmt.Println("No")
		return
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 1792
import math

global th
th = math.pi * (60/180)

def koch(d, p1, p2):
    if d == 0:
        return
    else:
        s_x = (2 * p1[0] + p2[0]) / 3
        s_y = (2 * p1[1] + p2[1]) / 3
        s = (s_x, s_y)
        t_x = (p1[0] + 2 * p2[0]) / 3
        t_y = (p1[1] + 2 * p2[1]) / 3
        t = (t_x, t_y)
        u_x = (t[0] - s[0]) * math.cos(th) - (t[1] - s[1]) * math.sin(th) + s[0]
        u_y = (t[0] - s[0]) * math.sin(th) + (t[1] - s[1]) * math.cos(th) + s[1]
        u = (u_x, u_y)

        koch(d-1, p1, s)
        print(*s, sep=" ")
        koch(d-1, s, u)
        print(*u, sep=" ")
        koch(d-1, u, t)
        print(*t, sep=" ")
        koch(d-1, t, p2)

n = int(input())
p1 = (0.0, 0.0)
p2 = (100.0, 0.0)
print(*p1, sep=" ")
koch(n, p1, p2)
print(*p2, sep=" ")


Measured memory_bytes: 5788
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
ans = []
for i in range(H-1):
    for j in range(W):
        if a[i][j] % 2 == 1:
            ans.append((i+1, j+1, i+2, j+1))
            a[i+1][j]+=1
for i in range(W-1):
    if a[H-1][i] % 2 == 1:
        ans.append((H, i+1, H, i+2))
        a[H-1][i+1] +=1
print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 73052
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repr(i,n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
        ll h, w;
        cin >> h >> w;
        if (h == 1 || w == 1) cout << 1 << endl;
        else cout << (((h+1)/2)*((w+1)/2)) + ((h/2)*(w/2)) << endl;
    return 0;
}

Measured memory_bytes: 256
// abc160_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;

    if (S[2] == S[3] && S[4] == S[5]){
        print("Yes");
    } else {
        print("No");
    }


    return 0;
}


Measured memory_bytes: 256
def cmb(n):
    if n < 2:
        return 0
    else:
        return (n*(n-1)/2)

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

num_dict = {i:0 for i in range(1,N+1)}
for i in range(N):
    num_dict[A[i]] += 1

S = 0
for i in range(1,N+1):
    S += cmb(num_dict[i])

for i in range(N):
    tmp = 0
    S_dif = cmb(num_dict[A[i]]-1) - cmb(num_dict[A[i]])
    tmp = S + S_dif
    print(int(tmp))

Measured memory_bytes: 40908
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve(){
	int a;
	cin >> a;
	string s;
	for (int i = 1; i < a; ++i) {
		a -= i;
		s.push_back(')');
	}
	s.push_back(')');
	a -= s.length();
	s.push_back('(');
	for (int q = s.length() - 1; a != 0; --q, a++) {
		swap(s[q], s[q - 1]);
	}
	int cnt = 0;
	REP(i, s.length()) {
		if (s[i] == ')')cnt++;
		else cnt--;
	}
	while (cnt != 0) {
		s.push_back('(');
		cnt--;
	}
	cout << s << endl;
}

#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3356
fun main(args: Array<String>) {
    var n = readInputLine().toInt()
    
    val aList = readInputLine().split(" ").map { it.toLong() }.toList().toLongArray()

    val sum = aList.sum()
    
    var x = aList.foldIndexed(sum, {i, a, e -> if (i % 2 == 1) a - e * 2 else a})
    
    print(x)
    print(" ")
    
    for (i in 1 until n) {
        x = aList[i - 1] * 2 - x
        print(x)
        if (i != n - 1) {
            print(" ")
        }
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 75460
#include<stdio.h>

int main(void)
{
  int x,y,z,counter=0,i;
  scanf("%d %d %d",&x,&y,&z);
  x -= 2 * z;
  while(x>0)
    {
      if(x - y >= 0)
	{
	  counter++;
	}
      x = x - y - z;
    }
  printf("%d\n",counter);
  return 0;
}


Measured memory_bytes: 128
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"

using namespace std;
typedef long long ll;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b < c - 1)
  {
    cout << a + 2 * b + 1 << "\n";
  }
  else
  {
    cout << b + c << "\n";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }


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


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
from itertools import combinations 
INF = int(1e9)*15
def main():
    n, k = map(int, readline().split()) 
    a = np.array(readline().split(), np.int32)
    c = np.array([int(i) for i in range(1, n)])
    ans = INF
    for comb in combinations(c, k-1):
        s = set(comb)
        mx = a[0]
        cost = 0
        for i in range(n):
            if i in s:
                if a[i] > mx:
                    mx = a[i]
                    continue
                else:
                    mx += 1
                    cost += mx-a[i] 
                    continue
            mx = max(mx, a[i])
        ans = min(cost, ans)
    print(ans)
if __name__ == '__main__':
    main()


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


typedef long long ll;
typedef pair<ll,int> P;

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int a;
  cin >> a;
  int ans = a + a*a + a*a*a;
  cout  << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


//組み合わせの数
//1 <= x の値を3つ使ってnを作成

//1,6,2
//1,5,3

int main(){
    //std::ifstream in("resource/input.txt");
    //std::cin.rdbuf(in.rdbuf());

    while(true)
    {
        int n, x;
        cin >> n >> x;
        if(n == 0)break;

        int cnt = 0;

        for(int i = 1; i <= n; ++i)
        {
            for(int j = i+1; j <= n; ++j)
            {
                //if(i == j)continue;

                int k = x - (i + j);
                if(k <= n && j < k)
                {
                    //cout << i << j << k << endl;
                    ++cnt;
                }
            }
        }

        cout << cnt << endl;
    }
    //cout << endl;

    return 0;    
}




Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  string A, B, C;
  cin >> A >> B >> C;
  
  if(  (A.at(A.size() - 1) == B.at(0)) && \
       (B.at(B.size() - 1) == C.at(0))  ){
    cout << "YES";
  }else{
    cout << "NO";
  }
}

Measured memory_bytes: 256
l, r, d = map(int, input().split())
w = 1
count = 0
if l % d == 0:
    start = l // d
else:
    start = (l // d) + 1
while w < r:
    w = d * start
    if w <= r:
        start += 1
        count += 1

print(count)


Measured memory_bytes: 9160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	double L;

	cin >> L;
	printf("%.10lf\n", L * L * L / 27);

	return 0;
}


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

int main()
{
    int S, W;

    cin >> S >> W;

    if (S <= W)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
N,S = map(int,input().split())
A = list(map(int,input().split()))
MOD = 998244353

dp = [[0]*(S+1) for i in range(N+1)]
dp[0][0] = 1

for i,a in enumerate(A):
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]*2
        dp[i+1][j] %= MOD
        if j+a <= S:
            dp[i+1][j+a] += dp[i][j]
            dp[i+1][j+a] %= MOD
print(dp[-1][-1])

Measured memory_bytes: 139488
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>

using namespace std;
vector<string> split(string str, char del);

int main() {
	int n, c=0;
	cin >> n;
	vector<int> v(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

	for (int i = 1; i < n - 1; i++) {
		vector<int> t(3);
		t[0] = v[i - 1];
		t[1] = v[i];
		t[2] = v[i + 1];
		sort(t.begin(), t.end());
		if (v[i] == t[1]) {
			c++;
		}
	}

	cout << c << endl;

	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int dp[101][101];
vector<P> v[101];
int n,m,c;

struct dat{
  int s,d,p;
  bool operator < (dat x)const{return s>x.s;}
};

int cal(){
  memset(dp,-1,sizeof(dp));
  priority_queue<dat> Q;
  Q.push((dat){0,0,1});
  while(!Q.empty()){
    dat a=Q.top();
    Q.pop();
    if(dp[a.p][a.d]!=-1||a.d>n)continue;
    dp[a.p][a.d]=a.s;
    for(int i=0;i<v[a.p].size();i++){
      Q.push((dat){a.s+v[a.p][i].second,a.d,v[a.p][i].first});
      Q.push((dat){a.s,a.d+1,v[a.p][i].first});
    }
  }
  for(int i=0;i<n;i++)
    if(dp[n][i]<=c&&dp[n][i]!=-1)return i;
}

int main(){
  while(cin>>n>>m>>c,n){
    for(int i=0;i<=n;i++)v[i].clear();
    for(int i=0,f,t,a;i<m;i++){
      cin>>f>>t>>a;
      v[f].push_back(P(t,a));
    }
    cout<<cal()<<endl;
  }
  return 0;
}

Measured memory_bytes: 7592
/*期末試験を実施した．期末試験は，5 人全員が受験した．期末試験の点数が 40 点以上の生徒は，期末試験の点数がそのまま成績になった．期末試験の点数が 40 点未満の生徒は全員，補習を受け，成績が 40 点になった． 
5 人の生徒の期末試験の点数が与えられたとき，5 人の成績の平均点を計算するプログラムを作成せよ．*/
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a<40){
		a=40;
	}
	if(b<40){
		b=40;
	}
	if(c<40){
		c=40;
	}
	if(d<40){
		d=40;
	}
	if(e<40){
		e=40;
	}
	cout<<(a+b+c+d+e)/5<<endl;
	return 0;
}	


Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        var hw = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        if (hw[0] == 1 || hw[1] == 1)
        {
            Console.WriteLine(1);
            return;
        }
        var val = hw[0] * hw[1];
        if (val % 2 == 0)
        {
            Console.WriteLine(val / 2);
        }
        else
        {
            Console.WriteLine((long)Math.Floor((double)(val / 2)) + 1);
        }
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,a,b,n;
	cin>>k>>a>>b;
	if((a-a%k)==a)cout<<"OK";
	else{
		n=a-a%k;
		if((n+k)>=a&&(n+k)<=b)cout<<"OK";
		else cout<<"NG";
	}
}

Measured memory_bytes: 3636
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

map <int, vector <int> > mp;

int a[100010];
int ans[100010];
int pptr[100010];
bool u[100010];
int ptr[1000010];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i < n; ++i) {
        mp[0].push_back(i);
    }
    int q;
    cin >> q;
    for (int i = q; i >= 1; --i) {
        cin >> a[i];
    }
    int cnt = 1;
    for (int i = 1; i <= q; ++i) {
        if (!u[a[i]]) {
            ans[cnt] = a[i];
            pptr[a[i]] = cnt;
            ++cnt;
            u[a[i]] = 1;
        } else {
            if (mp.find(pptr[a[i]] - 1) == mp.end() || mp[pptr[a[i]] - 1].empty()) {
                continue;
            } else {
                mp[pptr[a[i]]].push_back(mp[pptr[a[i]] - 1].back());
                mp[pptr[a[i]] - 1].pop_back();
                if (mp[pptr[a[i]] - 1].empty()) {
                    mp.erase(pptr[a[i]] - 1);
                }
            }
        }
    }
    vector <int> help;
    int mn = mp.begin()->first;
    for (int i = 1; i <= mn; ++i) {
        help.push_back(ans[i]);
    }
    sort(help.begin(), help.end());
    int qqwe = 0;
    int qsr = 1;
    ++mn;
    for (; mn < cnt; ++mn) {
        while (qqwe < help.size() && qsr == help[qqwe]) {
            ++qsr;
            ++qqwe;
        }
        if (ans[mn] != qsr) {
            cout << "No\n";
            return 0;
        }
        ++qsr;
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    vll sum(n+1,0);
    rep(i,n) sum[i+1] = sum[i] + a[i];
    int id;
    rep(i,n) {
        if (2*sum[i+1] < a[i+1]) id = i+1;
    }
    cout << n-id << endl;
}

Measured memory_bytes: 1408
n=int(input())
h=list(map(int,input().split()))
cost=[0,abs(h[1]-h[0])]
for i in range(2,n):
  cost.append(min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1])))
print(cost[n-1])


Measured memory_bytes: 20520
#include <stdio.h>

#define N 300000

int main(){

  int i,j,n,prm[N],count;

  for(i=0;i<300000;i++){
    prm[i]=1;
  }



  for(i=2;i<N;i++){
  if(prm[i]==1){
  for(j=2*i;j<N;j+=i)prm[j]=0;
}
}


  while(1){
    scanf("%d",&n);
    if(n==0)break;

    count=0;

    for(i=n+1;i<=2*n;i++){
      count+=prm[i];
    }
    printf("%d\n",count);
  }

  return 0;
}

Measured memory_bytes: 1772
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	char a;
	cin>>a;
	if(a=='a'||a=='i'||a=='u'||a=='e'||a=='o'){
		cout<<"vowel"<<endl;
	}
	else cout<<"consonant"<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define co(A) cout<<A<<endl
#define cosp(A) cout<<A<<" "
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	int n;
	cin >> n;
	VI a(n);
	ll sum = 0;
	map<int, int> cnt;
	rep(i, 0, n) {
		cin >> a[i];
		cnt[a[i]]++;
		sum += a[i];
	}
	int  q;
	cin >> q;
	while (q -- ) {
		int b, c;
		cin >> b >> c;
		sum += 1LL*(c - b)*(cnt[b]);
		cnt[c] += cnt[b];
		cnt[b] = 0;
		cout << sum << endl;
	}
	
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 8044
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    vector<ll> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(),a.end());
    cout << a[2]*10+a[0]+a[1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
   
   int x,y,z,i=0;
   
   for (i=0; i<3000; i++) {
      scanf("%d%d",&x,&y);
      if (x == 0 && y == 0) {
         break;
      }
      if (x>y) {
         z=x;
         x=y;
         y=z;
      } 
      printf("%d %d\n",x,y);
      
   }

   return 0;
} 

Measured memory_bytes: 600
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


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


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


s = input()
print(s.count('+') - s.count('-'))


Measured memory_bytes: 3572
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LS()
    if a[-1] == b[0] and b[-1] == c[0]:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    a, b, c = LI()
    for i in range(1, b):
        if a * i % b == c:
            print("YES")
            return
    print("NO")
    return

#C
def C():
    _, T = LI()
    t = LI()
    ans = 0
    now = t[0]
    for i in t[1:]:
        if now + T <= i:
            ans += T
        else:
            ans += i - now
        now = i
    print(ans + T)
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 80848
#include <stdio.h>

int main()
{
  int i, n, v, x, y, z, dx, dy;
  char *p, buf[32];
  buf[31]=0;
  buf[30]='\n';
  fgets(buf, 32, stdin);
  for (n=0,p=buf; *p!=' '; n=n*10+*(p++)-'0'); 
  int s[n], d[n];
  for (i=0; i<n; s[i]=i,d[i++]=0);
  while (fgets(buf, 32, stdin)) {
    for (x=0,p=buf+2; *p!=' '; x=x*10+*(p++)-'0');
    if (buf[0]=='0') { // relate x y z
      for (y=0,p++; *p!=' '; y=y*10+*(p++)-'0');
      for (z=0,p++; *p!='\n'; z=z*10+*(p++)-'0');
      for (dx=0; s[x]!=x; dx+=d[x],x=s[x]);
      for (dy=0; s[y]!=y; dy+=d[y],y=s[y]);
      if (x==y) continue;
      if (x<y) {
	s[y] = x;
	d[y] = dx + z - dy;
      }	else {
	s[x] = y;
	d[x] = dy - z - dx;
      }
    } else { // diff
      for (y=0,p++; *p!='\n'; y=y*10+*(p++)-'0');
      for (v=0; s[x]!=x; v-=d[x], x=s[x]);
      for (;s[y]!=y; v+=d[y], y=s[y]);
      if (x!=y) {
	putc_unlocked('?', stdout);
	putc_unlocked('\n', stdout);
      } else {
	i=30;
	if (v>0)  for (; v>0; buf[--i]='0'+v%10,v/=10);
	else if (v<0) {
	  for (; v<0; buf[--i]='0'-v%10,v/=10);
	  buf[--i] = '-';
	} else  buf[--i] = '0';
	fputs(buf+i, stdout);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2388
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void YAY(bool b = true) {cout << (b ? "Yay!" : ":(") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
V<> VEC(ll n) {V<> v(n); REP(i, n) cin >> v[i]; return v;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1;} return ret;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, k; cin >> n >> k;
    V<> a = VEC(n);
    REP(i, n) a[i]--;
    ll next[n][60];
    REP(i, n) next[i][0] = a[i];
    REP(i, 59) REP(j, n) next[j][i+1] = next[next[j][i]][i];
    ll now  = 0;   
    REP(i, 60) if((k >> i) & 1) now = next[now][i];
    cout << now + 1<< '\n';
}

Measured memory_bytes: 98480
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


string to_s(int n) {
	string s;
	do { s += n % 10 + '0'; n /= 10; } while (n);
	reverse(s.begin(), s.end());
	return s;
}


bool a[10] = {};

bool ok(int n) {
	string s(to_s(n));
	for (char c:s) {
		if (a[c - '0'])return false;
	}
	return true;
}


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

	
	int n,k;
	cin >> n>>k;
	rep(i,k) {
		int d;
		cin >> d;
		a[d] = true;
	}
	while (!ok(n)) {
		n++;
	}
	cout << n << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0) b[i] = a[i];
    else b[i] += a[i]+b[i-1];
  }
  ll ans = INF;
  for (ll i = 0; i < n-1; i++) {
    ans = min(ans, abs(b[i]-(b[n-1]-b[i])));
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3328
s = input()
# sは回文
# n = s.len
# lenの1文字目から(len - 1)/2 までからなる文字列は回文
# sの(len + 3 )/2 から　lenまでからなる文字列は回文

moji1 = s[: int((len(s) - 1) / 2)]
moji2 = s[int((len(s) + 2) / 2): int(len(s))]

moji3 = s[: int((len(s) - 1) / 2)]
moji4 = s[int((len(s) + 2) / 2): int(len(s))]
while int(len(moji1)) > 1:
    a = moji1[0:1]
    b = moji1[-1]
    if a != b:
        print('No')
        exit()
    moji1 = moji1[1:-1]
if (moji3 != moji4):
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3064
#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;
  bool yel = false; // Yellowが存在するかどうか
  rep(i, N){
    string S;
    cin >> S;
    if(S=="Y"){
      yel = true;
    }
  }
  if(yel){
    cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int N = scan.nextInt();
			int []A = new int[N];
			int []B = new int[N];
			long nowtime = 0;
			
			Map<Integer,ArrayList<Integer>>map = new TreeMap<Integer,ArrayList<Integer>>();
			
			
			
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = scan.nextInt();
				
				if(!map.containsKey(B[i])) {
					map.put(B[i], new ArrayList<Integer>());
					map.get(B[i]).add(A[i]);
				}else {
					map.get(B[i]).add(A[i]);
				}
			}
			
			for(Integer key:map.keySet()) {
				Collections.sort(map.get(key));
				for(int i = 0;i<map.get(key).size();i++) {
					nowtime+=map.get(key).get(i);
					//System.out.print(nowtime);
					//System.out.print(" ");
					//System.out.println(key);
					if(nowtime>key) {
						System.out.println("No");
						System.exit(0);
					}
					//System.out.print(map.get(key).get(i));
					//System.out.print(" ");
				}
				//System.out.println();
			}
			
			
			
			System.out.println("Yes");
			
			
			
			
			
			
			
			
			
		}
	}
	
	 
	
}


Measured memory_bytes: 149328
n=int(input())
s=input()
lst=[0]*n
lst[0]=s[1:].count("E")
for i in range(1,n):
    lst[i] = lst[i-1]
    if s[i-1]=="W":
        lst[i]+=1
    if s[i]=="E":
        lst[i]-=1
print(min(lst))

Measured memory_bytes: 15436
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double area = r * r * pi;
        double length = 2 * r * pi;
        System.out.printf("%f %f", area, length);
        sc.close();
    }
}


Measured memory_bytes: 28180
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[n];
		for (int i = 0; i < num.length; i++) {
			num[i] = sc.nextInt();
		}
		int max = 0;
		for (int i = 0; i < num.length; i++) {
			max+=(num[i]-1);
		}
		System.out.println(max);

	}

}


Measured memory_bytes: 25776
m,i,j,k,t[16],c[16],p,d;
main(n){
	for(*t=1;++i<16;)t[i]=n*=3;
	for(;scanf("%d%d",&n,&m),n;printf("%d\n",j>m?-1:j)){
		for(k=3;k--;)
			for(scanf("%d",&i);i--;c[j]=k)scanf("%d",&j);
		for(p=j=k=0;k++<n;)
			j+=t[n-k]*abs(i=p-c[k]),p=i%2*2+p&3;
		j=fmin(j,t[n]+~j);
	}
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		int H = stdIn.nextInt();
		int W = stdIn.nextInt();
		int K = stdIn.nextInt();
		char[][] c = new char[H][W];
		ArrayList<String> s = new ArrayList<String>();
		
		for(int i = 0; i < H; i ++) {
			s.add(stdIn.next());
		}
		
		for(int i = 0; i < H; i ++) {
			for(int j = 0; j < W; j ++) {
				c[i][j] = s.get(i).toCharArray()[j];
			}
		}
		
		int h = (int) Math.pow(2, H) - 1;
		int w = (int) Math.pow(2, W) - 1;
		
		int ans = 0;
		
		for(int i = h; 0 <= i; i --) {
			String hBin = String.format("%" + H + "s", Integer.toBinaryString(i)).replace(" ", "0");
			for(int j = w; 0 <= j; j --) {
				String wBin = String.format("%" + W + "s", Integer.toBinaryString(j)).replace(" ", "0");
				int blackCnt = 0;
				for(int hcnt = 0; hcnt < H; hcnt ++) {
					for(int wcnt = 0; wcnt < W; wcnt ++) {
						if(hBin.substring(hcnt, hcnt + 1).equals("0") && wBin.substring(wcnt, wcnt + 1).equals("0")) {
							if(c[hcnt][wcnt] == '#') {
								blackCnt ++;
							}
						}
					}
				}
				if(blackCnt == K) {
					ans ++;
				}
			}
		}
		
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 60180
#include<bits/stdc++.h>
using namespace std;
int b[1111111];
bool c[1111111];
int main()
{
	int n,cnt=0,a;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		b[a]++;
		c[a]=1;
	}
	if(b[1]>1)
	{
		cout<<0;
		return 0;
	}
	if(b[1]==1)
	{
		cout<<1;
		return 0;
	}
	
	for(int i=2;i<=1000;i++)
	{
		if(b[i]>=1)
		{
			for(int j=2;j<=1000000/i;j++)
				c[i*j]=0;
		//	cout<<"s2"<<i<<" ";
		}
		else
		{
			for(int j=1001;j<=1000000/i;j++)
			{
				if(b[j]>=1&&b[i*j]>=1)
					c[i*j]=0;//,cout<<i*j<<" ";
			}
			
		}
		if(b[i]>1)
			c[i]=0;
		
	}
	for(int i=2;i<=1000000;i++)
	{
		if(b[i]>=2)
			c[i]=0;
	}

	for(int i=1;i<=1000000;i++)
	{
		if(c[i])
			cnt++;
	}
	cout<<cnt;
	return 0;
 } 

Measured memory_bytes: 8452
#include <iostream>

using namespace std;

int main(){
	int N = 0, sum = 0;
	cin>>N;
	int d[N] = {0};
	for( int i=0; i<N; i++ ){
		cin>>d[i];
	}
	
	for( int i=0; i<N-1; i++ ){
		for( int j=i+1; j<N; j++ ){
			sum = sum + d[i]*d[j];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
ary = Array.new(26, 0)
n.times do
  name = gets
  ary[name.ord-'A'.ord] += 1
end
str = 'MARCH'
cnt = Array.new
str.each_char do |c|
  cnt.push(ary[c.ord-'A'.ord])
end
sum = 0
cnt.combination(3) do |a|
  sum += a[0]*a[1]*a[2]
end
puts sum.to_s

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

int main(){
  string a,b;

  cin >> a >> b;

  string ab = a + b;

  int s = stoi(ab);

  for(int i = 1;i <= s;i++){
    if(i * i == s){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
int w,h;
vector<int> Xs;
vector<int> Ys;
int n;
int X1[1000];
int Y1[1000];
int X2[1000];
int Y2[1000];
int table[2002][2002];
void dfs(int i, int j){
	table[i][j]=1;
	int dX=1,dY=0;
	for(int k=0;k<4;k++,swap(dX,dY),dX=-dX){
		int X=i+dX;
		int Y=j+dY;
		if(0<=X&&X<Xs.size()&&0<=Y&&Y<Ys.size()&&table[X][Y]==0){
			dfs(X,Y);
		}
	}
}
int main() {
while(1){
	cin >> w >> h;
	if(w==0&&h==0){
		return 0;
	}
	memset(table,0,sizeof(table));
	Xs.clear();
	Xs.push_back(0);
	Ys.push_back(0);
	Xs.push_back(w-1);
	Ys.push_back(h-1);
	Ys.clear();
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
		Xs.push_back(X1[i]);
		Xs.push_back(X2[i]);
		Ys.push_back(Y1[i]);
		Ys.push_back(Y2[i]);
	}
	sort(Xs.begin(),Xs.end());
	Xs.resize(unique(Xs.begin(),Xs.end())-Xs.begin());
	sort(Ys.begin(),Ys.end());
	Ys.resize(unique(Ys.begin(),Ys.end())-Ys.begin());
	for(int i=0;i<n;i++){
		int s=lower_bound(Xs.begin(),Xs.end(),X1[i])-Xs.begin();
		int t=lower_bound(Ys.begin(),Ys.end(),Y1[i])-Ys.begin();
		int u=lower_bound(Xs.begin(),Xs.end(),X2[i])-Xs.begin();
		int v=lower_bound(Ys.begin(),Ys.end(),Y2[i])-Ys.begin();
		table[s][t]++;
		table[s][v]--;
		table[u][t]--;
		table[u][v]++;
	}
	if(Xs.back()>=w)Xs.pop_back();
	if(Ys.back()>=h)Ys.pop_back();
	for(int i=0;i<Xs.size();i++){
		for(int j=1;j<Ys.size();j++){
			table[i][j]+=table[i][j-1];
		}
	}
	for(int i=1;i<Xs.size();i++){
		for(int j=0;j<Ys.size();j++){
			table[i][j]+=table[i-1][j];
		}
	}
	/*
	for(int j=Ys.size()-1;j>=0;j--){
		for(int i=0;i<Xs.size();i++){
			cout << table[i][j];
		}
		cout << endl;
	}*/
	int ret=0;
	for(int i=0;i<Xs.size();i++){
		for(int j=0;j<Ys.size();j++){
			if(table[i][j]==0){
				//cout << i << ", " << j << endl;
				dfs(i,j);
				ret++;
			}
		}
	}
	cout << ret << endl;

}
}

Measured memory_bytes: 20184
#include <stdio.h>
#include <string.h>
 
int main(void)
{
  int k;
  char s[110];
  scanf("%d",&k);
  scanf("%s",s);
  if (strlen(s) <= k) printf("%s\n",s);
  else {
    for (int i = 0; i < k; ++i) printf("%c",s[i]);
    printf("...\n");
  }
  return 0;
}


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

using namespace std;

int main() {

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

    sort(N.begin(), N.end(), greater<int>());

    cout << N[0] * 10 + N[1] + N[2] << endl;

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, K; cin >> N >> K;
	vector<ll> A(N);
	vector<pii> C(N);
	for (int i = 0; i < N;i++) C[i].second = i;
	for (auto& in : A) {
		cin >> in;
		in--;
		C[in].first++;
	}
	sort(C.begin(), C.end());
	reverse(C.begin(), C.end());
	for (int i = N - 1; i >= 0; i--) {
		if (C[i].first == 0) {
			C.erase(C.begin() + i);
		}
	}
	reverse(C.begin(), C.end());
	ll ans = 0;
	for (int i = 0; i < (int)C.size();i++) {
		if (C.size() - i <= K)break;
		ans += C[i].first;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define mod 998244353
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

/**********************************************************************************************************************/
ll n,a,b,c,d;
map<ll,ll>mp;
ll solve(ll n)
{
    if(n==1)return d;
    if(n==0)return 0;
    if(mp[n])return mp[n];
    ll ans=(ll)1e18;
    if(ans/d>n)ans=n*d;
    ll l2,r2,l3,r3,l5,r5;
    
    l2=(n/2)*2;
    r2=((n+1)/2)*2;
    l3=(n/3)*3;
    r3=((n+2)/3)*3;
    l5=(n/5)*5;
    r5=((n+4)/5)*5;
    ans=min(ans,abs(l2-n)*d+a+solve(l2/2));
    ans=min(ans,abs(r2-n)*d+a+solve(r2/2));
    
    ans=min(ans,abs(l3-n)*d+b+solve(l3/3));
    ans=min(ans,abs(r3-n)*d+b+solve(r3/3));
    
    ans=min(ans,abs(l5-n)*d+c+solve(l5/5));
    ans=min(ans,abs(r5-n)*d+c+solve(r5/5));
    mp[n]=ans;
    return ans;
}
signed main()/*Check flow ---question galat mat padhna */
{
    fast;
    ll t;
    cin>>t;
    while(t--)
    {
        mp.clear();
        cin>>n>>a>>b>>c>>d;
        ll ans=solve(n);
        cout<<ans<<endl;
    }
}   

Measured memory_bytes: 4408
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>


const int M=1e9+7;
ll n,res,c;



bool prime(int i)
{
	if(i<2)return 0;
	for(int j=2;j*j<=i;j++)if(i%j==0)return 0;
	return 1;
}




void solve()
{
	cin>>n;
	res=1;
	for(int i=2;i<=n;i++)
	{
		if(prime(i))
		{
			c=1;
			for(int j=i;j<=n;j*=i)c+=(n/j);
			res=(res*c)%M;
		}
	}
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100000

int main(void)
{
  int N;
  int A[MAX], B[MAX];
  int i;

  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&A[i]);

  for(i=0;i<N;i++)B[A[i]-1] = i+1;

  for(i=0;i<N;i++)printf("%d ",B[i]);


  return 0;
}








Measured memory_bytes: 1536
N,K = map(int, input().split())
List = []
for i in range(N):
    List.append(int(input()))
    
List.sort()
ans_list = []
for i in range(N-K+1):
    ans_list.append(List[i+K-1]-List[i])

ans_list.sort()
print(ans_list[0])

Measured memory_bytes: 11288
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=1e5+1e3+7;

int n,a[N],ans,cnt;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]!=a[i-1])
			ans+=cnt/2,cnt=1;
		else
			cnt++; 
	}
	ans+=cnt/2;
	printf("%d",ans);
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
template <typename T> using lim = numeric_limits<T>;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    auto f = [&](ll x) {
        return x - x / c - x / d + x / (c / __gcd(c, d) * d);
    };
    cout << f(b) - f(a - 1) << endl;
    return 0;
}


Measured memory_bytes: 256