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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

map<int, int> cnt;

void solve(){
	int n, a, ans;
	scanf("%d", &n);
	REP(i, 0, n){
		scanf("%d", &a);
		cnt[a]++;
	}
	ans = 0;
	FA(it, cnt){
		if (it->_2 >= it->_1){
			ans += it->_2 - it->_1;
		} else {
			ans += it->_2;
		}
	}
	printf("%d\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 4736
program main
   implicit none
   INTEGER :: n, i, ans = 0
   INTEGER, ALLOCATABLE :: a(:)
   INTEGER data(1 : 100)
   data(1 : 100) = 0
   READ(*, *) n
   ALLOCATE(a(1 : n))
   READ(*, *) (a(i), i = 1, n)
   do i = 1, n
    data(a(i)) = 1
   enddo
   WRITE(*, *) sum(data)
end program main

Measured memory_bytes: 2796
n=int(input())
l=list(map(int, input().split()))
br=0
p=0
for i in range (n):
    if l[i]%2==0:
        p+=1
        if l[i]%5==0 or l[i]%3==0:
            br+=1
   
if br==p:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long R) { printf("%.16f\n", 2 * R * 3.1415926535); }

int main() {
    long long R;
    scanf("%lld", &R);
    solve(R);
    return 0;
}


Measured memory_bytes: 3832
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;




void main() {
    int N, M;
    scan(N, M);
    auto a = new int[](N);
    auto b = new int[](N);
    foreach (i ; 0 .. N) {
        scan(a[i], b[i]);
    }
    auto c = new int[](M);
    auto d = new int[](M);
    foreach (i ; 0 .. M) {
        scan(c[i], d[i]);
    }
    auto ans = new int[](N);
    foreach (i ; 0 .. N) {
        int md = inf;
        int k = -1;
        foreach (j ; 0 .. M) {
            auto dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (dist < md) {
                md = dist;
                k = j;
            }
        }
        ans[i] = k + 1;
    }
    writefln("%(%s\n%)", ans);
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

vector<pii> g[1000][1000], rev[1000][1000];
vector<pii> toppo; //最後までチョコたっぷり
char flg[1000][1000];

bool dfs(pii u) {
    int a = u.first, b = u.second;
    if(flg[a][b] == 1) return false;
    else if(flg[a][b] == 0) {
        flg[a][b] = 1;
        bool result = true;
        for(auto && e : g[a][b]) result = dfs(e) & result;
        if(!result) return result;
        toppo.push_back(u);
        flg[a][b] = 2;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        int bef = -1;
        for(int j = 0; j < n-1; ++j){
            int a;
            cin >> a;
            --a;
            if(bef >= 0){
                g[min(i, bef)][max(i,bef)].push_back({min(i, a), max(i, a)});
            }
            bef = a;
        }
    }
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            dfs({i, j});
        }
    }
    reverse(begin(toppo), end(toppo));
    if(toppo.size() != n * (n-1) / 2) cout << "-1\n";
    else {
        int ans = 0;
        vector<int> dist(n * (n-1) / 2);
        int ptot[1000][1000];
        for(int i = 0; i < n * (n-1) / 2; ++i){
            pii p = toppo[i];
            ptot[p.first][p.second] = i;
        }
        for(int i = 0; i < n * (n-1) / 2; ++i){
            pii v = toppo[i];
            for(auto && p : g[v.first][v.second]){
                dist[ptot[p.first][p.second]] = max(dist[ptot[p.first][p.second]], dist[ptot[v.first][v.second]] + 1);
            }
            ans = max(ans, dist[ptot[v.first][v.second]]);
        }
        cout << ans + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 73584
/**
 *    author:  tourist
 *    created: 09.12.2019 15:16:41       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  p[0] = -1;
  for (int i = 1; i < n; i++) {
    cin >> p[i];
  }
  vector<int> d(n);
  for (int i = 1; i < n; i++) {
    d[i] = d[p[i]] + 1;
  }
  vector<vector<int>> is_parent(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    int x = i;
    while (x >= 0) {
      is_parent[x][i] = 1;
      x = p[x];
    }
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> ret;
  while (true) {
    int to = 0;
    for (int i = 1; i < n; i++) {
      if (is_parent[a[0]][i] && (!is_parent[a[i]][i] || d[a[i]] < d[a[0]])) {
        if (d[i] > d[to]) {
          to = i;
        }
      }
    }
    if (to == 0) {
      break;
    }
    ret.push_back(to);
    int v = to;
    while (v > 0) {
      swap(a[0], a[v]);
      v = p[v];
    }
  }
  assert(ret.size() <= 8750);
  cout << ret.size() << '\n';
  for (int x : ret) {
    cout << x << '\n';
  }
  return 0;
}


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

using namespace std;

inline void quit(){ exit(0); }

typedef long long ll;

ll mpow(ll _x, ll _y, ll _mod){
    if(_y==0) return 1;
    if(_y==1) return _x%_mod;
    if(_y&1) return (mpow(_x, _y-1, _mod)*_x)%_mod;
    ll _tmp = mpow(_x, _y>>1, _mod);
    return (_tmp*_tmp)%_mod;
}

int n;

int main(){
    cin>>n;
    printf("%.9f", (double)((n+1)/2)/n);
}


Measured memory_bytes: 256
e, y = gets.split.map(&:to_i)
case e
when 0
  if y <= 1911
    puts "M#{y - 1867}"
  elsif y <= 1925
    puts "T#{y - 1911}"
  elsif y <= 1988
    puts "S#{y - 1925}"
  else
    puts "H#{y - 1988}"
  end
when 1 then puts 1867 + y
when 2 then puts 1911 + y
when 3 then puts 1925 + y
when 4 then puts 1988 + y
end



Measured memory_bytes: 6872
import Data.List (foldl')
import Data.Maybe (fromJust)
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    n <- readLn
    as <- (map readInt . B.words) <$> B.getLine
    print $ solve n as

-- |
--
-- >>> solve 2 [3,1,4,1,5,9]
-- 1
--
-- >>> solve 1 [1,2,3]
-- -1
--
-- >>> solve 3 [8,2,2,7,4,6,5,3,8]
-- 5
solve :: Int -> [Int] -> Int
solve n as = maximum $ zipWith diff y1s y2s
  where
    diff (lh,_) (rh,_) = lh - negate rh
    (a1s, cs) = splitAt n as
    (bs, a2s) = splitAt n cs
    q1 = foldl' push Empty a1s
    q2 = foldl' push Empty (map negate a2s)
    lh0 = sum a1s
    rh0 = negate $ sum a2s
    y1s = scanl (flip pushpop) (lh0,q1) bs
    y2s = scanr pushpop (rh0,q2) (map negate bs)

-- Util
readInt :: B.ByteString -> Int
readInt = fst . fromJust . B.readInt

-- Heap
data SkewHeap a = Empty | Node !a !(SkewHeap a) !(SkewHeap a)
            deriving (Show, Read, Eq)

singleton :: a -> SkewHeap a
singleton x = Node x Empty Empty

(+@+) :: Ord a => SkewHeap a -> SkewHeap a -> SkewHeap a
Empty               +@+ t2                  = t2
t1                  +@+ Empty               = t1
t1@(Node x1 l1 r1)  +@+ t2@(Node x2 l2 r2)
   | x1 <= x2   = Node x1 (t2 +@+ r1) l1
   | otherwise  = Node x2 (t1 +@+ r2) l2

push :: Ord a => SkewHeap a -> a -> SkewHeap a
heap `push` x = singleton x +@+ heap

pop :: Ord a => SkewHeap a -> (a, SkewHeap a)
pop Empty         = undefined
pop (Node x l r)  = (x, l +@+ r)

pushpop :: (Num a, Ord a) => a -> (a, SkewHeap a) -> (a, SkewHeap a)
x `pushpop` (y, h) = (y + x - x', h')
  where (x', h') = pop $ push h x


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

using namespace std;

int main()
{
    int A[5];
    for(int i = 0; i < 3; i ++)
        cin >> A[i];
    sort(A, A + 3);
    int ans = 0;
    for(int i = 1; i < 3; i ++)
        ans += A[i] - A[i - 1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 105
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, t = 0;
int color[N], d[N], f[N], array[N][N];

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

  int i, u, v, j, e;
  for(i = 1; i < n+1; i++){
    for(j = 1; j < n+1; j++){
      array[i][j] = 0;
    }
  }

  for(i = 1; i < n+1; i++){
    scanf("%d%d", &u, &e);
    for(j = 1; j < e+1; j++){
      scanf("%d", &v);
      array[i][v] = 1;
    }
  }

  DFS();

  for(i = 1; i < n+1; i++){
    printf("%d ", i);
    printf("%d ", d[i]);
    printf("%d\n", f[i]);
  }
  return 0;
}

void DFS(){
  int i, time;
  for(i = 1; i < n+1; i++){
    color[i] = WHITE;
  }

  for(i = 1; i < n+1; i++){
    if(color[i] == WHITE) DFSvisit(i);
  }
}

void DFSvisit(int u){
  int i;
  color[u] = GRAY;
  d[u] = ++t;

  for(i = 1; i < n+1; i++){
    if((color[i] == WHITE) && (array[u][i] == 1)) DFSvisit(i);
  }
  color[u] = BLACK;
  f[u] = ++t;
}

Measured memory_bytes: 640
a=[list(map(int,input().split()))for i in range(3)]
s=a[0]+a[1]+a[2]
def f(i):
    return s[i]+s[i+2]-s[i-1]-s[i+3]
if s[0]+s[4]+s[8]==sum(s)//3 and f(1)==0 and f(2)==0 and f(4)==0 and f(5)==0:
    print("Yes")
else:
    print("No")

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

int main(){
  int K, S;
  cin >> K >> S;
  int cnt=0;
  for(int i=0;i<K+1;i++){
    for(int j=0;j<K+1;j++){
      if(S-(i+j)<K+1 && S-(i+j)>-1){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3640
#include <iostream>

int gcd(int x, int y)
{
	if (x==0) return y;
	if (y==0) return x;
	if (x>y)  return gcd(y, x%y);
	if (x<=y) return gcd(x, y%x);
}

int main()
{
	int a, b;
	std::cin >> a >> b;
	std::cout << gcd(a,b) << std::endl;
	
	return 0;
}




Measured memory_bytes: 3104
#include <stdio.h>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int main()
{
	int x[500005] = { 0 };
	int le = 250000, ri = 250001;
	int n, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		int t;
		scanf("%d", &t);
		if (i % 2 == 0)
		{
			x[le] = t;
			le--;
		}
		else
		{
			x[ri] = t;
			ri++;
		}
	}
	if (n % 2 == 1)
	{
		for (auto idx = le + 1; idx < ri; idx++)
			printf("%d ", x[idx]);
		printf("\n");
	}
	else
	{
		for (auto idx = ri-1; idx > le ; idx--)
			printf("%d ", x[idx]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 4224
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N];
    int[] b = new int[N-1];
    
    for(int i=0;i<N;i++){
      a[i] = sc.nextInt();
    }
    
    for(int j=0;j<N-1;j++){
      if(a[j+1]<=a[j]){
        b[j] = 1;
      }else{
        b[j] = 0;
      }
    }
    
    int  b_max = 0;
    int count = 0;
    for(int c=0;c<N-1;c++){
      if(b[c]==1){
        count++;
      }else{
        if(count>b_max){
          b_max = count;
        }
        count = 0;
      }
    }
    if(count>b_max){
          b_max = count;
    }
    System.out.println(b_max);
  }
}

Measured memory_bytes: 51560
#include <bits/stdc++.h>
using namespace std;
using vlai=array<int,26>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
int main(){
	string s1,s2;
	while(cin>>s1>>s2){
		if(s1.size()>s2.size()) swap(s1,s2);
		int n1=s1.size(), n2=s2.size();
		vector<vlai> h1(n1+1),h2(n2+1);
		
		rep(i,n1){
			h1[i+1]=h1[i];
			h1[i+1][s1[i]-'a']++;
		}
		rep(i,n2){
			h2[i+1]=h2[i];
			h2[i+1][s2[i]-'a']++;
		}
		
		set<vlai> list1;
		for(int l=n1;l>=1;l--){
			list1.clear();
			rep(i,n1-l+1){
				auto his1=h1[i+l];
				rep(j,26) his1[j]-=h1[i][j];
				list1.insert(his1);
			}
			rep(i,n2-l+1){
				auto his2=h2[i+l];
				rep(j,26) his2[j]-=h2[i][j];
				if(list1.find(his2) != list1.end()){
					cout<<l<<endl;
					goto end;
				}
			}
		}
		cout<<0<<endl;
		end: ;
	}
	return 0;
}



Measured memory_bytes: 4328
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,sum=0,sum2=0;;
	string s;
	cin>>n;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='W')
		{
			sum++;
		}
	}
	for(int i=n-1;i>=n-sum;i--)
	{
		if(s[i]=='W')sum2++; 
	}
	cout<<sum-sum2<<endl;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    //コンストラクタ
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n, m; cin >> n >> m;
    UnionFind path(n);
    rep(i,m){
        int a, b; cin >> a >> b;
        path.unite(a-1,b-1);
    }
    set<int> s;
    rep(i,n) s.insert(path.root(i));
    cout << s.size() - 1 << endl;
}

Measured memory_bytes: 7536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <map>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i > (b); --i)
#define SZ(a) a.size()
#define ll long long
#define ull unsigned long long
using namespace std;

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

	int A;
	int B;
	int C;

	cin >> A >> B >> C;

	if (A == 5 && B == 5 && C == 7 ||
		A == 5 && B == 7 && C == 5 ||
		A == 7 && B == 5 && C == 5)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;


	system("pause");
	return 0;
}

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

int gcd(int a,int b)
{
  if(a>b)swap(a,b);
  if(a==0)return b;
  else
    return gcd(a,b%a);
}

int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
  
  //  rest();
    int t=1;
    while(t--)
    {
      
      int count;
      cin>>count;
      long long int ans=0;
       for(int i=1;i<=count;i++)
       {
        for(int j=1;j<=count;j++)
        {
          for(int k=1;k<=count;k++)
          {
            int temp=gcd(i,j);
            ans+=gcd(temp,k);
          }
        }
       }


       cout<<ans<<endl;

    }

return 0;

}

Measured memory_bytes: 3648
//https://atcoder.jp/contests/abc171/tasks/abc171_d
#include<iostream>
using namespace std;
int main(){
    long long int a[100001]={0};
    long long int sum=0,temp=0,n,q;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>temp;
        a[temp]++;
        sum+=temp;
    }
    cin>>q;
    long long int ans[q]={0};
    for(int i=0;i<q;i++){
        long long int b,c;
        cin>>b>>c;
        sum=sum + a[b]*(c-b);
        a[c]+=a[b];
        a[b]=0;
        ans[i]=sum;
    }
    for(auto s:ans){
        cout<<s<<"\n";
    }
    return 0;
}

Measured memory_bytes: 5164
#include <iostream>
#include <algorithm>
#include <complex>
#define pb push_back
#define pll pair <ll, ll>
#define MOMI using namespace std;
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#pragma optimize("TKACHENKO-GORYACHENKO")
#pragma GCC optimize("O3")
 
//#pragma GCC optimize("unroll-loops")
 
typedef long long ll;
 
typedef long double ld;
 
using namespace std;
 
const ll maxn = 3e6;

ll A[maxn];
 
ll n, m, k;

int main() {
    ll q, w, e, a, b, c;
    ll ans = 0;
    cin >> n;
    for (q = 0; q < n; q++) {
        cin >> A[q];
    }
    for (q = 0; q < n; q++) {
        for (w = q + 1; w < n; w++) {
            ans += A[q] * A[w];
        }
    }
    cout << ans;
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int a[305], b[5];
double dp[305][305][305];

int main() {
    int n;
    scanf("%d", &n);
    double x = 0.0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        b[a[i]]++;
    }

    for (int i = 0, cnt; i <= n; i++) {
        for (int j = 0; i + j <= n; j++) {
            for (int k = 0; i + j + k <= n; k++) {
                cnt = i + j + k;
                if (!cnt) continue;
                x = n * 1.0 / cnt;
                dp[i][j][k] = x;
                if (i) dp[i][j][k] += dp[i - 1][j + 1][k] * i / cnt;
                if (j) dp[i][j][k] += dp[i][j - 1][k + 1] * j / cnt;
                if (k) dp[i][j][k] += dp[i][j][k - 1] * k / cnt;
            }
        }
    }

    printf("%.14lf\n", dp[b[3]][b[2]][b[1]]);
	return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    for (int k = 0; k <= N; ++k){
        for (int l = 0; l <= M; ++l){
            if (M * k + N * l - 2 * k * l == K){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()

ans = 0
for i in range(10):
    if str(i) in s:
        x = s.index(str(i))
        for j in range(10):
            if str(j) in s[x+1:]:
                y = s[x+1:].index(str(j))
                for k in range(10):
                    if str(k) in s[x+1:][y+1:]:
                        ans += 1

print(ans)

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

int main() {

  int n;
  int in;
  int i, j;

  cin >> n;
  int vv[2][n];
  int ansvv[2][n];
  for(i = 0; i < 2; i++){
    for(j = 0; j < n; j++){
      // cout << "ok" << endl;
      cin >> vv[i][j];
    }
  }

  for(i = 0; i < n; i++) {
    if (i == 0) {
      ansvv[0][i] = vv[0][i];
      ansvv[1][i] = vv[0][i] + vv[1][i];
    } else {
      ansvv[0][i] = ansvv[0][i - 1] + vv[0][i];
      ansvv[1][i] = vv[1][i] + max(ansvv[0][i], ansvv[1][i - 1]);
    }
  }

  cout << ansvv[1][n - 1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(register int i=a;i<=b;i++)

using namespace std;

inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

int main(){
	
	//freopen("date.txt","r",stdin);
	//freopen("mine.txt","w",stdout);
	
	int n=read();
	int num[n+2];
	memset(num,0,sizeof(num));
	FOR(i,1,n){
		int a=read();
		num[i]+=a;
		num[n-(i-1)]+=a;
	}
	
//	int n=100000;
//	int num[100000];
//	memset(num,0,sizeof(num));
//	FOR(i,1,n){
//		num[i]=i;
//	}
	
	//FOR(i,1,n) cout<<num[i]<<" "; cout<<endl;
	
	long long Ans=0;
	
	FOR(k,1,n-1){
		if((n-1)%k==0) continue;
		long long nAns=0;
		for(int now=1;now+k<=n;now+=k){
			nAns+=num[now];
			Ans=max(Ans,nAns);
		}
	}
	
	FOR(k,1,n-1){
		if((n-1)%k!=0) continue;
		long long nAns=0;
		for(int now=1;now<=n/2;now+=k){
			nAns+=num[now];
			Ans=max(Ans,nAns);
		}
	}
	
	cout<<Ans;
		
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}


int ban[12][12];
signed main(){
    int h,w,k;
    cin >> h >> w >> k;
    REP(i,h){
        string s1;
        cin >> s1;
        REP(j,w){
            if(s1[j]=='#') ban[i][j] = 1;
        }
    }
    int h2 = pow(2,h) + eps;
    int w2 = pow(2,w) + eps;
    int ans = 0;
    REP(i,h2){
        REP(j,w2){
            int now = 0;
            REP(i2,h){
                REP(j2,w){
                    if(i & (1<<i2)){
                        continue;
                    }
                    else{
                        if(j & (1<<j2)){
                            continue;
                        }
                        else{
                            if(ban[i2][j2]==1){
                                now ++;
                            }
                        }
                    }

                }
            }
            if(now == k) ans ++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4028
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){
  int A, B; cin >> A >> B;

  if (A - 2 * B >= 0){
    cout << A - 2 * B << endl;
  }else{
    cout << 0 << endl;
  }
    

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n, v) rep(i, n) cin >> v[i]

using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1, 0, -1, 0}, y_pos[4] = {0, 1, 0, -1};
int ctoi(char c)
{
	if (c >= '0' && c <= '9')
	{
		return c - '0';
	}
	return 0;
}

char upper(char c)
{
	return c - 0x20;
}

char lower(char c)
{
	return c + 0x20;
}

void unique_vector(vector<int> &v)
{
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	std::fill((T *)array, (T *)(array + N), val);
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y)
{
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

//最小公倍数
ll lcm(ll x, ll y)
{
	ll g = gcd(x, y);
	return x / g * y;
}

ll myPow(ll x, ll n, ll m)
{
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

//k!
ll facctorialMethod(ll k)
{
	ll sum = 1;
	for (ll i = 1; i <= k; ++i)
	{
		sum *= i;
		sum %= MOD;
	}
	return sum;
}

//nCr
ll permutationMethod(ll n, ll r)
{
	ll n_sum, r_sum;
	r = n - r;
	n_sum = facctorialMethod(n);
	r_sum = facctorialMethod(r);
	return n_sum / r_sum;
}

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

ll pow_kai(int a, int n)
{ //aのn乗を計算します。
	ll x = 1;
	while (n > 0)
	{ //全てのbitが捨てられるまで。
		if (n & 1)
		{ //1番右のbitが1のとき。
			x = (x * a) % MOD;
		}
		a = (a * a) % MOD;
		n >>= 1; //bit全体を右に1つシフトして一番右を捨てる。
	}
	return x % MOD;
}

ll sum(ll a, ll d, ll n, ll mod)
{
	mod *= 2;
	ll ret = (2 * a + d * (n - 1)) % mod;
	ret = ret * n % mod;
	return ret / 2;
}

int main()
{
	int n;
	cin >> n;
	vector<int> v(n,0);
	rep(i,n-1){
		int a;
		cin >> a;
		v[a - 1] += 1;
	}
	rep(i,n){
		cout << v[i] << endl;
	}
}


Measured memory_bytes: 4056
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<climits>
#include<algorithm>
#include <iomanip> 
#define ll long long int
using namespace std;

int main(){
	double r,area,pi=3.141592653589;
	cin>>r;
	area=2*pi*r;
	cout<<setprecision(10)<<area<<endl;
	}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
int main() {
    int r, c, n; cin >> r >> c >> n;
    map<int, int> m;
    auto encode = [&](int x, int y) {
        if (x == 0) return y;
        else if (y == c) return c + x;
        else if (x == r) return c + r + (c - y);
        else if (y == 0) return c * 2 + r + (r - x);
        return -1;
    };
    for (int i = 0; i < n; i++) {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        int p = encode(x1, y1), q = encode(x2, y2);
        if (p >= 0 && q >= 0) m[p] = m[q] = i;
    }
    stack<int> s;
    for (auto &iter: m) {
        if (iter.first == -1) continue;
        if (!s.empty() && s.top() == iter.second) s.pop();
        else s.emplace(iter.second);
    }
    if (s.empty()) cout << "YES\n";
    else cout << "NO\n";
}

Measured memory_bytes: 9984
//TAKOYAKI FESTIVAL 2019
#include <iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    int d[n];
    for(int i=0; i<n; i++){
        cin >> d[i];
    }
    int sum=0;
    for(int i=0; i<(n-1); i++){
        for(int j=(i+1); j<n; j++){
            sum+=d[i]*d[j];
        }
    }
    cout << sum << endl;

    return 0;

}

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

using namespace std;

vector<int> parse() {
  int n, x;
  cin >> n;
  vector<int> A;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    A.push_back(x);
  }
  return A;
}

int main() {
  auto A = parse();
  auto B = parse();
  cout << includes(A.begin(), A.end(), B.begin(), B.end()) << endl;
}


Measured memory_bytes: 5020
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

int main(){
//int W,H,x,y,r;
    int a,b,c;
    cin>>a>>b>>c;
    int x=0;

     for(int i=a;i<b+1;i++){  
        if(c%i==0){
          x++;   
        }
    
    }
    cout<<x<<"\n";   
  return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,ll> pii;
const int MOD=1e9+7;
int N;
double ans=0.0;
string board[1005];
double coin[3005];
vector<vector<double>> dp(3005,vector<double>(3005,-1.0));
double bfs(int front,int back)
{
  if(front+back==N && front>=N/2 + 1)
    {
      return dp[front][back]=1.0;
    }
  else if(front+back==N && back>=N/2 + 1)
    {
      return dp[front][back]=0.0;
    }
  if(abs(dp[front][back]+1.0)>1e-9) return dp[front][back];
  double ret=0.0;
  ret=ret+coin[front+back]*bfs(front+1,back);
  ret=ret+(1.0-coin[front+back])*bfs(front,back+1);
  return dp[front][back]=ret;
}
int main()
{
  cin >> N;
  for(int i=0;i<N;i++)
    {
      cin >> coin[i];
    }
  cout << fixed << setprecision(10) << bfs(0,0) << endl;
  return 0;
}


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

using namespace std;

int main(void)
{
        int n, z, w;
        int a[2010];
        cin >> n >> z >> w;
        for(int i = 0; i < n; i++) cin >> a[i];
        cout << max(abs(w-a[n-1]), abs(a[n-2]-a[n-1])) << endl;
        return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int c[][] = new int[3][3];
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        c[i][j] = sc.nextInt();
      }
    }
    int x[] = new int[3];
    int y[] = new int[3];
    x[0] = 0;
    for (int i = 0; i < 3; i++)
      y[i] = c[0][i] - x[0];
    for (int i = 0; i < 3; i++)
      x[i] = c[i][0] - y[0];

    boolean flag = true;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (x[i] + y[j] != c[i][j])
          flag = false;
      }
    }
    System.out.println(flag ? "Yes" : "No");
  }
}

Measured memory_bytes: 23380
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int w, h;
	cin >> h >> w;
	vector<string> v(h);
	REP(i, h)cin >> v[i];
	int f = 1;
	REP(i, h) {
		REP(j, w) {
			if (v[i][j] == '#') {
				queue<pii> q;
				q.push({ i,j });
				v[i][j] = '.';
				int cnt = 0;
				while (!q.empty()) {
					pii p = q.front(); q.pop();
					int x = p.first, y = p.second;
					REP(k, 4) {
						int nx = x + dx[k * 2], ny = y + dy[k * 2];
						if (nx < 0 || ny < 0 || nx >= h || ny >= w)continue;
						if (v[nx][ny] == '#') {
							v[nx][ny] = '.';
							cnt++;
							q.push({ nx,ny });
						}
					}
				}
				if (cnt == 0)f = 0;
			}
		}
	}
	if (f)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int count = 0;
  int i, n;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    int l, r;
    scanf("%d%d", &l, &r);
    count += r - l + 1;
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 128
// abc078_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, Z, W;
    cin >> N >> Z >> W;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    int ans;
    if (N == 1){
        ans = abs(A[0] - W);
    } else{
        ans = max(abs(A[N-1] - W), abs(A[N-1] - A[N-2]));
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
    int i,cnt0,cnt1;
    char s[100010];
    cnt0 = 0;
    cnt1 = 0;

    scanf("%s",s);

    for(i=0; i<strlen(s); i++){
        if(s[i] == '0'){
            cnt0++;
        }else if(s[i] == '1'){
            cnt1++;
        }
    }

    if(cnt0 > cnt1){
        printf("%d\n",cnt1 * 2);
    }else if(cnt1 >= cnt0){
        printf("%d\n",cnt0 * 2);
    }
    return 0;
}

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

int n, ans;
string a, b, c;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> a >> b >> c;
	for(int i=0; i<n; ++i){
		if(a[i] == b[i]){
			if(b[i] != c[i]) ++ans;
		}else{
			if(b[i] == c[i] || a[i] == c[i]) ++ans;
			else ans += 2;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<cstdio>


int solve(int w, int h, int k)
{
	for(int y=0;y<=h;y++)
	{
		int black=y*w;
		for(int x=0;x<=w;x++)
		{
			if(black==k) return 1;
			black+=(h-y)-y;
		}
	}
	return 0;
}


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

	while(scanf("%d%d%d", &n, &m, &k)==3)
	{
		printf("%s\n", solve(n, m, k)?"Yes":"No");
	}

	return 0;
}


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

int main() {
  string S; cin >> S;
  bool flag = false;
  
  if (S[0] == S[1]) {
    if (S[0] != S[2] && S[2] == S[3]) {
      flag = true;
    }
  } else {
    if ((S[0] == S[2] && S[1] == S[3]) || (S[0] == S[3] && S[1] == S[2])) {
      flag = true;
    }
  }
  
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

s = list(input())
if s[a] != "-":
    print("No")
    exit()

s.pop(a)
try:
    a = list(map(int,s))
    #print(a)
except:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P,ll> PPI;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
ll h,w,x,y;
int main(){
    cin>>h>>w;
    char s[h+1][w+1];
    bool vis[h+1][w+1];
    ll tmp = 0;
    memset(vis,0,sizeof(vis));
    rep(i,h)rep(j,w) {
        cin>>s[i][j];
        if(s[i][j]=='.') tmp++;
    }
    queue<PPI> que;
    que.push(PPI(P(0,0),0));
    ll dx[4] = {1,0,-1,0};
    ll dy[4] = {0,1,0,-1};
    ll ans = INF;
    s[0][0] = '#';
    while(!que.empty()){
        PPI p = que.front();que.pop();
        if(p.fi.fi == h-1 and p.fi.se == w-1){
                minch(ans,p.se);
        }
        rep(i,4){
            y = p.fi.fi + dy[i];
            x = p.fi.se + dx[i];
            if(0<=y and y < h and 0<=x and x < w and  s[y][x]=='.'){
                s[y][x] = '#';
                que.push(PPI(P(y,x),p.se+1));
            }
        }
    }
    if(ans == INF) cout<<-1<<endl;
    else cout<<tmp - ans-1<<endl;
return 0;}

Measured memory_bytes: 256
/*author : Yashvardhan
Sunday, April 19, 2020
5:36 PM
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n,m;
	cin >> n >> m;

	int tot = 0;
	for(int i = 0; i < m; i++){
		int x;
		cin >> x;
		tot += x;
	}

	if(tot > n) cout << - 1 << endl;
	else cout << n - tot << endl;
	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 3648
#include<stdio.h>
int main(){
  int a,b,c,x;
  scanf("%d %d",&a,&b);
  if(a<b){
    x=a;
    a=b;
    b=x;
  }
  c=a%b;
  while(c!=0){
    a=b;
    b=c;
    c=a%b;
  }
  printf("%d\n",b);
  return 0;
}



Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

class UF
{
  public:
    vi rank, data;
    UF() {}
    UF(ll size)
    {
        rank.resize(size, 0);
        data.resize(size, 0);
        REP(i, size)
        {
            init(i);
        }
    }
    void init(ll x)
    {
        data[x] = x;
        rank[x] = 0;
    }

    bool same(ll x, ll y)
    {
        return root(x) == root(y);
    }

    void unite(ll x, ll y)
    {
        link(root(x), root(y));
    }

    void link(ll x, ll y)
    {
        if (rank[x] > rank[y])
        {
            data[y] = x;
        }
        else
        {
            data[x] = y;
            if (rank[x] == rank[y])
            {
                rank[y]++;
            }
        }
    }
    // xの根を探す。同じ集合なら同じ根が帰る, O(A^-1)
    ll root(ll x)
    {
        return (x == data[x] ? data[x] : data[x] = root(data[x]));
    }

    // 分離されている集合の数を返す, O(n)
    ll getSetNum(){
        map<ll, ll> c;
        REP(i,data.size()) {
            c[root(i)]++;
        }
        return c.size();
    }

    // 頂点vと連結な集合を返す, O(n)
    vi getContainingSet(int v)
    {
        vi ret;
        REP(i,data.size()) {
            if(root(i)==root(v)){
                ret.push_back(i);
            }
        }
        return ret;
    }
};

int main() {
    ll l;
    cin >> n >> k >> l;
    UF ufa(n);
    UF ufb(n);
    REP(i,k){
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        ufa.unite(a, b);
    }
    REP(i, l)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        ufb.unite(a, b);
    }
    vector<P> temp(n);
    REP(i,n){
        temp[i] = {ufa.root(i), ufb.root(i)};
    }
    map<P, ll> mp;
    REP(i,n){
        mp[temp[i]]++;
    }
    REP(i,n) {
        cout << mp[temp[i]] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 21120
s = input()
q = int(input())
seq1 = ''
seq2 = ''
flg = 1
for i in range(q):
    ii = input().split()
    if ii[0] == '1':
        seq1, seq2 = seq2, seq1
        flg *= -1
    else:
        if ii[1] == '1':
            seq1 += ii[2]
        else:
            seq2 += ii[2]
print(seq1[::-1] + s[::flg] + seq2)

Measured memory_bytes: 4468
import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.max

fun main() {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val (n, m) = jin.readLine().split(" ").map { it.toInt() }
    val intervals = Array(n + 1) { mutableListOf<Interval>() }
    for (j in 1..m) {
        val (l, r, v) = jin.readLine().split(" ").map { it.toInt() }
        intervals[r].add(Interval(l, v.toLong()))
    }
    val segTree = LazySegmentTree(0, n)
    for (r in 1..n) {
        var new = segTree[0, r - 1]
        for (interval in intervals[r]) {
            new += interval.value
            segTree.update(interval.from, r - 1, interval.value)
        }
        segTree.update(r, r, new)
    }
    println(segTree[0, n])
}

data class Interval(val from: Int, val value: Long)

class LazySegmentTree(val treeFrom: Int, val treeTo: Int) {
    val value: LongArray
    val lazy: LongArray

    init {
        val length = treeTo - treeFrom + 1
        var e = 0
        while (1 shl e < length) {
            e++
        }
        value = LongArray(1 shl (e + 1))
        lazy = LongArray(1 shl (e + 1))
    }

    fun update(from: Int, to: Int, delta: Long) {
        update(from, to, treeFrom, treeTo, 1, delta)
    }

    fun update(from: Int, to: Int, segFrom: Int, segTo: Int, node: Int, delta: Long): Long {
        if (from > segTo || to < segFrom) {

        } else if (from <= segFrom && to >= segTo) {
            value[node] += delta
            lazy[node] += delta
        } else {
            val mid = (segFrom + segTo) / 2
            value[node] = lazy[node] + max(
                    update(from, to, segFrom, mid, 2 * node, delta),
                    update(from, to, mid + 1, segTo, (2 * node) + 1, delta)
            )
        }
        return value[node]
    }

    operator fun get(from: Int, to: Int) = query(from, to, treeFrom, treeTo, 1)

    fun query(from: Int, to: Int, segFrom: Int, segTo: Int, node: Int): Long {
        if (from > segTo || to < segFrom) {
            return Long.MIN_VALUE
        } else if (from <= segFrom && to >= segTo) {
            return value[node]
        } else {
            val mid = (segFrom + segTo) / 2
            return lazy[node] + max(
                    query(from, to, segFrom, mid, 2 * node),
                    query(from, to, mid + 1, segTo, (2 * node) + 1)
            )
        }
    }
}

Measured memory_bytes: 85172
N = int(input())
A = list(map(int, input().split()))
M = max(A)+1
cnt = [0]*M
ans = 0
for a in A:
    if cnt[a] != 0:
        cnt[a] = 2
    else:
        for i in range(a, M, a):
            cnt[i] += 1
for a in A:
    if cnt[a] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 121848
#include<stdio.h>

int cmpt_gcd(int large, int small){
  int r = large%small;
  if(r==0){
    return small;
  }
  cmpt_gcd(small, r);
}

int main(){
  int a, b, k, r, cnt=0, kth_gcd;
  scanf("%d %d %d", &a, &b, &k);
  
  if(a<b){
    int tmp = a;
    a = b;
    b = tmp;
  }
  r = cmpt_gcd(a, b);
//  printf("%d\n",r);
  
  for(int i=r; cnt<k; i--){
    if(a%i==0 && b%i==0){
      cnt++;
      kth_gcd = i;
//      printf("cnt %d  i %d\n",cnt, i);
    }
  }
  
  printf("%d", kth_gcd);

  return 0;
}

Measured memory_bytes: 128
A, B = map(int, input().split())
ans = 0

def f(n):
    # F(0, n)
    if n % 2 == 0:
        if (n//2) % 2 == 0:
            return 0^n
        else:
            return 1^n
    else:
        if ((n+1)//2) % 2 == 0:
            return 0
        else:
            return 1

print(f(A-1)^f(B))

Measured memory_bytes: 61948