akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using P = pair<ll, ll>;
const int INF = 1001001001;

vector<P> to[100000];
bool visit[100000];
ll dist[100000];

bool dfs(ll v, ll d){
  if(visit[v]){
    return (d != dist[v]) ? false : true;
  }
  visit[v] = true;
  dist[v] = d;
  for(P p : to[v]){
    if(!dfs(p.first, d+p.second)) return false;
  }
  return true;
}

int main(void){
  ll n, m;
  cin >> n >> m;
  REP(i, m){
    ll l, r, d;
    cin >> l >> r >> d;
    l--; r--;
    to[l].emplace_back(P(r, d));
    to[r].emplace_back(P(l, -d));
  }
  
  bool ans = true;
  REP(i, n) ans &= dfs(i, dist[i]);
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 15616
import math
eps = 10 ** -7
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
ans = float('inf')
if n == 2:
    x1, y1 = l[0]
    x2, y2 = l[1]
    d = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5
    print(d / 2)
    exit(0)
for i in range(n):
    x1, y1 = l[i]
    for j in range(i + 1, n):
        x2, y2 = l[j]
        for k in range(j + 1, n):
            x3, y3 = l[k]
            d1, d2, d3 = [(x1 - x2) ** 2 + (y1 - y2) ** 2, (x1 - x3)
                          ** 2 + (y1 - y3) ** 2, (x2 - x3) ** 2 + (y2 - y3) ** 2]
            sd1, sd2, sd3 = sorted([d1, d2, d3])
            if sd1 + sd2 > sd3:
                points = [x1, y1, x2, y2, x3, y3]
                a = points[0]
                b = points[1]
                c = points[2]
                d = points[3]
                e = points[4]
                f = points[5]

                aa = a * a
                bb = b * b
                cc = c * c
                dd = d * d
                ee = e * e
                ff = f * f

                y = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee - ff)
                     ) / (2 * (e - a)*(b - d) - 2 * (c - a) * (b - f))

                x = (2 * (b - f) * y - aa - bb + ee + ff) / (2 * (e - a)) \
                    if (c == a) else (2 * (b - d) * y - aa - bb + cc + dd) / (2 * (c - a))

                r = math.hypot(x - a, y - b)
            else:
                idx = [d1, d2, d3].index(max(d1, d2, d3))
                if idx == 0:
                    x = x1 + (x2 - x1) / 2
                    y = y1 + (y2 - y1) / 2
                    r = d1 ** .5 / 2
                elif idx == 1:
                    x = x1 + (x3 - x1) / 2
                    y = y1 + (y3 - y1) / 2
                    r = d2 ** .5 / 2
                else:
                    x = x3 + (x2 - x3) / 2
                    y = y3 + (y2 - y3) / 2
                    r = d3 ** .5 / 2
            for s in range(n):
                px, py = l[s]
                if ((px - x) ** 2 + (py - y) ** 2) ** .5 - r > eps:
                    break
            else:
                ans = min(ans, r)
print(ans)


Measured memory_bytes: 63852
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,a[100],cnt1=0,cnt2=0,ans=10000000;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    cnt1+=a[i];
  }
  for(int i=0; i<n; i++) {
    cnt2+=a[i];
    if(abs((cnt1-cnt2)-cnt2)<ans) {
      ans=abs((cnt1-cnt2)-cnt2);
    }
  }
  cout << ans << endl;
}

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

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int mod = (int) 1e9 + 7;
const int N = 1e6 + 6;

ll f[N], inv[N], finv[N];

void init() {
	f[0] = f[1] = inv[0] = inv[1] = finv[0] = finv[1] = 1;
	for (int i = 2; i < N; i++) {
		f[i] = (f[i - 1] * i) % mod;
		inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
		finv[i] = (finv[i - 1] * inv[i]) % mod;
	}
}

ll nCr(ll n, ll r) {
	return (f[n] * ((finv[r] * finv[n - r]) % mod)) % mod;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	init();
	int n, m;
	cin >> n >> m;
	int res = 0;
	for (int i = 0; i <= n; i++) {
		if ((n - i) % 2 != 0)
			continue;
		int j = (n - i) / 2;
		if (i * 2 + j != m)
			continue;
		(res += nCr(i + j, j)) %= mod;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 23680
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var p, q, r int
	fmt.Fscan(read, &p, &q, &r)
	fmt.Fprintln(write, min(p+q, min(q+r, r+p)))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
	x = 0;
	char ch = 0;
	bool sign = false;
	while (ch < '0' || '9' < ch) sign |= ch == '-', ch = getchar();
	while ('0' <= ch && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	x = sign ? -x : x;
}
template <typename T>
inline void print(T x) {
	static char outp[64];
	if (!x) { putchar('0'); return; }
	if (x < 0) putchar('-'), x = -x;
	int tot = 0;
	while (x) outp[tot++] = x % 10 + '0', x /= 10;
	while (tot) putchar(outp[--tot]);
}
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define all(it) it.begin(), it.end()
#define rep(it, f, e) for (rint it = f; it <= e; ++it)
#define per(it, f, e) for (rint it = f; it >= e; --it)
int main() {
	//filename("");
	//ios::sync_with_stdio(false);
	//cin.tie(NULL), cout.tie(NULL);
	ll k, a, b, ans = 0;
	cin >> k >> a >> b;
	++k;
	if (k <= a) {
		ans = k;
	} else {
		if (b - a > 2) {
			ans = a;
			k -= a;
			if (k & 1) {
				ans += (k - 1) / 2 * (b - a) + 1;
			} else {
				ans += k / 2 * (b - a);
			}
		} else {
			ans = k;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  string s;
  cin >> s;
  cout << s.substr(0, s.size() - 8) << endl;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split(" ")))
sws = []
for i in range(M):
    tmp = list(map(int, input().split(" ")))[1:]
    sws.append(sum(2 ** (i - 1) for i in tmp))
p = list(map(int, input().split(" ")))

count = 0
for i in range(2 ** N):
    for j in range(M):
        if bin(i & sws[j]).count("1") % 2 != p[j]:
            break
    else:
        count += 1
print(count)

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  while (1) {
    bool flg = true;
    rep(i, n) {
      if (a[i] % 2) flg = false;
      a[i] /= 2;
    }
    if (!flg) break;
    ans++;
  }
  cout << ans << endl;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int r;
  cin >> r;
  cout << r * r << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = "";
		;
		int a, b;

		while (true) {

			a = sc.nextInt();
			s = sc.next();
			b = sc.nextInt();

			if (s.equals("+")) {
				System.out.println(a + b);
			} else if (s.equals("-")) {
				System.out.println(a - b);
			} else if (s.equals("*")) {
				System.out.println(a * b);
			} else if (s.equals("/")) {
				System.out.println(a / b);
			} else {
				break;
			}

		}

	}

}

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

int main()
{
	int N;
	cin >> N;
	vector<int> h(N + 2), mi(N + 2), ma(N + 2);
	for (int i = 1; i <= N; i++) {
		cin >> h[i];
	}
	vector<P> st;
	for (int i = 1; i <= N + 1; i++) {
		while (!st.empty() && st.back().second > h[i]) {
			ma[st.back().first] = i - 1;
			st.pop_back();
		}
		st.push_back(P(i, h[i]));
	}
	st.clear();
	for (int i = N; i >= 0; i--) {
		while (!st.empty() && st.back().second > h[i]) {
			mi[st.back().first] = i + 1;
			st.pop_back();
		}
		st.push_back(P(i, h[i]));
	}
	long long res = 0;
	for (int i = 1; i <= N; i++) {
		res = max(res, (long long)(ma[i] - mi[i] + 1) * h[i]);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 4960
unittest
{
	assert( [ "3 4" ].parse.expand.solve == "Even" );
	assert( [ "1 21" ].parse.expand.solve == "Odd" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ab = input.front.split.to!( long[] );
	return tuple( ab[ 0 ], ab[ 1 ] );
}

auto solve( long a, long b )
{
	return ( a * b % 2 == 0 ) ? "Even" : "Odd";
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
 
#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define pb push_back
 
using namespace std;
 
const int N = 100010;
 
vector<int> G[N];
int n, mask[N];
 
void DFS(int o, int f){
	int label = 0, s = 0;
	//for(int v : G[o]){
	for (int i=0;i<G[o].size();++i)
	{
	int v=G[o][i];
		if(v == f) continue;
		DFS(v, o);
		label |= s & mask[v];// 值域> 
		s |= mask[v];//子树的前缀值域 或 
	}
	label = label << 1 | 1;
	Forr(i, 30, 0) if(label & (1 << i))
		For(j, i, 30) if(!(s & (1 << j))){//不能等于s中的值 
			mask[o] = //(s ^ (s & ((1 << j) - 1))) | (1 << j);
			  (s>>j<<j)|(1<<j);
			return;
		}
}
 
int main(){
	scanf("%d", &n);
	For(i, 2, n){
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].pb(v), G[v].pb(u);
	}
	DFS(1, 0);
	//for(int i=1;i<=n;++i) printf("%d\n",mask[i]) ;
	Forr(i, 30, 0) if(mask[1] & (1 << i)){
		printf("%d\n", i);
		return 0;
	}
}

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

int main(){
  string str = "1";
  int count = 0;
  
  while(1){
    cin >> str;
    if(str == "0") break;
    for(int i = 0; i < str.size(); i++){
      count += str.at(i) - '0';
    }
    cout << count << endl;
    count = 0;
  
  }
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#include <cstring>
#include <map>
#include <set>
#define int long long int
using namespace std;
const int MAX = 1000000007;

double dp[4000][4000];

signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    
    int n, i, j;
    cin>>n;
    double a[n+1], sum=0;
    for(i=1;i<=n;i++)
        cin>>a[i];
    dp[0][0] = 1;
    for(i=1;i<=n;i++)
        dp[i][0]=dp[i-1][0]*(1-a[i]);
    for(int i=1;i<=n;i++){
        for(j=1;j<=i;j++){
            dp[i][j] = dp[i-1][j]*(1-a[i]) + dp[i-1][j-1]*(a[i]);
        }
    }
    for(i=(n+1)/2;i<=n;i++){
        sum+=dp[n][i];
    }
    cout<<fixed<<setprecision(15)<<sum<<endl;
    
}


Measured memory_bytes: 92800
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,A,B;
  cin >> N >> A >> B;
  long long int a = 0,b =0,c = 0;
  a = N/(A + B);
  b = N%(A + B);
  long long int answer = 0;
  if(b > A){
    b = A;
  }
  answer = A*a + b;
  cout << answer << endl;
}


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

struct Node{
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		} else {
			x = x->right;
		}
	}
	z->parent = y;
	if( y == NIL){
		root = z;
	} else {
		if(z->key < y->key){
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

bool find(int k, Node *u){
	if(u == NIL) return false;
	if(u->key == k) return true;
	return (u->key > k)?find(k,u->left):find(k,u->right);
}

void inorder(Node *u){
	if( u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preoder(Node *u){
	if( u == NIL) return;
	printf(" %d", u->key);
	preoder(u->left);
	preoder(u->right);
}

int main(){
	int n;
	string s;
	
	cin>>n;
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++){
		// scanf("%s", s);
		cin>>s;
		if(s == "print"){
			inorder(root);
			printf("\n");
			preoder(root);
			printf("\n");
		} else if(s == "insert"){
			int x;
			scanf("%d", &x);
			insert(x);
		} else if(s == "find"){
			int k;
			scanf("%d", &k);
			printf(("%s",find(k,root)?"yes":"no"));
			printf("\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 22020
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    ll a,b,k;
    cin>>a>>b>>k;
    bool t=1;
    while (k--)
    {
        if (t)
        {
            if (a&1)
                a--;
            b=b+a/2;
            a/=2;
            t=0;
        }
        else
        {
            if (b&1)
                b--;
            a=a+b/2;
            b/=2;
            t=1;
        }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 3568
import sys
from bisect import bisect_left, bisect_right, insort

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
S = list('-' + sr())
d = [[] for _ in range(26)]
for i in range(1, N+1):
    s = S[i]
    o = ord(s) - ord('a')
    d[o].append(i)

Q = ir()
for _ in range(Q):
    q, a, b = sr().split()
    if q == '1':
        a = int(a)
        if S[a] == b:
            continue
        prev = ord(S[a]) - ord('a')
        d[prev].remove(a)
        next = ord(b) - ord('a')
        insort(d[next], a)
        S[a] = b
    else:
        a = int(a); b = int(b)
        ans = 0
        for alpha in range(26):
            if bisect_right(d[alpha], b) - bisect_left(d[alpha], a) >= 1:
                ans += 1
        print(ans)


Measured memory_bytes: 94556
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pi 3.14159265358979323846
#define mod 1000000007
int main()
{ 
    ll p;
    p=1;
    while(p--)
    {
        ll a,b,c,d,e,cnt=0;
        cin>>a;
        ll A[a];
        for(b=0;b<a;b++)
        {
            cin>>A[b];
        }
        sort(A,A+a);
        for(b=0;b<a;b++)
        {
            for(c=b+1;c<a;c++)
            {
                if(A[b]!=A[c])
                {
                for(d=c+1;d<a;d++)
                {
                    if(A[b]+A[c]>A[d] && A[b]!=A[d] && A[c]!=A[d]) cnt++;
                }
                }
            }
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 3676
#include <cstdio>
#include <iostream>

int max(int a,int b){
    return a > b ? a : b;
}

int main(){
    int a,b;
    std::cin >> a >> b;
    int ans = max(max(2*a-1,a+b),2*b-1);
    std::cout << ans << std::endl;
    return 0;
}

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

#define ACS(A) (A + 10000)

string S;
int x, y;


int siz;

int end_;

int dx[16000];
int dy[16000];


int main()
{
    cin >> S;
    cin >> x >> y;
    int i = 0;
    int cou = 0;
    for(;i < S.size();i++)
    {
        if(S[i] == 'T') break;
        cou++;
    }
    S += "T";
    x-=cou;
    int swi = -1;
    cou = 0;
    int ix = 0,iy = 0;
    i++;
    for(;i < S.size();i++)
    {
        if(S[i] == 'T')
        {
            if(swi == 1)
            {
                dx[ix] = cou;
                ix++;
            }
            else
            {
                dy[iy] = cou;
                iy++;
            }
            swi *= -1;
            cou = 0;
        }
        else cou++;
    }

    bool dpx[ix + 1][8010 * 2 + 1];
    dpx[0][8010] = true;
    for(int j = 0;j < ix;j++)
    {
        for(int k = 0;k < 8010 * 2;k++)
        {
            if(dpx[j][k] && k - dx[j] >= 0) dpx[j + 1][k - dx[j]] = true;
            if(dpx[j][k] && k + dx[j] <= 8010 * 2) dpx[j + 1][k + dx[j]] = true;
        }
    }

    bool dpy[iy + 1][8010 * 2 + 1];
    dpy[0][8010] = true;
    for(int j = 0;j < iy;j++)
    {
        for(int k = 0;k < 8010 * 2;k++)
        {
            if(dpy[j][k] && k - dy[j] >= 0) dpy[j + 1][k - dy[j]] = true;
            if(dpy[j][k] && k + dy[j] <= 8010 * 2) dpy[j + 1][k + dy[j]] = true;
        }
    }

    if(dpx[ix][8010 + x] && dpy[iy][8010 + y]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 121984
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
int main() {
    int n;
    scanf("%d", &n);
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    double ave = sum * 1.0 / n;
    int g = 0;
    double m = 200;
    for (int i = 1; i <= n; i++) {
        if(abs(a[i] - ave) < m) {
            m = abs(a[i] - ave);
            g = i;
        }
    }
    printf("%d\n", g - 1);
    return 0;
}

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

using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> dp(3,0);

    for(int day=0; day<n; ++day){
        vector<int> cost(3);
        for(int i=0; i<3; ++i){
            cin>>cost[i];
        }
        vector<int> new_dp(3,0);
        for(int i=0; i<3; ++i){
            for(int j=0; j<3; ++j){
                if(i!=j)
                    new_dp[i] = max(new_dp[i], dp[j]+cost[i]);
            }
        }
        dp = new_dp;
    }
    cout<<*max_element(dp.begin(), dp.end())<<'\n';
}

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

    // int t; cin>>t;
    // while(t--)
        solve();
}

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

int main()
{
ll n , k ;
cin >> n >> k ;
vector<ll> p(n);
rep(i, n){
  cin >> p[i];
}
double sum=0;
rep(i,k){
  sum+=p[i];
}
ans=sum;
rep(i,n-k){
  sum-=p[i];
  sum+=p[k+i];
  ans=max(ans,sum);
}
cout<<fixed<<setprecision(12)<<(ans+k)/2<<endl;

return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#define maxn 100005
using namespace std;
int a[maxn][3];
int dp[maxn][3];
void DFS(int n){
    if(n<1) return;
    int maxN = 0, index;
    for(int i=0; i<3; i++){
        if(dp[n][i] > maxN){
            maxN = dp[n][i];
            index = i;
        }
    }
    DFS(n-1);
    cout << (char)(index+'a') <<  " ";
}
int main(void)
{

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i][0];
        dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + a[i][1];
        dp[i][2] = max(dp[i-1][1], dp[i-1][0]) + a[i][2];
    }
//    DFS(n);
//    cout <<endl;
    cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
    return 0;
}



Measured memory_bytes: 2560
/*
* Author : Omkar Deshmukh
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define all(v) v.begin(), v.end()
#define intvect vector<int>
#define llvect vector<ll>
#define pb push_back
#define all(v) v.begin(), v.end()
#define ull unsigned long long
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
const int mod = 1e9 + 7;

void solve()
{
    int s,w;
    cin >> s >> w;
    if(w>=s)
    cout << "unsafe";
    else
    cout << "safe";
}
int main()
{
    fast;
    solve();
    return 0;
}

Measured memory_bytes: 3664
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

ls = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
S = raw_input()
for i in range(7):
    if S == ls[i]:
        print 7 - i


Measured memory_bytes: 4268
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int X, A;
  std::cin >> X >> A;

  // Main
  if (X < A)
    std::cout << 0 << std::endl;
  else
    std::cout << 10 << std::endl;

  // Output

  return 0;
}


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

using namespace std;

#define ll long long
typedef complex<double> P;

int main() {
  int n; cin >> n;
  int s[n];
  int score = 0;

  for (size_t i = 0; i < n; i++) {
    cin >> s[i];
    score += s[i];
  }

  sort(s, s+n);

  if(score % 10 == 0) {
    for (size_t i = 0; i < n; i++) {
      if(s[i] % 10 != 0) {
        score -= s[i];
        break;
      }
    }
  }

  if(score % 10 == 0) {
    cout << 0 << endl;
  }
  else {
    cout << score << endl;
  }
}


Measured memory_bytes: 256
LI = lambda: list(map(int, input().split()))

N = int(input())


def main():
    ans = 0
    for a in range(1, N):
        x = N // a
        if N % a == 0:
            x -= 1
        ans += x
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9168
N = int(input())
a = [0]*N
for i in range(N):
  a[i] = list(map(int, input().split()))

sa = sorted(a, key=lambda x:x[1])
suma = 0
flag = True
for i in range(N):
  suma += sa[i][0]
  if suma > sa[i][1]:
    flag = False
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 55252
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int t = sc.nextInt();
        int c = (n % x == 0) ? n / x : n / x + 1;
        System.out.println(c * t);
    }
}


Measured memory_bytes: 35652
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int field[4][4];
	string f;

	while(cin >> f)
	{

		for(int i = 0; i < 3; i++)
		{
			for(int j = 0; j < 3; j++)
			{
				if(f[3*i+j] == 'o') field[i][j] = 1;
				else if(f[3*i+j] == 'x') field[i][j] = -1;
				else field[i][j] = 0;
			}
		}
		int jo[8];
		for(int i = 0; i < 8; i++)
			jo[i] = 0;

		for(int i = 0; i < 3; i++)
		{
			for(int j = 0; j < 3; j++)
			{
				if(i == j) jo[0] += field[i][j];
				if(i+j == 2) jo[1] += field[i][j];
				if(j == 0) jo[2] += field[i][j];
				if(j == 1) jo[3] += field[i][j];
				if(j == 2) jo[4] += field[i][j];
				if(i == 0) jo[5] += field[i][j];
				if(i == 1) jo[6] += field[i][j];
				if(i == 2) jo[7] += field[i][j];
			}
		}

		int ans = 0;

		for(int i = 0; i < 8; i++)
		{
			if(jo[i] == 3) ans = 1;
			else if(jo[i] == -3) ans = -1;
		}

		if(ans == 1) cout << 'o' << endl;
		else if(ans == -1) cout << 'x' << endl;
		else cout << 'd' << endl;
	}
}

Measured memory_bytes: 1172
line = readlines.map(&:chomp)
a=0
for i in 0..line[1].length-1 do
  if line[1][i]=="A" then
    if line[1][i+1]=="B" then
      if line[1][i+2]=="C" then
        a=a+1
      end
    end
  end
end
puts a

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

int main()
{
	int n, c;
	map <int, int> mp;
	scanf("%d", &n);
	
	for (int i = 1; i <= n; i++) {
		scanf("%d", &c);
		mp[c]++;
	}
	
	if (n % 3 != 0) {
		if (mp.size() > 1 || mp.find(0) == mp.end())
			cout << "No\n";
		else
			cout << "Yes\n";
		return 0;
	}
	
	vector <int> val;
	
	for (auto i : mp) {
		if (i.second % (n / 3) != 0) {
			cout << "No\n";
			return 0;
		}
		while (i.second)
			val.push_back(i.first), i.second -= n / 3;
	}
	
	if ((val[0] ^ val[1]) == val[2] && (val[1] ^ val[2]) == val[0] && (val[2] ^ val[0]) == val[1])
		cout << "Yes\n";
	else
		cout << "No\n";
	
	return 0;
}



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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

// double dis(double dx, double dy)
// {
// }

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, m) cin >> a[i] >> b[i];

    vector<int> per(n);
    rep2(i, 1, n + 1) per[i - 1] = i;

    int ans = 0;
    do
    {
        if (per[0] != 1)
        {
            continue;
        }
        bool all_path = true;
        rep(i, n - 1)
        {
            bool path = false;
            rep(j, m)
            {
                if (a[j] == per[i] && b[j] == per[i + 1] || a[j] == per[i + 1] && b[j] == per[i])
                {
                    path = true;
                }
            }
            if (!path)
            {
                all_path = false;
            }
        }
        if (all_path)
        {
            ans++;
        }
    } while (next_permutation(all(per)));

    cout << ans << endl;

    return 0;
}

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

int main(){
    int i,j,k,s;
    int h,w;
    std::vector<int> H,W;

    k=0;
    while(h!=0&&w!=0){
        std::cin>>h>>w;
        H.push_back(h);
        W.push_back(w);
        k=k+1;
    }

    for(s=0;s<k-1;s++){
        for(i=1;i<=H[s];i++){
            for(j=1;j<=W[s];j++){
                if(i%2==1){
                    if(j%2==1){
                        std::cout<<"#"<<std::flush;
                    }else if(j%2==0){
                        std::cout<<"."<<std::flush;
                   }
                }else if(i%2==0){   
                    if(j%2==1){
                        std::cout<<"."<<std::flush;
                    }else if(j%2==0){
                        std::cout<<"#"<<std::flush;
                   }
                }
            }
        std::cout<<std::endl;
        }
    std::cout<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3148
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

main = do
  [n, x] <- getIntList
  xs <- getIntList
  print $ foldr1 gcd (map (\y -> abs (y - x)) xs)


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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
#define int long long

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 ll a,b,c,s,t,x,y,z;
 ll A,B,C,S,T,X,Y,Z;

 ll count;

 long double pi=3.14159265358979323846;

 string N,M;

unsigned long long D;

signed main(){

	cin>>N;

	a=0;

	REP(i,N.size()){
		a=a+ctoi(N[i]);
	}

	if(a%9==0) cout<<"Yes";
	else cout<<"No";



	return 0;

}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

vector<int> PermutationComposite(const vector<int>& ps, const vector<int>& qs) {
  int n = ps.size();
  vector<int> rs(n);
  for (int i = 0; i < n; i++) {
    rs[i] = ps[qs[i]];
  }
  return rs;
}

vector<int> PermutationPower(const vector<int>& ps, int64 power) {
  if (power == 0) {
    int n = ps.size();
    vector<int> qs(n);
    for (int i = 0; i < n; i++) qs[i] = i;
    return qs;
  } else if (power == 1) {
    return ps;
  } else if (power % 2 == 0) {
    auto qs = PermutationPower(ps, power / 2);
    return PermutationComposite(qs, qs);
  } else {
    return PermutationComposite(PermutationPower(ps, power - 1), ps);
  }
}

// Vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
  }
  s << "]";
  return s;
}

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

  int n;
  cin >> n;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  vector<int64> ds(n - 1);
  for (int i = 0; i < n - 1; i++) {
    ds[i] = xs[i + 1] - xs[i];
  }

  vector<int> ps(n - 1);
  for (int i = 0; i < n - 1; i++) {
    ps[i] = i;
  }

  int m;
  int64 k;
  cin >> m >> k;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    a--;
    swap(ps[a - 1], ps[a]);
  }

  // cout << "ps: " << ps << endl;
  auto qs = PermutationPower(ps, k);
  // cout << "qs: " << ps << endl;

  vector<int64> es(n - 1);
  for (int i = 0; i < n - 1; i++) {
    es[i] = ds[qs[i]];
  }

  vector<int64> ys(n);
  ys[0] = xs[0];
  for (int i = 1; i < n; i++) {
    ys[i] = ys[i - 1] + es[i - 1];
  }

  for (int i = 0; i < n; i++) {
    cout << ys[i] << "\n";
  }
}


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




signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n;
    cin>>n;
    ll a[n];
    ll b[n+1];
    ll INF = 1e9;
    for(int i=0;i<=n;i++) b[i] = -INF;
    b[0]=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[a[i]] = max(b[a[i]-1]+1,b[a[i]]); 
    }
    ll ans = 0;
    for(int i=0;i<=n;i++){
        ans = max(ans,b[i]);
    }
    if(ans==0){
        cout << -1 << endl;
        return 0;
    }
    ans = n-ans;
    cout << ans << endl;

    
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>

using namespace std;

int N;
vector<int> G[100005];

int dfs(int v, int prev)
{
	int ret = 0;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == prev) continue;
		ret ^= dfs(G[v][i], v);
	}
	return ret + 1;
}

int main(void)
{
	cin >> N;
	int x, y;
	for(int i = 1; i <= N-1; i++){
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	
	int ans = 0;
	for(int i = 0; i < G[1].size(); i++){
		ans ^= dfs(G[1][i], 1);
	}
	
	if(ans) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	
	return 0;
}

Measured memory_bytes: 11904
/*
      author : nishi5451
      created: 11.08.2020 21:18:57
*/

#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 t,x;
    cin >> t >> x;
    double ans;
    ans = (double)t/x;
    printf("%.12lf",ans);
    return 0;
}


Measured memory_bytes: 3704
#include<stdio.h>
int main(void){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    if(x<y&&y<z){
        printf("%d %d %d\n",x,y,z);
    } else if(x<z&&z<y){
        printf("%d %d %d\n",x,z,y);
    }else if(y<x&&x<z){
        printf("%d %d %d\n",y,x,z);
    }else if(y<z&&z<x){
        printf("%d %d %d\n",y,z,x);
    }else if(z<x&&x<y){
        printf("%d %d %d\n",z,x,y);
    }else if(z<y&&y<x){
        printf("%d %d %d\n",z,y,x);
    }else if(x==y&&y<z){
        printf("%d %d %d\n",x,y,z);
    }else if(x==y&&y>z){
        printf("%d %d %d\n",z,x,y);
    }else if(x==z&&z<y){
        printf("%d %d %d\n",x,z,y);
    }else if(x==z&&z>y){
        printf("%d %d %d\n",y,x,z);
    }else if(y==z&&z<x){
        printf("%d %d %d\n",y,z,x);
    }else if(y==z&&z>x){
        printf("%d %d %d\n",x,y,z);
    }else if(x==y&&y==z){
        printf("%d %d %d\n",x,y,z);
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll a[310],y,z = 0,b;
vector<ll> v,w;
int main(){
    int i,j,n;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
        z ^= a[i];
    }
    z ^= a[0]^a[1];
    b = a[0];
    ll sum = a[0] + a[1];
    for(i=0;i<=50;i++){
        if(z & (1LL<<i)){
            sum -= (1LL<<i);
        }else{
            v.push_back(i);
        }
    }
    if(sum<0 || sum&1){
        cout << -1 << endl;
        return 0;
    }
    sum /= 2;
    for(i=50;i>=0;i--){
        if(z & (1LL<<i)) continue;
        if(sum>=(1LL<<i)){
            sum -= (1LL<<i);
            w.push_back(i);
        }
    }
    if(sum!=0){
        cout << -1 << endl;
        return 0;
    }
    for(i=0;i<w.size();i++){
        int d = w[i];
        a[0] -= (1LL<<d);
    }
    if(a[0]<0){
        cout << -1 << endl;
        return 0;
    }
    for(i=50;i>=0;i--){
        bool flag = true;
        for(j=0;j<v.size();j++){
            if(v[j]==i) flag = false;
        }
        if(!flag) continue;
        if(a[0] >= (1LL<<i)) a[0] -= (1LL<<i);
    }
    if(b==a[0]){
        cout << -1 << endl;
        return 0;
    }
    cout << a[0] << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <atcoder/convolution>
#include <atcoder/modint>
using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

using ll = long long int;

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
vector<ll> A,B;
inline void input(){
    fast_io();
    cin >> N >> M;
    A = fetch_vec<ll>(N);
    B = fetch_vec<ll>(M);
}

ll const mod = 998244353;

inline int solve(){
    auto cv = atcoder::convolution<mod>(A,B);
    cout << cv << endl;
    return 0;
}   

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


Measured memory_bytes: 27196
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> d(N);
    for (int& x : d) cin >> x;
    int sum = 0, sq_sum = 0;
    for (int x : d) {
      sum += x;
      sq_sum += x * x;
    }
    int res = (sum * sum - sq_sum) / 2;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int main(){
	int S,W;
	cin>>S>>W;
	if(W>=S){
		cout<<"unsafe"<<endl;
	}else{
		cout<<"safe"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int) x.size())
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {sws;

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    while ( k > 0 and (c <= a or b <= a or c <= b)  ) {
        while ( k > 0 and (c <= a or c <= b) ) {
            c *= 2;
            k--;
        }

        while ( k > 0 and b <= a ) {
            b *= 2;
            k--;
        }
    }

    if ( b > a and c > a and c > b ) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> button(N);
  vector<int> cnt(1);
  vector<int> goal = {2};
  
  for (int i = 0; i < N; i++) {
    cin >> button.at(i);
  }
  int j = 1;
   cnt.at(0) = button.at(0);
  while (j <= N) {
    if (cnt.at(0) == goal.at(0)) {
      // cout << "break!" << endl;
      break;
    }
    cnt.at(0) = button.at(cnt.at(0)-1);
    j++;
  }
  // cout << j << endl;
  if (cnt.at(0) == goal.at(0)) {
    cout << j << endl;
  } else {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 640
n=int(input())
#print(n)
while n!=0:
    icecream=[0]*10
    for i in range(n):
        a=int(input())
        icecream[a]+=1
    #print(icecream)
    for j in range(10):
        if icecream[j]==0:
            print('-')
        else:
            print('*'*icecream[j])
    n=int(input())


Measured memory_bytes: 5624
from operator import itemgetter

N,M = [int(x) for x in input().split()]
LR = [[int(x) for x in input().split()]for _ in range(M)]
max_l = max(LR,key = itemgetter(0))[0]
min_r = min(LR,key = itemgetter(1))[1]
print(max(min_r-max_l+1,0))


Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long t;
    t=1;
    // cin>>t;
    while(t--)
    {
        long n,i,j,x,y,flag=1,a=0,b,ans,count;
        string s;
        cin>>n;
        for(i=1;i<=n;i++)
        {
            if(i%3==0 || i%5==0)
            continue;
            else a+=i;
        }
        cout<<a;
        
        
    }
    
}

Measured memory_bytes: 3628
straight = [[i for i in range(j,j + 5)] for j in range(1,10)]
straight.append([1,10,11,12,13])
while True:
    try:
        h = list(map(int, input().split(",")))
        h_s = sorted(h)
        p = []
        for i in range(4):
            if h_s[i] != h_s[i + 1]:
                p.append(i)
        if len(p) == 1:
            if p[0] == 0 or p[0] == 3:
                print("four card")
            else:
                print("full house")
        elif h_s in straight:
            print("straight")
        elif len(p) == 2:
            if p[0] == 1 or p == [0,2]:
                print("two pair")
            else:
                print("three card")
        elif len(p) == 3:
            print("one pair")
        else:
            print("null")
    except:
        break



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

#define int long long 

const int N = 1e5+10;
const int mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s1,s2;
	cin >> s1 >> s2;
	int n = s1.length();
	int m = s2.length();
	vector<vector<int>> dp(n+1,vector<int>(m+1));
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j <= m; ++j)
		{
			if(s1[i-1] == s2[j-1])
			{
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else
			{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	
	string ans;
	//~ for(auto x : dp)
	//~ {
		//~ for(auto y : x)
		//~ cout << y << " ";
		//~ cout << '\n';
	//~ }
	int x = n, y = m;
	while(x > 0 && y > 0)
	{
		if(dp[x-1][y-1] >= dp[x-1][y] && dp[x-1][y-1] >= dp[x][y-1] && dp[x][y] == dp[x-1][y-1] + 1)
		{ans += s1[x-1];
			--x,--y;
		}
		else if(dp[x-1][y] >= dp[x][y-1]) x--;
		else y--;
	}
	
	reverse(ans.begin(),ans.end());
	cout << ans;
}



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

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int N,jur;
	jur = 0;
	cin >> N;
	for (int i=0;i<26; i++) {
		for (int j=0; j < 15; j++) {
			if (4 * i + 7 * j == N)jur = 1;
		}
	}
	if (jur == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
}



Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int a,b;
  cin>>a>>b;
  if(a==0||b==0)cout<<"Zero"<<endl;
  else if(a<0&&b<0){
    if(abs(a-b)%2==0)cout<<"Negative"<<endl;
    else cout<<"Positive"<<endl;
  }else if((a<0&&0<b)||(a>0&&b<0))cout<<"Zero"<<endl;
  else cout<<"Positive"<<endl;
  return 0;
}







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

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

  int ans = INT_MAX;

  if(X <= Y){ int v = Y - X; if(v < ans) ans = v; }
  if(-X <= Y){ int v = Y + X + 1; if(v < ans) ans = v; }
  if(X <= -Y){ int v = -Y - X + 1; if(v < ans) ans = v; }
  if(-X <= -Y){ int v = -Y + X + 2; if(v < ans) ans = v; }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
const int MAXN = 100000;
int x[MAXN + 5], y[MAXN + 5], t[MAXN + 5];
int abs(int x) {
	return x >= 0 ? x : -x;
}
int dist(int i,int j) {
	return abs(x[i]-x[j]) + abs(y[i]-y[j]);
}
int main() {
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d %d %d",&t[i],&x[i],&y[i]);
	for(int i=1;i<=N;i++) {
		int d = dist(i-1,i),dt = t[i] - t[i-1];
		if( d > dt || (dt - d) % 2 == 1 ) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}

Measured memory_bytes: 1280