akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;
const ll MAX_H = 2e5;
const ll MAX_W = 2e5;

int main(void){
	ll h, w, n;
	cin >> h >> w >> n;
	P p;
	cin >> p.fs >> p.sc;
	string s, t;
	cin >> s >> t;
    ll u = 0, d = h+1;
	repr(i, n-1){
		if(t[i] == 'U') d = min(h+1, d+1);
		else if(t[i] == 'D') u = max(0LL, u-1);
		if(s[i] == 'U') u++;
		else if(s[i] == 'D') d--;
        if(u == h || d == 1){
            puts("NO");
            return 0;
        }
	}
    if(u >= p.fs || d <= p.fs){
        puts("NO");
        return 0;
    }

    ll l = 0, r = w+1;
	repr(i, n-1){
		if(t[i] == 'L') r = min(w+1, r+1);
		else if(t[i] == 'R') l = max(0LL, l-1);
		if(s[i] == 'L') l++;
		else if(s[i] == 'R') r--;
        if(l == w || r == 1){
            puts("NO");
            return 0;
        }
	}
	if(l >= p.sc || r <= p.sc){
		puts("NO");
		return 0;
	}

	puts("YES");
	return 0;
}


Measured memory_bytes: 776
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	Nnum = [0 for i in range(N+1)]

	for i in range(1,N+1):
		for j in range(i,N+1,i):
			Nnum[j] += 1

	ans = 0
	for i,val in enumerate(Nnum):
		ans += i * val

	print(ans)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 235184
#include <bits/stdc++.h>
using namespace std;
#define vaibhav ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define pb push_back
#define ll long long int
#define ld long double
#define M  998244353
// freopen("user1.dat", "r", stdin);
// freopen("user1.dat", "w", stdout);



int main()
{
	vaibhav
	string s;
	cin>>s;
	int n=s.length();

	if(s[n-1]=='s')
    {
    	s.pb('e');
    	s.pb('s');

    }
    else
    	s.pb('s');
    cout<<s;
	return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, T b ) { if ( a < b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, T b ) { if ( a > b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp( a, b ) make_pair( a, b )
#define mt( ... ) make_tuple( __VA_ARGS__ )

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( 1e9 + 7 )


int main()
{
	char b;
	cin >> b;

	switch ( b )
	{
	case 'A' : cout << "T" << endl; break;
	case 'C' : cout << "G" << endl; break;
	case 'G' : cout << "C" << endl; break;
	case 'T' : cout << "A" << endl; break;
	}

	return ( 0 );
}


Measured memory_bytes: 256
while 1:
    H, W = list(map(int, input().split()))
    if H == W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or j == 0 or i == H - 1 or j == W - 1:
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()

Measured memory_bytes: 6812
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
	
#define roop(i, start, end) for(int i=start;i<end;i++)
	
using namespace std;
using ll = long long int;
using ull = unsigned long long;
	
float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}
	
int main() {
	string s, t;
    cin >> s;
    cin >> t;
    cout << t + s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
      int N;
      cin >> N;
      string W[N+10];
      cin >> W[0];
      for(int j=1; j<N; j++){
        cin >> W[j];
        if(W[j-1][W[j-1].size()-1]!=W[j][0]){
          cout << "No" << endl;
          return 0;
        }
      }for(int a=0; a<N-1; a++){
        for(int b=a+1; b<N; b++){
          if(W[a]==W[b]){
            cout << "No" << endl;
            return 0;
          }
        }
      }
      cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    int sum = 0;
    int M = 0;
    for(int i = 1; ; i++){
      sum += i;
      if(sum >= N){
        M = i;
        break;
      }
    }
    
    int except = sum - N;
    for(int i = 1; i <= M; i++){
      if(i != except){
        System.out.println(i);
      }
    }
  }
}

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

int main()
{
    int A, B , C;
    cin >> A >> B >> C;
    if ((A < C && B < C) || (C < A && C < B))
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();
		String a = S.substring(0, S.length()-1);

		while(a.length()>0) {
			if(a.length()%2==0) {
				String[] z = new String[2];
				z[0] = S.substring(0, a.length()/2);
				z[1] = S.substring(a.length()/2, a.length());

				if(z[0].equals(z[1])) {
					System.out.println(a.length());
					break;
				}
			}
			a = a.substring(0, a.length()-1);
		}
	}

}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
using namespace std;
long long pow(long long a, long long b){
    if(b == 0)return 1;
    if(b%2 == 0)return pow(a*a, b/2);
    return a*pow(a, b-1);
}
int n, a[50], b[50], d[51][51];
vector<int> v;

void init(){
    for(int j=0;j<=50;j++){
        for(int k=0;k<=50;k++){
            d[j][k] = 1e7;
        }
        d[j][j]=0;
    }
}

void cal(){
    for(int k=0;k<=50;k++){
        for(int l=0;l<=50;l++){
            for(int j=0;j<=50;j++){
                d[l][j] = min(d[l][j], d[l][k]+d[k][j]);
            }
        }
    }
}

long long func(int x){
    long long ans = 0;
    init();
    for(int j=0;j<v.size();j++){
        for(int k=0;k<=50;k++){
            d[k][k%v[j]]=0;
        }
        ans += pow(2, v[j]);
    }
    for(int j=1;j<x;j++){
        for(int k=0;k<=50;k++){
            d[k][k%j]=0;
        }
    }
    cal();
    return ans;
}

bool judge(){
    for(int k=0;k<n;k++){
        if(d[a[k]][b[k]]>=1e7){
            return false;
        }
    }
    return true;
}

int main(void){
    long long ans;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    for(int i=50;i>0;i--){
        ans = func(i);
        if(!judge()){
            v.push_back(i);
        }
    }
    ans = func(0);
    if(judge()){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IREP(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define IMAX INT_MAX
#define IMIN INT_MIN
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
template<typename T> inline void chmin(T &a, T b){ if(a > b) a = b; }
template<typename T> inline void chmax(T &a, T b){ if(a < b) a = b; }
template<typename T> inline void xch(T &a, T &b){ T w = a; a = b; b = w; }


int main() {
    struct edge{int cur, to, cost;
        edge(int cu, int t, int c){
            cur = cu; to = t; cost = c;
        }
        bool operator>(const edge& arg0) const{
            return cost > arg0.cost;
        }
    };
    int N, M;
    cin >> N >> M;
    vector<vector<int>> link(N);
    int ans[N];
    int cost[N];
    REP(i, N){
        ans[i] = N + 1;
        cost[i] = IMAX;
    }
    REP(i, M){
        int A, B;
        cin >> A >> B;
        A--; B--;
        link[A].push_back(B);
        link[B].push_back(A);
    }
    priority_queue<edge, vector<edge>, greater<edge>> pq;
    pq.push(edge(0, 0, 0));
    while(!pq.empty()){
        edge e = pq.top(); pq.pop();
        if(cost[e.to] <= e.cost) continue;
        cost[e.to] = e.cost;
        ans[e.to] = e.cur;
        REP(i, link[e.to].size()){
            pq.push(edge(e.to, link[e.to][i], e.cost + 1));
        }
    }
    REP(i, N){
        if(ans[i] >= N){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i < N; i++){
        cout << ans[i] + 1 << endl;
    }
    
}


Measured memory_bytes: 16544
//
//  main.cpp
//  at1995
//
//  Created by horse on 2019/4/8.
//  Copyright © 2019 horse. All rights reserved.
//

#include <iostream>
using namespace std;
int main() {
    long long a,b;
    cin>>a>>b;
    if(a>0 && b>0) cout<<"Positive"<<endl;
    else if(a<=0 && b>=0) cout<<"Zero"<<endl;
    else{
        long long negnum=0;
        for(long long i=a;i<=b;i++)
        {
            if(i<0) negnum++;
        }
        if(negnum%2==0) cout<<"Positive"<<endl;
        else cout<<"Negative"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define MOD (LL)pow(10,9) + 7


int main(){
    int a,b,m;
    cin >> a >> b >> m;
    vector<int> A(a);
    vector<int> B(b);

    int minA = 100000,minB = 1000000;

    for(int i = 0; i < a; ++i){
        cin >> A[i];
        minA = min(minA,A[i]);
    } 
    for(int i = 0; i < b; ++i){
        cin >> B[i];
        minB = min(minB,B[i]);
    }

    int ans = minA + minB;

    for(int i = 0; i < m; ++i){
        int x,y,c;
        cin >> x >> y >> c;
        ans = min(ans , A[x - 1] + B[y - 1] - c);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;

const int N = 256;
array<array<int, N>, N> val;
array<int, N> ope;

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

	map<string, int> mp;
	rep(i, 4) ope["+-*/"[i]] = 1;

	int m;
	cin >> m;
	rep(i, m){
		string s;
		int lb, ub;
		cin >> s >> lb >> ub;
		mp[s] = i;
		for (int j = lb; j <= ub; ++j) val[i][j] = 1;
	}

	int n;
	cin >> n;
	stack<array<int, N>> st;
	bool ok = true;
	rep(i, n){
		string s;
		cin >> s;
		array<int, N> ele = {};
		if ('0' <= s[0] && s[0] <= '9'){
			ele[stoi(s)] = 1;
			st.push(ele);
		}
		else if(ope[s[0]]){
			array<int, N> lhs, rhs, res = {};
			rhs = st.top(); st.pop();
			lhs = st.top(); st.pop();
			rep(i, N) rep(j, N){
				unsigned char r;
				if (lhs[i] && rhs[j]){
					switch (s[0]){
					case '+':
						r = i + j;
						break;
					case '-':
						r = i - j;
						break;
					case '*':
						r = i*j;
						break;
					case '/':
						if (!j) ok = false;
						else r = i / j;
						break;
					}
					res[r] = 1;
				}

			}
			st.push(res);
		}
		else{
			st.push(val[mp[s]]);
		}
	}

	cout << (ok ? "correct" : "error") << endl;

	return 0;
}

Measured memory_bytes: 1292
import math

a, b, h, m = map(int, input().split())
p1 = 30 * h + m / 2
p2 = 6 * m
s = min(abs(p1 - p2), abs(abs(p1 - p2) - 360))
ans = pow(a * math.sin(math.radians(s)), 2) + pow((b - a * math.cos(math.radians(s))), 2)
print((ans) ** (1 / 2))

Measured memory_bytes: 9548
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n;
	scanf("%d", &n);
	int a = 1;
	rep2(i, n + 1) {
		rep2(j, n + 1) {
			if (pow(i, j) <= n)a = max(a, (int)pow(i, j));
			else break;
		}
	}
	printf("%d\n", a);
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

void out(){cout << "\n";}
template<class T,class... Args>
void out(const T &x,const Args &... args){
	cout << x << " ";
	out(args...);
}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll ans=0;
	string s,t;
	cin >> t;
	while(cin >> s && s!="END_OF_TEXT"){
		for(auto&& e:s){
			if(isupper(e)) e+=32;
		}
		if(s==t) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; }
// ll nCr(ll n, ll r) {
//     return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod );
// }
// const ll sz = 1e6 + 5;
// vector<ll> fac(sz, 1);

// * ALways PASS arrays, strings etc to functions BY REFERENCE

vector<vector<int>> adj;

int main() {
    // for (int i = 1; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    int t = 1;
    // cin >> t;
    
    while(t--) {
        int n;
        cin >> n;
        
        vector<ll> arr(n);
        for (auto &x: arr)
            cin >> x;
        
        ll res = 0, mx = arr[0];
        for (int i = 1; i < n; i++) {
            if (arr[i] >= mx)
                mx = arr[i];
            else
                res += (mx - arr[i]);
        }
        
        cout << res << endl;
    }
    
	return 0;
}


Measured memory_bytes: 4768
#include<stdio.h>
#include<math.h>

int main(){
  double x[1001],y[1001],D1=0,D2=0,D3=0,max=0,D4;
  int i,j,n;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%lf",&x[i]);
  }

  for(i=0;i<n;i++){
    scanf("%lf",&y[i]);
  }

  for(i=0;i<n;i++){
    D1+=fabs(x[i]-y[i]);
  }
  printf("%.11f\n",D1);

  for(i=0;i<n;i++){
    D2+=fabs(x[i]-y[i])*fabs(x[i]-y[i]);
  }
  D2=sqrt(D2);

  printf("%.11f\n",D2);

  for(i=0;i<n;i++){
    D4+=fabs(x[i]-y[i])*fabs(x[i]-y[i])*fabs(x[i]-y[i]);
  }
  D4=cbrt(D4);
  printf("%.11f\n",D4);
  
  
  for(i=0;i<n;i++){
    if(max<fabs(x[i]-y[i])) max=fabs(x[i]-y[i]);
  }
  printf("%.11f\n",max);
  return 0;
}
		     

Measured memory_bytes: 692
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	string a;
	string b = "YAKI";
	cin >> a;
	ll flag = 1;
	rep(i, 0, 4) {
		if (a[i] != b[i])flag = 0;
	}
	if (flag == 1)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}








Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

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

ll getrndll(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2>
inline bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
inline bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int MOD = 998244353;

int add(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    if (a < 0) a += MOD;
    return a;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

int binpow(int a, ll n) {
    if (n < 0)
        a = binpow(a, MOD - 2), n *= -1;
    
    int res = 1;
    while (n) {
        if (n & 1)
            res = mul(res, a);
        a = mul(a, a);
        n /= 2;
    }
    return res;
}

int inv(int x) {
    return binpow(x, MOD - 2);
}

void solve() {
    int n, s;
    cin >> n >> s;
    
    vector<vector<int>> dp(n + 1, vector<int>(s + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        
        for (int j = 0; j <= s; ++j) {
            dp[i + 1][j] = add(dp[i + 1][j], mul(2, dp[i][j]));
            if (j + x <= s)
                dp[i + 1][j + x] = add(dp[i + 1][j + x], dp[i][j]);
        }
    }
    cout << dp[n][s] << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}



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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n,m;
	cin >> n >> m;
	VL sum(m,0);
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int a;
			cin >> a;
			sum[a-1] += 1;
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (sum[i] == n) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
  int n,ans,b;
  cin >> n;
  b = 1;

  for (int i = 0; i < 10; i++) {
    if (n <= (i*100+i*10+i) && b == 1) {
      ans = i*100 + i*10 + i;
      b = 0;
    }
  }

  cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <array>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <unordered_map>


using std::string;
using std::vector;



using valueAndIndex = std::pair<int, int>;

void printList(const vector<valueAndIndex>& list){
    for(auto each: list) {
        printf("%d => %d\n", each.first, each.second);
    }
}

// // 前方にサーチ
// int searchBenefitToForword(const vector<int>& list, int point, int benefit) {
//     int currentBenefit;
//     for(int i = point; i < list.size(); i++){
//         list[i]
//     }
// }

int main() {
    
    // create list
    int n;
    scanf("%d", &n);
    vector<int> list(n, 0);
    // put list
    int v;

    for (int i = 0; i < n; i++) {
        scanf("%d", &v);
        list[i] = v;
    }
    int min = list[0];
    int max = list[1];
    int benefit = max - min;
    // printf("default min:%d\n", min);
    for (int i = 1; i < list.size(); i++){
        // printf("*%d* %d\n", list[i], benefit);
        benefit = std::max(benefit, list[i] - min);
        min = std::min(min, list[i]);
        // printf("min:%d\n", min);
    }
    printf("%d\n", benefit);
    
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> K(N);
    vector<vector<int>> A(N, vector<int>(2));
    for (int i=0; i<N; i++) {
        cin >> K[i];
        A[i].resize(K[i]);
        for (int j=0; j<K[i]; j++) {
            cin >> A[i][j];
        }
    }
    
    vector<int> food(M, 0);
    for (int i=0; i<N; i++) {
        for (int j=0; j<K[i]; j++) {
            food[A[i][j]-1]++;
        }
    }
    
    int ans=0;
    for (int m=0; m<M; m++) {
        if (food[m]==N) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

/*
int main(){
    int N, M; cin >> N >> M;
    vi a(M), b(M);
    vii c(M);
    for(int i=0; i<M; i++){
        cin >> a[i] >> b[i];
        c[i].resize(b[i]);
        for(int j=0; j<b[i]; j++){
            cin >> c[i][j];
            c[i][j]--;
        }
    }
    vector<int> cost(1<<N, 1e9);
    cost[0]=0;
    for(int i=0; i<M; i++){
        int bit=0;
        for(int j=0; j<(int)c[i].size(); j++){
            bit=bit|(1<<c[i][j]);
        }
        cost[bit]=min(cost[bit], a[i]);
    }
    for(int i=0; i<(1<<N); i++){
        for(int j=0; j<(1<<N); j++){
            int bit=i|j;
            cost[bit]=min(cost[bit], cost[i]+cost[j]);
        }
    }
    if(cost[(1<<N)-1] == 1e9) cout << -1 << endl;
    else cout << cost[(1<<N)-1] << endl;
    return 0;   
}
*/

int main(){
    int N, M; cin >> N >> M;
    vi a(M), b(M);
    vii c(M);
    vi d(M, 0);
    for(int i=0; i<M; i++){
        cin >> a[i] >> b[i];
        c[i].resize(b[i]);
        for(int j=0; j<b[i]; j++){
            cin >> c[i][j];
            c[i][j]--;
            d[i]=d[i] | (1<<c[i][j]);
        }
    }
    vector<vector<ll>> dp(M+1, vector<ll>(1<<N, LINF));
    dp[0][0]=0;
    for(int i=0; i<M; i++){
        for(int bit=0; bit<(1<<N); bit++){
            dp[i+1][bit]=min(dp[i+1][bit], dp[i][bit]);
            dp[i+1][(bit|d[i])]=min(dp[i+1][bit|d[i]], min(dp[i][(bit|d[i])], dp[i][bit]+a[i]));
        }
    }
    if(dp[M][(1<<N)-1] == LINF) cout << -1 << endl;
    else cout << dp[M][(1<<N)-1] << endl;
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  rep(i,0,3){
    if(s[i]=='7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  int ans=0;
  for(int i=1; i<50000; i++){
    if(i*108<(N+1)*100 && i*108>=N*100){
      ans=i;
      break;
    }
  }
  if(ans==0) cout << ":(" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 764
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

main :: IO ()
main = do
  (a:b:c:_) <- fmap (map read . words) getLine :: IO [Int]
  print $ solve a b c

solve a b c = min c (b `div` a)

Measured memory_bytes: 508
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextLineInt() []int {
	lineString := strings.Split(nextLine(), " ")
	var lineInt []int
	for i := range lineString {
		v, _ := strconv.Atoi(lineString[i])
		lineInt = append(lineInt, v)
	}
	return lineInt
}

func bool2int(b bool) int {
	if b {
		return 1
	}else {
		return 0
	}
}

func main() {
	nm := nextLineInt()

	var foods [31]bool

	for i := 0;i < 31;i++ {
		foods[i] = true
	}

	for i := 0;i < nm[0];i++ {
		var row []int
		row = nextLineInt()
		row = row[1:]
		
		var isExist [31]bool

		for j := 0;j < 31;j++ {
			isExist[j] = false
		}

		for _,v := range row {
			isExist[v] = true
		}

		for j := range isExist {
			if !(isExist[j] && foods[j]) {
				foods[j] = false
			}
		}

	}

	total := 0
	for _,v := range foods {
		total += bool2int(v)
	}

	fmt.Println(total)
}


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

int main()
{
	long long N, M;
	cin >> N >> M;
	if (N == 1)
	{
		if (M == 1)
		{
			cout << 1 << endl;
		}
		else
		{
			cout << M - 2 << endl;
		}
	}
	else{
		
		if (M == 1)
		{
			cout << N - 2 << endl;

		}
		else {
			cout << (N - 2) * (M - 2) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(i);
// sort(arr, arr+n, greater<int>());
// const long double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll cnt = 0;
	if(k>0)
	{
		if(a>=k)
		{
			cnt = cnt+k;
			k = 0;
		}
		else if(a<k)
		{
			cnt = cnt+a;
			k = k-a;
		}
	}
	if(k>0)
	{
		if(b>=k)
		{
			k = 0;
		}
		else if(b<k)
		{
			k=k-b;
		}
	}
	if(k>0)
	{
		cnt = cnt-k;
		k = 0;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x; }

int main(){
    ll a,b; cin >> a >> b;
    cout << a*b/gcd(a,b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t N,M,ans=0; cin>>N>>M;
  vector<pair<int64_t,int64_t>> S(N);
  rep(i,N){
    int64_t a,b; cin>>a>>b;
    S.at(i)=make_pair(a,b);
  }
  sort(S.begin(),S.end());
  int64_t i=0;
  while(M>0){
    if(S.at(i).second>M){
      ans+=M*S.at(i).first;
      M=0;
    }
    else{
      ans+=S.at(i).first*S.at(i).second;
      M-=S.at(i).second;
    }
    i++;
  }
  cout<<ans;
}


Measured memory_bytes: 4776
n = int(input())
c = [int(input()) for _ in range(n)]
mod = 10 ** 9 + 7

# 解説AC
dp = [1] * n
color = [-1] * max(c)
for i, ci in enumerate(c):
    dp[i] = dp[i - 1]
    if 0 <= color[ci - 1] < i - 1:
        dp[i] += dp[color[ci - 1]]
        dp[i] %= mod
    color[ci - 1] = i
print(dp[-1])


Measured memory_bytes: 90776
from bisect import bisect_right,bisect_left
n=int(input())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))

ans=0
for b in B:
    a_index=bisect_left(A,b)
    c_index=bisect_right(C,b)
    ans +=a_index*(n-c_index)

print(ans)

Measured memory_bytes: 23348
#include<iostream>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1LL << 60)
#define rep(i, n) for(int i=0; i<(n); ++i)

//初級編
//https://qiita.com/drken/items/e77685614f3c6bf86f44

//確率DP
//https://atcoder.jp/contests/dp/tasks/dp_i
//LCS
//https://atcoder.jp/contests/dp/tasks/dp_f
//グラフ
//https://atcoder.jp/contests/code-festival-2017-qualb/tasks/code_festival_2017_qualb_c

int main()
{
	string S; cin >> S;
	auto bitcalc = [&](int bit)
	{
		int from = 0;
		int to = 1;
		vector<ll> num;
		while (bit > 0) {
			if (bit & 1) {
				num.push_back(stoi(S.substr(from, to - from)));
				from = to;
			}
			bit = bit >> 1;
			++to;
		}
		num.push_back(stoll(S.substr(from, S.size() - from)));
		ll sum = 0;
		rep(i, num.size()) sum += num[i];
		return sum;
	};
	ll ans = 0;
	rep(i, 1 << (S.size() - 1)) ans += bitcalc(i);
	cout << ans << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(3 * N);
    for (int i = 0; i < 3 * N; i++) {
        cin >> a.at(i);
    }
    long sum = 0;
    sort(a.begin(), a.end(), greater<int>());
    for (int i = 0; i < N; i++) {
        sum += a.at(2 * i + 1);
    }
    cout << sum << endl;
}


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

#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
namespace mp = boost::multiprecision;

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

  // int64_t a, ans;
  // mp::cpp_dec_float_50 b;
  // cin >> a >> b;

  // b *= a;
  // ans = (int64_t)b;

  int64_t a, ans;
  double b;
  cin >> a >> b;
  ans = (a * (int64_t)floor(b * 100)) / 100;

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define intt long long
using namespace std;
int i , j;
pair<int,int> a[100005];
int main ()
{
    int  n,  m;
    cin >> n >> m;
    for ( i = 1 ; i <= m ; i++ )
    {
        cin >> a[i].second >> a[i].first;
    }
    int cnt = 0     ;
    sort(a+1,a+m+1);
    int last = 0;
    for ( i = 1 ; i <= m ; i++ )
    {
        if ( a[i].second <= last-1)
        {
            continue;
        }
        else
        {
            last = a[i].first;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

int main(){
  int64_t n;
  cin >> n;
  vector<int64_t> A(n);
  vector<int64_t> B(n);
  vector<int64_t> C(n);
  rep(i, n) cin >>A[i];
  rep(i, n){
    int64_t t = A[i]-1;
    B[t] += 1; 
  }
  int64_t sum = 0LL;
  rep(i, n){
    if(B[i] == 1) C[i] = 0LL;
    else if(B[i] == 0) C[i] = 0LL;
    else {
      int64_t q = B[i];
      C[i] = q*(q-1)/2;
    }
  }
  rep(i, n) sum += C[i];
  rep(i, n){
    int64_t t = A[i]-1;
    int64_t b = B[t]-1;
    int64_t c = C[t];
    int64_t so = sum-c;
    //cout << so << endl;
    if(b==0) cout << so << endl;
    else if(b==1) cout << so << endl;
    else {
      int64_t g = b*(b-1)/2;
      cout << so+g << endl;
    }
  }
  //rep(i, n) cout << C[i] << endl;
  //cout << sum << endl;
}

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

int main () {
  int N;
  cin >> N;
  string s;
  
  map<string, int> tohyo_map;
  rep(i, N) {
    cin >> s;
    tohyo_map[s] += 1;
  }
  
  int max_value = 0;
  for (const auto& m: tohyo_map) {
    int v = m.second;
    if (v > max_value) {
      max_value = v;
    }
  }
  
  for (const auto& m: tohyo_map) {
    string k = m.first;
    int v = m.second;
    if (v==max_value) {
      cout << k << endl;
    }
  }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  int ans=0;
  for(int i=0; i<N; i++) cin >> A.at(i);
  for(int i=0; i<N; i++){
    cin >> B.at(i);
    ans+=B.at(i);
  }
  for(int i=0; i<N-1; i++) cin >> C.at(i);
  for(int i=0; i<N-1; i++){
    if(A.at(i+1)-A.at(i)==1) ans+=C.at(A.at(i)-1);
  }  
  cout << ans << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl d(n);
  rep(i, n) cin >> d[i];
  ll ans = 0;
  rep(i, n - 1) rep2(j, i + 1, n) ans += d[i] * d[j];
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#define ll long long
#define mod 998244353
#define maxn 200010
int main()
{
    ll a,b;std::cin>>a>>b;
    if(a%2==b%2)
    {
    	std::cout<<(a+b)/2<<std::endl;
	}
	else std::cout<<"IMPOSSIBLE"<<std::endl;
    return 0;
}
/*5
0 0
1 1
2 2
3 -1
4 -2*/

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

signed main()
{
  int n;
  cin >> n;
  int a[n + 5];

  for (int i = 1; i < n + 1; i++) {
    int cnt = 0;
    int kanade = i;
    while (true) {
      if (kanade == 1 || kanade == 0) {
        break;
      }
      kanade = kanade / 2;
      cnt++;
    }
    a[i] = cnt;
  }

  int m = -100;
  int res = 0;
  for (int i = 1; i < n + 1; i++) {
    if (a[i] > m) {
      m = a[i];
      res = i;
    }
  }

  cout << res << endl;

  return (0);
}


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

int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	return gcd(b, a % b);
}
int main() {
	int n, X, x;
	cin >> n >> X >> x;
	n--;
	int ans = abs(x - X);
	for (int i = 0; i < n; i++) {
		cin >> x;
		ans = gcd(ans, abs(x - X));
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
#my_answer
N=int(input())

l=[]
l=[0]*(N)
for i in range(N):##N=6 0,1,2,3,4,5
	d=i#unchanged 0 1 2 3 4 5 
	l[d]=0 #l[0] 1 2 3 4 5
	pra=i+1
	while pra%2==0:#1~6
		pra/=2
		l[d]+=1
#print(l)#from left 1 2 3 4 5 6's divideble times

for i in range(N):
	if(l[i]==max(l)):#0-5
		print(i+1)#1-6

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 400005
#define inf 0x7fffffff
using namespace std;
 
struct E {int next, to, dis;} e[N];
int n, m, num, flag, cnt;
int h[N], a[N], pos[N], obj[N];
bool vis[N];
 
int read()
{
    int x = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
    return x;
}
 
void add(int u, int v, int w)
{
    e[++num].next = h[u];
    e[num].to = v;
    e[num].dis = w;
    h[u] = num;
}
 
void dfs(int x)
{
    if(flag) return;
    vis[x] = 1;
    for(int i = h[x]; i != 0; i = e[i].next)
    {
        int t = pos[x] + e[i].dis;
        if(pos[e[i].to] == inf) pos[e[i].to] = t, dfs(e[i].to);
        else if(t != pos[e[i].to]) {flag = 1; return;}
    }
}
 
int main()
{
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        int a = read(), b = read(), c = read();
        add(a, b, c), add(b, a, -c);
        pos[a] = pos[b] = inf;
        obj[++cnt] = a, obj[++cnt] = b;
    }
    sort(obj + 1, obj + 1 + cnt);
    cnt = unique(obj + 1, obj + 1 + cnt) - obj - 1;
    for(int i = 1; i <= cnt; i++)
        if(!vis[obj[i]])
        {
            flag = 0;
            pos[obj[i]] = 0;
            dfs(obj[i]);
            if(flag) {cout << "No"; return 0;}
        }
    cout << "Yes";
    return 0;
}

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

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
    ll i, j, k;
    ll N, K;
    cin >> N >> K;
    vll P(N);
    for(auto &e : P)
        cin >> e;
    sort(P.begin(), P.end());
    cout << accumulate(P.begin(), P.begin() + K, 0) << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main ()
{
  prep();
  int n;
  cin >> n;
  int nums[1001] = {0};
  int temp = n;
  for (int i=2; i<=n; i++){
      int tempi = i;
      
      for (int j=2; j<=i; j++){
          int cnt = 0;
          while (tempi%j == 0){
              tempi /= j;
              cnt++;
          }
          nums[j] += cnt;
      }
      
  }
  long long res = 1;
  for (int i : nums){
      res *= i+1;
      res %= mod;
  }
  cout << res;
  return 0; 
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	scanf("%lld",&n);
	if(n%2 == 0)
		printf("%lld\n",n);
	else
		printf("%lld\n",n*2);
	return 0;
}

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

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

    long long a, b, q;
    cin >> a >> b >> q;
    vector<long long> va(a), vb(b);
    for(int i = 0; i < a; i++) {
        cin >> va[i];
    }
    for(int i = 0; i < b; i++) {
        cin >> vb[i];
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    for(int j = 0; j < q; j++) {
        long long t;
        cin >> t;
        long long ans = LLONG_MAX;
        for(int i = 0; i < 4; i++) {
            long long d1 = i & 1
            ? *upper_bound(va.begin(), va.end(), t)
            : *upper_bound(va.begin(), va.end(), t) == va.front()
                ? va.front()
                : *(upper_bound(va.begin(), va.end(), t) - 1);
            long long d2 = i & 2
            ? *upper_bound(vb.begin(), vb.end(), d1)
            : *upper_bound(vb.begin(), vb.end(), d1) == vb.front()
                ? vb.front()
                : *(upper_bound(vb.begin(), vb.end(), d1) - 1);
            long long tt1 = llabs(t - d1) + llabs(d1 - d2);

            long long d4 = i & 1
            ? *upper_bound(vb.begin(), vb.end(), t)
            : *upper_bound(vb.begin(), vb.end(), t) == vb.front()
                ? vb.front()
                : *(upper_bound(vb.begin(), vb.end(), t) - 1);
            long long d3 = i & 2
            ? *upper_bound(va.begin(), va.end(), d4)
            : *upper_bound(va.begin(), va.end(), d4) == va.front()
                ? va.front()
                : *(upper_bound(va.begin(), va.end(), d4) - 1);
            long long tt2 = llabs(t - d4) + llabs(d4 - d3);

            ans = min(ans, min(tt1, tt2));
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3072