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


int main()
{

    int n;
    cin>>n;

    vector<int> A(n);
    for(int i=0;i<n;i++){
        cin>>A.at(i);
    }

    vector<int> B(n);
    for(int i=0;i<n;i++){
        cin>>B.at(i);
    }

    vector<int> C(n);
    for(int i=0;i<n-1;i++){
        cin>>C.at(i);
    }


    int sum=0;
    int wk=-10,wk_old=-10;
    for(int i=0;i<n;i++){
        wk=A.at(i)-1;
        sum+=B.at(wk);
        if(wk-wk_old==1)
            sum+=C.at(wk_old);

        wk_old=wk;
    }

    cout<<sum<<endl;

    return 0;
}   

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int cnt = 0;
		for (int a = 1; a < n; a++) {
			cnt += (n - 1) / a;
		}
		
		System.out.println(cnt);
		
		sc.close();
	}
}



Measured memory_bytes: 27080
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb(n) push_back(n);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi[maxii];
vector<lln> vl;
vector<vector<pair<int, int> > > vii;
//vector<pii> vii;
vector<pll> vll;
//vii.clear();
//vii.resize(n + 1);


int in[maxii];
int low[maxii];
bool check[maxii];
bool check2[1000][1000];
int n,m;
int t=1,ans=0;
void dfs(int node,int par)
{
    check[node]=true;
    //cout<<node<<endl;
    low[node]=in[node]=t++;
    for(int child=0;child<vi[node].size();child++)
    {
        if(vi[node][child]==par)continue;
        else if(check[vi[node][child]]==true)
        {
            low[node]=min(low[node],in[vi[node][child]]);
        }
        else
        {
            dfs(vi[node][child],node);
            if(low[vi[node][child]]>in[node])
            {
                ans++;
            }
            low[node]=min(low[node],low[vi[node][child]]);

        }

    }
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //int n;
    sc(n)
    sc(m)
    int a,b;
    for(int i=0;i<m;i++)
    {
        sc(a)
        sc(b)
        vi[a].pb(b)
        vi[b].pb(a)
    }
    for(int i=1;i<=n;i++)
    {
        if(check[i]==false)
        {
            dfs(i,i);
        }
    }
    cout<<ans<<endl;



}






Measured memory_bytes: 5996
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N = int(input())
    A = input_nums()[::-1]
    B = input_nums()[::-1]
    B = [0] + B
    total = 0
    for i in range(N):
        # 後続の勇者が倒す
        mb = min(A[i], B[i])
        A[i] -= mb
        B[i] -= mb
        total += mb
        # 後続の勇者が倒し着れなかった場合
        if A[i] > 0:
            mb = min(A[i], B[i+1])
            A[i] -= mb
            B[i+1] -= mb
            total += mb
    mb = min(A[N], B[N])
    total += mb
    print(total)

if __name__ == '__main__':
    main()


Measured memory_bytes: 19412
from itertools import combinations
from itertools import permutations
N = int(input())
lis = []
for v in combinations([3,5,7,11,13],3):
  if v[0]*v[1]*v[2] <= N: lis.append(v[0]*v[1]*v[2]) 
for v in permutations([3,5,7],2):
  if (v[0]**3)*v[1] <= N: lis.append((v[0]**3)*v[1]) 

print(len(lis))

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**8)
T = int(input())
for _ in range(T):
    N,A,B,C,D = map(int,input().split())
    INF = float('inf')
    mem = {}
    def solve(n):
        if n==0: return 0
        if n==1: return D
        if n in mem: return mem[n]
        tmp = n*D
        if n%2==0:
            tmp = min(tmp, solve(n//2) + A)
        else:
            tmp = min(tmp, solve(n//2) + A+D, solve(n//2+1) + A+D)
        if n%3==0:
            tmp = min(tmp, solve(n//3) + B)
        else:
            d = n%3
            u = 3-d
            tmp = min(tmp, solve(n//3) + B+d*D, solve(n//3+1) + B+u*D)
        if n%5==0:
            tmp = min(tmp, solve(n//5) + C)
        else:
            d = n%5
            u = 5-d
            tmp = min(tmp, solve(n//5) + C+d*D, solve(n//5+1) + C+u*D)
        mem[n] = tmp
        return tmp
    print(solve(N))

Measured memory_bytes: 11072
#include "bits/stdc++.h"
using namespace std;

int main(){
int a,b,c,x;
cin >> a >> b >> c>>x;
int ans =0;
for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
        for(int k=0;k<=c;k++){
            if(i*500+j*100+k*50==x){
               ans++; 
            }
        }
    }
}
cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 998244353
#define MAXT 1100000
using namespace std;
typedef long long LL;
LL powmod(LL a, LL n){
	if(n == 0) return 1;
	if(n % 2) return (a * powmod(a,n-1)) % MOD;
	return powmod((a*a) % MOD,n/2);
}

LL inv(LL a){
	return powmod(a,MOD-2);
}

LL fact[MAXT];
LL invfact[MAXT];
int main(){
	for(int i = 0; i < MAXT; i++){
		if(i == 0){
			fact[i] = 1;
			continue;
		}
		fact[i] = (i*fact[i-1]) % MOD;
	}
	invfact[MAXT-1] = inv(fact[MAXT-1]);
	for(LL j = MAXT-2; j >= 0; j--){
		invfact[j] = ((j+1) * invfact[j+1]) % MOD;
	}

	LL n, m;
	cin >> n >> m;
	if(n < m) swap(n,m);
	LL ans = n;
	LL sum = 0;
	LL cur = 0;
	for(LL i = 2; i <= n + m; i += 2){
		LL k = i/2;
		if(n < k || m < k) continue;
		LL v = 1;
		v = (v * fact[2*k]) % MOD;
		v = (v * invfact[k]) % MOD;
		v = (v * invfact[k]) % MOD;
		v = (v * fact[m+n-2*k]) % MOD;
		v = (v * invfact[n-k]) % MOD;
		v = (v * invfact[m-k]) % MOD;
		sum += v;
		sum %= MOD;
	}
	sum = (sum * invfact[2]) % MOD;
	sum = (sum * invfact[m+n]) % MOD;
	sum = (sum * fact[m]) % MOD;
	sum = (sum * fact[n]) % MOD;
	ans += sum;
	ans %= MOD;
	while(ans < 0) ans += MOD;
	cout << ans << endl;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define push push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
int main(){
    vector<string>s(3,"");
    vector<int> at(3,-1);
    int turn =0;
    char ans;
    at[0]++;
    rep(i,3){
        cin>>s[i];
    }
    while(at[0] != s[0].size() and at[1]!=s[1].size() and at[2] != s[2].size()){
        
        switch(s[turn][at[turn]]){
            case 'a':
                turn =0;
                break;
                  case 'b':
                turn =1;
                break;
                  case 'c':
                      turn = 2;
                      break;
        }
        at[turn]++;
    }

    if(at[0]==s[0].size()){
        ans='A';
    }
    if (at[1] == s[1].size() )
    {
        ans = 'B';
    }
    if (at[2] == s[2].size() )
    {
        ans = 'C';
    }
    cout<<ans<<endl;
   // cout<<at[0]<<endl;
   // cout << at[1] << endl;
   // cout << at[2] << endl;
}

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

int main() {
  int x,y,z;
  cin>>x>>y>>z;
  int res=0;
  for (int i=z; i+y+z-1<x; i=i+y+z) {
    res++;
  }
  
  cout<<res<<endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>

int main() {
	int n; std::cin >> n;
	std::vector<int> difficulty(100000, 0);
	for (auto i = 0; i < n; ++i) {
		int d; std::cin >> d;
		difficulty[d - 1]++;
	}
	for (auto i = 1; i < difficulty.size(); ++i) {
		difficulty[i] += difficulty[i - 1];
	}
	std::cout << std::count(difficulty.begin(), difficulty.end(), n / 2) << std::endl;
}


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

#define LL long long
#define pii pair<int,int>
using namespace std;
const int inf = 2147483647;
const int N = 100001;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

bool v[1 << 15];
int cc[N], cnt[16], bin[16], f[1 << 15], one[1 << 15];

int main() {
	int n = read();
	for(int i = 1; i < n; i++) {
		int x = read(), y = read(), c = read();
		cc[x] ^= c, cc[y] ^= c;
	} for(int i = 0; i < n; i++) cnt[cc[i]]++;
	bin[0] = 1; for(int i = 1; i < 16; i++) bin[i] = bin[i - 1] << 1;
	int ans = 0, S = 0; for(int i = 1; i < 16; i++) ans += cnt[i] / 2, S += cnt[i] & 1 ? bin[i - 1] : 0;
	for(int i = 0; i < bin[15]; i++) {
		int sum = 0;
		for(int j = 0; j < 15; j++) if(i & bin[j]) sum ^= j + 1;
		if(!sum) v[i] = 1;
	} memset(f, 63, sizeof(f));
	f[0] = 0; for(int i = 1; i <= S; i++) {
		one[i] = one[i >> 1] + (i & 1);
		if(v[i]) {
			f[i] = one[i] - 1;
			for(int j = (i - 1) & i; j; j = (j - 1) & i) if(v[j]) f[i] = _min(f[i], f[i ^ j] + f[j]);
		}
	} put(f[S] + ans);
	return 0;
}


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

int lenghtOfLongestAP(vector<int> set)  { 
    int n = set.size();
    if (n <= 2)  return n; 

    vector<vector<int>> L(n, vector<int>(n));
    int llap = 2;

    for (int i = 0; i < n; i++) 
        L[i][n-1] = 2; 
  
    for (int j=n-2; j>=1; j--) { 
        int i = j-1, k = j+1; 
        while (i >= 0 && k <= n-1) 
        { 
           if (set[i] + set[k] < 2*set[j]) 
               k++; 
  
           else if (set[i] + set[k] > 2*set[j]) 
           {   L[i][j] = 2, i--;   } 
  
           else
           { 
               L[i][j] = L[j][k] + 1; 
  
               llap = max(llap, L[i][j]); 
  
               i--; k++; 
           } 
        } 
        while (i >= 0) 
        { 
            L[i][j] = 2; 
            i--; 
        } 
    } 
    return llap; 
} 

int main() {
    int n;
    cin >> n;
    vector<int> as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    sort(as.begin(), as.end());

    cout << lenghtOfLongestAP(as) << endl;
}


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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
#define smaller_queue_p  priority_queue <pll, vector<pll>, greater<pll> >
//------------------------------------------------------

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

    ll n, c;
    cin >> n >> c;
    map<ll, ll> x, v;
    REP(i, 1, n + 1) cin >> x[i] >> v[i];
    x[n + 1] = c;
    map<ll, ll> right, left, right_best, left_best;
    REP(i, 1, n + 1) right[i] = right[i - 1] + v[i] - (x[i] - x[i - 1]);
    REP(i, 1, n + 1) left[i] = left[i - 1] + v[n - i + 1] - (x[n - i + 2] - x[n - i + 1]);
    REP(i, 1, n + 1) right_best[i] = max(right_best[i - 1], right[i]);
    REP(i, 1, n + 1) left_best[i] = max(left_best[i - 1], left[i]);

    ll ans = 0;

    rep(i, n + 1) {
        ans = max(ans, right[i] - x[i] + left_best[n - i]);
    }
    cout << endl;

    rep(i, n + 1) {
        ans = max(ans, left[i] - (c - x[n - i + 1]) + right_best[n - i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 37760
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    
    int a[3];
    for(int i=0;i<3;i++) cin>>a[i];
   
   sort(a,a+3);
   
   cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
   
}


Measured memory_bytes: 3116
package main

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

func main() {
	N := nextInt()
	K := nextInt()

	var ans float64
	for i := 1; i <= N; i++ {
		p := float64(1)
		x := i
		for x < K {
			p *= 0.5
			x *= 2
		}
		ans += p / float64(N)
	}

	fmt.Printf("%.10f\n", ans)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

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

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	int count = 0;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == '1') {
			count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  
  vector<string> s(n);
  
  for(int i = 0; i < n; i++){
    cin >> s[i];
    if(s[i] == "AC") c0++;
    if(s[i] == "WA") c1++;
    if(s[i] == "TLE") c2++;
    if(s[i] == "RE") c3++;
  }
  cout << "AC" << " " << "x" << " " << c0 << endl;
  cout << "WA" << " " << "x" << " " << c1 << endl;
  cout << "TLE" << " " << "x" << " " << c2 << endl;
  cout << "RE" << " " << "x" << " " << c3 << endl;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
bool checked[1000005], ok[1000005];
ll cnt[1000005];

int main() {
    init();
    ll N;
    cin>>N;
    vl A(N);
    map<ll, ll> mp;
    rep(i, N) cin >> A[i], mp[A[i]]++;

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

    ll ans = 0;
    repa(p,mp){
        ll x = p.first, c = p.second;
        repe(j, 1, 1000000/x + 1){
            cnt[x * j]+=c;
        }
    }

    rep(i,N){
        if (cnt[A[i]] == 1) ans++;
    }

    cout << ans << endl;
}       

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


from scipy.special import comb


# def get_n_of_len(ln):

"""
N = 6: (3,3), (7)
N = 7: (3,4), (4,3), (7)
N = 8: (3,5), (4,4), (5,3), (8)
N = 9: (3,3,3), (3,6), (4,5), (5,4), (6,3), (9)
N = 10: (3,3,4), (3,4,3), (4,3,3) | (3-7), (7-3) | 1
...
N = 20: 3 pair >= 3
-> N=11: 3 pair: 11+3-1C(3-1)
"""


def get_n_of_len(N, ln):
    N2 = N - 3*ln
    # return (N2 + ln - 1) * (N2 + ln - 2) // 2
    return comb(N2 + ln - 1, ln-1, exact=True)


max_len = N // 3

total = 0
for ln in range(1, max_len+1):
    # total += get_n_of_len(N, ln)
    n = get_n_of_len(N, ln)
    total += get_n_of_len(N, ln)

print(total % (10**9+7))

Measured memory_bytes: 42376
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (int i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": ";
    printvec(tree[i]);
  }
}

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N, K;
  cin >> N >> K;
  vector<ll> a(N);
  rep(i, N) {
    cin >> a[i];
  }
  // printvec(a);

  vector<ll> s(N+1);
  rep(i, N) {
    s[i+1] = s[i] + a[i];
  }

  vector<ll> p_s(N+1); // The summention of positive ones.
  rep(i, N) {
    p_s[i+1] = p_s[i] + (a[i] > 0 ? a[i] : 0);
  }

  ll ans = 0;
  for (int i = 0; i + K <= N; ++i) {
    ll c = 0;
    ll k = s[i+K] - s[i]; // sum of [i, i+K-1] = sum of [0,i+K-1] - sum of [0,i-1]
    if (k > 0) { c += k; }
    ll rest = p_s[i] + p_s[N] - p_s[i+K]; // sum of [0,i-1] + sum of [i+K, N-1]
    c += rest;

    if (ans < c) {
      ans = c;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int data[100010] = {};
    rep(i, 0, n){
        int m, d, s, v;
        cin >> m >> d >> v >> s;
        m--; d--;
        int st = m * 30 + d;
        int ed = st + v - 1;
        rep(k, 0, 3){
            rep(j, 0, 36 * 30){
                if(st <= j && j <= ed) chmax(data[j], s);
                else chmax(data[j], max(0LL, s - min(abs(st - j), abs(j - ed))));
            }
            st += 12 * 30; ed += 12 * 30;
        }
    }
    int ans = INF;
    rep(i, 12 * 30, 24 * 30) chmin(ans, data[i]);
    cout << ans << endl;
}

Measured memory_bytes: 3968
N = int(input())
A = list(map(int, input().split()))
sumlist = [0]
for i in range(N-1):
  sumlist.append(sumlist[i]+A[N-1-i])
ans = 0
for i in range(N-1):
  ans += A[i]*sumlist[N-1-i]
print(ans%(1000000007))

Measured memory_bytes: 31444
#include <iostream>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <utility>
using namespace std;

typedef long long LL;
typedef pair<LL,LL> pii;
const int MAX_N = 1e5 + 6;

struct Treap {
	Treap *lc,*rc;
	LL sum,pri,key,sz;
	Treap(LL _key) {
		lc=rc=NULL;
		sum=_key;
		key = _key;
		sz=1;
		pri=rand();
	}
};

LL Sz(Treap* t) {
	return t?t->sz:0;
}

LL Sum(Treap* t) {
	return t?t->sum:0;
}

void pull(Treap* t) {
	t->sz = Sz(t->lc) + Sz(t->rc) + 1;
	t->sum = Sum(t->lc) + Sum(t->rc) + t->key;
}

Treap* merge(Treap *a,Treap* b) {
	if (!a||!b) return a?a:b;
	else if (a->pri > b->pri) {
		a->rc=merge(a->rc,b);
		pull(a);
		return a;
	}
	else {
		b->lc=merge(a,b->lc);
		pull(b);
		return b;
	}
}

void split(Treap* t,LL k,Treap* &a,Treap* &b) {
	if (!t) a=b=NULL;
	else if (t->key <= k) {
		a=t;
		split(t->rc,k,a->rc,b);
		pull(a);
	}
	else {
		b=t;
		split(t->lc,k,a,b->lc);
		pull(b);
	}
}

Treap* root;

void add(LL a) {
	Treap* tl;
	split(root,a,tl,root);
	root=merge(tl,merge(new Treap(a),root));
}

LL ans[MAX_N];

pii p[MAX_N];

int main () {
	int n;
	while (scanf("%d",&n) != EOF) {
		root = NULL;
		deque<pii> dq;
		for (int i=1;n>=i;i++) {
			int a;
			scanf("%d",&a);
			add(a);
			if (dq.empty()) {
				dq.push_back(make_pair(a,i));
			}
			else if (a > dq[dq.size()-1].first) {
				dq.push_back(make_pair(a,i));
			}
		}
		dq.push_front(make_pair(0,0));
		int dq_sz = dq.size();
		for (int i=0;dq_sz>i;i++) {
			p[i] = dq.front();
			dq.pop_front();
		}
		int m=dq_sz;
		for (int i=m;i>=1;i--) {
			Treap *tl,*tr;
			split(root,p[i-1].first,tl,root);
			split(root,p[i].first-1,root,tr);
			ans[p[i].second] = Sz(tr)*(p[i].first-p[i-1].first) + (Sum(root)-Sz(root)*p[i-1].first);
			root=merge(merge(tl,root),tr);
		}
		for (int i=1;n>=i;i++) {
			printf("%lld\n",ans[i]);
		}
	}
}



Measured memory_bytes: 11264
#include <stdio.h>

#define Q 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs_visit(int);
void dfs();

int n,M[Q][Q];
int color[Q],d[Q],f[Q],tt;

int main(){
  int u,v,k,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;

    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}

void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;

  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]==BLACK;
  f[u]=++tt;
}

void dfs(){
  int u;

  for(u=0;u<n;u++){
    color[u]=WHITE;
  }

  tt=0;

  for(u=0;u<n;u++){
    if(color[u]==WHITE)dfs_visit(u);
  }

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



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll m = 1e9 + 7;
int main()
{
   ll a,b,k;
   cin>>a>>b>>k;
   if(a>=k)
   {
       cout<<a-k<<" "<<b<<"\n";
       return 0;
   }
   k-=a;
   a=0;
   cout<<a<<" "<<max((ll)0,b-k)<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<iostream>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
using namespace std;
#define REP(i,x) for (int i=0;i<x;i++)
#define REPP(i,x,y) for (int i=x;i<=y;i++)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define MX3(x,y,z) max({x,y,z})
#define MX4(x,y,z,p) max({x,y,z,p})
#define MX5(x,y,z,p,q) max({x,y,z,p,q})
#define MN3(x,y,z) min({x,y,z})
#define MN4(x,y,z,p) min({x,y,z,p})
#define MN5(x,y,z,p,q) min({x,y,z,p,q})
#define amax(x,y) x=max(x,y)
#define amin(x,y) x=min(x,y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef tuple<int,int,int> ti;
typedef tuple<ll,ll,ll> tl;
// #####################################################################

void solve() {

    int n;
    SI(n);
    string a;
    cin >>a;
    if(n%2 == 1) puts("No");
    else {
        bool ans = true;
        for(int i = 0 ; i < n/2 ; i++) {
            ans &= a[i] == a[i+n/2];
        }
        if(ans)puts("Yes");
        else puts("No");
    }

}

void init() {
    


}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, M, X, A[M];
	cin >> N >> M >> X;
	for (int i = 0; i < M; i++) {
		cin >> A[i];
	}
	int B[N];
	for (int i = 0; i < N; i++) {
		B[i] = 0;
	}
	for (int i = 0; i < M; i++) {
		B[A[i]] = 1;
	}
	int cost1 = 0;
	int cost2 = 0;
	for (int i = X + 1; i <= N - 1; i++) {
		if (B[i] == 1) {
			cost1++;
		}
	}
	for (int i =1; i <= X - 1; i++) {
		if (B[i] == 1) {
			cost2++;
		}
	}


	cout << min(cost1, cost2) << endl;

}

Measured memory_bytes: 256
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N;
    cin>>N;
    string S;
    S=to_string(N);
    int M=S.size();
    int P=0;
    REP(i,M){
        P+=S[i]-'0';
    }
    if(N%P==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,i;
    char op;
    
    for(i=0;i<=20000;i++){
    
        scanf("%d %c %d",&a,&op,&b);
    
        if(op == '+') {
            printf("%d\n", a + b);
        }
        if(op == '-') {
            printf("%d\n", a - b);
        }
        if(op == '*') {
            printf("%d\n", a * b);
        }
        if(op == '/') {
            printf("%d\n", a / b);
        }
        if(op == '?') break;
    }
    
    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

int INF = - (1 << 30);

int N;
int F[100][10];
int P[100][11];

int solve(int mask[]) {
	int res = 0;
	for (int i = 0; i < N; i++) {
		int cnt = 0;
		for (int j = 0; j < 10; j++) {
			if (mask[j] && F[i][j])cnt++;
		}
		res += P[i][cnt];
	}
	return res;
}

int main() {
	int ans = INF;

	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> F[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 11; j++) {
			cin >> P[i][j];
		}
	}

	for (int i = 1; i < 1 << 10; i++) {
		int mask[10];
		for (int j = 0; j < 10; j++) {
			mask[j] = i >> j & 1;
		}
		ans = max(solve(mask), ans);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()

const string YES = "Yes";
const string NO = "No";

int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> up, down;
    REP(i, n){
        ll cur = 0, bottom = 0;
        string s;
        cin >> s;
        for(char c : s){
            if(c == '('){
                cur++;
            }else{
                cur--;
            }
            bottom = min(cur, bottom);
        }
        if(cur >= 0){
            up.emplace_back(bottom, cur);
        }else{
            down.emplace_back(bottom - cur, - cur);
        }
    }

    sort(up.rbegin(), up.rend());
    ll cur_up = 0;
    for(auto p : up){
        ll btm = p.first;
        if(cur_up + btm < 0){
            cout << NO << endl;
            return 0;
        }
        cur_up += p.second;
    }

    sort(down.rbegin(), down.rend());
    ll cur_down = 0;
    for(auto p : down){
        ll btm = p.first;
        if(cur_down + btm < 0){
            cout << NO << endl;
            return 0;
        }
        cur_down += p.second;
    }

    if(cur_up != cur_down){
        cout << NO << endl;
    }else{
        cout << YES << endl;
    }
    return 0;
}


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

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



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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;

#define rep(i, n) \
for(int i = 0; i <n; i++)
#define REP(i, a, b) \
for(int i = int(a); i <= int(b); i++)
#define TRvi(c, it) \
for(vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for(vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for(msi::iterator it = (c).begin(); it != (c).end(); it++)

#define INF 2000000000

#define MEMSET_INF 127
#define MEMSET_HALF_INF 63

void solve(){
    int n;
    cin>>n;
    vector<ll> nums(n);
    rep(i,n) cin>>nums[i];
    sort(nums.begin(), nums.end());
    ll ans = 0;
    rep(i,n-1){
        ans+=nums[n-1-(i+1)/2];
    }
    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


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

#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define all(v) v.begin(),v.end()
#define mod %
#define pb push_back

const ll N = (ll)(100007);


int main()
{
	FIO
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	vector<char> ans;
	for(int i=0; i<n; i++) {
		ans.push_back(s[i]);
		ans.push_back(t[i]);
	}
	for(auto i : ans) {
		cout << i;
	}
	return 0;	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
	int  b, c, d, e, k, deter = 0;
	int a[50];
	for(int i = 0; i < 5; i++){
		cin >> a[i];
	}
	for(int i = 0; i < 5; i++){
		if(a[i]%10)deter += (a[i]/10+1)*10;
		else deter+=a[i];
	}
	int min = 123*10;
	for(int i = 0; i < 5; i++){
		if(deter-(10-a[i]%10) < min && a[i]%10)min = deter-(10-a[i]%10);
	}
	if(min == 123*10){
		min = 0;
		for(int i = 0; i < 5; i++){
			min+=a[i];
		}
	}
	cout << min << '\n';
	
return 0;
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
#define pb(s) push_back(s)
#define SZ(x) ((int)(x).size())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template< unsigned mod >
struct RollingHash {
  vector< unsigned > hashed, power;

  inline unsigned mul(unsigned a, unsigned b) const {
    unsigned long long x = (unsigned long long) a * b;
    unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
    asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod));
    return m;
  }

  RollingHash(const string &s, unsigned base = 10007) {
    int sz = (int) s.size();
    hashed.assign(sz + 1, 0);
    power.assign(sz + 1, 0);
    power[0] = 1;
    for(int i = 0; i < sz; i++) {
      power[i + 1] = mul(power[i], base);
      hashed[i + 1] = mul(hashed[i], base) + s[i];
      if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
    }
  }

  unsigned get(int l, int r) const {
    unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
    if(ret >= mod) ret -= mod;
    return ret;
  }

  unsigned connect(unsigned h1, int h2, int h2len) const {
    unsigned ret = mul(h1, power[h2len]) + h2;
    if(ret >= mod) ret -= mod;
    return ret;
  }

  int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = -1, high = len + 1;
    while(high - low > 1) {
      int mid = (low + high) / 2;
      if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
      else high = mid;
    }
    return (low);
  }
};

using RH = RollingHash< 1000000007 >;

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

    // input
    ll N; cin >> N;
    string s; cin >> s;

    // 存在しない場合をチェック
    map<char, ll> mp;
    for(char c : s){
      mp[c]++;
    }
    if(mp.size()==N){
      p(0);
      return 0;
    }

    RH rh(s);

    ll left = 1; // can
    ll right = N/2+1; // can't

    ll ma = 0;
    while(left+1!=right){
      ll L = (left+right)/2; // この長さで見つけられるか
      bool found = false;
      FOR(i, 0, N){
        FOR(j, i+L, N){
          if(found) break;
          if(j+L>N) continue;
          ll hash0 = rh.get(i, i+L);
          ll hash1 = rh.get(j, j+L);
          if(hash0==hash1 && s.substr(i, L)==s.substr(j, L)){
            found = true;
            chmax(ma, L);
          }
        }
      }
      if(found){
        left = L;
      }else{
        right = L;
      }
    }

    p(ma);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2006;
const int mod=1e9+7;

ll n,dp[N];

ll add(ll a,ll b){ 
    return ((a%mod)+(b%mod))%mod;
}

ll cal(int sum){
	if(sum==n)return 1;
	if(dp[sum]!=-1)return dp[sum];
	ll sol=0;
	for(int i=3;i<=n;i++){
		if(sum+i<=n)sol=add(sol,cal(sum+i));
	}
	return dp[sum]=sol;
}


int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    memset(dp,-1,sizeof dp);
    cout<<cal(0);




}
    


Measured memory_bytes: 3664
use std::cmp::{max, min};
use std::io::{self, Read};
use std::iter::FromIterator;

#[allow(dead_code)]
struct Source {
    chars: Box<Iterator<Item = char>>,
}

#[allow(dead_code)]
impl Source {
    fn next_chr(&mut self) -> char {
        self.chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .next()
            .expect("eof")
    }

    fn next_str(&mut self) -> String {
        let it = self
            .chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .take_while(|c| !char::is_whitespace(*c));
        let s = String::from_iter(it);
        if s.is_empty() {
            panic!("eof")
        } else {
            s
        }
    }

    fn from_stdin() -> Self {
        let mut data = String::new();
        io::stdin().read_to_string(&mut data).expect("Input error");
        Self::from_str(&data)
    }

    fn from_str(s: &str) -> Self {
        let data = String::from(s);
        let chars = data.chars().collect::<Vec<char>>().into_iter();
        Source {
            chars: Box::new(chars),
        }
    }
}

#[allow(unused_macros)]
macro_rules! input {
    ($src:expr; $($elem:tt)*) => {
        input_inner!($src, $($elem)*)
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($src:expr) => {};
    ($src:expr,) => {};
    ($src:expr, $var:ident : mut $ty:tt $($rest:tt)*) => {
        let mut $var = parse!($src, $ty);
        input_inner!($src $($rest)*)
    };
    ($src:expr, $var:ident : $ty:tt $($rest:tt)*) => {
        let $var = parse!($src, $ty);
        input_inner!($src $($rest)*)
    };
}

#[allow(unused_macros)]
macro_rules! parse {
    ($src:expr, ( $($ty:tt),* )) => {
        ( $(parse!($src,$ty)),* )
    };
    ($src:expr, char) => {
        $src.next_chr()
    };
    ($src:expr, [ $ty:tt; $len:expr ]) => {
        (0..$len).map(|_| parse!($src,$ty)).collect::<Vec<_>>()
    };
    ($src:expr, $ty:tt) => {
        parse_str!($src,$ty)
    };
}

#[allow(unused_macros)]
macro_rules! parse_str {
    ($src:expr, chars) => {
        $src.next_str().chars().collect::<Vec<char>>()
    };
    ($src:expr, $ty:ty) => {
        $src.next_str().parse::<$ty>().expect("Parse error")
    };
}

fn main() {
    let mut src = Source::from_stdin();
    input! { src;
             s: mut usize
    }

    let mut seen = vec![false; 1_000_001];

    let mut i = 1;
    loop {
        if seen[s] {
            println!("{}", i);
            return;
        }
        seen[s] = true;
        i += 1;
        s = if s % 2 == 0 { s / 2 } else { 3 * s + 1 }
    }
}


Measured memory_bytes: 4352
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

S = s()
T = s()

for i in range(len(S)+1):
    SD = S[len(S)-i:] + S[:len(S)-i]
    if T == SD:
        print('Yes')
        import sys
        sys.exit()

print('No')


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

int main(void){
    int n;
    string s;

    cin >> n >> s;

    int count_w[n];
    int count_e[n];

    count_w[0] = 0;
    count_e[n-1] = 0;

    rep(i, n - 1){
        if(s[i] == 'W')
            count_w[i]++;
        count_w[i+1] = count_w[i];
    }

    for(int i = n - 1; i > 0; i--){
        if(s[i] == 'E')
            count_e[i]++;
        count_e[i-1] = count_e[i];
    }

    int mi = 3000000;

    rep(i, n){
        mi = min(mi, count_w[i] + count_e[i]);
    }

    cout << mi - 1 << endl;

    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N, A, B; cin >> N >> A >> B;
  cout << min(A*N, B) << endl;
}

Measured memory_bytes: 256
#warshall_floyd法
def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
n = int(input())
d = [[float("inf") for i in range(n)] for i in range(n)] 
l=[]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(n):
    s=input()
    for j in range(n):
        if s[j]=="1":
            d[i][j] = 1
            l.append([i,j])
for i in range(n):
    d[i][i] = 0
wf=warshall_floyd(d)
visited = [1]+[0 for i in range(n-1)]
for _ in range(1000):
    for i in l:
        if visited[i[0]]!=0:
            if visited[i[0]]==1:
                if visited[i[1]]==1:
                    print(-1)
                    exit()
                elif visited[i[1]]==0:
                    visited[i[1]]=-1
            else:
                if visited[i[1]]==-1:
                    print(-1)
                    exit()
                elif visited[i[1]]==0:
                    visited[i[1]]=1
ans=0
for i in wf:
    ans=max(ans,max(i)+1)
print(ans)

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

int Euclidean_Algorithm(int i,int j){
    int r = j % i;

    while(r != 0){
        j = i;
        i = r;
        r = j % i;
    }
    return i;
}

int main(){
    int N;
    cin >> N;
    vector<int> monster(N);

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

    sort(monster.begin(),monster.end());
    int counter = monster[0];
    for(int i = 1;i < N;i++){
        counter = Euclidean_Algorithm(counter,monster[i]);
    }

    cout << counter << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        int N = sc.nextInt();
        int[] d = new int[N];
        int total = 0;
        
        for(int i = 0; i<N; i++){
            d[i] = sc.nextInt();
        }

        for(int i = 0; i<N-1; i++){
            for(int j = i+1; j<N; j++){
                total += d[i]*d[j];
            }
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define mp              make_pair
#define pb              push_back
#define all(a)          (a).begin(), (a).end()
#define sz(a)           a.size()
#define srt(a)          sort(all(a))
#define mem(a, h)       memset(a, (h), sizeof(a))
#define F               first
#define S               second
#define forr(i, b, e)   for(ll i = b; i < e; i++)
#define forg(i, b, e, m)    for(ll i = b; i < e; i+=m)
//ll in(){ll r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}
 
using namespace std;
//using namespace __gnu_pbds;
 
typedef long long       ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const ll tam = 5200;
const ll MOD = 1e9+7;
const ll MOD1 = 988244535;
const double EPS = 1e-9;
const double PI = acos(-1);
#define offset 1000020
#define forite(it,a,b) for(auto it=a;it!=b;it++)
deque<int> v;
int dp[tam][tam],invdp[tam][tam];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n>>k;
    int c=0,valor;
    forr(i,1,n+1)
    {
        cin>>valor;
        if (valor>=k){
            //c++;
            continue;
        }
        v.pb(valor);
    }
    v.push_front(0);
    n=v.size()-1;
    
    dp[0][0]=1;
    forr(i,1,n+1)
    {
        forr(j,0,tam)
        {
            dp[i][j]=dp[i-1][j];
            if (j-v[i]<0)continue;
            dp[i][j]|=dp[i-1][j-v[i]];
        }
        
    }

    invdp[n+1][0]=1;
    for(int i=n;i>=1;i--)
    {
        forr(j,0,tam)
        {
            invdp[i][j]=invdp[i+1][j];
            if (j-v[i]<0)continue;
            invdp[i][j]|=invdp[i+1][j-v[i]];
        }
    }
    int respuesta=0;
    forr(i,1,n+1)
    {
        set<int> s;
        forr(j,0,tam)
            if (invdp[i+1][j])
                s.insert(j);
        bool valid=0;
        //cout<<i<<' '<<v[i]<<":\n";
        forr(j,0,k)
        {
            if (!dp[i-1][j]|| valid)continue;
            if (j>=k-v[i])valid=1;
            //cout<<j<<" mayor a "<<k-v[i]-j<<endl;
            auto ite=s.lower_bound(k-v[i]-j);
            if (ite!=s.end())
            {
                //cout<<j<<' '<<(*ite)<<endl;
                if ((*ite)+j>=k-v[i] && (*ite)+j<k)
                    valid=1;
            }
        }
        if (!valid)respuesta++;
    }
    cout<<respuesta<<endl;
}   
// read the question correctly (is y a vowel? what are the exact constralls?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs ll?) ARRAY OUT OF BOUNDS

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

/*
template<size_t max_N>
struct Prime{
    bool is_prime[max_N];
    constexpr Prime() : is_prime() {
        for(int i = 0; i < max_N; i++) is_prime[i] = true;
        is_prime[0] = is_prime[1] = false;
        for (int i = 0; i < max_N; i++)
        {
            if(!is_prime[i]) continue;
            for (int j = i*i; j < max_N; j+=i) is_prime[j] = false;
        }
        
    }
};
*/

template<size_t max_N, size_t prime_size>
struct Prime{
    bool sieve[max_N];
    int_fast64_t prime[prime_size];
    int_fast64_t nlike[max_N];
    size_t counter = 0;
    constexpr Prime() : sieve(), prime(), nlike() {
        for(int_fast64_t i = 0; i < max_N; ++i)
            sieve[i] = true;
        sieve[0] = sieve[1] = false;
        for(int_fast64_t i = 2; i < max_N; ++i){
            if(sieve[i]){
                prime[counter] = i;
                ++counter;
                if(counter > prime_size)break;
            }
            for(int_fast64_t j = i * i; j < max_N; j += i)
                sieve[j] = false;
        }
        for (int i = 1; i < max_N; i++)
        {
            if(i%2==1 && sieve[i] && sieve[(i+1)/2]) nlike[i] = nlike[i-1] + 1;
            else nlike[i] = nlike[i-1];
        }
    }
};

constexpr void check_like(std::vector<int>& n_like, const Prime<100100, 10000>& p){
}
int main(){
    using namespace std;
    const int PRIME_MAX = 1e5+100;
    int Q; cin >> Q;
    vector<int> l(Q), r(Q);
    vector<int> n_like(PRIME_MAX, 0);
    for (int i = 0; i < Q; i++) cin >> l[i] >> r[i];
    constexpr auto p = Prime<PRIME_MAX, 10000>();
    
    for (int i = 0; i < Q; i++)
    {
        cout << p.nlike[r[i]] - p.nlike[l[i]-1] << "\n";
    }
}


Measured memory_bytes: 2816
s[50],i,j,p,q;main(n){for(;n=atoi(gets(s)),n;printf("%d\n",i)){for(i=0;i<n;s[i++]=strlen(gets(s+i)));for(i=j=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=j++>5?0:j-2&&j-4?8:6;q>1;q-=s[p++]);}}

Measured memory_bytes: 532
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        var l = sc.nextInt();
        var r = sc.nextInt();

        long ans = long.MaxValue;
        for (long i = l; i < r; i++)
        {
            for (long j = i + 1; j <= Math.Min(r, i + 3000); j++)
            {
                ans = Math.Min(ans, (i * j) % 2019);
                if (ans == 0) break;
            }
            if (ans == 0) break;
        }

        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var line = System.Console.ReadLine().Split(' ').Select(ulong.Parse).ToArray();

        var a = line[0];
        var b = line[1];

        var div = a > b ? a : b;
        var kouyaku = a < b ? a : b;
        var amari = ulong.MaxValue;
        while (true)
        {
            amari = div % kouyaku;
            if(amari == 0)
            {
                break;
            }
            div = kouyaku;
            kouyaku = amari;
        }

        var koubai = a * b / kouyaku;

        System.Console.WriteLine(koubai);
    }
}



Measured memory_bytes: 13396