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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

vector<int> MEM(200001, -1);

int	F(const int &S) {
	if (MEM.at(S)>=0)
		return MEM.at(S);
	if (0==S) {
		MEM.at(S)=0;
	} else {
		int S0=S;
		int B=0;
		while (S0>0) {
			if (1==S0%2)
				B++;
			S0 /=2;
		}
		MEM.at(S)=F(S%B)+1;
	}
	return MEM.at(S);
}

int	main() {
	int N;
	string X;
	cin >>N >>X;
	Rev(X);
	int M=0;
	Rep0(i, N)
		if ('1'==X.at(i))
			M++;
	int I0=1;
	int I1=1;
	int D0=0;
	int D1=0;
	Rep0(i, N) {
		if ('1'==X.at(i)) {
			if (1!=M) {
				D0 +=I0;
				D0 %=M-1;
			}
			D1 +=I1;
			D1 %=M+1;
		}
		if (1!=M) {
			I0 *=2;
			I0 %=M-1;
		}
		I1 *=2;
		I1 %=M+1;
	}
	int DD0=D0;
	int DD1=D1;
	I0=1;
	I1=1;
	vector<int> A(N+1, -1);
	Rep0(i, N) {
		int SS=0;
		int SSS=0;
		if ('1'==X.at(i)) {
			if (1!=M) {
				SS=DD0;
				SS +=-I0+M-1;
				SS %=M-1;
				SSS++;
			} else { // 1==M
				A.at(N-i)=0;
			}
		} else {
			SS=DD1;
			SS +=I1;
			SS %=M+1;
			SSS++;
		}
		if (-1==A.at(N-i))
			A.at(N-i)=F(SS)+SSS;
		//
		if (1!=M) {
			I0 *=2;
			I0 %=M-1;
		}
		I1 *=2;
		I1 %=M+1;
	}
	Rep1(i, N)
		cout <<A.at(i) <<endl;
	return 0;
}



Measured memory_bytes: 5152
main(y,m,d,v){
	for(;~scanf("%d%d%d",&y,&m,&d);){
		v=y*416+m*32+d;
		if(v<777384)puts("pre-meiji");
		else if(v<795646)printf("meiji %d %d %d\n",y-1867,m,d);
		else if(v<801625)printf("taisho %d %d %d\n",y-1911,m,d);
		else if(v<827464)printf("showa %d %d %d\n",y-1925,m,d);
		else printf("heisei %d %d %d\n",y-1988,m,d);
	}exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i=0; i<n; i++) {
    cin >> h[i];
  }
  ll dp[n+k];
  for (int i=0; i<n; i++) {
    dp[i] = INT_MAX;
  }
  dp[0] = 0;
  for (int i=0; i<n; i++) {
    for (int j=1; j<=k; j++) {
      dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
      //      cout << i+j << " " << dp[i+j] << endl;
    }
  }
  cout << dp[n-1] << endl;
	     
  return 0;
}


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

using namespace std;
using ll = long long;

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

	int res = 0;
	for (int i = 1; i < N - 1; ++i) {
		if ((v[i] < max(v[i + 1], v[i - 1])) && (v[i] > min(v[i+1], v[i-1]))) {
			++res;
		}
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
typedef long long ll;

ll dp[3010][3010];
int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    // dp[i][j]:=区間[i,j)の状態から出発して、両方が最善を尽くした場合のX-Yの値
    for(int len = 1; len <= N; len++) {
        for(int i = 0; i + len <= N; i++) {
            int j = i + len;
            //先手
            if((N - len) % 2 == 0) {
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);
            } else {
                //後手
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
            }
        }
    }
    cout << dp[0][N] << endl;
    return 0;
}

Measured memory_bytes: 70016
n = int(input())
cnt = 0
p = 0
for i in range(n):
    a,b = map(int,input().split())
    if(a == b):
        cnt += 1
    else:
        cnt *= 0
    if(cnt >= 3):
        p = 1
if(p == 1):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62336
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
#define PI 3.14159265358979323846  
typedef pair<int, int> P;

int main() {
	vector<ll> l;
	int n,ans=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		ll temp;
		cin >> temp;
		l.push_back(temp);
	}
	sort(l.begin(), l.end());
	for (int k = 0; k < n - 2;k++) {
		for (int t = k+1; t < n - 1; t++) {
			for (int u = t + 1; u < n; u++) {
				if (l.at(k) != l.at(t) && l.at(t) != l.at(u) && l.at(u) != l.at(k) && l.at(k) + l.at(t) > l.at(u)) {
					ans++;
				}
			}
		}
		
		
		
	}
	cout << ans << endl;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;
 
template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
 
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const LL LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, k;
	cin >> n >> k;
	VI p(n), c(n);
	FOR(i, 0, n)
	{
		cin >> p[i];
		p[i]--;
	}
	FOR(i, 0, n)
		cin >> c[i];
	LL ans = -INF;
	FOR(i, 0, n)
	{
		vector<LL> prefsum;
		prefsum.PB(0);
		int v = i;
		do
		{
			v = p[v];
			prefsum.PB(prefsum.back() + c[v]);
		}while(v != i);
		//cout << i << " " << prefsum.back() << " " << SZ(prefsum) << endl;
		LL res = -INF;
		if(prefsum.back() > 0)
		{
			int numb = k / (SZ(prefsum) - 1);
			FOR(j, (numb == 0), k %(SZ(prefsum) - 1) + 1)
				setmax(res, prefsum[j]);
			res += numb * prefsum.back();
			if(numb)
			{
				numb--;
				LL res1 = -INF;
				FOR(j, (numb == 0), SZ(prefsum))
					setmax(res1, prefsum[j]);
				res1 += numb * prefsum.back();
				setmax(res, res1);
			}
		}
		else
		{
			FOR(j, 1, SZ(prefsum))
				setmax(res, prefsum[j]);
		}
		setmax(ans, res);
	}
	cout << ans << endl;
	
	
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}
 


Measured memory_bytes: 3996
#include <bits/stdc++.h>
typedef long long       ll;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    string s;
    cin >> s;
    fore(i, 0, s.size())
    {
    	cout << 'x';
    }
    cout << '\n';
    return 0;
}
// PLUS ULTRA!

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }

int n;
int m;

vector<pair<int, ii> > v;

int cnt[4];
int p[100000];
ll s[200001];

ll ans;

int go (int i, int j, ll cur) {
	if (j == n) {
		if (cnt[0] == 0 && cnt[1] > 0 && cnt[2] > 0) re 0;
		ans = min (ans, cur);
		re 0;
	}
	int rem = n - j;
	if (2 * n - i < rem || cur + s[i] - s[i + rem] >= ans) re 0;
	cnt[p[v[i].se.fi]]--;
	p[v[i].se.fi] ^= 1 << v[i].se.se;
	cnt[p[v[i].se.fi]]++;
	go (i + 1, j + 1, cur + v[i].fi);
	cnt[p[v[i].se.fi]]--;
	p[v[i].se.fi] ^= 1 << v[i].se.se;
	cnt[p[v[i].se.fi]]++;
	go (i + 1, j, cur);
	re 0;
}

int main () {
	scanf ("%d", &n);
	for (int i = 0; i < n; i++) {
		int a, b;
		scanf ("%d%d", &a, &b);
		v.pb (mp (a, mp (i, 0)));
		v.pb (mp (b, mp (i, 1)));
	}
	sort (all (v));
	ans = 1e18;
	for (int i = 2 * n - 1; i >= 0; i--) s[i] = s[i + 1] + v[i].fi;
	cnt[0] = n;
	go (0, 0, 0);
	cout << ans << endl;
	cerr << clock () << endl;
	return 0;
}

Measured memory_bytes: 10136
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x,vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1,s) + f(x - 2,s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b,ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m-1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}

int main(){
	int n;
	cin >> n;
	whei(int) s(3, hei(int)(n+1, 0)),dp(3,hei(int)(n+1,0));
	rep(i, 0, 2) {
		rep(j, 0, n) {
			cin >> s[i + 1][j + 1];
		}
	}
	rep(i, 0, 2) {
		rep(j, 0, n) {
			dp[i + 1][j + 1] = s[i + 1][j + 1] + max(dp[i + 1][j], dp[i][j + 1]);
		}
	}
		
	cout << dp[2][n] << endl;
	return 0;
}




  



Measured memory_bytes: 888
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, k) = [int(e) for e in lines[0].split(' ')]
    p = [int(e) for e in lines[1].split(' ')]

    return (n, k, p)


def solve(n, k, p):
    
    p.sort()
    result = sum(p[:k])
                
    return result    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 62652
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int A, B, C, D, P, X, Y;

	cin >> A >> B >> C >> D >> P;

	X = P * A;
	Y = (P > C ? B + D * (P - C) : B);

	cout << min(X, Y) << endl;

	return 0;
}

Measured memory_bytes: 1160
import sys #追加
sys.setrecursionlimit(500*500)

n,q=map(int,input().split())

cost=[0]*n
edge = [[] for _ in range(n)]

for _ in range(n-1):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    edge[a].append(b)
    edge[b].append(a)

for _ in range(q):
    p,x=map(int,input().split())
    cost[p-1]+=x


visited=[-1]*n


def dfs(n,c):

    cost[n]+=c
    tmp=cost[n]
    visited[n]=0

    for v in edge[n]:
        if visited[v]==-1:
            dfs(v,tmp)
    

dfs(0,0)

print(*cost)

Measured memory_bytes: 223284
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 0x3f3f3f3f3f3f3f3f

struct node
{
    bool friend operator < (node n1,node n2)
    {
        return n1.val<n2.val;
    }
    ll val;
};

map <string,bool> mp;
priority_queue <node> que;
ll book[100];
int n,k;

int main()
{
    string s;
    node cur,tmp;
    ll gou[100];
    ll minn,ans;
    int i,j;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        memset(book,0,sizeof(book));
        mp.clear();
        for(i=1;i<=n;i++)
        {
            cin>>s;
            if(!mp[s])
            {
                book[s[0]-'A']++;
                mp[s]=true;
            }
        }
        while(!que.empty()) que.pop();
        for(i=0;i<26;i++)
        {
            if(book[i]!=0)
            {
                tmp.val=book[i];
                que.push(tmp);
            }
        }
        ans=0;
        while(!que.empty())
        {
            if(que.size()<k) break;
            for(i=0;i<k;i++)
            {
                cur=que.top();
                que.pop();
                gou[i]=cur.val;
            }
            ans++;
            for(i=0;i<k;i++)
            {
                gou[i]--;
                if(gou[i]!=0)
                {
                    tmp.val=gou[i];
                    que.push(tmp);
                }
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

/*
10 2
A A A A B B B C C D
*/


Measured memory_bytes: 1280
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	r := getNextInt(scanner)
	c := getNextInt(scanner)
	maze := make([][]byte, r)
	steps := make([][]int, r)
	queue := make([][]int, 0)
	for y := 0; y < r; y++ {
		maze[y] = make([]byte, c)
		steps[y] = make([]int, c)
		s := getNextString(scanner)
		for x := 0; x < c; x++ {
			maze[y][x] = s[x]
			if s[x] == '.' {
				continue
			}
			steps[y][x] = 1
			queue = append(queue, []int{
				y, x, 0,
			})
		}
	}

	dy := [4]int{-1, 0, 0, 1}
	dx := [4]int{0, -1, 1, 0}
	ans := -1
	for len(queue) > 0 {
		p := queue[0]
		queue = queue[1:]
		ans = p[2]
		for i := 0; i < 4; i++ {
			yy := p[0] + dy[i]
			xx := p[1] + dx[i]
			if yy < 0 || yy >= r {
				continue
			}
			if xx < 0 || xx >= c {
				continue
			}
			if maze[yy][xx] == '#' {
				continue
			}
			if steps[yy][xx] > 0 {
				continue
			}
			steps[yy][xx] = 1
			queue = append(queue, []int{
				yy,
				xx,
				p[2] + 1,
			})
		}
	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}


Measured memory_bytes: 125568
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//struct custom_hash {
//    static uint64_t splitmix64(uint64_t x) {
//        // http://xorshift.di.unimi.it/splitmix64.c
//        x += 0x9e3779b97f4a7c15;
//        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//        return x ^ (x >> 31);
//    }
//    size_t operator()(uint64_t x) const {
//        static const uint64_t FIXED_RANDOM = 
//            chrono::steady_clock::now().time_since_epoch().count();
//        return splitmix64(x + FIXED_RANDOM);
//    }
//};

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	ll sum=0;
	for(ll i=1;i<=n;i++)
	{
		if(i%3==0 || i%5==0)
			continue;
		sum+=i;
	}
	cout<<sum;
    return 0;
}


//252908XL

/*
comments:-

*/


Measured memory_bytes: 3600
//stringray

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

/*#ifndef __LOCAL__ 
#pragma comment(linker,"/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif*/ 

using namespace std;
using namespace __gnu_pbds;
 
//#define int int64_t

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ost;

typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<set<int>> vsi;

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define F first
#define S second
#define fore(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define debug(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0)


const int N1=100*1000;
const int N2=1000*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T>
istream& operator >> (istream& is,vector<T>& vec){
  for(T &x:vec)is>>x;
  //for(int i=0;i<vec.size();++i)is>>x[i];
  return is;
}

template<typename T>
ostream& operator << (ostream& os,vector<T>& vec){
  for(int i=0;i<vec.size();++i){
    os<<vec[i]<<(i+1==vec.size()?"":" ");
  }
  return os;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll FIXED_RANDOM=chrono::steady_clock::now().time_since_epoch().count();

struct chash {
    static unsigned long long hash_f(unsigned long long x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }
    int operator()(int x) const { return hash_f(x); }
};
//unordered_map <int, int, chash> m; way to use this 
//the way you're supposed to do is it by initializing FIXED_RANDOM with something like chrono::steady_clock::now().time_since_epoch().count()(current time in microseconds or something like that) and instead of hash_f(x) do hash_f(FIXED_RANDOM^x) 

int getRand(int l, int r)
{
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}

ll mpow(ll a, ll b){
  ll ret=1;
  while(b>0){
    if(b&1LL)(ret*=a)%=mod;
    (a*=a)%=mod;
    b>>=1LL;
  }
  return ret;
}
int d[103];
void solve(){
  int n;cin>>n;
  for(int i=1;i<=n;++i){
    cin>>d[i];
  }
  int ans=0;
  for(int i=1;i<=n;++i)for(int j=i+1;j<=n;++j)ans+=d[i]*d[j];
  cout<<ans<<endl;
}
int32_t  main(){
  IOS;
  cout<<(fixed)<<setprecision(6);
  solve();
  return 0;
}



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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int used[30];
int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	string s;
	cin >> s;

	for(int i=0; i<s.size(); i++){
		used[s[i] - 'a']++;
		if(used[s[i] - 'a'] > 1){
			puts("no");
			return 0;
		}
	}
	puts("yes");
	
	return 0;
}


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

int main(){
    int N;
    vector<int> ans;
    cin >> N;
    while (N != 0){
        int r = N % 2;
        if(r < 0) r += 2;
        
        N = (N -r) / (-2);
        ans.push_back(r);
    }
    reverse(ans.begin(), ans.end());
    if(ans.empty()){
        cout << "0" << endl;
        return 0;
    }
    for(vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr){
        cout << *itr;
    }
        
    return 0;
}


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

int main(){
    ll D;
    cin >> D;
    vector<ll> c(26), t(D), last(26, -1);
    vector< vector<ll> > s(365, vector<ll> (26));
    rep(i, 0, 26) cin >> c[i];
    rep(i, 0, D){
        rep(j, 0, 26) cin >> s[i][j];
    }
    srand((unsigned int)time(NULL));
    rep(i, 0, D){
        t[i] = (ll) (rand() % 26);
    }
    ll M = 2e6;
    vector<ll> rec(26, 0);
    /*
    vector<ll> d(M), q(M), rec(26, 0);
    rep(i, 0, M){
        d[i] = (ll) (rand() % D);
        q[i] = (ll) (rand() % 26);
    }
    */
    ll res = 0;
    rep(d, 0, D){
        res += s[d][t[d]];
        last[t[d]] = d;
        rep(j, 0, 26) {
            res -= c[j] * (d - last[j]);
            rec[j] += c[j] * (d - last[j]);
        }
    }
    vector<ll> median(D);
    rep(i, 0, D){
        auto cp = s[i];
        sort(cp.begin(), cp.end());
        median[i] = cp[20];
    }
    ll rec_sum = 0;
    rep(i, 0, 26) rec_sum += rec[i]; 
    // t[d[m]] := 0 - 25
    rep(m, 0, M){
        ll prev_res = res;
        // ll d = (ll) (rand() % D);
        ll d = m % D;
        ll q = (ll) (rand() % 26);
        // ll q = m % 26;
        // if(rec[q] < c[q] * 100) continue; 
        if(s[d][q] < median[min(25LL, 13 * m / M + 13)]) continue;
        res -= s[d][t[d]];
        res += s[d][q];
        res += rec[t[d]];
        res += rec[q];
        ll tdrec = 0, qrec = 0;
        ll lst = -1;
        rep(i, 0, D){
            if(i != d && t[i] == t[d]){
                lst = i;
            }
            res -= c[t[d]] * (i - lst);
            // rec[t[d[m]]] +=  c[t[d[m]]] * (i - lst);
            tdrec +=  c[t[d]] * (i - lst);
        }
        lst = -1;
        rep(i, 0, D){
            if(i == d || t[i] == q){
                lst = i;
            }
            res -= c[q] * (i - lst);
            // rec[q[m]] += c[q[m]] * (i - lst);
            qrec += c[q] * (i - lst);
        }
        if(res > prev_res){
            rec_sum -= rec[t[d]];
            rec_sum += tdrec;
            rec_sum -= rec[q];
            rec_sum += qrec;
            rec[t[d]] = tdrec;
            rec[q] = qrec;
            t[d] = q;
        }else{
            res = prev_res;
        }
        // cout << res << endl;
    }
    rep(i, 0, D) cout << t[i]+1 << endl;
    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


int main() {
    int n;
    cin >> n;

    string s[n];
    int p[n];
    int flag[n] = {};
    rep(i,n){
        cin >> s[i] >> p[i]; 
    }
    rep(i,n){
        int a = -1;
        string x = "zzzzzzzzzzzz";
        int b = -1;
        rep(j,n){
            if(flag[j]==0){
                if(s[j]<x){
                    x = s[j];
                    a = p[j];
                    b = j+1;
                }else if(s[j]==x){
                    if(a<p[j]){
                        a = p[j];
                        b = j+1;
                    }
                }
            }
        }
        cout << b << endl;
        flag[b-1]=1;
    }


    return 0;
}
 
 


Measured memory_bytes: 256
#include <cstdio>
#include <vector>

std::vector<int> s[1024];

int main() {
	int n, k = 2;
	scanf("%d",&n);
	while (k * (k-1) < n<<1) k++;
	if (k * (k-1) != n<<1) {puts("No"); return 0;}
	for (int i = 1; i < k; i++)
		for (int j = 0; j < i; j++) {
			s[i].push_back(n);
			s[j].push_back(n);
			n--;
		}
	puts("Yes");
	printf("%d\n",k);
	for (int i = 0; i < k; i++) {
		printf("%lld ",s[i].size());
		for (int a : s[i])
			printf("%d ",a);
		putchar(10);
	}
	return 0;
}


Measured memory_bytes: 2304
n = input()
m = [0] * n
max_rieki = -1000000000



for i in xrange(n):
 m[i] = input()

min_rieki = m[0]
for i in xrange(1,n): 
  if max_rieki < m[i] - min_rieki:
     max_rieki = m[i] - min_rieki
  if min_rieki > m[i]:
     min_rieki = m[i]

print max_rieki

Measured memory_bytes: 12680
let a, b = Scanf.scanf "%d %d\n" (fun a b -> a, b)
let rec pow n x =
  match n with
  | 1 -> x
  | n' -> x * pow (n'-1) x

let ans =
  if a = 1 then b
  else b * pow (a-1) (b-1)

let () =
  print_int ans; print_newline ()

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
  int n, k = 0, val;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> val;
    if(val == k+1){
      k = val;
    }
  }
  if(k == 0){
    cout << -1;
  }else{
    cout << n - k;
  }
  return 0;
}


Measured memory_bytes: 256
a, b, k = map(int, input().split())

if a+k-1 < b-k+1:
    for i in range(a, a+k):
        print(i)
    for j in range(b-k+1, b+1):
        print(j)
else:
    for i in range(a, b+1):
        print(i)


Measured memory_bytes: 3060
import itertools
N=int(input())
A=[0]*5
for i in range(N):
    S=input()
    if(S[0]=='M'):
        A[0]+=1
    elif(S[0]=='A'):
        A[1]+=1
    elif(S[0]=='R'):
        A[2]+=1
    elif(S[0]=='C'):
        A[3]+=1
    elif(S[0]=='H'):
        A[4]+=1
sum=0
for v in itertools.combinations(A,3):
    sum+=v[0]*v[1]*v[2]
print(sum)

Measured memory_bytes: 3064
#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, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#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--)
#define mp make_pair
#define fi first
#define sc second
ll a,b;
int main(){
    cin >> a >> b;

    if(a * b <= 0)
        cout << "Zero" << endl;
    else if(a > 0)
        cout << "Positive" << endl;
    else
        if((b - a + 1) % 2)
            cout << "Negative" << endl;
        else
            cout << "Positive" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 1010;

int main(int argc, char const *argv[]) {
  int q;
  cin >> q;
  for (auto k = 0; k < q; k++) {
    vector<vector<int>> dp(MAXN, vector<int>(MAXN, 0));
    string s1, s2;
    cin >> s1 >> s2;
    auto n = s1.size();
    auto m = s2.size();
    for (size_t i = 0; i < n; i++) {
      for (size_t j = 0; j < m; j++) {
        if (s1[i] == s2[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
        } else {
          dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
        }
      }
    }
    cout << dp[n][m] << endl;
  }

  return 0;
}

Measured memory_bytes: 6824
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define MAX 1000000000000000000LL
long long inf=1000000007;
using namespace std;
int main(){
    int h,w,n;
    cin>>h>>w>>n;
    int a[10005];
    int color[105][105]={};
    
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    
    int k=1;
    
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(a[k]==0)k++;
            color[i][j]=k;
            a[k]--;
        }
    }
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w;j++){
            if(j!=1)cout<<" ";
            if(i%2==1)cout<<color[i][j];
            else cout<<color[i][w-j+1];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using P = pair<int, int>;
int s, d, m;
int f[101];
P dp1[102][302];
int cost[102][302];
P dfs1(int idx, int p) {
    // printf("%d %d\n", idx, p);
    if (idx == d) return P(0, 0);
    if (dp1[idx][p] != P(-INF, -INF)) return dp1[idx][p];
    auto res = P(0, 0);

    rep(i, p + 1) {
        auto t = dfs1(idx + 1, p - i);
        t.first += cost[f[idx]][i];
        t.second -= i;
        res = max(res, t);
    }
    return dp1[idx][p] = res;
}
int main() {
    while (cin >> s >> d >> m && s) {
        rep(i, 102) rep(j, 302) dp1[i][j] = P(-INF, -INF);
        rep(i, 102) rep(j, 302) cost[i][j] = 0;
        rep(i, s) {
            int k;
            cin >> k;
            vector<int> ws, ps;
            rep(j, k) {
                int w, p;
                cin >> w >> p;
                ws.push_back(w);
                ps.push_back(p);
            }
            rep(a, k) for (int j = m + 1; j >= ps[a]; j--) {
                cost[i][j] = max(cost[i][j], cost[i][j - ps[a]] + ws[a]);
            }
        }
        rep(i, d) cin >> f[i];
        auto ans1 = dfs1(0, m);
        cout << ans1.first << " " << -ans1.second << endl;
    }
    return 0;
}

Measured memory_bytes: 3480
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

static bool is_prime(large x) {
    if (x <= 1 || x % 2 == 0 || x % 3 == 0)
        return false;
    for (auto k = 5LL; k * k <= x; k += 6) {
        if (x % k == 0)
            return false;
        if (x % (k + 2) == 0)
            return false;
    }

    return true;
}

int main() {
    large n;
    cin >> n;

    auto primes = std::vector<large>();
    primes.push_back(2);
    primes.push_back(3);
    for (auto x = 5LL; x * x <= 1'000'000'000'000; x += 6) {
        if (is_prime(x))
            primes.push_back(x);
        if (is_prime(x + 2))
            primes.push_back(x + 2);
    }

    auto counter = map<large, large>();
    {
        auto x = n;
        for (auto p : primes) {
            if (x < p)
                break;
            if (x % p == 0) {
                x /= p;
                auto cnt = 1LL;
                while (x % p == 0) {
                    x /= p;
                    cnt++;
                }
                counter[p] = cnt;
            }
        }
        if (x != 1) {
            counter[x] = 1;
        }
    }

    auto total = 0LL;
    for (auto [val, cnt] : counter) {
        // cout << val << " for " << cnt << "times\n";
        for (auto size = 1; size <= cnt; size++) {
            cnt -= size;
            total++;
        }
    }

    cout << total << endl;
    return 0;
}


Measured memory_bytes: 4320
#include <stdio.h>

int main(void){

    int H = 0;
    int N = 0;

    scanf("%d %d", &H, &N);

    int A[N];

    for (int i = 0; i < N; i++){
        scanf("%d", &A[i]);
        H = H - A[i];

    }

    if (H <= 0){
        printf("Yes\n");

    } else{
        printf("No\n");

    }

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
LL A[505050];
int n,ans;
bool Tag[2020202];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%lld",&A[i]);
	sort(A+1,A+n+1);
	for (LL x=(1ll<<31);x>0;x>>=1ll){
		int r=n;
		for (int l=1;l<=n;l++){
			if (l>=r) break;
			if (Tag[l]) continue;
			while (r>l&&(Tag[r]||A[l]+A[r]>x)) r--;
			if (l>=r) break;
			if (A[l]+A[r]==x){
				Tag[l]=1; Tag[r]=1; ans++;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using i64 = long long;

template <typename T, typename U, typename V>
auto pow(T x_, U n_, V mod_) {
    std::common_type_t<T, U, V> ret = 1, x = x_, n = n_, mod = mod_;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <typename T, typename U>
auto inverse(T x, U p) { return pow(x, p - 2, p); }

int main() {
    constexpr i64 mod = 998244353;
    constexpr int m = 1000001;
    int n;
    std::cin >> n;
    std::vector<i64> a(n), w(m, 1), c(m);
    for (auto &e : a) {
        std::cin >> e;
        c[e]++;
    }

    for (int i = 2; i < m; i++) {
        auto inv = inverse(i, mod);
        w[i] = (inv - w[i] + mod) % mod;
        for (int j = 2; j * i < m; j++) w[j * i] = (w[j * i] + w[i]) % mod;
    }

    i64 ret = 0, inv2 = inverse(2, mod);
    for (int i = 1; i < m; i++) {
        i64 s = 0, sq = 0;
        for (int j = 1; j * i < m; j++) {
            s = (s + c[j * i] * j % mod * i % mod) % mod;
            sq = (sq + c[j * i] * j % mod * j % mod * i % mod * i % mod) % mod;
        }
        i64 t = (s * s % mod + mod - sq) % mod * inv2 % mod;
        ret = (ret + w[i] * t % mod) % mod;
    }

    std::cout << ret << std::endl;

    return 0;
}


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

long gcd(long a, long b){
    if (a<b)
        swap(a,b);
    while(b>0){
        a = a%b;
        swap(a,b);
    }
    return a;
}

int main(void){
    // Your code here!
    long A,B;
    cin >> A >> B;
    cout << A*B/gcd(A,B);
    return 0;
}

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

int main(){
	
	string s={};
	cin>>s;
	
	int num=0;
	for(int i=0;s[i]!=0;i++){
		num++;
	}
	
	cout<<s[0]<<num-2<<s[num-1]<<endl;
	
	return 0;
}

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

using namespace std;

int H, W;
int main() {
  cin >> H >> W;

  string board[H];

  for (int i = 0; i < H; ++i) cin >> board[i];

  const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (board[i][j] == '#') continue;

      int num = 0;
      for (int d = 0; d < 8; ++d) {
        const int ni = i + dy[d];
        const int nj = j + dx[d];

        if (ni < 0 or H <= ni) continue;
        if (nj < 0 or W <= nj) continue;
        if (board[ni][nj] == '#') num++;
      }

      board[i][j] = char('0' + num);

    }
  }

  for (int i = 0; i < H; ++i) cout << board[i] << endl;

  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

vector<pair<int,int>> G[100009];
bool visited[100009] = {false};
int cost[100009] = {INF};

bool bfs(int s) {
    visited[s] = true;
    cost[s] = 0;
    queue<int> q; q.push(s);
    
    while( !q.empty() ) {
        
        int u = q.front(); q.pop();
        
        rep(i,G[u].size()) {
            int t = G[u][i].first, c = G[u][i].second;
            if ( !visited[t] ) {
                visited[t] = true;
                cost[t] = cost[u] + c;
                q.push(t);
            } else {
                if ( cost[u] + c != cost[t] ) return false;
            }
        }
    }
    return true;
}

int main() {
    int N, M;
    cin >> N >> M;
    
    int L, R, D;
    rep(i,M) {
        cin >> L >> R >> D;
        G[L].push_back({R,D});
        G[R].push_back({L,-D});
    }
    
    rep1(i,N) {
        if ( visited[i] || G[i].empty() || bfs(i) )  continue;
        cout1("No");
        return 0;
    }
    
    cout1("Yes");
}

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

const int MOD = (int)1e9+7;

int main(){
	string s,t;
	cin >> s >> t;
	
	vector<bool> alf(26,false);
	for(int i=0;i<s.size();i++){
		alf.at(s.at(i)-'a')=true;
	}
	for(int i=0;i<t.size();i++){
		if(alf.at(t.at(i)-'a')==false){
			cout << -1 << endl;
			return 0;
		}
	}
	
	vector<vector<int>> ss(26);
	for(int i=0;i<s.size();i++){
		ss.at(s.at(i)-'a').push_back(i);
	}
	/*
	for(int i=0;i<ss.size();i++){
	printf("%c :",i+'a');
	for(int j=0;j<ss.at(i).size();j++){
	cout << ss.at(i).at(j) << ",";
}
cout << endl;
}
*/
long long ans=0;
long long now=0;
for(int i=0;i<t.size();i++){
	int xx=t.at(i)-'a';
	auto iter=lower_bound(ss.at(xx).begin(),ss.at(xx).end(),now);
	int yy=iter-ss.at(xx).begin();
	if(yy>=ss.at(xx).size()){
		//cout << "if :";
		ans+=(s.size()-now);
		iter=lower_bound(ss.at(xx).begin(),ss.at(xx).end(),0);
		yy=iter-ss.at(xx).begin();
		long long zz=ss.at(xx).at(yy);
		ans+=zz+1;
		now=zz+1;
	}
	else{
		long long zz=ss.at(xx).at(yy);
		//cout << "el :";
		ans+=(zz+1-now);
		now=zz+1;
	}
	//cout << i << ": " << ans << ": " << now << endl;
}
cout << ans << endl;

return 0;
}


Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

const ll MOD = 1e9 + 7;

ll power(ll x,ll y){
    ll res = 1;

    while(y){
        if(y&1) res = (res*x)%MOD;
        x = (x*x)%MOD;
        y >>= 1;
    }
    return res;
}

const ll MAXN = 1e4 + 100;
set<ll> graph[MAXN];
ll arr[MAXN];
ll u[MAXN],v[MAXN];
bool visit[MAXN];
ll ass[MAXN];

ll ans = 0;
void dfs(ll u,ll p){
    
    for(ll v:graph[u]){
        if(v!=p){
            ans += min(ass[u],ass[v]);
            dfs(v,u);
        }
    }
}

void solve(){   
    ll n; cin>>n;

    FOR(i,1,n-1){
        cin>>u[i]>>v[i];
        graph[u[i]].insert(v[i]);
        graph[v[i]].insert(u[i]);
    }

    FOR(i,1,n) cin>>arr[i];
    sort(arr+1,arr+n+1);
    reverse(arr+1,arr+n+1);

    queue<ll> q;

    q.push(1);
    visit[1] = true;
    ll j = 1;
    ass[1] = arr[j++];
    
    while(q.size()){
        ll u = q.front();
        q.pop();
        for(ll v:graph[u]){
            if(!visit[v]){
                ass[v] = arr[j++];
                q.push(v);
                visit[v] = true;
            }
        }
    } 

    dfs(1,-1);
    ll sum_1 = accumulate(arr+1,arr+n+1,0) - *max_element(arr+1,arr+n+1);

    cout<<ans<<endl;
    FOR(i,1,n) cout<<ass[i]<<" ";
    assert(ans == sum_1);
}   

signed main(){

   FastRead;    


    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}




Measured memory_bytes: 2560
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
//cout << std::fixed << std::setprecision(15) << y << endl;

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

  if(S[S.size()-1] == 's') cout << S + "es" << endl;
  else cout << S + "s" << endl;
  return 0;
}

Measured memory_bytes: 3636
n=int(input())
a =list(map(int,input().split()))
b =list(map(int,input().split()))

res=0
for i in range(n):

    if b[i] >= a[i]:
        res+=a[i]
        t = b[i] - a[i]
        res+=min(t,a[i+1])
        a[i+1] = max(0,a[i+1] - t)

    else:
        res+=b[i]

print(res)

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

	int main(){
		int a, b, sum=0, max=0;
		vector<int>rest;
		for (int i=0; i<5; i++){
			cin >> a;
			sum += a;
			b = 10 - a%10;
			if (a%10 != 0){
				rest.push_back(b);
			}
			if (max < b && a%10 != 0){
				max =b;
			}
		}
		for (int i=0; i<rest.size(); i++){
			sum += rest[i];
		}
		cout << sum - max << endl;
		return 0;
	}

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

typedef long long ll;
typedef pair<int, int> ii;

int main()
{
    int l;
    scanf("%d", &l);

    double edge = l * 1.0 / 3;

    printf("%.15f\n", edge * edge * edge);

    return 0;
}


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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        string s;
        cin >> s;
        for( int i = 1; i < s.size(); i++ ) {
                if( s[i] == s[i-1] ) return cout << "Bad" << endl,0;
        }
        cout << "Good" << endl;
        return 0;
}










Measured memory_bytes: 256
#include <iostream>

using namespace std;


class Solution{

public:
    int ways(int N, int K){

        int res = K;
        for(int i = 1; i < N; i ++)
            res *= (K - 1);
        return res;
    }
};

int main() {

    int N, K;
    scanf("%d%d", &N, &K);
    printf("%d\n", Solution().ways(N, K));

    return 0;
}


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

int main(){
    int N, M;  cin >> N >> M;
    ll mod = 1e9+7;

    vector<ll> S(N+1,0), T(M+1,0);
    for(int i=1; i<=N; i++) cin >> S[i];
    for(int i=1; i<=M; i++) cin >> T[i];

    vector<vector<ll>> dp(N+1, vector<ll>(M+1,0));
    vector<vector<ll>> sum(N+1, vector<ll>(M+1,0));
    dp[0][0] = 1;
    for(int n=0; n<=N; n++) sum[n][0] = 1;
    for(int m=0; m<=M; m++) sum[0][m] = 1;

    for(int n=1; n<=N; n++) for(int m=1; m<=M; m++){
        if(S[n] == T[m]) dp[n][m] = sum[n-1][m-1];
        sum[n][m] = sum[n-1][m];
        sum[n][m] = (sum[n][m] + sum[n][m-1])%mod;
        sum[n][m] = (sum[n][m] + dp[n][m])%mod;
        sum[n][m] = (sum[n][m] - sum[n-1][m-1])%mod;
        while(sum[n][m]<0){
            sum[n][m] += mod;
        }

    }

    cout << sum[N][M] << endl;
}



Measured memory_bytes: 62976
def main():
    n = int(input())

    dic = dict()

    for i in range(n):
        s = input()
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1

    m = int(input())

    for i in range(m):
        t = input()
        if t in dic:
            dic[t] -= 1

    max_v = 0
    for k, v in dic.items():
        if v > max_v:
            max_v = v

    print(max_v)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
N, M = map(int, input().split())
 
f = set()
t = set()
 
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        f.add(b)
    elif a == N:
        t.add(b)
    if b == 1:
        f.add(a)
    elif b == N:
        t.add(a)
 
pos = "IMPOSSIBLE"
 
if f&t:
    pos = "POSSIBLE"
 
print(pos)

Measured memory_bytes: 19024