akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x; cin >>x;
    if(x >= 30) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3636
def main():
    s=list(input())
    k=int(input())
    n=len(s)

    ans=cnt=key=0
    for i in range(n-1):
        if key==0 and s[i]==s[i+1]:
            cnt+=1
            key=1
        elif key==1 and s[i]==s[i+1]:
            key=0
        else:
            key=0
    ans=cnt*k
    a=b=1
    for i in range(n-1):
        if s[i]==s[i+1]:
            a+=1
        else:
            break
    for i in range(n-1):
        if s[n-1-i]==s[n-2-i]:
            b+=1
        else:
            break
    if a!=n and s[0]==s[n-1]:
        ans+=(((a+b)//2)-(a//2)-(b//2))*(k-1)
    if a==n:
        if n%2==0:
            print(cnt*k)
            return
        else:
            print((n*k)//2)
            return
    print(ans)
main()

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
set <int> a;
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if(a.find(x)==a.end())
		a.insert(x);
		else
		a.erase(x);
	}
	cout<<a.size()<<"\n";
	return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int n; scanf("%d", &n);
	long long ans = 1;
	for (int i = 0; i < n; ++i) {
		long long t; scanf("%lld", &t);
		ans = max(t, ans)/__gcd(t, ans)*min(t, ans);
		//ans = __lcm(t, ans);
	}
	printf("%lld", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back


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

vector<pair<ll,ll>> pfact(ll n)
{
    vector<pair<ll,ll>> pf;
    ll t = n, cnt;
    
    for(ll i=2; i*i<=t; ++i) {
        cnt = 0;
        if(t % i != 0) continue;
        while(t % i == 0) {
            t /= i;
            ++cnt;
        }
        pf.pb(make_pair(i, cnt));
    }
    
    if(t != 1) pf.pb(make_pair(t, 1));
    
    return pf;
}


int main()
{
    ll A, B;
    cin >> A >> B;

    ll G = gcd(A, B);
    auto P = pfact(G);
    PR(SZ(P)+1);

    return 0;
}

/*



*/

Measured memory_bytes: 3604
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Info{
	bool operator<(const struct Info &arg) const{
		return t < arg.t;
	};
	Info(){
		t = from = to = 0;
	}
	int t,from,to;
};

void func(int N, int M){
	bool table[N+1];
	table[1] = false;
	for(int i = 2; i <= N; i++)table[i] = true;

	Info info[M];

	for(int i = 0; i < M; i++){
		scanf("%d %d %d",&info[i].t,&info[i].from,&info[i].to);
	}

	sort(info,info+M);

	int count = 1;

	for(int i = 0; i < M; i++){
		if(table[info[i].from] == false && table[info[i].to] == true){
			table[info[i].to] = false;
			count++;
		}
	}

	printf("%d\n",count);

}

int main(){

	int N,M;

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func(N,M);

	}

	return 0;
}

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

int main(){
  int a,x;
  cin >> a;
  int A[a];
  for(int i = 0;i < a;i++)cin >> A[i];
  for(int i = 0;i < a;i++){
    for(int k = i + 1;k < a;k++){
      x += A[i] * A[k];
    }
  }
  cout << x << endl;
}

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

int main()
{
    ll N,M;
    cin >> N >> M;
    
    ll ans;

    if(N == 2 || M == 2)ans = 0;
    else if(N == 1 && M == 1)ans = 1;
    else if(N == 1 && M > 2)ans = M - 2;
    else if(M == 1 && N > 2)ans = N - 2;
    else ans = (M - 2) * (N - 2);

    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

N,M,Q = map(int, input().split())
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i]=map(int, input().split())
    a[i]-=1
    b[i]-=1

#Aの定義
A=list(itertools.combinations_with_replacement(range(1,M+1), N))

#Aを総当たりで、得点計算
best_score=0
for k in range(len(A)):
    score=0
    for i in range(Q):
        if A[k][b[i]]-A[k][a[i]]==c[i]:
            score+=d[i]
    best_score=max(best_score,score)

print(best_score)

Measured memory_bytes: 21444
/*
ID: varunra2
LANG: C++
TASK: gangs
*/
 
#include<bits/stdc++.h>
using namespace std;
 
#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif
 
#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second
 
const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions
 
 
int main() {
#ifndef ONLINE_JUDGE
  freopen("gangs.in", "r", stdin);
  freopen("gangs.out", "w", stdout);
#endif
  cin.sync_with_stdio(0); cin.tie(0);
 int n;
  cin >> n;
  VI vals(n);
  
  for(int i = 0; i < n; i++) {
  	cin >> vals[i];
  }
  
  ll ret = 1000;
  
  for(int i = 1; i < n; i++) {
  	if(vals[i] > vals[i - 1]) {
    	//we first calculate the number of stonks we can buy
      	ll cnt = ret/vals[i - 1];
      	ret -= cnt*vals[i - 1];
      	ret += cnt*vals[i];
    }
  }
  
  cout << ret << endl;
  
 
  return 0;
}

Measured memory_bytes: 3596
from itertools import accumulate
import bisect


class Bit():
    def __init__(self, N):
        self.size = N
        self.bit = [0] * (self.size+1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += i & -i

    def __str__(self):
        return str(self.bit)


N, K = map(int, input().split())
A = [-10**9] + [int(input()) for i in range(N)]

diff = [a - K for a in A]
diff = list(accumulate(diff))
graph = Bit(N+1)
temp = sorted(diff)
order = [bisect.bisect_right(temp, d) for d in diff]
ans = 0

for x in order:
    ans += graph.sum(x)
    graph.add(x, 1)

print(ans)

Measured memory_bytes: 31516
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
#include<map>
#include<queue>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)

int main(){
  while(1){
    int d;
    cin>>d;
    if(d==0)break;
    int n,m;
    cin>>n>>m;
    vector<int> mise;
    mise.push_back(0);
    mise.push_back(d);
    rep(i,n-1){
      int a;
      cin>>a;
      mise.push_back(a);
    }
    sort(mise.begin(),mise.end());
    int ans=0;
    rep(i,m){
      int a;
      cin>>a;

      vector<int>::iterator c;
      c=upper_bound(mise.begin(),mise.end(),a);
      ans+=min(*c-a,a-*(c-1));
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 1432
#pragma GCC optimize("Ofast", "unroll-loops")

// #define TEST

#include <bits/stdc++.h>

using namespace std;

int main() {
	int N, K, C;
	cin >> N >> K >> C;
	string S; cin >> S;
	vector<int> L(K);
	int ptr_L = 0, ptr_S = 0;
	while (ptr_L < K) {
		while (S[ptr_S] != 'o')
			++ptr_S;
		L[ptr_L++] = ptr_S;
		ptr_S += C + 1;
	}
#ifdef TEST
	for (auto i : L)
		cout << i << " ";
	cout << endl;
#endif
	vector<int> R(K);
	int ptr_R = K - 1;
	ptr_S = N - 1;
	while (ptr_R >= 0) {
		while (S[ptr_S] != 'o')
			--ptr_S;
		R[ptr_R--] = ptr_S;
		ptr_S -= C + 1;
	}
#ifdef TEST
	for (auto i : R)
		cout << i << " ";
	cout << endl;
#endif
	for (int i = 0; i < K; ++i)
		if (L[i] == R[i])
			cout << (L[i] + 1) << endl;
	return 0;
}

Measured memory_bytes: 3332
#include<bits/stdc++.h>
using namespace std;
#define LL long long int;
int main()
{
    long int n;
    cin>>n;
    long int arr[n][3];
    long int dp[n][3];
    for(long int i=0;i<n;i++)
    {
        for(long int j=0;j<3;j++)
        cin>>arr[i][j];
    }
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    for(long int i=1;i<n;i++)
    {
        for(long int j=0;j<3;j++)
        {
            if(j==0)
            {
                dp[i][j] = arr[i][j]+max(dp[i-1][1],dp[i-1][2]);
            }
            else if(j==1)
            {
                dp[i][j] = arr[i][j]+max(dp[i-1][0],dp[i-1][2]);
            }
            else
            {
                dp[i][j] = arr[i][j]+max(dp[i-1][1],dp[i-1][0]);
            }
        }
    }
    long int ans = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    cout<<ans<<endl;
    return 0;
    
}

Measured memory_bytes: 4864
#include<stdio.h>
int main(){
 	int a,b,c,t;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b)t=a,a=b,b=t;
	if(b>c)t=b,b=c,c=t;
	if(a>b)t=a,a=b,b=t;
	printf("%d %d %d\n",a,b,c);
}




Measured memory_bytes: 2028
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <random>
#include <chrono>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

using namespace std;

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

  string c;
  cin >> c;

  uint64_t counter = 0;
  auto l_itr = c.begin(), r_itr = --c.end();
  while (l_itr < r_itr) {
    if ((*l_itr == 'W') && (*r_itr == 'R')) {
      *l_itr = 'R';
      *r_itr = 'W';
      ++counter;
    }
    
    if (*l_itr == 'R') { ++l_itr; }
    if (*r_itr == 'W') { --r_itr; }
  }
  cout << counter << endl;

  return 0;
}


Measured memory_bytes: 3752
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N, K = map(int, input().split())
X = list(map(int, input().split()))

has_zero = 0 in X
negs = [val for val in X if val<0]
poss = [val for val in X if val>0]
lenn = len(negs)
lenp = len(poss)
negs.append(0)
poss = [0] + poss

# print(negs)
# print(poss)

minval = 10**9
if has_zero: K-=1
for left in range(0, K+1):
    right = K-left
    if lenn<left or lenp<right: continue
    # print(left, right)
    negv = abs(negs[lenn-left])
    posv = abs(poss[right])
    val = max(negv, posv) + 2*min(negv, posv)
    if val < minval: minval = val
print(minval)


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

int main(){
  vector<int> N(4);
  for(int i=0;i<4;i++)  cin >> N.at(i);

  sort(N.begin(),N.end());
  if(N.at(0)==1 && N.at(1)==4 && N.at(2)==7 && N.at(3)==9)  cout << "YES" << endl;
  else  cout << "NO" << endl;

  return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    for (int i=1; i<n-1; ++i) {
        if ((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i+1]<p[i]&&p[i]<p[i-1])) 
            ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    vector<string> de = {"maerd", "remaerd", "esare", "resare"};

    int now = 0;
    while(true)
    {
        if(now == s.size())
        {
            cout << "YES" << endl;
            return 0;
        }
        bool flag = false;
        for(int i = 0; i < 4; i++)
        {
            if(s.size() - now >= de[i].size() && s.compare(now, de[i].size(), de[i]) == 0)
            {
                flag = true;
                now += de[i].size();
            }
        }
        if(!flag)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
}             





Measured memory_bytes: 512
#include <unistd.h>
#include <cstdio>
#include <algorithm>
#include <x86intrin.h>

typedef long long ll;
int mat[3000][3000]; 
ll dp0[3000] __attribute((aligned(32)));

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

#pragma clang attribute push(__attribute__((target("avx2"))), apply_to=function)
int main(int argc, char **argv)
{
    int rr = rd();
    int cc = rd();
    int k  = rd();

    for (int i = 1; i <= k; i++) {
        int r = rd();
        int c = rd();
        int v = rd();
        mat[r - 1][c - 1] = v;
    }
    for (int y = 0; y < rr; y++) {
        ll work0 = 0, work1 = 0, work2 = 0, work3 = 0;
        for (int x = 0; x < cc; x++) {
            if (dp0[x] > work0) work0 = dp0[x];
            int v = mat[y][x];

            if (work3 < work2 + v) work3 = work2 + v;
            if (work2 < work1 + v) work2 = work1 + v;
            if (work1 < work0 + v) work1 = work0 + v;
            dp0[x] = std::max(std::max(work0, work1), std::max(work2, work3));
        }
    }
    std::printf("%lld\n", dp0[cc - 1]);
    return 0;
}
#pragma clang attribute pop

Measured memory_bytes: 39160
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int N, A;
    cin >> N >> A;
    int x[50];
    for (int i = 0; i < N; i++) {
        cin >> x[i];
        x[i] -= A;
    }
    ll dp[51][5001] = {}; // dp[i][j]: x[0] ~ x[i-1] の中から選んで合計 j - 2500 にする選び方の総数
    // dp[0][2500] = 1
    // dp[i][j] = dp[i-1][j] + dp[i-1][j-x[i-1]]
    dp[0][2500] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= 5000; j++) {
            if (j - x[i - 1] >= 0 && j - x[i - 1] <= 5000) {
                dp[i][j] = dp[i - 1][j] + dp[i - 1][j - x[i - 1]];
            }
            else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    cout << dp[N][2500] - 1 << endl;

    return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>

int main()
{
    int a,b,x;
    scanf("%d %d",&a,&b);
    x=(a+b)/2;
    if((a+b)%2==0)
    {
        printf("%d\n",x);
    }
    else
    {
        x+=1;
        printf("%d\n",x);
    }
    return 0;
}


Measured memory_bytes: 128
// 問題の URL を書いておく
// https://atcoder.jp/contests/abc160/tasks/abc160_e

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(int, const char**)
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int64_t> p(a, 0);
    rep(i, a) cin >> p[i]; 
    vector<int64_t> q(b, 0);
    rep(i, b) cin >> q[i]; 
    vector<int64_t> r(c, 0);
    rep(i, c) cin >> r[i]; 

    sort(p.begin(), p.end(), greater<int64_t>());
    sort(q.begin(), q.end(), greater<int64_t>());
    sort(r.begin(), r.end(), greater<int64_t>());

    p.resize(x);
    q.resize(y);
    r.resize(min(x + y, c));

    priority_queue<int64_t> pq;
    for(auto t : p) pq.push(t);
    for(auto t : q) pq.push(t);
    for(auto t : r) pq.push(t);

    int64_t ans = 0;
    rep(i, x + y)
    {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9780
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	ans := 0

	switch {
	case n < 10:
		ans = n
	case n < 100:
		ans = 9
	case n < 1000:
		ans = 9 + (n-99)
	case n < 10000:
		ans = 9 + 900
	case n < 100000:
		ans = 9 + 900 + (n-9999)
	case n < 1000000:
		ans = 9 + 900 + 90000
	}

	fmt.Println(ans)
}

Measured memory_bytes: 640
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let m: usize = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();
    let bc: Vec<(i32, i32)> = (0..m).map(|_| (input(), input())).collect();

    let mut heap = std::collections::BinaryHeap::new();
    for a in a {
        heap.push((a, 1));
    }
    for (b, c) in bc {
        heap.push((c, b));
    }

    let mut ans = 0i64;
    let mut rest = n as i32;
    while let Some((x, k)) = heap.pop() {
        if k <= rest {
            ans += x as i64 * k as i64;
            rest -= k;
        } else {
            ans += x as i64 * rest as i64;
            rest = 0;
        }
        if rest == 0 {
            break;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;

void solve()
{
	ll a,b;
	cin>>a>>b;
	ll ans=max(a+b,a-b);
	ans=max(ans,a*b);
	cout<<ans;
	
}
 
int main() {
    
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
 
    
    return 0;
}

Measured memory_bytes: 256
//abc162_a.cpp
//Sun Apr 12 20:57:48 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

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

	if (s[0]=='7' ||s[1]=='7' ||s[2]=='7'){
		cout << "Yes"<< endl;
	}else {
		cout << "No"<< endl;
	}
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3628
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, p[26][200009], dp[200009], cnt[26]; string s;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> s; s = '#' + s;
	int n = s.size();
	for (int i = 0; i < 26; i++) {
		p[i][n] = n + 1;
		for (int j = n - 1; j >= 0; j--) {
			p[i][j] = (s[j + 1] == i + 97 ? j + 1 : p[i][j + 1]);
		}
	}
	for (int i = n; i >= 0; i--) {
		dp[i] = n + 1;
		for (int j = 0; j < 26; j++) {
			dp[i] = min(dp[i], dp[p[j][i]] + 1);
		}
	}
	string ret;
	int ptr = 0;
	for (int i = dp[0] - 1; i >= 1; i--) {
		for (int j = 0; j < 26; j++) {
			if (dp[p[j][ptr]] == i) {
				ptr = p[j][ptr];
				ret += j + 97;
				break;
			}
		}
	}
	for (int i = 0; i < 26; i++) {
		if (p[i][ptr] == n + 1) {
			ret += i + 97;
			break;
		}
	}
	cout << ret << "\n";
	return 0;
}

Measured memory_bytes: 21840
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.nextLine();
    
    StringBuilder sb = new StringBuilder();
    
    int len = str.length();
    char c ;

    for(int i=0 ; i < len ; i++){
        
        c = str.charAt(i);
        
        switch(c){
            
            case '0':
            case '1':
                sb.append(c);
                break;
                
            case 'B':
                if(sb.length() == 0){
                    break;
                }else{
                    sb.setLength(sb.length()-1);
                }
                break;
        }
    }

    System.out.println(sb);
  }
}

Measured memory_bytes: 26924
#include <iostream>

int main()
{
	int n; std::cin >> n;
	int* A = new int[n];
	
	for (int i=0; i<n; i++) std::cin >> A[i];
	
	int q; std::cin >> q;
	for (int i=0; i<q; i++) {
		int b, e, k;
		std::cin >> b >> e >> k;
		int count = 0;
		for (int j=b; j<e; j++) {
			count += A[j]==k ? 1 : 0;
		}
		std::cout << count << std::endl;
	}
	
	delete[] A;
	
	return 0;
}
		



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int N;
	cin>>N;
	map<string,int>cnt;
	rep(i,N){
		string s;cin>>s;
		sort(all(s));cnt[s]++;
	}

	int ans=0;
	for(auto &p:cnt)ans+=p.se*(p.se-1)/2;
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<string, int> M;
    for (int i = 0; i < n; i++){
        string s;
        cin >> s;
        if (M.count(s)){
            M.at(s)++;
        }
        else{
            M[s] = 1;
        }
    }
    int m = 0;
    for (auto p : M){
        auto v = p.second;
        if(v > m){
            m = v;
        }
    }
    
    vector<string> ans;
    for (auto p : M){
        auto k = p.first;
        auto v = p.second;
        if (v == m){
            ans.push_back(k);
        }
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++){
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
using namespace std;
 
 
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

 
#define rep(var,n)  for(int var=0;var<(n);++var)
 
template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); } 
 
vi mts { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
 
 
void solve(int N, int M, vi& a) {
    vi u(8, -1);
    rep(i,M){
        int m = mts[ a[i] ];
        amax(u[m], a[i]);
    }
 
    vvi dp(N+10, vi(10, -1));
    dp[0] = vi(10, 0);
 
    rep(i,N){
        if (dp[i][0] == -1) continue;
        for (int m=2; m<=7; ++m) {
            if (u[m] == -1) continue;
            int p = 1 + (9 - u[m]);
            dp[i][0]++;
            dp[i][p]++;
            dp[i+m] = max(dp[i+m], dp[i]);
            dp[i][0]--;
            dp[i][p]--;
        }
    }
    for (int n=9; n>=1; --n) {
        rep(j, dp[N][1+9-n]) putchar('0'+n);
    }
    putchar('\n');
}
 
int main() {
    int N, M; cin >> N >> M;
    vi a(M);
    rep(i,M) cin >> a[i];
    solve(N,M,a);
    return 0;
}

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

using namespace std;
#define ll long long
#define int long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

#define MOD 1000000007

signed main()
{
	int n;
	cin >> n;
	int res = 0;
	rep(i, n+1) res += i;
	cout << res << endl;
}

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

#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)

#define si(a)               scanf("%d", &a)
#define sii(a,b)            scanf("%d %d", &a, &b)
#define siii(a,b,c)         scanf("%d %d %d", &a, &b, &c)

#define CLR(a)              memset(a, 0, sizeof(a))
#define SET(a)              memset(a, -1, sizeof(a))

#define PI                  acos(-1.0)

#define pb                  push_back
#define mp                  make_pair
#define SORT(v)             sort(v.begin(), v.end())
#define REV(v)              reverse(v.begin(), v.end())
#define FOR(i, n)           for(int i=0; i<n; i++)
#define FOR1(i, n)          for(int i=1; i<=n; i++)
#define ROF(i, n)           for(int i=n-1; i>=0; i--)
#define ROF1(i, n)          for(int i=n; i>=1; i--)
#define LOOP(i, x, y)       for(int i=x; i<=y; i++)
#define fastIO()            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long              LL;
typedef unsigned long long     ULL;
typedef vector<int>            VI;
typedef pair<int, int>         PII;
typedef pair<string, int>      PSI;
typedef pair<char, int>        PCI;

const int MAX = 100005;
const LL LMAX = 12158598925;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int kx[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky[] = {2, -2, 1, -1, 2, -2, 1, -1};

int n, w;
int weight[MAX], price[MAX];
LL dp[105][MAX];


LL solve(int pos, int W)
{
    if(pos == 0 or W == 0) return 0;
    if(dp[pos][W] != -1) return dp[pos][W];
    if(weight[pos] > W) return solve(pos-1, W);

    LL p = solve(pos-1, W-weight[pos]) + price[pos];
    LL q = solve(pos-1, W);

    return dp[pos][W] = max(p, q);
}

int main()
{
//    READ;
//    WRITE;
    memset(dp, -1, sizeof dp);
    sii(n, w);

    FOR1(i, n) sii(weight[i], price[i]);

    LL res = solve(n, w);

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 82304
using System;

public class Test
{
	static public void Main( )
	{	
		string[] strs = Console.ReadLine().Split( ' ' );
		var a = int.Parse( strs[0] );
		var b = int.Parse( strs[1] );
		
		var d = a/b;
		var r = a%b;
		var f = (double)a/b;
		Console.WriteLine( "{0} {1} {2}" , d, r, f.ToString( "0.00000" ) );
	}
}

Measured memory_bytes: 5764
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	ll n,k,s;
	cin>>n>>k>>s;
	vl ans;
	rep(i,k)ans.push_back(s);
	int a=0;
	rep(i,sqrt(s)+2){
		if(i==0)continue;
		if(s%i!=0){
		a=i;
		break;
		}
	}
	//if(a==0)a=1;
	rep(i,n-k)ans.push_back(a);
	rep(i,n-1)cout<<ans[i]<<' ';
	cout<<ans[n-1]<<endl;
}

Measured memory_bytes: 2292
s=str(input())
if(int(s[:2])>12 and int(s[2:])<=12 and int(s[2:])>0):
	print("YYMM")
elif(int(s[2:])>12 and int(s[:2])<=12  and int(s[:2])>0):
	print("MMYY")
elif(int(s[2:])<=12 and int(s[:2])<=12 and int(s[2:])>0 and int(s[:2])==0):
	print("YYMM")
elif(int(s[2:])<=12 and int(s[:2])<=12 and int(s[2:])==0 and int(s[:2])>0):
	print("MMYY")
elif(int(s[2:])<=12 and int(s[:2])<=12 and int(s[2:])>0 and int(s[:2])>0):
	print("AMBIGUOUS")
else:
	print('NA') 

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

#define int long long
const int MOD = 1000000007LL;

signed main(){

    int h, w; cin >> h >> w;
    vector<vector<int> > dp(h, vector<int> (w, MOD));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char input; cin >> input;
            if(input == '.') dp[i][j] = 0;
        }
    }

    dp[0][0] = 1;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(dp[i][j] == MOD) continue;

            if(i != h - 1 && dp[i + 1][j] != MOD){
                dp[i + 1][j] += dp[i][j]; 
                dp[i + 1][j] %= MOD;
            }

            if(j != w - 1 && dp[i][j + 1] != MOD){
                dp[i][j + 1] += dp[i][j];
                dp[i][j + 1] %= MOD;
            }
        }
    }

    cout << dp[h - 1][w - 1] << endl;
    
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for (i = 0; i < n; i++)
#define P pair<int, int>

int main()
{
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  vector<int> Nums;
  int now = 1;
  int cnt = 0;
  for (int i = 0; i < n; i++)
  {
    if ((s[i] - '0') == now)
    {
      cnt++;
    }
    else
    {
      Nums.push_back(cnt);
      now ^= 1;
      cnt = 1;
    }
  }
  Nums.push_back(cnt);
  if (Nums.size() % 2 == 0)
  {
    Nums.push_back(0);
  }

  vector<int> sum(Nums.size() + 1);
  for (int i = 0; i < Nums.size(); i++)
  {
    sum[i + 1] = sum[i] + Nums[i];
  }

  int Add = 2 * k + 1;

  int ans = 0;
  for (int i = 0; i < Nums.size(); i += 2)
  {
    int left = i;
    int right = min(i + Add, (int)Nums.size());
    int tmp = sum[right] - sum[left];

    ans = max(tmp, ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }

  int main(){
    lint N;
    cin>>N;
    lint ans=0;
    lint cnt=1;
    while(N!=0){
        ans+=cnt;
        N/=2;
        cnt*=2;
    }
    cout<<ans;

  }
  

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

struct edge { int to,cost; };

int main() {
  int N;cin>>N;
  map<int,int> mp;
  REP(i,N) {
    int a;cin>>a;
    mp[a]++;
  }

  // Nが奇数の場合、0をのぞいて同じ偶数が二つづつ存在する2,4,6,...N-1
  // Nが偶数の場合、1,3,5..N-1が2個づつ存在する
  // 全体の個数はペアのかず*2
  bool ok = true;
  int pair_cnt = 0;
  if (N%2==0) {
    for(int i=1;i<=N-1;i+=2) {
      if (mp[i]!=2) ok = false;
      pair_cnt++;
    }
  } else {
    if (mp[0]!=1) ok = false;
    for(int i=2;i<=N-1;i+=2) {
      if (mp[i]!=2) ok = false;
      pair_cnt++;
    }
  }

  if (!ok) {
    OUT(0);
  } else {
    ll res = 1;
    const int MOD = 1e9+7;
    REP(i,pair_cnt) res = res*2%MOD;
    OUT(res);
  }

  return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> p;
typedef vector<p> vp;

int a,b,c,x,y,half;
ll ans=0;
int main(int argc,char const* argv[])
{
  cin >> a >> b >> c >> x >> y;
  half=min(x,y);
  if(2*c<a+b)
    {
      x-=half;
      y-=half;
      ans+=2*half*c;   
      if(x!=0)
	{
	  if(a*x>2*x*c)
	    {
	      ans+=2*x*c;
	    }
	  else
	    {
	      ans+=a*x;
	    }
	}
      else if(y!=0)
	{
	  if(b*y>2*y*c)
	    {
	      ans+=2*y*c;
	    }
	  else
	    {
	      ans+=b*y;
	    }
	}
    }
  else
    {
      ans+=a*x;
      ans+=b*y;
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        int[] ints = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        System.out.println(ints[i-1]);
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>


int N_in;
long int *A_in;


int main(int argc, char* argv[]){
    int i,j;
    int count;
    count=0;
    scanf("%d",&N_in);
    long int temp=0;
    long int temp2=0;
    A_in = (long int *) malloc( sizeof(long int) *(N_in+1)  );
    for(i=1;i<=N_in;i++){
        scanf("%ld",&A_in[i]);
    }
//    for(i=2;i<=N_in;i++){
//        temp += A_in[i];
//    }
    //temp = temp % (1000000000 + 7);
    temp = A_in[N_in];
    for(j=N_in-1;j>=1;j--){
        temp2 += temp*A_in[j];
        temp2 = temp2 % (1000000000 + 7);
        temp = temp + A_in[j];      
        temp = temp % (1000000000 + 7);
    }
    printf("%ld",temp2);
    return 0;
}

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int maxn=1e7+7;
const int mod=1e9+7;
ll C[5005][5005];
ll inv[maxn],f[maxn],finv[maxn];
void init() //inv,f,finv 都开ll
{
    inv[1] = 1;
    for (int i = 2; i < maxn; i++)
        inv[i] = (mod - mod / i) * inv[mod % i] % mod; //inv: 逆元
    f[0] = finv[0] = 1;                                //f: 阶乘    finv:阶乘逆元(1/f)
    for (int i = 1; i < maxn; i++)
    {
        f[i] = f[i - 1] * i % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
	for(int i=0;i<5005;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
}
int main()
{
	init();
	int n,a;
	cin>>n>>a;
	ll ans=0;
	for(int i=2;i<=a+1;i++)
	{
		for(int j=0;j<i;j++)
		{
			int x=i-1-j,b=n-a,rem=max(0,a-i);
			ll cur=C[i-1][j]*x%mod*inv[x+b]%mod*f[x+b+rem]%mod;
			//dbg(i,j,cur,x,b,rem);
			if(j&1) ans=(ans-cur+mod)%mod;
			else ans=(ans+cur)%mod;
		}
		//dbg(i,ans);
	}
	print(ans);
}


Measured memory_bytes: 354736
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
   if(a==0)
   return b;

     else
     return gcd(b % a,a);
}
int main()
{
     int k;
      cin>>k;

        long long int sum=0;

          for(int i=1;i<=k;i++)
           for(int j=1;j<=k;j++)
            for(int p=1;p<=k;p++)
             {
                int l=gcd(i,j);
                l=gcd(l,p);

                 sum+=l;
             }
        cout<<sum;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;

bool check(vi A, int n) {
	ll size = 0;
	if (n == A.size() - 1)return true;
	rep(i, n + 1) {
		size += A[i];
	}
	int idx = n + 1;
	while (idx < A.size() && size * 2 >= A[idx]) {
		size += A[idx];
		idx++;
	}
	if (idx == A.size())return true;
	else return false;
}


int main() {
	int N;
	cin >> N;
	vi A(N);
	rep(i, N) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());

	if (check(A, 0)) {
		cout << N << endl;
		return 0;
	}
	int ng = 0, ok = N - 1;
	while (ok - ng > 1) {
		int med = (ok + ng) / 2;
		if (check(A, med)) {
			ok = med;
		}
		else {
			ng = med;
		}
	}
	cout << N - ok << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a  >>b;
    
    if (a > b){
        cout << "a > b" << endl;
    } else if (a < b){
        cout << "a < b" << endl;
    } else if (a == b){
        cout << "a == b" << endl;
    }
    
    return 0;
}


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

#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--)
#define ll long long
#define st f
#define nd s
#define pb PB
#define eb emplace_back
#define mp make_pair
#define siz(c) SIZ(c)
const int inf = 1e9 + 7;
const LL INF = 1e18L + 7;

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type
{int o = 0; p << "{"; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if (p > y) p = y;}
sim, class s> void maxi(n &p, s y) {if (p < y) p = y;}

#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
}

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

int main(void){
    int h, w;
    cin >> h >> w;
    
    char m[52][54] = {{0}};
    int i;
    for(i = 1; i <= h; i++){
        cin >> &m[i][1];
    }
    
    int cnt;
    int j, k, l;
    for(i = 1; i <= h; i++){
        for(j = 1; j <= w; j++){
            if(m[i][j] == '#'){
                cout << '#';
                continue;
            }
            cnt = 0;
            for(k = -1; k <= 1; k++){
                for(l = -1; l <= 1; l++){
                    if(!(k == 0 && l == 0) && m[i + k][j + l] == '#'){
                        cnt++;
                    }
                }
            }
            cout << cnt;
        }
        cout << endl;
    }
    
    return 0;
}


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


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

    int ans = 0;
    if(s == "SUN") ans = 7;
    else if(s == "MON") ans = 6;
    else if(s == "TUE") ans = 5;
    else if(s == "WED") ans = 4;
    else if(s == "THU") ans = 3;
    else if(s == "FRI") ans = 2;
    else if(s == "SAT") ans = 1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import math

H, W = map(int,input().split())
if H == 1 or W ==1:
    print(1)
elif H%2 == 0 and W%2 ==0:
    print(H//2 * W//2 *2)
elif H%2 == 1 and W%2 ==1:
    print(math.ceil(H*W/2))
else:
    print(H*W//2)

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

using namespace std;

int main() {
	int n; cin>>n;
	int x[n], ans = 2e6;

	for(int i=0; i<n; i++) cin>>x[i];

	for(int p=0; p<=100; p++) {
		int curr = 0;
		for(int i=0; i<n; i++)
			curr += (x[i] - p) * (x[i] - p);

		ans = min(ans, curr);
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
ll dp[3010][3010] = {},sum[3010] = {},mod = 1000000007;
int main(){
	int i,j,n;
	string s;
	cin >> n >> s;
	for(i=1;i<=n;i++){
		dp[0][i] = 1;
		sum[i] = i;
	}
	for(i=1;i<n;i++){
		if(s[i - 1]=='<'){
			for(j=1;j<=n + 1 - i;j++){
				dp[i][j] = sum[j]; 
			}
		}else{
			for(j=1;j<=n + 1 - i;j++){
				dp[i][j] = (sum[n + 1 - i] - sum[j] + mod)%mod;
			}
		}
		sum[0] = 0;
		for(j=1;j<=n;j++){
			sum[j] = (sum[j-1] + dp[i][j])%mod;
		}
	}
	cout << dp[n - 1][1] << endl;
}

Measured memory_bytes: 70016
#include <iostream>
using namespace std;
int dp[100005],a[100005];
int main(int argc, char** argv) {
	int n,k;
	cin >> n >> k;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i>=a[j]&&dp[i-a[j]]==0)
				dp[i]=1;
		}
	}
	if(dp[k]) puts("First");
	else puts("Second"); 
	return 0;
}

Measured memory_bytes: 640