akhauriyash/Code-Regression huggingface dataset:
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

void createA(string &s, v &target, char c){
  if(s[0] == c) target[0] = 1;
  for(int i = 1; i < s.size(); i++)
  {
    if(s[i] == c){
      target[i] = target[i - 1] + 1;
    }else{
      target[i] = target[i - 1];
    }
  }
}

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  v r(n, 0);
  v g(n, 0);
  v b(n, 0);
  createA(s, r, 'R');
  createA(s, g, 'G');
  createA(s, b, 'B');
  ll result = 0;
  rep(i, n)
  {
    for(int j = i + 1; j < n; j++)
    {
      if(s[i] == s[j]) continue;
      if(s[i] == 'R'){
        if(s[j] == 'B') result += g[n - 1] - g[j];
        if(s[j] == 'G') result += b[n - 1] - b[j];
      }else if(s[i] == 'G'){
        if(s[j] == 'R') result += b[n - 1] - b[j];
        if(s[j] == 'B') result += r[n - 1] - r[j];
      }else if(s[i] == 'B'){
        if(s[j] == 'R') result += g[n - 1] - g[j];
        if(s[j] == 'G') result += r[n - 1] - r[j];
      }
    }
  }
  rep(i, n)
  {
    for(int radius = 1; radius < n; radius++)
    {
      if(i + radius > n || i + 2 * radius > n) continue;
      string temp;
      temp.push_back(s[i]);
      temp.push_back(s[i + radius]);
      temp.push_back(s[i + 2 * radius]);
      int tempr = 0;
      int tempg = 0;
      int tempb = 0;
      for(auto e : temp)
      {
        if(e == 'R') tempr++;
        if(e == 'G') tempg++;
        if(e == 'B') tempb++;
      }
      if(tempr == 1 && tempg == 1 && tempb == 1) result--;
    }
  }
  cout << result << endl;

}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define endl '\n'

const int N = 2e5+10;
const int M = 1e9+7;

using namespace std;

ll f[N],inv[N];

ll fexp (ll x, ll y)
{
    ll r=1;
    x=x%M;
    while (y)
    {
        if (y&1)
            r=(r*x)%M;
        x=(x*x)%M;
        y>>=1;
    }
    return r;
}

main()
{
    fast;
    ll m,n,x,y,i;
    f[0]=inv[0]=f[1]=inv[1]=1;
    for (i=2;i<N;i++)
    {    
        f[i]=(f[i-1]*i)%M;
        inv[i]=fexp(f[i],M-2)%M;
    }
    ll ans=0,tp1,tp2;
    cin>>m>>n>>x>>y;
    for (i=m-x-1;i>=0;i--)
    {
        tp1=(f[i+y-1]%M*inv[i]%M*inv[y-1]%M)%M;
        tp2=(f[m-1-i+n-1-y]%M*inv[m-1-i]%M*inv[n-1-y]%M)%M;
        ans=(ans+(tp1*tp2)%M)%M;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
D=[1<<99]*K=gets.to_i
q=[D[1]=1]
while n=q.shift;[[n*10%K,0,:unshift],[-~n%K,1,:<<]].map{|e,d,m|(D[e]>x=D[n]+d)&&(D[e]=x;q.send(m,e))};end
p D[0]

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-2, -1};
int dx[4] = {-1, -2};

const int MAX = 1000050;
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 

int n,q;
multiset<pair<int, pair<int, int> > > a;
set<pair<int, int> > b;
vector<int> c;

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n >> q;
	rep(i,0,n) {
		int s, t, x;
		cin >> s >> t >> x;
		a.insert(mp(x, mp(x-t,x-s)));
	}
	c = vector<int>(q, -1);
	rep(i,0,q) {
		cin >> c[i];
		b.insert(mp(-c[i],i));
		c[i] = -1;
	}

	for(auto it = a.begin(); it != a.end(); ++it) {
		int x = it->F;
		auto locbegin = b.upper_bound(mp(it->S.F, q));
		auto locend = b.upper_bound(mp(it->S.S, q));
		if(locbegin == b.end()) {
			continue;
		}
		for(auto iit = locbegin ; iit != locend; ++iit) {
			int idx = iit->S;
			c[idx] = x;
		}
		b.erase(locbegin, locend);
	}

	rep(i,0,q) {
		cout << c[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 24576
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import qualified Data.IntMap as IM
import Data.List.Split (splitOn)

main :: IO ()
main = do
  xs <- getc $ splitOnSp toInt
  mapM_ putStrLn $ solve xs

solve :: [[Int]] -> [String]
solve xs = patrol [] $ splitOn [[0,0]] xs

patrol :: [String] -> [[[Int]]] -> [String]
patrol acc (x:xs)
  | null x = reverse acc
  | otherwise = patrol (judge x : acc) xs

judge :: [[Int]] -> String
judge xs = if ok then "OK" else "NG"
  where
    rmap = foldl (\im [a,b] -> IM.insertWith (+) b 1 (IM.insertWith (+) a 1 im)) IM.empty xs
    ok = odd (rmap IM.! 1) && odd (rmap IM.! 2) && ((== 2) . length . filter odd . IM.elems) rmap

toInt :: String -> Int
toInt s = read s

splitOnSp :: (String -> a) -> String -> [a]
splitOnSp f = map f . words

getc :: (String -> a) -> IO [a]
getc f = map f . lines <$> getContents

Measured memory_bytes: 5312
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int check_text (string s, char x) ;
int main() {
    int a , b , x ;
    cin >> a >> b >> x ;
    if (x >= a && b >= (x-a)){
        cout << "YES" ;
    }
    else {
        cout << "NO" ;
    }
    return 0 ;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

struct edge{int u,v,cost;};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<vector<P>> g(n);
  rep(i,m){
    int l,r,c;
    cin>>l>>r>>c;
    l--,r--;
    g[l].push_back(P{r,c});
  }
  for(int i=n-1;i>=1;i--){
    g[i].push_back(P(i-1,0));
  }
  vector<ll> dist(n,inf);
  dist[0]=0;
  priority_queue<P,vector<P>,greater<P>> que;
  que.push(P(0,0));
  while(!que.empty()){
    P now=que.top();
    que.pop();
    int v=now.se;
    if(dist[v]<now.fi) continue;
    for(auto itr:g[v]){
      if(dist[itr.fi]>dist[v]+itr.se){
        dist[itr.fi]=dist[v]+itr.se;
        que.push(P(dist[itr.fi],itr.fi));
      }
    }
  }
  cout<<(dist[n-1]!=inf ? dist[n-1]:-1)<<endl;
}

Measured memory_bytes: 9468
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,i,j,k,l,f=0,a[200005][2],b[200005],c[200005];
int main(int argc, char *argv[])
{
	
	scanf("%d%d",&n,&m);
	for(i=0,j=0,k=0;i<m;i++)
	{
		scanf("%d%d",&a[i][0],&a[i][1]);
		if(a[i][0]==1&&a[i][1]!=n){b[j++]=a[i][1];}
		if(a[i][1]==n){c[k++]=a[i][0];}
	}
	sort(b,b+j);
	sort(c,c+k);
	for(i=0,l=0;i<j&&l<k;)
	{
		if(b[i]==c[l]){f=1;break;}
		else if(b[i]>c[l])l++;
		else if(b[i]<c[l])i++;
	}
	if(f)printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

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


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	int k;
	cin >> s >> k;

	rep(i,s.size()) {
		if (k == 0)break;
		if (s[i] == 'a')continue;
		int a = 'z' - s[i] + 1;
		if (a<=k) {
			k -= a;
			s[i] = 'a';
		}
	}
	k %= 26;
	s.back() += k;


	cout << s << endl;
	return 0;
}

Measured memory_bytes: 592
#include<cstdio>
#include<vector>
char l[100001];
using ll = long long;
using pll = std::pair<ll,ll>;
ll const p=1e9+7;
int main(){
    scanf("%s",l);
    //ans={a+b==Lになりうる場合の数,a+b<Lが確定した場合の数}
    pll ans={2,1};
    for(int i=1;l[i]!='\0';i++){
        if(l[i]=='0'){
            ans={ans.first,(3*ans.second)%p};
        }else{
            ans={(2*ans.first)%p,(3*ans.second+ans.first)%p};
        }
    }
    printf("%lld\n",(ans.first+ans.second)%p);
    return 0;
}

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

signed main(void){
    string s ; 
    cin>>s;
    int a = stoi(s);
    itn sum = 0;
    rep(i, s.size())  sum+= s[i] - '0';
    
    if(a % sum==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using P = pair<int,int>;
//Write From this Line

vector<int> to[100010];
int main()
{
	ll n;
	cin >> n;
	vector<ll> c(n);
	rep(i,n-1){
		int x, y;
		cin >> x >> y;
		--x, --y;
		to[x].push_back(y);
		to[y].push_back(x);
	}
	rep(i,n) cin >> c[i];

	sort(c.rbegin(),c.rend());
	int ans = 0;
	rep(i,n){
		if(i==0) continue;
		ans += c[i];
	}

	// BFS
	vector<bool> check(n,false);
	queue<int> que;
	que.push(0);
	int count = 0;
	check[0] = true;
	vector<int> write(n);
	while(!que.empty()){
		int now = que.front(); que.pop();
		write[now] = c[count];
		count ++;

		for(auto x:to[now]){
			if(check[x]) continue;
			que.push(x);
			check[x] = true;
		}
	}
	cout << ans << endl;
	rep(i,n) cout << write[i] << " ";
}


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

int main(){
  int N;
  cin >>N;
  vector<int> H(N);
  rep(i,N) cin >>H[i];
  reverse(H);
  bool suc = 1;
  rep(i,N){
    if(H[i]+1 == H[i+1])H[i+1]--;
    if(H[i]+1 < H[i+1]){
      suc = 0;
      break;
    }
  }
  string ans = (suc)?"Yes":"No";
  cout << ans << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
     
    int ans = 0;
    for (int i = 0, j; i < N; i = j) {
        for (j = i + 1; j < N; ++j) {
            if (S[j] != S[i]) break;
        }

        ans++;
    }

    write(ans);
}

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

using namespace std;

int findsum(int m){
	int sum = 0;
	while(m>0){
		sum += m%10;
		m /= 10;
	}
	return sum;
}
int main(){
	int n;
	cin >> n;

	if(n % findsum(n) == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main() {
    int n;
    cin >> n;
    ll ans=1;
    bool hantei = true;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    if(a[0]==0) cout << "0" << endl;
    else{
        rep(i,n){
            if(a[n-i-1]>1000000000000000000/ans){
                cout<< "-1" <<endl;
                return 0;
            }else{ans*=a[n-i-1];}
        }
        cout << ans << endl;
    }
}

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

ll solve() {
    ll L, R, D;
    cin >> L >> R >> D;
    ll ans = 0;
    for ( int i = L; i <= R; i++ ) {
        if ( i % D == 0) ans++;
    }
    
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#define N 100005
using namespace std;
typedef long long ll;
ll n, m, M=1e9+7, v[N], fac[N]={1}, inv[N];
ll pow(ll p, ll q) {
	ll ret=1;
	for(; q; q>>=1, p = p*p%M) if(q&1) ret = ret*p%M;
	return ret;
}
ll C(ll p, ll q) {return p<q ? 0 : fac[p] * inv[q]%M * inv[p-q]%M;}

int main() {
	ll i, t;
	scanf("%d", &n);
	for(i=1; i<=n+1; i++) {
		scanf("%d", &t);
		v[t] ? m = v[t]+n-i : v[t] = i;
	}
	for(i=1; i<=n+1; i++) fac[i] = i * fac[i-1] % M;
	inv[n+1] = pow(fac[n+1], M-2);
	for(i=n; i>=0; i--) inv[i] = (i+1) * inv[i+1] % M;
	for(i=1; i<=n+1; i++) printf("%d\n",(C(n+1,i) - C(m,i-1) + M) % M);
	return 0;
}

Measured memory_bytes: 3456
import java.util.*;

public class Main {
	public Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new aoj1193().doIt();
	}
	class aoj1193{
		int a[][];
		int point(int n){
			int result = 0;
			for(int i = 0;i < n;i++){
				if(a[i][0] == a[i][1] && a[i][1] == a[i][2] && a[i][2] == a[i][3] && a[i][3] == a[i][4] && a[i][0] != 0){
					result = result + (a[i][0] * 5);
					for(int j = 0;j < 5;j++)a[i][j] = 0;
				}
				for(int j = 0;j < 2;j++){
					if(a[i][j] == a[i][j+1] && a[i][j+1] == a[i][j+2] && a[i][j+2] == a[i][j+3] && a[i][j] != 0){
						result = result + (a[i][j] * 4);
						for(int k = j;k < j + 4;k++)a[i][k] = 0;
					}
				}
				for(int j = 0;j < 3;j++){
					if(a[i][j] == a[i][j+1] && a[i][j+1] == a[i][j+2] && a[i][j] != 0){
						result = result + (a[i][j] * 3);
						for(int k = j;k < j + 3;k++)a[i][k] = 0;
					}
				}
			}
			return result;
		}
		void sort(int n){
			while(true){
				boolean s = false;
				for(int i = n-1;i > 0;i--){
					for(int j = 0;j < 5;j++){
						if(a[i][j] == 0 && a[i-1][j] != 0){
							a[i][j] = a[i-1][j];
							a[i-1][j] = 0;
							s = true;
						}
					}
				}
				if(!s)break;
			}
		}
		void doIt() {
			while(true){
				int n = sc.nextInt();
				if(n == 0)break;
				int cnt = 0;
				a = new int [n][5];
				for(int i = 0;i < n;i++){
					for(int j = 0;j < 5;j++){
						a[i][j] = sc.nextInt();
					}
				}
				while(true){
					int num = point(n);
					cnt = cnt + num;
					if(num == 0)break;
					sort(n);
				}
				System.out.println(cnt);
			}
		}
	}
}

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

#define sfi(x) scanf("%d", &x)
#define pii pair<int, int>

int main(){
    int n, t;
    cin >> n >> t;
    int a[n+5];
    for(int i=0; i<n; i++)
        cin >> a[i];

    int m[n+5] = {0};
    for(int i=n-1; i>=0; i--)
        m[i] = max(a[i], m[i+1]);

//    for(int i=0; i<n; i++)
//        cout << m[i] << " ";
//        cout << endl;

    int best = 0;
    for(int i=0; i<n-1; i++)
        if(a[i] < m[i+1])
            best = max(best, m[i+1] - a[i]);

//    cout << best << endl;
    int ans = 0;
    for(int i=0; i<n-1; i++)
        if(a[i]<m[i+1] && m[i+1]-a[i]==best)
            ans++;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
package main
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
	//      "sort"
)

func ToIntSlice(stra []string) []int {
	var inta = make([]int, len(stra))
	for i, v := range stra {
		inta[i], _ = strconv.Atoi(v)
	}
	return inta
}

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	nmline :=strings.Split(stdin.Text()," ")
	n ,_:= strconv.Atoi(nmline[0])
	//m ,_:= strconv.Atoi(nmline[1])
	nlike :=0
	tmap := make(map[int]int)
	for first :=1; first<=30; first++ {
		tmap[first]=0
	}
	for i := 0; i <= n-1; i++ {
		stdin.Scan()
		ist := ToIntSlice(strings.Split(stdin.Text(), " "))
		for _,val := range ist[1:] {
			tmap[val]+=1
		}
	}
	for _,val := range tmap {
		if val == n {
			nlike++
		}
	}
	fmt.Println(nlike)
}


Measured memory_bytes: 640
def isPrime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= x**(0.5):
        if x % i == 0:
          return False
        i += 2
    return True

if __name__=='__main__':
    N = int(input())
    count = 0
    for _ in range(N):
        if isPrime(int(input())):
            count += 1
    print(count)



Measured memory_bytes: 5672
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {

	public static void main(String[] args) throws Exception {

		List<String> resultList = new ArrayList<String>();
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        for(int i = 0; i < N; i++) {
        	String line = br.readLine().replaceAll("Hoshino", "Hoshina");
        	resultList.add(line);
        }
        Iterator<String> it = resultList.iterator();
        while(it.hasNext()) {
        	System.out.println(it.next());
        }
	}
}

Measured memory_bytes: 24360
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

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

	int arr[50];
	for (int i = 0; i < N; ++i) cin >> arr[i];

	ll ans = 0;
	for (int i = 0; i < N; ++i)
		for (int j = i + 1; j < N; ++j)
			ans += arr[i] * arr[j];

	cout << ans;

	return 0;
}

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

namespace kozaiyApp
{
    public class SingleSourceShortestPath
    {
        static void Main()
        {
            // 入力
            string[] input = Console.ReadLine().Split(' ');
            int V = int.Parse(input[0]); // 頂点の数
            int E = int.Parse(input[1]); // 辺の数
            int r = int.Parse(input[2]); // 始点
            List<edge> edges = new List<edge>();

            for (int i = 0; i < E; i++)
            {
                string[] inputEdge = Console.ReadLine().Split(' ');
                edge edgeItem = new edge
                {
                    s = int.Parse(inputEdge[0]),
                    t = int.Parse(inputEdge[1]),
                    cost = int.Parse(inputEdge[2])
                };
                edges.Add(edgeItem);
            }

            // ベルマンフォード法
            int INF = 100000000;
            int[] k = Enumerable.Repeat<int>(INF, V).ToArray(); // 始点〜各頂点までの最短経路の重みの和
            k[r] = 0; // 始点は0にしておく

            for (int i = 0; i < V; i++) // すべての頂点をループ
            {
                foreach (var e in edges) // すべての辺をループ
                {
                    if (k[e.s] == INF) continue; // 始点〜辺の頂点sまでの最短経路がINFならループを抜ける

                    var cost = k[e.s] + e.cost;
                    if (cost < k[e.t]) // いま調べている経路の方が最小だったら
                    {
                        k[e.t] = cost; // 更新
                        if (i == V - 1) // v回目にも更新がある→負の閉路が存在する
                        {
                            Console.WriteLine("NEGATIVE CYCLE");
                            return;
                        }
                    }
                }
            }

            foreach (var ans in k)
            {
                if (ans == INF)
                {
                    Console.WriteLine("INF");
                }
                else
                {
                    Console.WriteLine(ans);
                }
            }
        }
    }

    public class edge
    {
        public int s { get; set; }
        public int t { get; set; }
        public int cost { get; set; }
    }

}



Measured memory_bytes: 20324
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    H,W = i_map()
    dy_dx=[[1,0],[0,1],[-1,0],[0,-1]]
    rc=[input() for i in range(H)]
    ans = 0

    for sy in range(H):
        for sx in range(W):
            if rc[sy][sx] == "#":
                continue
            dist=[[-1 for _ in range(W)] for _ in range(H)]
            dist[sy][sx] = 0
            d=deque()
            d.append([sx,sy])
            while d:
                nx, ny = d.popleft()
                for dy,dx in dy_dx:
                    y,x = ny+dy,nx+dx
                    if 0<=y<H and 0<=x<W and rc[y][x] != "#" and dist[y][x] == -1:
                        dist[y][x] = dist[ny][nx] + 1
                        d.append([x,y])
            ans = max(ans, max(list(itertools.chain.from_iterable(dist))))
    print(ans)


if __name__=="__main__":
    main()


Measured memory_bytes: 9940
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}



signed main(){
	int A,B;
	cin>>A>>B;
	if(B==1){
		cout<<0<<endl;
		return 0;
	}
	int ans = 1;
	int sum = A;
	while(sum<B){
		ans++;
		sum += A-1;
	}
	cout<<ans<<endl;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

ll POW(ll a, ll b){
        ll res = 1;
        while(b > 0){
            if(b & 1){
                res = res * a % MOD;
            }
            a = a * a % MOD;
            b >>= 1;
        }
        return res;
    }

signed main(){
    string L;
    cin >> L;
    int n = L.size();

    vector<ll> dp(n);
    REP(i, n){
        if(i == 0) dp[i] = 1;
        else dp[i] = dp[i-1] + (L[i] == '1');
    }

    ll ans = 0;

    REP(i, n){
        if(L[i] == '1'){
            ans += (POW(2, dp[i] - 1) * POW(3, n - i - 1)) % MOD;
            ans %= MOD;
        }
    }

    ans += POW(2, dp.back());
    ans %= MOD;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5;
ll n,m,ans,p[N],par[N],sz[N];
void init(){
    for(ll i=0;i<N;i++)par[i]=i,sz[i]=1;
}
ll dsu_parent(ll node){
    if(node==par[node])return node;
    return par[node]=dsu_parent(par[node]);
}
void dsu_union(ll a,ll b){
    a = dsu_parent(a);
    b = dsu_parent(b);
    if(a==b)return;

    if(sz[a]<sz[b])swap(a,b);
    par[b]=a;
    sz[a]+=sz[b];
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    init();
    cin>>n>>m;
    for(ll i=1;i<=n;i++)cin>>p[i];
    for(ll i=1,x,y;i<=m;i++)cin>>x>>y,dsu_union(x,y);
    for(ll i=1;i<=n;i++)if(dsu_parent(i)==dsu_parent(p[i]))ans++;
    cout<<ans;
}




Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<class Val>
struct BinaryIndexedTree {
    int n;
    vector<Val> t;
    BinaryIndexedTree() {}
    BinaryIndexedTree(int _n) :n(_n + 1), t(_n + 1) {}
    void add(int k, Val val) {
        k++;
        while (k < n) {
            t[k] += val;
            k += (k&-k);
        }
    }
    void set(int k, Val val) {
        add(k, -sum(k, k + 1));
        add(k, val);
    }
    Val sum(int k) {
        Val r = 0;
        while (k > 0) {
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    Val sum(int l, int r) {
        return sum(r) - sum(l);
    }
};

/*
区間にO(log(n))加算できる区間和のBITバージョン
加算: O(log(n))
クエリ: O(log(n))
参考:
蟻本
使い方:
SegmentSum<long long> ss(n); // 初期化
ss.add(l, r, x); // [l, r)にxを加算
auto res = ss.sum(l, r); // [l, r)の和を求める
*/
template<class Val>
struct SegmentSum {
    SegmentSum() {}
    SegmentSum(int n) : bit0(n), bit1(n) {}
    /*
    [l, r)にvalを加える
    */
    void add(int l, int r, Val val) {
        bit0.add(l, val*(-l));
        bit0.add(r, val*r);
        bit1.add(l, val);
        bit1.add(r, val*(-1));
    }
    /*
    [l, r)の和を求める
    */
    Val sum(int l, int r) {
        Val sumr = bit0.sum(r) + bit1.sum(r)*r;
        Val suml = bit0.sum(l) + bit1.sum(l)*l;
        return sumr - suml;
    }
    BinaryIndexedTree<Val> bit0, bit1;
};

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

    string S;
    cin >> S;
    int N = sz(S);

    vi idx[26], freq(26);

    rep(i, N) {
        idx[S[i] - 'a'].push_back(i);
        freq[S[i] - 'a']++;
    }

    int odd = 0;
    rep(i, 26)odd += freq[i] % 2;
    if (odd >= 2) {
        cout << -1 << endl;
        return 0;
    }

    vi crsp(N);

    rep(i, 26) {
        int num = sz(idx[i]);
        rep(j, (num + 1) / 2) {
            crsp[idx[i][j]] = idx[i][num - 1 - j];
        }
    }

    const int INF = 1 << 30;
    SegmentSum<ll> pos(N);
    rep(i, N)pos.add(i, i + 1, i);

    ll ans = 0;
    int len = N;
    rep(i, N) {
        if (pos.sum(i, i + 1) == 0) {
            int j = crsp[i];
            if (i==j) {
                ans += abs(len / 2 - pos.sum(j, j + 1));
                pos.add(j, N, -1);
                len--;
            } else {
                ans += len - pos.sum(j, j + 1) - 1;
                pos.add(0, j, -1);
                pos.add(j, N, -2);
                len -= 2;
            }
            pos.add(i, i + 1, INF);
            pos.add(j, j + 1, INF);
        }
    }

    cout << ans << endl;
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        while(true){
            String str[] = br.readLine().split(" ");
            if(str[1].equals("?")) break;
            int a = Integer.parseInt(str[0]);
            int b = Integer.parseInt(str[2]);
            int c=0;
            switch (str[1]) {
                case "+":
                    c = a+b;
                    break;
                case "-":
                    c = a-b;
                    break;
                case "*":
                    c = a*b;
                    break;
                case "/":
                    c = a/b;
                    break;
                default:
                    break;
            }
            sb.append(c+"\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 24484
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
void push(vector<vector<Int>>&bitcnt,Int num){
    for(int i = 0; i < bitcnt[0].size(); ++i){
        Int bit = num & 1LL;
        bitcnt[bit][i] += 1;
        num >>= 1LL;
    }
    return;
};
int main(){
    constexpr Int mod = 1e9 + 7;
    Int ans = 0;
    vector<vector<Int>>bitcnt(2,vector<Int>(100,0LL));
    //push(bitcnt, 85LL);
    Int N; cin >> N;
    vector<Int>v(N);
    for(auto& e : v) cin >> e;
    reverse(v.begin(),v.end());
    for(Int i = 0; i < N; ++i){
        if(i != 0){
            Int num = v[i];
            for(Int i = 0; i  < bitcnt[0].size(); ++i){
                Int bit = num & 1LL;
                ans += ((1LL << i) % mod) * bitcnt[(1+bit)%2][i];
                ans %= mod;
                num >>= 1LL;
            }
        }
        push(bitcnt,v[i]);
    }
    cout << ans % mod << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
using ll=long long;

int N_MAX=100;
int main(){
    long i,N,tsum,t[N_MAX+4],v[N_MAX+2],tn,vpre,va,ans;
    cin>>N;
    tsum=0;
    for(i=0;i<N;i++){
        cin>>t[i+2];
        t[i+2]+=t[i+1];
        tsum+=t[i+2];
    }
    v[0]=0;
    v[N+1]=0;
    for(i=0;i<N;i++){
        cin>>v[i+1];
    }
    t[0]=0;
    t[1]=0;
    t[N+2]=tsum;
    vpre=0.0;
    ans=0.0;
    for(tn=1;tn<2*tsum+1;tn+=1){
        va=1e7;
        for(i=0;i<N+2;i++){
            if(tn<=2*t[i]){
                //va=min(double(va),v[i]+(t[i]-double(tn)/2));
                va=min(va,2*v[i]+(2*t[i]-tn));
            }
            else if(2*t[i]<=tn && tn<=2*t[i+1]){
                //va=min(double(va),double(v[i]));
                va=min(va,2*v[i]);
            }
            else if(2*t[i+1]<=tn){
                //va=min(double(va),v[i]+(double(tn)/2)-t[i+1]);
                va=min(va,2*v[i]+tn-2*t[i+1]);
            }
        }
        //cout<<va<<" "<<vpre<<endl;
        ans+=va+vpre;
        vpre=va;
    }
    //for(i=0;i<N+4;i++){
    //    cout<<t[i]<<endl;
    //}
    //cout << fixed;
    cout << fixed << setprecision(6) << double(ans)/8<<endl;
//    printf("%.12f", double(ans)/8);
//    cout<< std::setprecision(2)<<double(ans)/8<<endl;
    return 0;
}


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

#define CodeTyper main
#define Bye return 0
#define ll long long

using namespace std;

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

    int cont = 0;
    int maxi = 0;
    for (int i=0; i<n-1; i++){
        if(h[i]<h[i+1])
            cont = 0;
        else cont++;
        maxi = max(maxi, cont);
    }
    cout<<maxi<<endl;
}

int CodeTyper(){
    solve();
    Bye;
}

Measured memory_bytes: 4012
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = []
ans.append(min(A)+min(B))


for i in range(m):
    M = list(map(int,input().split()))
    tmp = A[M[0]-1] + B[M[1]-1] -M[2]
    ans.append(tmp)

print(min(ans))


Measured memory_bytes: 18736
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.EducationalDP
{
    class E
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nw = ReadInts();
            int n = nw[0];
            int w = nw[1];
            int[][] wvs = new int[n][];
            for(int i = 0; i < n; i++)
            {
                wvs[i] = ReadInts();
            }
            var vDict = new Dictionary<int, long>();
            vDict.Add(0, 0);
            for (int i = 0; i < n; i++)
            {
                var nextDict = new Dictionary<int, long>();
                foreach (int key in vDict.Keys)
                {
                    if (nextDict.ContainsKey(key))
                    {
                        nextDict[key] = Math.Min(vDict[key], nextDict[key]);
                    }
                    else nextDict.Add(key, vDict[key]);
                    int next = key + wvs[i][1];
                    if (nextDict.ContainsKey(next))
                    {
                        nextDict[next] = Math.Min(
                                nextDict[next], vDict[key] + wvs[i][0]);
                    }
                    else nextDict.Add(next, vDict[key] + wvs[i][0]);
                }
                vDict = nextDict;
            }
            int max = 0;
            foreach(int key in vDict.Keys)
            {
                if (vDict[key] <= w) max = Math.Max(max, key);
            }
            Console.WriteLine(max);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 32064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;

int main() {
  int n;
  cin >> n;
  set<int> a;

  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.insert(x);
  }

  if (a.size() < n) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}

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

int c[3][3], a[3], b[3];

int main(void) {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }

    a[0] = 0;
    for (int i = 0; i < 3; i++) {
        b[i] = c[0][i] - a[0];
    }
    for (int i = 1; i < 3; i++) {
        a[i] = c[i][0] - b[0];
    }

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (c[i][j] != a[i] + b[j]) {
              cout << "No" << endl;
              return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define int long long

int count[100005];

signed main() {
  int n;
  std::cin >> n;

  int sum = 0;
  for(int i = 0; i < n; i++) {
    int x;
    std::cin >> x;
    sum += x;
    count[x]++;
  }

  int q;
  std::cin >> q;

  while(q--) {
    int b, c;
    std::cin >> b >> c;
    sum += (c-b)*count[b];
    count[c] += count[b];
    count[b] = 0;

    std::cout << sum << std::endl;
  }

  return 0;
}



Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,i;
    cin >> n >> i;
    
    cout << n+1 - i << endl;
    
    return 0;
}



Measured memory_bytes: 256
n, k = list(map(int, input().split()))
s = input()

if s[k-1] == "A" :
    s = s[:k-1]+"a"+s[k:]
elif s[k-1] == "B" :
    s = s[:k-1]+"b"+s[k:]
else :
    s = s[:k-1]+"c"+s[k:]

print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
struct edge{
	int x,y;
	ll z;
} gs[400400];
int n,m;
ll ans;
ll best[200200];

int p[200200];
int par(int x){
	return (p[x]==x)?x:(p[x]=par(p[x]));
}

int main(){
	scanf("%d%d",&n,&m);
	memset(best,0x7f,sizeof best);
	for (int i=0;i<n;++i)
		p[i]=i;

	for (int i=0;i<m;++i){
		static int x,y;
		static ll z;
		scanf("%d%d%lld",&x,&y,&z);
		gs[i]=(edge){x,y,z};
		best[x]=min(best[x],z+1);
		best[y]=min(best[y],z+2);
	}

	for (int it=0;it<2;++it)
		for (int i=0;i<n;++i)
			best[(i+1)%n]=min(best[(i+1)%n],best[i]+2);

	for (int i=0;i<n;++i)
		gs[m+i]=(edge){i,(i+1)%n,best[i]};

	sort(gs,gs+m+n,[](const edge &a,const edge &b){return a.z<b.z;});
	for (int i=0;i<m+n;++i){
		int fa=par(gs[i].x);
		int fb=par(gs[i].y);
		if (fa!=fb){
			ans+=gs[i].z;
			p[fa]=fb;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 11904
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(usize, usize);m],
    }
    let mut pairs = vec![vec![]; n];
    for pair in ab {
        pairs[pair.0 - 1].push(pair.1 - 1);
        pairs[pair.1 - 1].push(pair.0 - 1);
    }
    // println!("{:?}", pairs);

    let mut signs: Vec<i64> = vec![-1; n];
    let mut queue = std::collections::VecDeque::new();
    queue.push_back(0);
    while let Some(x) = queue.pop_front() {
        for &nx in pairs[x].iter() {
            if signs[nx] == -1 {
                signs[nx] = x as i64;
                queue.push_back(nx);
            }
        }
    }
    println!("Yes");
    for s in signs[1..].iter() {
        println!("{}", s + 1);
    }
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
 
using namespace std;
 
const int md = (int) 1e9 + 7;
 
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
 
inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}
 
inline int mul(int a, int b) {
#if !defined(_WIN32) || defined(_WIN64)
  return (int) ((long long) a * b % md);
#endif
  unsigned long long x = (long long) a * b;
  unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
  asm(
    "divl %4; \n\t"
    : "=a" (d), "=d" (m)
    : "d" (xh), "a" (xl), "r" (md)
  );
  return m;
}
 
inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
 
inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, tt;
  cin >> n >> tt;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<int>> b(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      b[i][j] = (a[i] < a[j]);
    }
  }
  int inv2 = inv(2);
  int final_coeff = power(2, tt);
  while (tt--) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    for (int i = 0; i < n; i++) {
      if (i != x && i != y) {
        {
          int sum = b[i][x];
          add(sum, b[i][y]);
          sum = mul(sum, inv2);
          b[i][x] = b[i][y] = sum;
        }
        {
          int sum = b[x][i];
          add(sum, b[y][i]);
          sum = mul(sum, inv2);
          b[x][i] = b[y][i] = sum;
        }
      }
    }
    {
      int sum = b[x][y];
      add(sum, b[y][x]);
      sum = mul(sum, inv2);
      b[x][y] = b[y][x] = sum;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      add(ans, b[i][j]);
    }
  }
  ans = mul(ans, final_coeff);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 35584
#include<iostream>
using namespace std;
int n,m,x,y,d;
int f[150000];
int dst[150000];

int find(int x)
{
    if (x==f[x])
    {
        return x;
    }else
    {
        int t1=f[x];
        int y=find(f[x]);
        dst[x]=dst[t1]+dst[x];
        f[x]=y;
        return f[x];
    }
}


int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; ++i)
        f[i]=i;
    bool flag=1;
    for (int i=1; i<=m; ++i)
    {
        scanf("%d%d%d",&x,&y,&d);
        if (flag==0) continue;
        if (find(x)==find(y))
        {
            flag=(dst[x]-dst[y]==d);
        }else
        {
            int t1=find(x),t2=find(y);
            f[t1]=t2;
            dst[t1]=d+dst[y]-dst[x];
        }

    }
    if (flag==0)
        cout<<"No"<<endl;
    else 
        cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 1024
require "prime"

loop {
    n = gets.to_i
    break if n == 0
    a = Prime.each(n).to_a
    i = 0
    j = a.size-1
    count = 0
    loop {
        j -= 1 until a[i] + a[j] <= n
        break if j < i
        count += 1 if a[i] + a[j] == n
        i += 1
        break if j < i
    }
    p count
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    string S; cin >> S;
    if(S == "ABC") {
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3624
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

bool calc(int[] ds, int[] ts) {
    int[int] map;
    foreach (d; ds)
        map[d]++;

    foreach (t; ts) {
        int x = map.get(t, 0);
        if (x > 0) {
            map[t]--;
        }
        else {
            return false;
        }
    }
    return true;
}

void main() {
    readint;
    auto ds = readints;
    readint;
    auto ts = readints;

    writeln(calc(ds, ts) ? "YES" : "NO");
}


Measured memory_bytes: 34916
from itertools import permutations
from math import ceil

times = list(int(input()) for _ in range(5))
orders = list(permutations(times, 5))
minimum = sum(ceil(time/10)*10 for time in times)

for order in orders:
    total = order[0]
    for i in range(1, 5):
        total += ceil(order[i]/10)*10
    minimum = min(minimum, total)
print(minimum)


Measured memory_bytes: 9080
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;



int main(){
    string s; cin>>s;
    if(s[0] == s[1] or s[1] == s[2] or s[2] == s[3]) cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,m,k,i,j,a[101],te;
	scanf("%d",&n);
	scanf("%d",&m);
	for(j=1;j<=n;j++){
		scanf("%d",&a[j]);
	}
	i=1;
	for(j=1;j<=m;){
		if(i<n&&1<=i){
			if(a[i]%j>a[i+1]%j){
			te=a[i];
			a[i]=a[i+1];
			a[i+1]=te;
			i++;
			}
			else{
				i++;
			}
		}
		if(i==n){
			j++;
			i=1;
		}
	}
	for(j=1;j<=n;j++){
		printf("%d\n",a[j]);
	}
	return 0;
}

Measured memory_bytes: 596
def prime_factorization(N):
    tmp = N
    ans = []
    for i in range(2, int(N ** 0.5) + 1):
        count = 0
        while tmp % i == 0:
            tmp //= i
            count += 1
        if count != 0:
            ans.append([i, count])
    if tmp != 1:
        ans.append([tmp, 1])
    if ans == []:
        ans.append([N, 1])
    return ans

def GetLimit(x):
    X = 2*x
    n = 1
    while True:
        if n*(n+1) <= 2 * x < (n+1)*(n+2):
            return n
        n += 1
N = int(input())
if N==1:
    print(0)
    exit()
PrimeList = prime_factorization(N)
ans = 0
for a, b in PrimeList:
    ans += GetLimit(b)
print(ans)


Measured memory_bytes: 9420