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

int main() {
    string S;
    cin >> S;
    ll ans = 0;
    int black = 0;
    for (int i = 0; i < S.size(); ++i) {
        if(S[i] == 'B') {
            black++;
        } else{
            ans += black;
        }
    }
    cout << ans;
    return 0;
}

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 15, M = 1003;
int dp[1<<N];

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m;
    scanf("%d %d", &n, &m);
    memset(dp, 0x7f, sizeof dp);
    int MAX = dp[0];
    dp[0] = 0;
    for (int i = 0; i < m; i++) {
        int cost, sz;
        scanf("%d %d", &cost, &sz);
        int mask = 0;
        while (sz--) {
            int x;
            scanf("%d", &x);
            x--;
            mask |= 1 << x;
        }
        for (int j = (1 << n) - 1; j >= 0; j--) {
            dp[j|mask] = min(dp[j|mask], dp[j] + cost);
        }
    }
    if (dp[(1 << n)-1] == MAX) {
        printf("-1");
    } else {
        printf("%d", dp[(1 << n)-1]);
    }
    return 0;
}


Measured memory_bytes: 3960
#include <stdio.h>

void print_list(int a[], int n)
{
    int i;
    for (i = 0; i < n; i++){
        printf("%d", a[i]);
        if (i < n-1)
            printf(" ");
    }
    printf("\n");
}


void selection_sort(int a[], int n)
{
	int i, j, min, tmp;
	int cnt = 0;
	
	for(i = 0; i < n-1; i++){
		min = i;
		for (j = i+1; j < n; j++){
			if (a[j] < a[min]){
				min = j;
			}
		}
		if(min != i){
			tmp = a[i]; a[i] = a[min]; a[min] = tmp;
			cnt++;
		}
	}
	
	print_list(a, n);
	printf("%d\n", cnt);
}

int main()
{
    int a[1000];
    int i, n;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    
    selection_sort(a, n);
    
    return 0;
}


Measured memory_bytes: 2764
from collections import deque

def main():
    h, w = map(int,input().split())
    A = [list(input()) for _ in range(h)]
    B = []

    for i,a in enumerate(A):
        for j,b in enumerate(a):
            if b == "#":
                B.append((i,j))

    dxy = [[1,0],[-1,0],[0,1],[0,-1]]

    stack = deque(B)
    darked = len(stack)
    targetd = h*w
    count = 0

    while darked < targetd:
        nextd = deque([])

        while stack:
            x, y = stack.popleft()
            for dx,dy in dxy:
                X = x + dx
                Y = y + dy
                if not(0 <= X < h) or not(0 <= Y < w):
                    continue
                if A[X][Y]==".":
                    A[X][Y]="#"
                    nextd.append((X,Y))
        count += 1
        stack = nextd
        darked += len(stack)
    print(count)
    
main()


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

int main(){
    int n, x;
    while(1){
        int idx = 0;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        for (int i = 1; i <= n-2; i++){
            for (int j = i+1; j <= n-1; j++){
                for (int k = j+1; k <= n; k++){
                    if (i + j + k == x) idx++;
                }
            }
        }
        cout << idx << endl;
    }
}


Measured memory_bytes: 3104
# -*- coding: utf-8 -*-
# M- Candy

# 子供iまででkを作った場合の組み合わせの数をdp[i][k]とすると、
# dp[i][k] = sum_a(in a[i]) dp[i-1][k-a] と計算できるが、
# N, Kに加えて各a_iについての3重ループになってしまうため工夫が必要（naive実装：TLE）


'''
3 4
1 2 3
'''

from itertools import accumulate

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

dp = [[0] * (K + 1) for i in range(N + 1)]
dp[0][0] = 1
DIVISOR = 10**9 + 7

dp_cum = [[0] * (K + 2) for i in range(N + 1)]
dp_cum[0] = [0] + [1]*(K+1)

for i in range(1, N + 1):
    dp[i][0] = 1

    # print(i, A[i - 1])
    for k in range(1, K + 1):
        # naive実装
        # res = 0
        # for a in range(0, A[i-1] + 1):
        #     if k - a >= 0:
        #         res += dp[i-1][k-a]
        # dp[i][k] = res % DIVISOR

        dp[i][k] = dp_cum[i-1][k+1] - dp_cum[i-1][max(0, k-A[i-1])]

    dp_cum[i] = [0] + list(accumulate(dp[i]))
    dp_cum[i] = [i % DIVISOR for i in dp_cum[i]]

# print(dp)
# print(dp_cum)

print(dp[N][K] % DIVISOR)



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

#define ff              first
#define ss              second
#define int             long long
// #define ll              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             998244353
#define endl            "\n"
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}
// #DEBUG
void __print(int x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// ###################################################################
int pow(int a, int b, int m) {
  int r = 1, e = a;
  while (b) {
    if (b & 1) r = (r * e) % m;
    e = (e * e) % m;
    b >>= 1;
  }
  return r;
}
void fast()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
// First write recursive with no ristrictions;
// Then apply ristrictions; (What can we do? and Can we do it?)
// We are adding mod because sometimes ans could be negeative (So always add mod when substracting 2 mod answers)
int32_t main() {
  fast();
  string aa;
  cin >> aa;
  if (aa.length() == 1) {
    char a = aa[0];
    if (a == '2' or a == '4' or a == '5' or a == '7' or a == '9') {
      cout << "hon" << endl;
    }
    if (a == '0' or a == '1' or a == '6' or a == '8') {
      cout << "pon" << endl;
    }
    if (a == '3') {
      cout << "bon" << endl;
    }
  }
  else {
    int n = aa.length();
    char a = aa[n - 1];
    if (a == '2' or a == '4' or a == '5' or a == '7' or a == '9') {
      cout << "hon" << endl;
    }
    if (a == '0' or a == '1' or a == '6' or a == '8') {
      cout << "pon" << endl;
    }
    if (a == '3') {
      cout << "bon" << endl;
    }
  }
}


Measured memory_bytes: 3668
#include<stdio.h>

int main (void) {
  int a, b;
  scanf("%d %d", &a, &b);

  if (a > b) {
    printf("a > b\n");
  } else if (a < b) {
    printf("a < b\n");
  } else {
    printf("a == b\n");
  }

  return 0;
}

Measured memory_bytes: 2564
Imports System
Imports System.Collections.Generic
class p
    shared sub main()
        dim n = Console.ReadLine().Split()
        dim s = new List(of String)
        for i as Integer = 0 To Integer.Parse(n(0))-1
            s.Add(Console.ReadLine())
        next i
        s.sort()
        for each i As String In s
            Console.Write(i)
        next
    end sub
end class

Measured memory_bytes: 13780
#include <bits/stdc++.h>
#define watch(x) std::cout << (#x) << " is " << (x) << std::endl
#define print(x) std::cout << (x) << std::endl
#define println std::cout << std::endl;
using LL = long long;

int main() {
	//freopen("in","r",stdin);
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n;
	std::cin >> n;
	for (int i = 0; i < n; ++i) std::cout << "ACL";
	println;
	return 0;
}

Measured memory_bytes: 3584
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, A, B;

  std::cin >> N >> A >> B;

  std::cout << ((B - A) % 2 == 0 ? "Alice" : "Borys") << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using P = std::pair<int,int>;

int main(){
        int n, m;
        scanf("%d %d", &n, &m);
        std::vector<P> city[n];
        for(int i=0; i<m; i++){
                int p, y;
                scanf("%d %d", &p, &y);
                city[p-1].emplace_back(i, y);
        }

        std::vector<std::pair<int,P>> ls(0);
        auto cmp = [](P a, P b){return a.second<b.second;};
        for(int i=0; i<n; i++){
                std::sort(city[i].begin(), city[i].end(), cmp);
                for(int j=0; j<city[i].size(); j++) ls.emplace_back(city[i][j].first, P(i+1, j+1));
        }

        std::sort(ls.begin(), ls.end());
        for(auto p: ls){
                int r, y;
                std::tie(r, y) = p.second;
                printf("%06d%06d\n", r, y);
        }
        return 0;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N), B(N);
  for (ll i = 0; i < N; i++) cin >> A.at(i) >> B.at(i);
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (N % 2 == 1) {
    ll a = A.at(N / 2);
    ll b = B.at(N / 2);
    cout << b - a + 1 << endl;
  }else {
    ll a = A.at(N / 2 - 1) + A.at(N / 2);
    ll b = B.at(N / 2 - 1) + B.at(N / 2);
    cout << b - a + 1 << endl;
  }

  return 0;
}



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

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    cout<<abs(a[n-1]-a[0]);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream f ("test.in"); ofstream g ("test.out");
vector < int > v[100005];
int n,m,dp[100005],viz[100005];
int parcurge(int nod)
{   if(!v[nod].size())  return 0;
    if(viz[nod]) return dp[nod];
    viz[nod]=1;
    int rasp=0;
    for(int i=0;i<v[nod].size();i++)
    {   int vecin=v[nod][i];
        int raspvecin=parcurge(vecin);
        rasp=max(rasp,raspvecin+1);
    }
    return dp[nod]=rasp;
}
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m;
    for(int a,b,i=1;i<=m;i++)
    {   cin>>a>>b;
        v[a].push_back(b);
    }
    for(int i=1;i<=n;i++)
        if(!viz[i])
            parcurge(i);
    cout<<*(max_element(dp+1,dp+n+1));
    return 0;
}


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


int main(void)
{
    int n;
    int t;
    cin>>n;
    set<int> s;
    int i =1;
    while(i<=n)
    {
        cin>>t;
        s.insert(t);
        i++;
    }
    if(s.size()%2==1)
    {
        cout << s.size()<< endl;
    }
    else
    {
        cout << s.size()-1<< endl;
    }
    return 0;
}


Measured memory_bytes: 4864
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
typedef long long ll;
 
int main() {
    int N, K, x, ans = 0;
    cin >> N >> K;
    rep(i, N) {
        cin >> x;
        ans += min(x, K - x) * 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S=readline()
T=readline()

function solve(S,T)
t=length(T)
res=0
for i=0:length(S)-t
    c=0
for j=1:t
    
#         println(S[1+i:t+i])
    if S[1+i:t+i][j]==T[j]
        c+=1
    end 
    end
    res=max(res,c)
end

println(t-res)
end
solve(S,T)

Measured memory_bytes: 203324
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())

if N == 1:
    ans = [min(map(int, input().split())) for _ in range(Q)]
    print(*ans, sep="\n")
    exit()

ans = [-1] * Q
for i in range(Q):
    x, y = map(int, input().split())
    x_memo = [x]
    y_memo = [y]
    while x:
        x = (x + N - 2) // N
        x_memo.append(x)
    while y:
        y = (y + N - 2) // N
        y_memo.append(y)

    res = -1
    while x_memo and y_memo:
        xi = x_memo.pop()
        yi = y_memo.pop()
        if xi == yi:
            res = xi
        else:
            break
    ans[i] = res

print(*ans, sep="\n")

Measured memory_bytes: 9684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		String[] tokens = in.nextLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = Integer.parseInt(tokens[i]);
		}
		int count = 0;
		int color = 10001;
		for (int i = 1; i < n; ++i) {
			if (a[i - 1] == a[i]) {
				++count;
				a[i] = color;
				++color;
			}
		}
		System.out.println(count);
		in.close();

	}

}

Measured memory_bytes: 23636
def OrdinaryNumber(n,p,flag=None):
    
    #リストの要素数が3未満なら０を返す（再帰終了）
    if n < 3:
        return 0
    
    #p[0]<p[1]の場合
    if flag == "LessThan":
        if p[1] < p[2]:
            count = OrdinaryNumber(n-1, p[1:], "LessThan")+1
        else:
            count = OrdinaryNumber(n-1, p[1:], "GreaterThan")
            
    #p[0]>p[1]の場合
    elif flag == "GreaterThan":
        if p[1] < p[2]:
            count = OrdinaryNumber(n-1, p[1:], "LessThan")
        else:
            count = OrdinaryNumber(n-1, p[1:], "GreaterThan")+1
    
    #最初のみ
    else:
        if p[1] < p[2]:
            count = OrdinaryNumber(n-1, p[1:], "LessThan")
            if p[0] < p[1]:
                count +=1
        else:
            count = OrdinaryNumber(n-1, p[1:], "GreaterThan")
            if p[0] > p[1]:
                count +=1
                
    return count

n = int(input())
print(OrdinaryNumber(n,list(map(int,input().split()))))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define ALL(a) a.begin(), a.end()
#define REP(i,a) for(ll i(0), _##i(a); i < _##i; ++i)
#define FOR(i,a,b) for(ll i(a), _##i(b); i <= _##i; ++i)
using namespace std;
using ll = long long;

void solve(){
    string s;
    cin >> s;

    int n = s.size();
    REP(i, n){
        if (i + 1 < n && s[i] == s[i + 1]){
            cout << i + 1 << " " << i + 2 << "\n";
            return;
        }
        if (i + 2 < n && s[i] == s[i + 2]){
            cout << i + 1 << " " << i + 3 << "\n";
            return;
        }
    }
    cout << "-1 -1\n";
}

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

    int T = 1;
    //cin >> T;
    FOR(i,1,T){
        solve();
    }
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int p[1000006];

int main(void) {

	int X;
	cin >> X;
	int N = 1000000;
	for (int i = 2; i <= N; i++) {
		p[i] = 1;
	}

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

	/*for (int i = 1; i <= 30; i++) {
		if (p[i] == 1) { cout << i << endl; }
	}*/

	int ans;
	for (int i = X; i <= N; i++) {
		if (p[i] == 1) { ans = i; break; }
	}

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

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

using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

ll dfs(const vector<vecint>& g, vecint& a, vecint& b,
    int i, int p, vecll& flow) {
  ll sum = a[i] - b[i];
  for (auto&& to : g[i]) {
    if (to == p) continue;
    sum += dfs(g, a, b, to, i, flow);
  }
  flow[i] = sum;
  return sum;
}

void dfs2(const vector<vecint>& g, vecint& a, vecint& b,
    int i, int p, vecll& flow, ll current, vecll& sum) {
  sum[i] = flow[i] + current;
  for (auto&& to : g[i]) {
    if (to == p) continue;
    dfs2(g,a,b,to,i,flow,sum[i],sum);
  }
}

int main() {
  int n;
  cin>>n;
  vector<vecint> g(n);
  REP(i,n-1) {
    int u,v;
    cin>>u>>v;
    --u;--v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vecint a(n);
  for(auto&& e:a)cin>>e;
  vecint b(n);
  for(auto&& e:b)cin>>e;
  vecll flow(n);
  vecll sum(n);
  dfs(g,a,b,0,-1,flow);
  dfs2(g,a,b,0,-1,flow,0,sum);
  ll mn = *min_element(ALL(sum));
  for(auto&& e:sum) e -= mn;
  ll ans = 0;
  for(auto&& e:sum) ans += e;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 20756
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

ll N,M,S,T;
vv_ll G;
vv_ll A;
int main(){
  cin >> N >> M;
  G.assign(N+10,v_ll());
  A.assign(N+10,v_ll(3,-1));
  for (ll i=1;i<=M;i++){
    ll x,y;
    cin >> x>>y;
    G[x].push_back(y);
  }
  cin >> S >> T;
  queue<ll>que;
  que.push(S);
  A[S][0]=0;
  while(!que.empty()){
    ll f=que.front();
    que.pop();
    ll x=f%N;
    if (x==0)x=N;
    ll y=(f-1)/N;
    ll z=(y+1)%3;
    for (ll j=0;j<G[x].size();j++){
      ll moveto=G[x][j];
      if (A[moveto][z]==-1){
        que.push(moveto+z*N);
        A[moveto][z]=A[x][y]+1;
      }
    }
  }
  TEST=false;
  //show(G);
  //show(A);
  ll ans=A[T][0];
  if (ans<0){
    cout << -1 <<endl;
  }
  else cout << ans/3 <<endl;
}


Measured memory_bytes: 11768
#include <stdio.h>

void DispArg(int elem[], int num)
{
    int i;

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

    return;
}

int main(void)
{
    int i, j, k;
    int num;
    int tmp;
    int elem[100];

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        scanf("%d", &elem[i]);
    }

    DispArg(elem, num);

    for (i = 1; i < num; i++) {
        int v = elem[i];
        for (j = i; j > 0; j--) {
            if (v < elem[j-1]) {
                elem[j] = elem[j-1];
            }
            else {
                break;
            }
        }
        elem[j] = v;
        DispArg(elem, num);
    }

    return 0;
}

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

typedef vector<int> vi;

int parse(string x, int &i)
{
	i++;
	if (x[i] != '[')
	{
		int v = 0;
		while (x[i] != ']')
		{
			v = v * 10 + x[i] - '0';
			i++;
		}
		i++;

		return v / 2 + 1;
	}

	vi vec;
	while (x[i] != ']')
	{
		vec.push_back(parse(x, i));
	}
	i++;

	sort(vec.begin(), vec.end());
	int ret = 0;
	rep(i, 0, vec.size() / 2 + 1) ret += vec[i];
	return ret;
}

int main()
{
	int n; cin >> n;
	rep(_n, 0, n)
	{
		string s; cin >> s;

		int i = 0;
		cout << parse(s, i) << endl;
	}
}

Measured memory_bytes: 3240
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);
	boolean second = false;
	while ( stdin.hasNext() ) {

	    if ( second ) {
		System.out.println();
	    }
	    
	    int n = stdin.nextInt();
	    final int[] digit = new int[5];

	    for ( int i = 0; i < digit.length; i++ ) {
		digit[i] = n % 10;
		n /= 10;
	    }

	    for ( int i = 4; i >= 0; i-- ) {
		if ( digit[i] < 5 ) {
		    System.out.print("*");
		} else {
		    System.out.print(" ");
		}
	    }
	    System.out.println();

	    for ( int i = 4; i >= 0; i-- ) {
		if ( digit[i] >= 5 ) {
		    System.out.print("*");
		} else {
		    System.out.print(" ");
		}
	    }
	    System.out.println();
	    
	    for ( int i = 4; i >= 0; i-- ) {
		System.out.print( "=" );
		if ( digit[i] >= 5 ) {
		    digit[i] -= 5;
		}
	    }
	    System.out.println();

	    for ( int i = 0; i < 5; i++ ) {
		for ( int j = 4; j >= 0; j-- ) {
		    if ( digit[j] == i ) {
			System.out.print( " " );			
		    } else {
			System.out.print( "*" );
		    }
		}
		System.out.println();
	    }
	    second = true;
	}
	
    }
    
}

Measured memory_bytes: 28144
#include <iostream>
#define oo 1000000007
typedef long long LL;
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	
	LL sum1 = 0, sum2 = 0, ans = 0;
	for (int i = 0,  j = n; i <= n; i++, j--){
		sum1 += i;
		sum2 += j;
		if (i >= k - 1){
			ans = (LL)(ans + (sum2 + 1 - sum1)) % oo;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define ll long long

using namespace std;

int pmod(int x, int y, int p){ int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1)  res = (res*x) % p;  y = y>>1; x = (x*x) % p; } return res; }  
ll pmod(ll x, ll y, ll p){ ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1)  res = (res*x) % p;  y = y>>1; x = (x*x) % p; } return res; } 
ll floorRoot5(ll n) 
{ 
    
    if (n == 0 || n == 1) 
        return n; 
 
    ll res = 0; 
  
    while (res*res*res*res*res <= n) 
        res++; 
  
    return res-1; 
} 


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

	int x;
	cin >> x;

	for(ll b = -1e3; b < 1e3; ++b){
		ll a = floorRoot5(pow(b,5) + x);
		if(pow(a,5) - pow(b,5) == x){
			cout << a << " " << b;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 4116
r=[int(input()) for _ in range(5)]
#1桁目が最小のものを求める
l=0
for i in range(5):
  if r[l]%10>r[i]%10 and r[i]%10!=0:
    l=i
ans=0
for i in range(5):
  if l==i:
    ans+=r[i]
  else:
    ans+=(r[i]+9)//10*10

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int n,a,b,c,d,e;
  cin >>n ;
  cin >>a ;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
    
 
  
  cout << (n+min({a,b,c,d,e})-1)/min({a,b,c,d,e}) +4 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll nax= 1e5+5;
ll vertices, edges;
vector<ll> graph[nax];
ll indegree[nax];
ll dist[nax];
bool visited[nax];
void dfs(ll a){
    visited[a]=true;
    for(auto b: graph[a]){
        dist[b]=max(dist[b], 1+dist[a]);
        --indegree[b];
        if(indegree[b]==0){
            dfs(b);
        }
    }
}

int main(){
cin>>vertices>>edges;
ll i,x,y;
for(i=0;i<edges;i++){
    cin>>x>>y;
    graph[x].push_back(y);
    indegree[y]++;
}
for(i=1;i<=vertices;i++){
    dist[i]=0;
    visited[i]=false;
}
for(i=1;i<=vertices;i++){
    if(!visited[i]&&indegree[i]==0){
        dfs(i);
    }
}
ll ans=INT_MIN;
for(i=1;i<=vertices;i++){
    ans=max(ans, dist[i]);
}

cout<<ans<<endl;



    return 0;
}

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

#pragma GCC diagnostic warning "-Wconversion"

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) begin(a), end(a)
#define has(a, b) (a.find(b) != a.end())
#define fora(i, n) for(int i = 0; i < n; i++)
#define forb(i, n) for(int i = 1; i <= n; i++)
#define forc(a, b) for(const auto &a : b)
#define ford(i, n) for(int i = n; i >= 0; i--)
#define maxval(t) numeric_limits<t>::max()
#define minval(t) numeric_limits<t>::min()
#define imin(a, b) a = min(a, b)
#define imax(a, b) a = max(a, b)

#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)

using ll = long long;

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

        cout << 50 << endl;

        ll n;
        cin >> n;

        ll div = n / 50;
        int mod = (int)(n % 50);


        ++div;
        int su = 50 - mod;
        ll co = div + 49;
        ll of = su - 50 - 1;

        fora(i, su)
        {
                cout << co + of << " ";
        }

        fora(i, 50 - su)
        {
                cout << co << " ";
        }
        cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, A, B;

int main() {
	cin >> N;
	if (N == 1) {
		cout << "Hello World" << endl;
	}
	else {
		cin >> A >> B;
		cout << A + B << endl;
	}
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$array = str_split(trim(fgets(STDIN)));
$array2 = $array;

$count = 1;
foreach ($array as $k => $v) {
  if ($k + 1 < count($array2) && $v != $array2[$k + 1]) {
    $count++;
  }
}

echo $count;


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

#define int long long
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

int N, C;
int x[110000], v[110000];
int x_rev[110000];
int imos_tokei[110000], imos_hanto[110000];
int max_tokei[110000], max_hanto[110000];

signed main() {
    cin >> N >> C;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> v[i];
        x_rev[i] = C - x[i];
        imos_tokei[i] = v[i];
        imos_hanto[i] = v[i];
    }
    for (int i = 1; i < N; i++) {
        imos_tokei[i] += imos_tokei[i - 1];
    }
    for (int i = N - 2; i >= 0; i--) {
        imos_hanto[i] += imos_hanto[i + 1];
    }

    max_tokei[0] = imos_tokei[0] - x[0];
    for (int i = 1; i < N; i++) {
        max_tokei[i] = max(max_tokei[i - 1], imos_tokei[i] - x[i]);
    }

    max_hanto[N - 1] = imos_hanto[N - 1] - x_rev[N - 1];
    for (int i = N - 2; i >= 0; i--) {
        max_hanto[i] = max(max_hanto[i + 1], imos_hanto[i] - x_rev[i]);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, imos_tokei[i] - x[i]);
        ans = max(ans, imos_hanto[i] - x_rev[i]);
        if (i != N)
            ans = max(ans, imos_tokei[i] - x[i] - x[i] + max_hanto[i + 1]);
        if (i != 0)
            ans = max(ans,
                      imos_hanto[i] - x_rev[i] - x_rev[i] + max_tokei[i - 1]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  deque<ll> deq;
  ll q;
  cin >> q;
  REP(i,q){
    ll com;
    cin >> com;
    if(com == 0){
      ll d, x;
      cin >> d >> x;
      if(d == 0) deq.push_front(x);
      else deq.push_back(x);
    }
    else if(com == 1){
      ll p;
      cin >> p;
      cout << deq[p] <<endl;
    }
    else{
      ll d;
      cin >> d;
      if(d == 0) deq.pop_front();
      else deq.pop_back();
    }
  }


  return 0;
}




Measured memory_bytes: 6288
A = list(map(int, input().split()))

a = abs(A[0] - A[1]) + abs(A[1] - A[2])
b = abs(A[0] - A[1]) + abs(A[0] - A[2])
c = abs(A[0] - A[2]) + abs(A[1] - A[2])

print(min(a, b, c))

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

int main(){
    int A, B, price;
    cin >> A >> B;
    if(A<=5){
        price = 0;
    }else if(A>=13){
        price = B;
    }else{
        price = B / 2;
    }
    cout << price <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

struct edge {
	int to, num;
};

signed main(){
	int n;
	cin >> n;
	std::vector<edge> d[100001];
	int color[100001]={};//点iの親の色リスト
	bool flag[100001]={};
	int ans[100001];
	queue<int> q;
	int deg[100001];
	int maxd = 1;
	LOOP(i,n-1){
		int a,b;
		cin >> a >> b;
		d[b].push_back({a,i});
		d[a].push_back({b,i});

		deg[a]++;	deg[b]++;
		if(deg[maxd] < deg[a]){
			maxd = a;
		}if(deg[maxd] < deg[b]){
			maxd = b;
		};
	}

	LOOP(i,d[maxd].size()){
		//さいこうじの点から各点に1から番号をつける
		// cerr << "*" << i << ":" << maxd;
		int to = d[maxd][i].to;
		int num = d[maxd][i].num;
		// cerr << "*" << to << ":" << num;
		ans[num]=i+1;
		color[to]=i+1;
		// cerr << "complete" << endl;
		q.push(to);
	}
	flag[maxd]=true;
	// cerr << "LOL" << endl;
	while(!q.empty()){
		int p = q.front(); q.pop();
		// cerr << "*" << p << endl;
		int j = 1;
		LOOP(i,d[p].size()){
			int to = d[p][i].to;
			int num = d[p][i].num;
			if(flag[to])continue;
			// cerr << " - " << to << ":" << num;
			if(j == color[p]){
				j++;
			}
			// cerr << ":" << j << endl;
			ans[num] = j;
			color[to] = j;
			q.push(to);

			j++;
		}
		flag[p]=true;
	}
	cout << deg[maxd] << endl;
	LOOP(i,n-1){
		cout << ans[i] << endl;
	}
}


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

int search(int n){
    int sum =0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}

int main (){
    int N,A,B;
    cin >> N >> A >> B;
    int total=0;
    for(int i=1;i<=N;i++){
        int sum=search(i);
        if(sum>=A && sum<=B){
            total+=i;
        }
    }
    cout << total <<endl;
}

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

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int x = in.nextInt();
        if (x <= 2) {
            out.println(2);
        } else {
            out.println(getPrime(x));
        }
    }

    static int getPrime(int n) {
        int num = 3;
        List<Integer> primes = new ArrayList<>();
        primes.add(2);
        while (true) {
            boolean isPrime = true;
            for (int prime : primes) {
                if (prime * prime > num) {
                    break;
                }
                if (num % prime == 0) {
                    isPrime = false;
                    break;
                }
            }
            if (isPrime) {
                if (n <= num) {
                    return num;
                }
                primes.add(num);
            }
            num += 2;
        }
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private static PrintWriter out = new PrintWriter(System.out);

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 24404
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
long long gcd(long long a,long long b){
    if(a<b) swap(a,b);
    while(a%b!=0){
        swap(a,b);
        b = b%a;
    }
    return b;
}
vector<long long> primes(long n){
    bool judge[n+1];
    for(int i = 0;i<=n;i++){
        judge[i] = true;
    }
    vector<long long> prime;
    for(int i = 2;i<=n;i++){
        if(judge[i]){
            for(int j = 2*i;j<=n;j+=i){
                judge[j] = false;
            }
            prime.push_back(i);//ここでprimeに入れられる素数の条件を指定できる
        }
    } 
    return prime;
}
int main(){
    long long a,b;
    cin >> a >> b;
    long long gcdab = gcd(a,b);
    vector<long long> prime = primes(long(1e6+4));
    long ans = 1;
    for(int i = 0;i<prime.size();i++){
        if(gcdab%prime[i]==0) ans++;
        while(gcdab%prime[i]==0){
            gcdab/=prime[i];
        }
    }
    if(gcdab!=1) ans++;
    cout << ans << endl;
}

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

int main() {
	char S[5];
	double ans = 0;

	for (int i = 0; i < 4; i++) {
		cin >> S[i];
		if (S[i] == '+') {
			ans += 1;
		}
		else {
			ans -= 1;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

ll lcm(ll a, ll b) {
    return a / __gcd(a, b) * b;
}

void SOE(ll N, vi & p) {
    int m = int(floor(sqrt(N))) + 1;
    int s[m];
    REP(i ,m) s[i] = i;

    FOR (i, 2, m) {
        if (s[i] != i) continue;

        p.pb(i);

        for (int j = i+i; j <= m; j += i) {
            s[j] = i;
        }
    }
}

void solve(int n, vll& a) {
    ll g = a[0];
    REP(i, n) g = __gcd(g, a[i]);

    vector<int> prime;
    SOE(1e12, prime);

    vi c(1e6 + 10, 0);

    REP(i, n) c[a[i]]++;

    bool f = true;
    for(auto &e: prime) {
        int cnt = 0;
        for(int i = e; i <= 1e6; i += e) {
            cnt += c[i];
        }

        if (cnt > 1) f = false;
    }

    if (f) {
        print("pairwise coprime");
    } else {
        if (g == 1) {
            print("setwise coprime");
        }
        else print("not coprime");
    }
}

int tle(int n, vll &a) {
    ll g = a[0];
    REP(i, n) g = __gcd(g, a[i]);

    bool f = true;
    REP(i, n) FOR(j, i + 1, n) {
        f &= __gcd(a[i], a[j]) == 1;
//        debug(a[i], a[j], __gcd(a[i], a[j]))
    }

    if (f) {
        return  1;
    } else {
        if (g == 1) return 2;
        return 3;
    }
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);


    int n;
    cin >> n;

    vll a(n); REP(i, n) cin >> a[i];

    solve(n, a);
}


Measured memory_bytes: 19292
n=int(input())
s=input()
t=sorted(s)
t.append("X")
cnt=1
ans=1
for i in range(n):
    if t[i]==t[i+1]:
        cnt+=1
    else:
        ans*=(cnt+1)
        cnt=1
print((ans-1)%(10**9+7))

Measured memory_bytes: 4404
import copy


def bubble(_v):
    v = copy.copy(_v)
    n = len(v)
    for i in range(n):
        for j in range(n-1, i, -1):
            if v[j][1] < v[j-1][1]:
                v[j], v[j-1] = v[j-1], v[j]
    return v


def selection(_v):
    v = copy.copy(_v)
    n = len(v)
    for i in range(n):
        mi = i
        for j in range(i, n):
            if v[j][1] < v[mi][1]:
                mi = j
        v[i], v[mi] = v[mi], v[i]
    return v


n = int(input())
v = input().split()

b = bubble(v)
s = selection(v)
print(" ".join(b))
print("Stable")
print(" ".join(s))
print("Stable" if b == s else "Not stable")



Measured memory_bytes: 6344
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<int> A(N);
    vector<long long> cumsum(N+1);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        cumsum[i+1] = (cumsum[i] + A[i]) % 1000000007;
    }
    mint ans = 0;
    for (int i = 0; i < N; i++) {
        ans += (mint)A[i] * (cumsum[N] - cumsum[i+1]);
    }
    cout << ans << '\n';
}

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

    solve();

    return 0;
}

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

int main() {
	int n = 0, a = 0, b = 0, c = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a >> b >> c;
		if (c < a) swap(c, a); // a <= c && b <= c ?????????
		if (c < b) swap(c, b);
		if (a*a + b*b == c*c) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

//.define
// #define FILE_IN_OUT
#define RET(_x)    return cout << (_x) << '\n', 0;
#define all(_obj)  (_obj).begin(), (_obj).end()
#define loop(_n)   for (int i = 0; i < (_n); ++i)
#define sz(_obj)   static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)  std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)  {}
#endif
#define endl "\n"
template<typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
int Add(int x, int y) {
    x += y;
    return x < MOD ? x : x - MOD;
}

int Sub(int x, int y) {
    x -= y;
    return x >= 0 ? x : x + MOD;
}

int Mul(int x, int y) {
    return int(1LL * x * y % MOD);
}

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n;
    cin >> n;
    vector<int> arr(n);
    int sum = 0;
    int sum2 = 0;
    loop(n) {
        cin >> arr[i];
        sum = Add(sum, arr[i]);
        sum2 = Add(sum2, Mul(arr[i], arr[i]));
    }
    int ans = Sub(Mul(sum, sum), sum2);
    ans = Mul(ans, (MOD + 1) / 2);
    cout << ans << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 3988
while True:
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for _ in range(n)]
    minv = tmp = 0
    maxv = -500000
    for i in range(n):
        tmp += a[i]
        maxv = max(maxv, tmp - minv)
        minv = min(minv, tmp)
    print(maxv)

Measured memory_bytes: 7776
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
using ll = long long;
 
const int nax = 10123;
char k[nax];
const int mod = 1e9 + 7;
 
void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}
 
int main() {
    scanf("%s", k);
    int D;
    scanf("%d", &D);
    int len = strlen(k);
    vector<array<int,2>> dp(D, array<int,2>{});
    // dp[sum][smaller_already] - the number of ways to choose digits so far
    // such that the sum of digits modulo D is 'sum' and 'smaller_already'
    // says whether we already chosen some digit smaller than in K
    dp[0][0] = 1;
    for(int where = 0; where < len; ++where) {
        vector<array<int,2>> new_dp(D, array<int,2>{});
        for(int sum = 0; sum < D; ++sum) {
            for(bool sm_already : {false, true}) {
                for(int digit = 0; digit < 10; ++digit) {
                    if(digit > k[where] - '0' && !sm_already) {
                        break;
                    }
                    add_self(new_dp[(sum + digit) % D][sm_already || (digit < k[where]-'0')],
                        dp[sum][sm_already]);
                }
            }
        }
        dp = move(new_dp);
    }
    int answer = (dp[0][false] + dp[0][true]) % mod;
    --answer;
    if(answer == -1) {
        answer = mod - 1;
    }
    printf("%d\n", answer);
}

Measured memory_bytes: 256