akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var qhsd = Reads();
            var n = Read();
            var q = qhsd[0];
            var h = qhsd[1];
            var s = qhsd[2];
            var d = qhsd[3];
            var x = new long[] { 8 * q, 4 * h, 2 * s, d };
            Array.Sort(x);

            if (x.Min() == d) Console.WriteLine(n / 2* x.Min() + x[1] * (n % 2)/2);
            else Console.WriteLine(x.Min() * n / 2);

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

    vector<pair<int,int>> que(q);
    REP(i,q){
        cin >> que[i].first;
        cin >> que[i].second;
        que[i].first--;
        que[i].second--;
    }

    vector<int> cnt(n, 0);
    FOR(i,1,n){
        if(s[i-1] == 'A' && s[i] == 'C'){
            cnt[i] = cnt[i-1] + 1;
        }
        else{
            cnt[i] = cnt[i - 1];
        }
    }

    REP(i,q){
        cout << cnt[que[i].second] - cnt[que[i].first] << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素



signed main(){
  int N,K;
  cin>>N>>K;
  int h[N];
  int i;
  REPD(i,N)cin>>h[i];
  K=min(K,N);
  ll dp[N];
  dp[0]=0;
  for(int i=1;i<K;i++){
    dp[i]=abs(h[i]-h[0]);
  }
  for(int i=K;i<N;i++){
    ll result=dp[i-K]+abs(h[i]-h[i-K]);
    for(int j=1;j<K;j++){
      result=min(result,dp[i-(K-j)]+abs(h[i]-h[i-(K-j)]));
    }
    dp[i]=result;
  }
  cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n;
    cin >> n;
    vector<ll> v(n), c(n);
    REP(i, n) cin >> v[i];
    REP(i, n) cin >> c[i];

    ll ans = 0;
    REP(i, n) {
        if (v[i] - c[i] > 0) {
            ans += v[i] - c[i];
        }
    }
    cout << ans << endl;
    
}

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

int main()
{
	int h, m, s;

	for (int i = 0; i < 3; i++){
		int sec[2];
		for (int j = 0; j < 2; j++){
			cin >> h >> m >> s;
			sec[j] = h * 3600 + m * 60 + s;
		}
		int diff = sec[1] - sec[0];
		
		cout << diff / 3600 << " " << diff % 3600 / 60 << " " <<  diff % 3600 % 60 << endl;
	}

	return (0);
}

Measured memory_bytes: 1160
#include<stdio.h>


int main(){
	
	int n,m;
	int input[100000];
	int cont;
	int now;
	int max;
	int i;
	while(1){
		
		scanf("%d%d",&n,&m);
		if(n==0 && m ==0){
			break;
		}
		
		for(i=0;i<n;i++){
			scanf("%d",&input[i]);
		}
		
		now = 0;
		
		for(i=0;i<m;i++){
			now += input[i];
		}
		max=now;
		
		cont = m;
		
		for(i=m;i<n;i++){
			now-=input[i-m];
			now+=input[i];
			
			if(now>max){
				max=now;
			}
		}
		
		printf("%d\n",max);
	}
	
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//ceil(a/(double)b)=(a+b-1)/b
//printf("myco\n");//for debug
/*--------------------------------------------*/
int main(){
    ll n;cin>>n;
    VLL h(n);rep(i,n)cin>>h[i];
    bool ok=true;
    ll pre=-INF;
    for(ll i=1;i<n;i++){
        if(pre>h[i])ok=false;
        if(!ok){
            //cout<<i<<" "<<h[i-2]<<" "<<h[i-1]<<" "<<h[i]<<" "<<h[i+1]<<endl;
            break;
        }
        if(pre!=h[i])pre=h[i]-1;
    }
    cout<<(ok?"Yes":"No")<<endl;
}




Measured memory_bytes: 1024
using System;
using System.Linq;

class E
{
	static void Main()
	{
		var N = int.Parse(Console.ReadLine());
		var S = Console.ReadLine();
		var s = new bool[N];
		for (var i = 0; i < N; i++) s[i] = S[i] == 'o';
		var b = new bool[N];
		for (var x = 0; x < 2; x++)
			for (var y = 0; y < 2; y++)
			{
				var answer = Func(x == 1, y == 1, s, N);
				if (answer != "-1")
				{
					Console.WriteLine(answer);
					return;
				}
			}
		Console.WriteLine(-1);
	}
	static string Func(bool r0, bool r1, bool[] s, int N)
	{
		var a = new bool[N];
		a[0] = r0;
		a[1] = r1;
		for (var i = 1; i + 1 < N; i++) a[i + 1] = a[i - 1] == (a[i] == s[i]);
		if ((s[0] == a[0]) == (a[1] == a[N - 1]) && (s[N - 1] == a[N - 1]) == (a[N - 2] == a[0]))
			return string.Join("", a.Select(z => z ? "S" : "W"));
		else return "-1";
	}
}

Measured memory_bytes: 13392
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int N,X;
	cin >> N;
	cin >> X;
	int ans = 1;
	int D = 0;
	for (int i = 0; i < N; i++)
	{
		int L;
		cin >> L;
		D += L;
		if (D <= X)
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[4]={0,0,1,1};
int dy[4]={0,1,0,1};
const int SIZE=1000050;
//ここまでテンプレ
int main(){
    string S;
    cin>>S;
    int ans=INF;
    for(int i=0;i<S.length()-2;i++){
        int N=0;
        N+=(int(S[i]-'0'))*100;
        N+=int(S[i+1]-'0')*10;
        N+=int(S[i+2]-'0');
        ans=min(ans,abs(N-753));
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n,x=map(int,input().split())

patty = [2**(i+1)-1 for i in range(n+1)][::-1]
length = [2**(i+2)-3 for i in range(n+1)][::-1]

ans=0
end=[0,1,2,3,3]

for i in range(n):
    hambergar=[1,1+length[i+1],2+length[i+1],2+2*length[i+1],3+2*length[i+1]]
    if i==n-1:
        ans+=end[x-1]
    else:
        if hambergar[0]<x and x<hambergar[2]:
            x-=1
        
        elif hambergar[2]<x and x<hambergar[4]:
            ans+=patty[i+1]+1
            x-=hambergar[2]
        
        elif hambergar[2]==x:
            ans+=patty[i+1]+1
            break

        elif hambergar[4]==x:
            ans+=patty[i]
            break
        
        elif hambergar[4]<x or x<=1:
            break

print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題167


            long N = long.Parse(Console.ReadLine());

            string[] line = Console.ReadLine().Split(' ');


            long[] A = new long[N];

            for (int i = 0; i < N; i++)
            {
                A[i] = long.Parse(line[i]);
            }


            long kane = 1000;
            long kabu = 0;


            for (int i = 0; i < N - 1; i++)
            {
                //株うる
                if (kabu > 0)
                {
                    kane += kabu * A[i];
                    kabu = 0;

                    //Console.WriteLine(i);
                }

                //株かう
                if (A[i] < A[i + 1])
                {
                    kabu = kane / A[i];
                    kane = kane % A[i];

                    //Console.WriteLine("aaaa");
                    //Console.WriteLine(i);
                    //Console.WriteLine(kabu);
                    //Console.WriteLine(kane);


                }
            }

            if (kabu > 0)
            {
                kane += A[N-1] * kabu;
                kabu = 0;
            }

            Console.WriteLine(kane);


        }


    }
}


Measured memory_bytes: 27532
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  int n, k;
  cin >> n >> k;
  vector<bool> available(10, true);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    available[d] = false;
  }
  vector<int> d;
  for (int i = 0; i < 10; i++) {
    if (available[i])
      d.push_back(i);
  }
 
  queue<int> q;
  q.push(0);
  while (true) {
    auto cur = q.front();
    q.pop();
    if (cur >= n) {
      cout << cur << endl;
      return 0;
    }
    for (auto x : d) {
      if (cur == 0 && x == 0)
        continue;
      q.push(cur * 10 + x);
    }
  }
  exit(1);
 
  return 0;
}

Measured memory_bytes: 3728
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s,t,some;
	int ans=0;
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		if(s[i]==t[t.size()-1-i]){
			ans++;
		}
	}
	if(ans==s.size()){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
input()
rates = [int(x) for x in input().split(' ')]

colors = set()

for rate in rates:
    if rate in range(1, 400):
        colors.add('gray')
    elif rate in range(800):
        colors.add('brown')
    elif rate in range(1200):
        colors.add('green')
    elif rate in range(1600):
        colors.add('lightblue')
    elif rate in range(2000):
        colors.add('blue')
    elif rate in range(2400):
        colors.add('yellow')
    elif rate in range(2800):
        colors.add('orange')
    elif rate in range(3200):
        colors.add('red')

print(max(len(colors), 1), len(colors) + len([x for x in rates if x >= 3200]))


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

typedef long long ll;

int N;
ll mem[10];
ll ans;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        char S[15];
        scanf(" %s",S);
        if(S[0] == 'M')mem[0]++;
        if(S[0] == 'A')mem[1]++;
        if(S[0] == 'R')mem[2]++;
        if(S[0] == 'C')mem[3]++;
        if(S[0] == 'H')mem[4]++;
    }

    for(int i = 0; i < 5; i++)
    {
        for(int j = i + 1; j < 5; j++)
        {
            for(int k = j + 1; k < 5; k++)
            {
                ans += mem[i] * mem[j] * mem[k];
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
#define ii pair<int, int>
#define fi first
#define se second
const int MAX = 200000; //2 * 10^5
const int MOD = 1000000007; //10^9 + 7
const int OO = 0x3f3f3f3f; // 0x3f3f3f3f;

int32_t main()
{
	int n, m;
	
	cin >> n >> m;
	
	int s = 0;
	
	for(int i = 0; i < m; i++)
	{
		int x;
		cin >> x;
		s += x;
	}
	
	if(s > n) return puts("-1"), 0;
	
	cout << n - s << endl;


	return 0;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
 
using namespace std;

const int N = 2e5 + 123;
const ll mod = 1e9 + 7;             

int n;
ll h[N], a[N], c[N];
ll t[N];

bool cmd(int x, int y){
	return h[x] < h[y];
}

void upd(int v, ll val){
	for(;v <= n;v |= (v + 1)){
		t[v] = max(t[v], val);
	}
}

ll get(int v){
	ll res = 0;
	for(;v >= 0;v = (v & (v + 1)) - 1)
		res = max(res, t[v]);
	return res;
}

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

	cin >> n;
	for(int i = 1;i <= n;i++)
		cin >> h[i];
	for(int i = 1;i <= n;i++)
		cin >> a[i];
	for(int i = 1;i <= n;i++)
		c[i] = i;

	sort(c + 1, c + n + 1, cmd);
	ll res = 0;
	for(int i = 1;i <= n;i++){
		int id = c[i];
		ll val = a[id] + get(id);
		res = max(res, val);
		upd(id, val);
	}
	cout << res;
}

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

int main() {
    int s[5],ans=0;
    vector<int>a;
    
    for(int i=0;i<5;++i){
        cin>>s[i];
        if(s[i]%10 !=0) {
            a.push_back(s[i]%10);
            ans+=s[i]- s[i]%10 + 10;
        }
        else ans+=s[i];
    }
    
    if(a.size()!=0){
        sort(a.begin(),a.end());
        ans=ans -10+a[0];
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
typedef long long ll;
int main() {
	char s[200001];
	int mod2019[2019] = {1};
	int dig = 1;
	scanf("%s", s);
	int len = strlen(s);
	ll ans = 0, sum = 0;
	for (int i = len - 1; i >= 0; i--) {
		sum = (sum + (s[i] - '0') * dig) % 2019;
		sum %= 2019;
		mod2019[sum]++;
		dig = dig * 10 % 2019;
		// printf("%lld\n", sum);
	}
	for (int i = 0; i < 2019; i++) {
		ans += (ll)mod2019[i] * (mod2019[i] - 1) / 2;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1936
package main

import (
	"fmt"
)

func solve(L []int) int {
	count := 0
	n := len(L)

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			for k := j + 1; k < n; k++ {
				if (L[i]+L[j] > L[k]) && (L[k]+L[j] > L[i]) && (L[k]+L[i] > L[j]) {
					if L[i] != L[j] && L[j] != L[k] && L[k] != L[i] {
						count++
					}
				}
			}
		}
	}

	return count
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func main() {
	var N int
	fmt.Scan(&N)

	L := scanNums(N)

	result := solve(L)
	fmt.Println(result)
}


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

using namespace std;

struct edge{
  int t,d;
};

int bit[10];
map<int,map<int,int> > mem;
int d[11][11];
int INF=1<<29;

int rec(int b,int p,int u){
  if(b==0)return d[p][0];
  if(mem[p].count(b))return mem[p][b];
  int m=INF;
  for(int i=0;i<11;i++){
    if(u>>i&1)continue;
    int nb=b&~bit[i-1];
    m=min(m,rec(nb,i,u|1<<i)+d[p][i]);
  }
  return mem[p][b]=m;
}

int main(){
  for(int n;cin>>n,n;){
    map<string,int> mc;
    map<string,int> sp[10];
    for(int i=0;i<n;i++){
      int k;
      cin>>k;
      while(k--){
	string n;
	int v;
	cin>>n>>v;
	if(mc.count(n)==0||mc[n]>v){
	  mc[n]=v;
	}
	if(sp[i].count(n)==0||sp[i][n]>v){
	  sp[i][n]=v;
	}
      }
      bit[i]=0;
    }
    int q;
    cin>>q;
    int sum=0;
    for(int i=0;i<q;i++){
      string name;
      cin>>name;
      sum+=mc[name];
      for(int j=0;j<n;j++){
	bit[j]|=(sp[j].count(name)&&sp[j][name]==mc[name])<<i;
      }
    }
    int m;
    cin>>m;
    fill(d[0],d[11],INF);
    for(int i=0;i<m;i++){
      int s,t,di;
      cin>>s>>t>>di;
      d[s][t]=d[t][s]=min(d[s][t],di);
    }
    for(int i=0;i<11;i++){
      for(int j=0;j<11;j++){
	for(int k=0;k<11;k++){
	  d[j][k]=min(d[j][i]+d[i][k],d[j][k]);
	}
      }
    }
    mem.clear();
    int md=rec((1<<q)-1,0,1);
    if(q==0){
      cout<<"0 0"<<endl;
    }else if(md>=INF){
      cout<<"impossible"<<endl;
    }else{
      cout<<sum<<' '<<md<<endl;
    }
  }
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  vector<int> exps(0);
  exps.push_back(1);
  for(int b=2; b<32; b++){
    for(int p=2; p<10; p++){
      if(pow(b, p)>1000){break;}
      exps.push_back(pow(b, p));
    }
  }
  sort(exps.begin(),exps.end());
  exps.erase(unique(exps.begin(),exps.end()),exps.end());
  for(int i=(exps.size()-1);i>=0;i--){
    if(n>=exps.at(i)){
      cout<<exps.at(i)<<endl;
      break;
    }
  }
}

Measured memory_bytes: 512
n, m = map(int, input().split())

roads = {}
for i in range(1, n + 1):
    roads[i] = []

for _ in range(m):
    a, b = map(int, input().split())
    roads[a].append(b)
    roads[b].append(a)

for i in sorted(roads):
    print(len(roads[i]))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int a[200000];
int b[200000];
int main(){
    while(1){
    int n;
    scanf("%d",&n);
    if(n == 0)
        break;
    REP(i,n)
        scanf("%d%d",a + i,b + i);

    int ap = 0,bp = 0;

    REP(i,n){
        if(a[i] > b[i])
            ap += a[i] + b[i];
        else if(a[i] < b[i]) 
            bp += a[i] + b[i];
        else{
            ap += a[i];
            bp += b[i];
        }
    }
    printf("%d %d\n",ap,bp);
    }
    return 0;
}

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

int main() {
  string a;
  cin >> a;
  if(a=="Sunny"){
    cout << "Cloudy" << endl;
  }
  else if(a=="Cloudy"){
    cout << "Rainy" << endl;
  }
  else {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
etime=[]
for i in range(5):
  etime.append(int(input()))
  
atime=[int(((i-1)//10+1)*10) for i in etime]
A=sum(atime)
c=[]
for k in range(5):
  c.append(A-atime[k]+etime[k])
  
print(min(c))
  
       


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


using namespace std;

vector<vector<int>> vec(100007);
int n;

long long meme[100007][5];


long long solve(int index, int flag){
    if(index==n){
        return 0;
    }
    
    long long &res = meme[index][flag]; 
    
    if(res != -1){
        return res;
    }
    res = 0;
    
    if(flag!=0){
        res = max(res,vec[index][0]+solve(index+1,0));
    }
    if(flag!=1){
        res =  max(res,vec[index][1]+solve(index+1,1));
    }
    if(flag!=2){
        res =  max(res,vec[index][2]+solve(index+1,2));
    }
    return res;
}

int main(){
    cin>>n;
    int num1,num2,num3;
    memset(meme,-1,sizeof(meme));
    for(int i = 0 ; i<n ; i++){
        cin>>num1>>num2>>num3;
        vec[i].push_back(num1);
        vec[i].push_back(num2);
        vec[i].push_back(num3);
    }
    long long sol = solve(0,3);
    cout<<sol<<endl;
    return 0;
}

Measured memory_bytes: 20340
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let x: i32 = read();
    let a: i32 = read();

    let ans = if x < a { 0 } else { 10 };
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>
int my_index(double *, double, int);
double my_min(double *, int);

int main(void){
  int N, a[110], i, sum = 0;
  double ave, d[110];

  scanf("%d", &N);
  for(i = 0;i < N;i++){
    scanf("%d", &a[i]);
    sum += a[i];
  }
  ave = (double) sum / N;
  for(i = 0;i < N;i++){
    d[i] = fabs(ave - (double) a[i]);
  }
  printf("%d\n", my_index(d, my_min(d, N), N));
}

int my_index(double *input0, double input1, int size){
  int i, ret;
  for(i = 0;i < size;i++){
    if(input0[i] == input1){
      return i;
    }
  }
}

double my_min(double *input, int size){
  int i;
  double min = input[0];
  for(i = 1;i < size;i++){
    if(input[i] < min){
      min = input[i];
    }
  }
  return min;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJHelloWorld1
{
    class Program
    {
        static void Main(string[] args)
        { 
            string[] str = Console.ReadLine().Split(' ');
            int W = int.Parse(str[0]);
            int H = int.Parse(str[1]);
            int x = int.Parse(str[2]);
            int y = int.Parse(str[3]);
            int r = int.Parse(str[4]);
         if(x+r>W || x-r<0 || y+r>H || y-r<0)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}


Measured memory_bytes: 17992
import heapq

N, M = map(int,input().split())
A = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(A)

for _ in range(M):
  tmp_min = heapq.heappop(A)
  heapq.heappush(A, (-1) * (-tmp_min // 2))

print(-sum(A))

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

int main() {
	int n;
	cin >> n;
	vector<ll> z(n),w(n);
	rep(i,n) {
		int x,y;
		cin >> x >> y;
		z[i] = x + y;
		w[i] = x - y;
	}
	ll zmax=-4e18,zmin=4e18,wmax=-4e18,wmin=4e18;
	rep(i,n) {
		if (zmax < z[i]) zmax = z[i];
		if (zmin > z[i]) zmin = z[i];
		if (wmax < w[i]) wmax = w[i];
		if (wmin > w[i]) wmin = w[i];
	}
	cout << max(zmax - zmin, wmax - wmin) << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;
 
/*
struct SegmentTree{
   
  vector<lol> SumV(1000005,0);
  vector<lol> MaxV(1000005,0);
  vector<lol> MinV(1000005,0);
  int N;
   
  void update(int i,int x){
    i += N - 1;
    minv[i] = x;
    maxv[i] = x;
    sumv[i] = x;
    while(i > 0){
      i = (i - 1)/2;
      maxv[i] = max(maxv[i*2+1],maxv[i*2+2]);
      minv[i] = min(minv[i*2+1],minv[i*2+2]);
      sumv[i] = sumv[i*2+1]+sumv[i*2+2];
    }
  }
   
  void add(int i,int x){
    i += N - 1;
    sumv[i] += x;
    maxv[i] += x;
    minv[i] += x;
    while(i > 0){
      i = (i - 1)/2;
      sumv[i] = sumv[i*2+1]+sumv[i*2+2];
      minv[i] = min(minv[i*2+1],minv[i*2+2]);
      maxv[i] = max(maxv[i*2+1],maxv[i*2+2]);
    }
  }
   
  int getmax(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return -INF;
    if(a <= l && r <= b) return maxv[k];
    else{
      int c1 = getmax(a,b,2*k+1,l,(l+r)/2);
      int c2 = getmax(a,b,2*k+2,(l+r)/2,r);
      return max(c1,c2);
    }
  }
   
  int getmin(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return minv[k];
    else{
      int c1 = getmin(a,b,2*k+1,l,(l+r)/2);
      int c2 = getmin(a,b,2*k+2,(l+r)/2,r);
      return min(c1,c2);
    }
  }
   
  int getsum(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return sumv[k];
    else{
      int c1 = getsum(a,b,2*k+1,l,(l+r)/2);
      int c2 = getsum(a,b,2*k+2,(l+r)/2,r);
      return c1+c2;
    }
  }
}
*/
 
//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int h, w, c;
  cin >> w >> h >> c;
  lol nasu = gcd(w, h);
  cout << c * (w / nasu) * (h / nasu) << '\n';
  return 0;
}



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

using namespace std;

vector<int> Divis(int n) {
	vector<int> divs;
	
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) divs.push_back(i);
	}
	
	for (int i = divs.size() - 1; i >= 0 ; i--) {
		if (n / divs[i] != divs[i]) divs.push_back(n / divs[i]);
	}
	
	divs.push_back(n);
	
	return divs;
}

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	
	vector<vector<int> > divs(n);
	for (int i = 0; i < min(2,n); i++) divs[i] = Divis(a[i]);
	
	set<int> mults;
	map<int, int> mp;
	
	for (int i = 0; i < min(n,2); i++) {
		for (int j = 0; j < divs[i].size(); j++) {
			mults.insert(divs[i][j]);
		}
	}
	
	int gcd = 0, close = 0;
	
	for (auto i = mults.begin(); i != mults.end(); i++) {
	    int cnt = 0;
	    for(int j = 0; j < n; j++){
	        if(a[j] % (*i) == 0) cnt += 1;
	    }
		if (cnt == n) gcd = (*i);
		if (cnt == n - 1) close = (*i);
	}
	
	if (gcd != 0 || close != 0) {
		if (gcd > close) cout << gcd;
		else cout << close;
	}
	else cout << 1;
	
	return 0;
}

Measured memory_bytes: 2944
def main():
    n, a, b = map(int, input().split())

    if a == 0:
        print(0)
        exit()
    if b == 0:
        print(n)
        exit()

    tmp = n % ( a + b )

    if tmp >= a:
        tmp = a

    print(n // (a+b) * a + tmp)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
n=int(input())
t=list(input())
t2=list(input())
cnt=0
ans=1
mod=10**9+7
isdif=False
isend=True
while cnt<n:
    if t[cnt]==t2[cnt]:
        if isend:
            ans*=3
            isend=False
        elif not isdif:
            ans*=2
            ans%=mod
        else:
            pass
        isdif=False
        cnt+=1
    elif t[cnt]!=t2[cnt]:
        if isend:
            ans*=6
            isend=False
        elif isdif:
            ans*=3
            ans%=mod
        else:
            ans*=2
            ans%=mod
        isdif=True
        cnt+=2
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
	int N, M, i; //N:夏休み日数 M:宿題の数 i:loop count
	scanf("%d %d", &N, &M);
	int A[M]; //かかる日数配列
	for (i = 0; i < M; i++){
		scanf("%d", &A[i]);
		N = N - A[i];
	}
	if (N < 0)
		printf("-1");
	else
		printf("%d", N);
	return 0;
}

Measured memory_bytes: 1740
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> P;
P T[200];
int J[1001];
int main(){
  int i = 0;
  while(1){
    int t,p;
    scanf("%d,%d",&t,&p);
    if(!t && !p) break;
    T[i]=P(p,t);
    i++;
  }
  sort(T,T+i);
  int rank=0;
  int tmp = 50;
  for(int j=i-1;j>-1;j--){
    if(tmp > T[j].first){
      rank++;
      tmp = T[j].first;
    }
    J[T[j].second]=rank;
  }
  int id;
  while(~scanf("%d",&id)){
    printf("%d\n",J[id]);
  }
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
 
using namespace std;
 
int n, k, a[123123], dp[123123];
 
int main() {
	cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 2; i <= k + 1; i++)
	dp[i] = abs(a[1] - a[i]);
  	
    for(int i = k + 2; i <= n; i++){
      dp[i] = 2e9;
      for(int j = 1; j <= k; j++)
      dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
    }
    cout << dp[n];
}

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

int main(){

  int N,A,flag;
  long long ans = 1;
  cin >> N;

  int lis[3] = {0,0,0};

  for (int i = 0 ; i < N ; i++){

    cin >> A;

    flag = 0;

    for (int j = 0 ; j < 3 ; j++){

      if (lis[j] == A){

	if (flag == 0){
	  lis[j] += 1;
	}

	flag += 1;

      }
    }

    ans *= flag;
    ans %= 1000000007;

  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = s[0];
            int K = s[1];
            List<int> ls = new List<int>();
            ls.AddRange(ReadLine().Split(' ').Select(int.Parse).ToArray());
            ls.Sort();
            int ans = 0;
            for (int i = ls.Count-1; (ls.Count-1)-i <K; i--)
            {
                ans += ls[i];
            }
            WriteLine(ans);
        }
    }
}


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

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    sc.nextLine();
    String[][] arr = new String[H][W];
    for(int i = 0; i < H; i++) {
      String line = sc.nextLine();
      for(int j = 0; j < W; j++) {
        arr[i][j] = line.charAt(j) + "";
      }
    }
    
    if(objective(arr, H, W))
      System.out.println("Yes");
    else
      System.out.println("No");
  }
  
  public static boolean objective(String[][] arr, int H, int W) {
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        if(arr[i][j].equals("#")) {
          boolean up = i != 0 && arr[i-1][j].equals("#");
          boolean left = j != 0 && arr[i][j-1].equals("#");
          boolean right = j != W-1 && arr[i][j+1].equals("#");
          boolean down = i != H-1 && arr[i+1][j].equals("#");
          if(!(up || left || right || down))
            return false;
        }
      }
    }
    return true;
  }
}


Measured memory_bytes: 21972
class Main{
	public static void main(String[] args) {
		int InputSecond = new java.util.Scanner(System.in).nextInt();
		int hours;
		int minutes;
		int seconds;
		
		hours = InputSecond / 3600;
		minutes = (InputSecond % 3600) / 60;
		seconds = InputSecond % 60;
		System.out.println(hours + ":" + minutes + ":" + seconds);
	}
}

Measured memory_bytes: 26184
N, M = map(int, input().split())
A = list(map(int, input().split()))
num = [0, 2, 5, 5, 4, 5 ,6, 3, 7, 6]
dp = ["" for i in range(50000)]
for i in range(N):
    if i!=0 and dp[i]=="":
        continue
    for a in A:
        if dp[i+num[a]] == "":
            dp[i+num[a]] = dp[i] + str(a)
        else:
            tmpscore = dp[i]+str(a)
            if len(dp[i+num[a]]) < len(tmpscore):
                dp[i+num[a]] = tmpscore
            elif len(dp[i+num[a]]) > len(tmpscore):
                continue
            else:
                dp[i+num[a]] = max(dp[i+num[a]], tmpscore)
print(dp[N])

Measured memory_bytes: 30488
# dp[S]=(集合Sに属するウサギのグループ分けの最高得点)=max(dp[T],dp[T\S])
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
INF=-10**12
dp=[INF]*(1<<n)
def memo(s):
    if dp[s]>INF:
        return dp[s]
    ans=0
    for i in range(n-1):
        for j in range(i,n):
            if s>>i&1 and s>>j&1:
                ans+=a[i][j]
    # sの部分集合tだけをループ
    # for(int t=s;t>=0;t=(t-1)&s)の空集合とsを除いてfor(int t=(s-1)&s;t>0;t=(t-1)&s)
    t=(s-1)&s
    while t>0:
        ans=max(ans,memo(t)+memo(t^s))
        t=(t-1)&s
    dp[s]=ans
    return ans
print(memo((1<<n)-1))

Measured memory_bytes: 46428
import numpy as np

N, M = [int(i) for i in input().split()]
k = [0]*M
s = []
for i in range(M):
    tmp = list(map(int, input().split()))

    k[i] = tmp[0]
    s.append(tmp[1:])
p = [int(i) for i in input().split()]

# N個のスイッチのon/offのパターン2^N通りをすべて調査
# 1がon、0がoff
answer = 0
for i in range(2 ** N):
# M個の電球について調査
    flag = 1 # 1: 全部点灯
    for j in range(M):
        count = 0
        need = s[j]
        for k in need:
            if ((i >> k-1) & 1):
                count += 1
        if np.mod(count, 2) != p[j]:
            flag = 0
    if flag == 1:
        answer += 1

print(answer)

Measured memory_bytes: 12444
def bisect_right_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番右側のidx+1となる。
    '''
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

def main():
  N = int(input())
  ans = 1
  lis_min = [int(input())]
  for i in range(N-1):
    a = int(input())
    index = bisect_right_reverse(lis_min, a)
    if index != len(lis_min):
      lis_min[index] = a
    else:
      ans += 1
      lis_min.append(a)
  print(ans)
if __name__ == "__main__":
  main()

Measured memory_bytes: 7092
#include <iostream>
using namespace std;
typedef long long ll;

int main(){
    ll s;
    int h,m,sec;
    cin >> s;
    h = s/3600;
    m = (s-h*3600)/60;
    sec = s-h*3600-m*60;
    cout << h << ":" << m << ":" << sec << "\n";
    return 0;
}


Measured memory_bytes: 3120
package main

import "fmt"

func main() {
	var A, B, C int
	fmt.Scan(&A, &B, &C)
	var ans string
	ans = "NO"
	for i := 1; i < 1000000; i++ {
		a := A * i
		if a%B == C {
			ans = "YES"
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    ll ans=0;
    rep(i,N){
        if (A[i]%2==0){
            ans+=A[i]/2;
        }
        else {
            if (i!=N-1&&A[i+1]>0){
                ans+=(A[i]+1)/2;
                A[i+1]--;
            }
            else {
                ans+=A[i]/2;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>   
using namespace std;   
typedef long long ll;  
int n;
int a[200];
int Min, Max;
int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	//freopen("input.txt", "rt", stdin);
	cin >> n;
	int t; cin >> t;
	Min = t; Max = t;
	a[0] = t;
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		Min = min(Min, a[i]);
		Max = max(Max, a[i]);
	}
	int ans = INT_MAX;
	for (int i = -100; i <= 100; i++) {
		int t = 0;	
		for (int j = 0; j < n; j++) {
			t += (i-a[j])*(i-a[j]);
		}
		ans = min(ans, t);
	}
	cout << ans << endl;

	return 0;   
}  

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main 
{
	public static void main(String[] Arguments) throws IOException 
	{
		BufferedReader BR = new BufferedReader(new InputStreamReader(System.in)); long Sum = 0;
		int N = Integer.parseInt(BR.readLine());
		for (long i = 1; i <= N; i++)
		{
			if (i % 3 != 0 && i % 5 != 0) Sum += i;
		}
		System.out.println(Sum);
	}
}


Measured memory_bytes: 25748
#include <iostream>
#define ll long long
using namespace std;

int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}

int main(){
    int n;
    cin >> n;
    ll val=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                ll z=gcd(i,j);
                z=gcd(z,k);
                val+=z;
            }
        }
    }
    cout << val;
    return 0;
}


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

const int mod = 1e9 + 7;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> wa(n + 1);
    rep(i, n) wa[i + 1] = wa[i] + a[i];
    // rep(i, n + 1) cout << wa[i] << endl;
    ll ans = 0;
    rep(i, n)
    {
        ans += (wa[n] - wa[i + 1]) % mod * a[i];
        ans %= mod;
        // cout << ans << endl;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 5560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <math.h>

using namespace std;

int main () {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int sum = min (A,B) +min(C,D);
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
X = int(input())
for i in range(10**4):
    for j in range(10**4):
        x = i - 10**4//2
        y = j - 10**4//2
        if x**5 - y**5 == X:
            s = str(x) + " " + str(y)
            print(s)
            break
    else:
        continue
    break


Measured memory_bytes: 66380
N = input()
A = map(int,raw_input().split())
temp = 0
q = 0
r = N-1

for i in range(N-1):
    if A[i] <= A[r] and q < i:
        A[q],A[i] = A[i],A[q]
        q += 1
    elif A[i] <= A[r]:
        q += 1


A[r],A[q] = A[q],A[r]
i = 0
for elem in A:
    if i == q:
        print("["+str(elem)+"]"),
    else:
        print(elem),
    i += 1

Measured memory_bytes: 14788
#include <stdio.h>
int main(void)
{
  int n,m,i;
  int a[3]={0};
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  m=a[0];
  for(i=0;i<n;i++){
    if(m>a[i])
      m=a[i];
  }
  for(i=1;i<=m;i++){
    if(a[0]%i==0&&a[1]%i==0&&a[2]%i==0)
      printf("%d\n",i);
  }
	
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N, M;
	cin >> N >> M;

	priority_queue<int> A;
	for( int i = 0; i < N; ++i ) {
		int x;
		cin >> x;
		A.push( x );
	}

	while( M > 0 ) {
		int x = A.top();
		A.pop();

		A.push( x/2 );
		M -= 1;
	}

	int64_t result = 0;

	while( !A.empty() ) {
		result += A.top();
		A.pop();
	}

	cout << result << endl;
}


Measured memory_bytes: 892
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=1e4+4;

int main()
{
	int n,m,k;

	scn(n); scn(m); scn(k);

	string s[n];

	rep(i,0,n)
	cin>>s[i];

	int ans=inf;

	rep(mask,0,(1<<(n-1)))
	{
		int here=__builtin_popcount(mask);

		vector<int> v;

		rep(i,0,n-1)
		if(mask&(1<<i))
		v.pb(i);

		v.pb(n-1);

		int fa[n]={0},tfa[n]={0};

		int should_proceed=1;

		for(int i=0;i<m and should_proceed;i++)
		{
			int ind=0,cntr=0;

			for(int r:v)
			{
				while(ind<=r)
				{
					if(s[ind][i]=='1')
					fa[cntr]++,tfa[cntr]++;

					ind++;
				}

				cntr++;
			}

			rep(j,0,cntr)
			if(tfa[j]>k)
			should_proceed=0;

			rep(j,0,n)
			tfa[j]=0;

			if(should_proceed==0)
			break;

			rep(j,0,cntr)
			if(fa[j]>k)
			{
				//ek naya vertical paritition lagana hoga

				here++; 

				rep(k,0,cntr)
				fa[k]=0;

				i--; //fir se dekhna padega parition laga ke 

				break;
			}
		}

		if(should_proceed)
		ans=min(ans,here);
	}

	pri(ans);

    return 0;
}


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

using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE 
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    long long int n;
    cin>>n;
    long long int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    long long int sum=0;
     for(int i=0;i<n-1;i++)
     {
        if(arr[i]<=arr[i+1])
            continue;
        else
        {
            sum+=arr[i]-arr[i+1];
            arr[i+1]=arr[i];
        }
     }
     cout<<sum<<"\n";


    return 0;
 } 

Measured memory_bytes: 5184
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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; }
const ll INF = 1LL << 60;
int main(){
    int n;
    string s;
    cin >> n >> s;
    ll r,g,b;
    r = g = b = 0;
    rep(i,n){
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else if(s[i]=='B') b++;
    }
    ll ans = r*g*b;
    for(int d=1; 2*d<n; d++){
        for(int cur=0; cur+2*d<n; cur++){
            int cur2 = cur+d;
            int cur3 = cur+2*d;
            if(s[cur]!=s[cur2]&&s[cur2]!=s[cur3]&&s[cur3]!=s[cur]) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
n = int(input())
A = list(map(int, input().split()))
def maxHeapify(A, i):
    if 2*i+1 < len(A):
        left = A[2*i+1]
        if 2*i+2 < len(A):
            right = A[2*i+2]
            if right < left and left > A[i]:
                A[i], A[2*i+1] = A[2*i+1], A[i]
                maxHeapify(A, 2*i+1)
            elif left < right and right > A[i]:
                A[i], A[2*i+2] = A[2*i+2], A[i]
                maxHeapify(A, 2*i+2)
        elif left > A[i]:
            A[i], A[2*i+1] = A[2*i+1], A[i]
            maxHeapify(A, 2*i+1)
i = (len(A)-1-1)//2
while i >= 0:
    maxHeapify(A, i)
    i-=1
ans = ''
for i in range(len(A)):
    ans+=' '+str(A[i])
print(ans)


Measured memory_bytes: 63776
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int n,m; cin >> n >> m;
	cout << (n*(n-1)+m*(m-1))/2 << endl;
	return 0;
}

Measured memory_bytes: 256
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed() ios::sync_with_stdio(0);cin.tie(0);
#define file() freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(v)   v.begin(),v.end()
#define rall(v)   v.rbegin(),v.rend()
#define pb push_back
#define pf push_front
#define mp make_pair
#define pi acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;

int main()
{
    speed();
    ll a=0,b,c,i,t,ans=0;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='R')
            ans++;
        else
        {
            a=max(a,ans);
            ans=0;
        }

    }
    a = max(a,ans);
    cout<<a<<endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<60;
const ll Mod=998244353;

int main(){
  int i,j;
  int a,b;
  cin>>a>>b;
  cout<<max(0,a-b-b)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
using ll = long long;
//西暦⇒時代の歴

ll h[100010];
int N;
ll A, B;
bool check(ll n)
{
    ll t = 0;
    for (int i = 0; i < N; ++i)
    {
        if (max(0LL, h[i] - B * n) % (A - B) == 0)
        {
            t += max(0LL, h[i] - B * n) / (A - B);
        }
        else
        {
            t += max(0LL, h[i] - B * n) / (A - B) + 1;
        }
    }
    if (t <= n)
        return true;
    else
        return false;
}
int main()
{

    cin >> N;

    cin >> A >> B;

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

    ll lb = -1, ub = 10000000000 - 1;

    while (ub - lb > 1)
    {
        ll mid = (lb + ub) / 2;
        if (check(mid))
        {
            ub = mid;
        }
        else
        {
            lb = mid;
        }
        //cout << lb << " " << ub << endl;
    }
    cout << ub << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,num[5];
char c[10];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {
		scanf("%s",c);
		if(c[0]=='A') num[1]++;
		else if(c[0]=='W') num[2]++;
		else if(c[0]=='T') num[3]++;
		else num[4]++;
	}
	printf("AC x %d\n",num[1]);
	printf("WA x %d\n",num[2]);
	printf("TLE x %d\n",num[3]);
	printf("RE x %d\n",num[4]);
	return 0;
}

Measured memory_bytes: 3812