akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 2e18;
const ll fact_table = 1200008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
// const ll mod = 998244353ll;
const ll mod = 1000000007ll;
  
ll mypow(ll number1,ll number2, ll mod){
    if(number2 == 0){
        return 1ll;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n,m,num,a,b,c,d,e,h,q;
ll w, k;
ll x[500005], y[500005], z[500005];
string s;
ll dp[2005][2005];

void solve(){
    cin >> n;
    vector<P> v;
    for(ll i=0;i<n;i++){
        cin >> x[i];
        v.pb(P(x[i], i));
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for(ll i=0;i<n;i++){
        ll put = i;
        ll val = v[i].first;
        ll idx = v[i].second;
        for(ll j=0;j<=put;j++){
            ll l = j, r = put - j;
            dp[l+1][r] = max(dp[l+1][r], dp[l][r] + abs(l - idx) * val);
            dp[l][r+1] = max(dp[l][r+1], dp[l][r] + abs((n - r - 1) - idx) * val);
        }
    }
    ll ans = 0;
    for(ll i=0;i<=n;i++){
        ans = max(ans, dp[i][n-i]);
    }
    p(ans);

    return;
}

int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
 
    if(multicase){
        cin >> q;
    }else{
        q = 1;
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    
    // solve();
    return 0;
 
}
















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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;


int main() {
    int n;cin>>n;
    vector<int>b,c;

    rep(i,n){
        int a;cin>>a;
        if(i%2==0){
            b.push_back(a);
        }
        else {
            c.push_back(a);
        }
    }

    if(n%2==0){
        for(int i=c.size()-1;i>=0;i--){
        cout<<c[i]<<" ";
    }
    for (int i=0;i<b.size();i++) {
        cout<<b[i]<<" ";
    }
    }

    else {
        for(int i=b.size()-1;i>=0;i--){
        cout<<b[i]<<" ";
    }
    for (int i=0;i<c.size();i++) {
        cout<<c[i]<<" ";
    }

    }

}


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>

using namespace std;

int main(){
	int h,w;
	cin >> h >> w;

	vector<vector<int> > s(h, vector<int>(w, 0));

	for(int i=0; i<h; i++){
		string str;
		cin >> str;
		for(int j=0; j<w; j++){
			s[i][j]= str[j]=='.' ? 0 : -1;
		}
	}

	for(int i=0; i<h; i++){
		int r=0;
		for(int j=0; j<w; j++){
			if(s[i][j]==-1) r=0;
			else{
				s[i][j]+=r;
				r++;
			}
		}
		r=0;
		for(int j=w-1; -1<j; j--){
			if(s[i][j]==-1) r=0;
			else{
				s[i][j]+=r;
				r++;
			}
		}
	}

	for(int j=0; j<w; j++){
		int r=0;
		for(int i=0; i<h; i++){
			if(s[i][j]==-1) r=0;
			else{
				s[i][j]+=r;
				r++;
			}
		}
		r=0;
		for(int i=h-1; -1<i; i--){
			if(s[i][j]==-1) r=0;
			else{
				s[i][j]+=r;
				r++;
			}
		}
	}

	int r=-1;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			r=max(r,s[i][j]);
		}
	}

	cout << r+1 << endl;

	return 0;

}



Measured memory_bytes: 16000
import sys

N = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if N == 1:
    print(0)
    sys.exit()

f = factorization(N)

result = 0
for p, e in f:
    i = 1
    while True:
        e -= i
        if e < 0:
            break
        result += 1
        i += 1

print(result)


Measured memory_bytes: 9432
MOD = 1000000007

n = int(input())
str_ary = input().split()
ary = [int(c) for c in str_ary]
# ary = []
# queue = [0 for i in range(n)]
# for i int range(n):
#   num = int(str_ary[i])
#   ary.append(num)
#   for j int range(i):
#     pre_queue = []
#     queue.append(pre_queue)

result = 0
sum = sum(ary[i] for i in range(n))
# for diff in range(1, n):
#   for i in range(n - diff):
#     # print(diff, i, i + diff)
#     sum += ary[i] * ary[i + diff] % MOD
for i in range(n):
  sum -= ary[i]
  result += ary[i] * sum

print(result % MOD)

Measured memory_bytes: 31484
import sys
from collections import deque

input = sys.stdin.readline
n, u, v = map(int, input().split())

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

memo = [[0, 0] for i in range(n)]

def dfs(cur, pre, p):
    stack = deque([[cur, pre]])
    while stack:
        cur, pre = stack.pop()
        if pre != -1:
            memo[cur][p] = memo[pre][p] + 1
        for e in E[cur]:
            if e != pre:
                stack.append([e, cur])

dfs(u - 1, - 1, 0)
dfs(v - 1, -1, 1)

# print(memo)
ans = 0
for a, b in memo:
    if a <= b:
        ans = max(ans, b - 1)
print(ans)


Measured memory_bytes: 71292
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
# https://atcoder.jp/contests/arc098/tasks/arc098_b

# xorは桁の繰り上がりがない足し算！→範囲で1が1回以下出てくるような範囲は大丈夫
# 1が2回以上出てこない最長の範囲ならどのようにl,rを選んでも題意が成り立つ
# 尺取法か,累積和で、足し算とxorが成り立つ最長の範囲を取ってくれば良い
# Alに対して範囲が成り立つ最長のArを探せば良い
# だけど一つずらしても最長の区間が存在する場合は？
#

N = read_a_int()
A = read_ints()
a_sum = 0
a_xor = 0
ans = 0
r = -1
for l in range(N):
    if r <= l:  # explicitに初期cumを決める
        r = l
        a_sum = A[r]
        a_xor = A[r]
    while r < N and a_sum == a_xor:
        r += 1
        if r == N:  # 終端処理用
            break
        a_sum += A[r]
        a_xor ^= A[r]
        # print(l, r, a_sum, a_xor)
    ans += r - l
    # print(l, r)
    a_sum -= A[l]
    a_xor ^= A[l]
print(ans)


Measured memory_bytes: 71244
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  auto s = readln.chomp.to!(char[]);
  auto t = readln.chomp.to!(char[]);

  char[char] map;
  foreach (i; 0 .. s.length) {
    if (s[i] in map) {
      if (t[i] != map[s[i]]) {
        writeln("No");
        return;
      }
    } else {
      map[s[i]] = t[i];
    }
  }
  char[char] map2;
  foreach (i; 0 .. t.length) {
    if (t[i] in map2) {
      if (s[i] != map2[t[i]]) {
        writeln("No");
        return;
      }
    } else {
      map2[t[i]] = s[i];
    }
  }
  writeln("Yes");
}

void rd(T...)(ref T x) {
  import std.stdio, std.string, std.conv;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 3128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n) {
        cin >> h[i];
    }
    if (n==1) {
        cout << "Yes" << "\n";
        return 0;
    }
    bool j = true;
    rep(i,n-1) {
        if (h[i] < h[i+1]) {
            h[i+1]--;
        } else if (h[i]==h[i+1]) {
            continue;
        }
        if (h[i] > h[i+1]) {
            cout << "No" << "\n";
            return 0;
        } 
    }
    cout << "Yes" << "\n";
}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define nrep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin>>s;
	string t="CODEFESTIVAL2016";
	int cnt=0;
	rep(i,16){
		if(s[i]!=t[i])cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
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;}

int main(){
	int m;
	cin >> m;
	REP(i,m){
		map<string,int> data;
		string in;
		cin >> in;
		FOR(i,1,in.size()){
			string s1 = in.substr(0,i);
			string s2 = in.substr(i);
			//cout << s1 << " " << s2 << endl;
			string s3 = s1;
			reverse(All(s3));
			string s4 = s2;
			reverse(All(s4));
			data[s1+s2]++;
			data[s1+s4]++;
			data[s2+s1]++;
			data[s2+s3]++;
			data[s3+s2]++;
			data[s3+s4]++;
			data[s4+s1]++;
			data[s4+s3]++;
		}
		cout << data.size() << endl;
	}
}

Measured memory_bytes: 1296
#include<stdio.h>
int main(void){
    int n;
    int h[1000001];
    int dpmax[1000001];
    int dpmin[1000001];
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&h[i]);
        dpmin[i]=((unsigned)-1)>>1;
    }
    for(i=0;i<n;i++){
        if(i==0){
            dpmin[i]=h[i]-1;
        }else
        if(h[i]-1>=dpmin[i-1]){
            dpmin[i]=h[i]-1;
        }else if(h[i]>=dpmin[i-1]){
            dpmin[i]=h[i];
        }else{
            
        }
    }
    if(dpmin[n-1]!=((unsigned)-1)>>1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 6400
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MOD = 1e9+7;

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

    int x;
    cin >> x;

    int i = 100;
    int time = 0;
    while(i<x){
        i += i/100;
        time++;
    }
    cout << time << endl;

    return 0;
}


Measured memory_bytes: 3608
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()
d = i_l()

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += d[i] * d[j]

print(ans)

Measured memory_bytes: 3064
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
  input! {
    k: usize,
  };

  let mut v = Vec::new();
  for a in 1..=k {
    for b in 1..=k {
      let x = a.gcd(&b);
      v.push(x);
    }
  }

  let mut table = vec![vec![1; k + 1]; k + 1];
  for a in 1..=k {
    for b in 1..=k {
      let x = a.gcd(&b);
      table[a][b] = x;
    }
  }

  let mut res = 0;
  for a in 1..=k {
    for &b in &v {
      res += table[a][b];
    }
  }

  println!("{}", res);
}


Measured memory_bytes: 2780
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){

    ll A;
    string S;
    cin >> A;
    cin >> S;

    if(A >= 3200 ){
        cout << S << endl;
        return 0;
    }

    cout << "red" << endl;
    

}

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

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> p(A);
  vector<ll> q(B);
  vector<ll> r(C);

  rep(i, A) cin >> p[i];
  rep(i, B) cin >> q[i];
  rep(i, C) cin >> r[i];

  sort(all(p));
  sort(all(q));
  sort(all(r));

  ll ans = 0LL;
  for (int i = A-X; i < A; i++) ans += p[i];
  for (int i = B-Y; i < B; i++) ans += q[i];

  reverse(all(r));
  int ip = A-X;
  int iq = B-Y;
  p.push_back(INF);
  q.push_back(INF);
  rep(i, C) {
    ll ir = r[i];
    if (ir <= p[ip] && ir <= q[iq]) break;
    if (ip == A && iq == B) break;

    if (p[ip] <= q[iq]) {
      ans -= p[ip];
      ip++;
    }
    else {
      ans -= q[iq];
      iq++;
    }
    ans += ir;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
int INF = numeric_limits<int>::max() / 2;
using ll = long long;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    ll k;
    cin >> s >> k;
    char ans = 0;
    int count = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '1') count++;
        else break;
    }
    if(k <= count){
        ans = '1';
    }else{
        ans = s[count];
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 998244353
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	vector <int> A(n), v(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		v[i] = A[i];
	}
	sort(all(v));
	for (int i = 0; i < n; i++) {
		int id = lower_bound(all(v), A[i]) - v.begin();
		id += 1;
		if(id <= n / 2) {
			cout << v[n / 2] << "\n";
		} 
		else {
			cout << v[n / 2 - 1] << "\n";
		}
	}
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  using P = pair<int,int>;
  vector<P> e(M);
  for(int i = 0,a,b; i < M; i++){cin >> a>>b,e[i]={b-1,a-1};}
  sort(e.begin(),e.end());
  int ans = 0;
  for(int i = 0,prev = -1; i < M; i++){
  	const int a = e[i].second,b=e[i].first;
    if(prev < a){ans++,prev=b-1;}
  }
  cout << ans << endl;
  
return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define inar ll ar[n];for(ll i=0;i<n;i++) cin>>ar[i];
#define loop for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL);
  #define endl "\n"
  #define inf ll(1e19)
  #define mod int(1000000007)
 typedef long long int ll;
using namespace std;
int main()
{
	int n;
	cin>>n;
	int m;
	cin>>m;
	if(n==1 and m==0)
	cout<<0;
	else{
	char ar[n];
	for(int i=0;i<n;i++)
	ar[i]='/';
	int flag=0;
	for(int i=0;i<m;i++)
{
	int me=0;
	char ae=0;
	cin>>me; cin>>ae;
	
	if(ar[me-1]!='/' and ar[me-1]!=ae)
	{flag=1;
}
    else
    {
		ar[me-1]=ae;
	}
}
for(int i=0;i<n;i++)
{
	if(ar[i]=='/' and i==0)
	ar[i]='1';
	else if(ar[i]=='/')
	ar[i]='0';
}
if(flag>0 or (ar[0]=='0' and n>1))
cout<<-1;
else{
for(int i= 0;i<n;i++)
{
	cout<<ar[i];
}
}
}}



Measured memory_bytes: 256
import copy
N, M, Q = list(map(int, input().split()))
Qs = [[0] * 4 for i in range(Q)]
for i in range(Q):
    Qs[i][0], Qs[i][1], Qs[i][2], Qs[i][3] = list(map(int, input().split()))
ans = -1

# 再帰で全探索
# 後ろから<=Mまで順番に1増加させることで、それぞれ<=Mの広義単調増加の全探索ができる
def dfs(A):
    global ans
    if len(A) == N + 1:
        sum_ = 0
        for i in range(Q):
            if A[Qs[i][1]] - A[Qs[i][0]] == Qs[i][2]:
                sum_ += Qs[i][3]
        ans = max(ans, sum_)
        return
        
    A.append(A[-1])
    while (A[-1] <= M):
        dfs(copy.copy(A))
        A[-1] += 1
    return

dfs([1])
print(ans)

Measured memory_bytes: 9356
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int i,j,n,v=1,idx;
ll a[2010],x,y,mx,mn;
pair<ll,ll>p[2010];
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>x>>y;
	int Y = y;
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n;i++)p[i].fr=INF;
	for(i=1;i<n;i++)
		for(j=i+1;j<=n;j++)
			p[i].fr=min(p[i].fr,abs(a[i]-a[j])),
			p[i].sc=max(p[i].sc,abs(a[i]-a[j]));
	p[n].fr=abs(a[n]-y),p[n].sc=abs(a[n]-x);
	for(i=1;i<=n;i++)
	{
		mx=0,mn=INF;
		for(j=i;j<=n;j++)
		{
			if(v==1 && p[j].fr>mx)mx=p[j].fr,idx=j;
			if(v==2 && p[j].sc<mn)mn=p[j].sc,idx=j;
		}
		if(v==1)x=a[idx],v=2;
		else if(v==2)y=a[idx],v=1;
		p[n].fr=abs(a[n]-y),p[n].sc=abs(a[n]-x),i=idx;
	}
	cout << max(abs(x - y), abs(a[n] - Y));
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n)  cin >> a[i];
    bool minus = true;
    rep(i, n)  if (a[i] > 0LL)   minus = false;
    if (minus) {
        int x = 0;
        rep(i, n)   if (a[x] < a[i])   x = i;
        cout << a[x] << endl;
        cout << n - 1 << endl;
        for (int i = n; i > x + 1; i--)  cout << i << endl;
        for (int i = x; i > 0; i--)  cout << 1 << endl;
        return 0;
    }
    ll ret1 = 0, ret2 = 0;
    for (int i = 0; i < n; i += 2)  ret1 += max(0LL, a[i]);
    for (int i = 1; i < n; i += 2)  ret2 += max(0LL, a[i]);
    vector<int> ret;
    if (ret1 < ret2) {
        ret1 = ret2;
        ret.push_back(1);
        n--;
        a.erase(a.begin());
    }
    if (n % 2 == 0) {
        ret.push_back(n);
        n--;
    }
    while (a[n - 1] <= 0) {
        ret.push_back(n);
        n--;
        ret.push_back(n);
        n--;
    }
    while (n > 1) {
        while (n >= 5 && a[n - 3] <= 0) {
            ret.push_back(n - 2);
            n -= 2;
        }
        if (n == 1)  break;
        else if (n == 3) {
            if (a[0] >= 0) {
                ret.push_back(2);
                n = 1;
                break;
            }
            else {
                ret.push_back(1);
                ret.push_back(1);
                n = 1;
                break;
            }
        }
        else {
            ret.push_back(n - 1);
            n -= 2;
        }
    }
    cout << ret1 << endl;
    cout << ret.size() << endl;
    rep(i, ret.size())  cout << ret[i] << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
bool vis[105];
int main(){
	int n,k,d,x,ans=0;scanf("%d%d",&n,&k);
	for(int i=0;i<k;i++){
		scanf("%d",&d);
		for(int j=0;j<d;j++)scanf("%d",&x),vis[x]=1;
	}
	for(int i=1;i<=n;i++)if(!vis[i])ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, v[101][101];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    int l = 1;
    int r = n - n % 2;
    while(l <= r){
        v[l][r] = 1;
        l++; r--;
    }
    cout << n * (n - 1) / 2 - n / 2 << endl;
    for(int i = 1 ; i <= n ; i++){
        for(int j = i + 1 ; j <= n ; j++){
            if(v[i][j] == 0) cout << i << " " << j << endl;
        }
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

struct Hashing {
    ull seed, mod;
    vector <ull> hs, pw;

    Hashing(ull seed = 31, ull mod = 1000173169) :
        seed(seed),
        mod(mod) {}

    void build(int n, const string& s) {
        hs.assign(n + 1, 0);
        pw.assign(n + 1, 1);
        pw[0] = 1;

        for (int i = 1; i <= n; ++i)
            pw[i] = pw[i - 1] * seed % mod;
        for (int i = 1; i <= n; ++i)
            hs[i] = (hs[i - 1] * seed + s[i]) % mod;
    }

    ull hash(int l, int r) {
        return (hs[r] - hs[l - 1] * pw[r - l + 1] % mod + mod) % mod;
    }
};

int solve()
{
    char c;

    std::cin >> c;
    ++c;

    cout << c << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
    double lowestsp;
    while(scanf("%lf",&lowestsp)!=EOF)
    {
        int N;
        for(N=0;;N++)
        {
            double y=5*N-5;
            double t=sqrt(y/4.9);
            double v=9.8*t;
            if(v>lowestsp)
                break;
        }
        printf("%d\n",N);
    }
    return 0;
}

Measured memory_bytes: 636
n, x, y = map(int, input().split())
D=[0]*n
 
def dist(i, j):
  d1 = abs(i - j)
  d2 = abs(x - i) + 1 + abs(y - j)
  return min(d1, d2)
 
for i in range(1,n):
	for j in range(i,n+1):
		a= dist(i,j)
		D[a]+=1
 
for i in range(1,n):
	print(D[i])

Measured memory_bytes: 3444
#include<cstdio>

int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while ( A[i] != key ) i++;
  return i != n;
}

int main() {
  int i, n, A[10000+1], q, key, sum = 0;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &key);
    if ( search(A, n, key) ) sum++;
  }

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

  return 0;
}

Measured memory_bytes: 2700
// Problem : B - Multiplication 2
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	int n;
	cin >> n;
	vector<ll> v(n);
	for(int i=0;i<n;++i) cin >> v[i];
	ll ans=1,last=1;
	for(int i=0;i<n;++i)
	{
		if(v[i]==0)
		{
			cout << 0 << endl;
			return;
		}
	}
	for(int i=0;i<n;++i)
	{
		ans*=v[i];
		if(ans<last || ans>(ll)1e18)
		{
			ans=-1;
			break;
		}
		last=ans;
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


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

class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        map<int, int> A;
        rep(i, N) {
            int a; cin >> a;
            A[a]++;
        }        
        int odd = 0, even = 0;
        for(auto p : A) {
            (p.second % 2 == 1 ? odd : even)++;
        }
        if(even % 2 == 0) {
            cout << odd + even << endl;            
        } else {
            cout << odd + even - 1 << endl;  
        }

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

int main() {
	int n;
	long long int sum = 0;
	int maxnum = -1e7;
	int minnum = 1e7;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		maxnum = max(maxnum, tmp);
		minnum = min(minnum, tmp);
		sum += tmp;
	}
	cout << minnum << " " << maxnum << " " << sum << endl;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int read() {
	int x = 0,f = 0;char ch = getchar();
	while(!isdigit(ch)) {if(ch == '-')f = 1;ch = getchar();}
	while(isdigit(ch)) {x = x * 10 + ch - '0';ch = getchar();}
	return f ? -x : x;
}
const int N = 1e5 + 100;
int fa[N],vis[N],n,m;
int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
int main() {
	n = read();m = read();
	for(int i = 1;i <= n;i++)fa[i] = i;
	for(int i = 1;i <= m;i++) {
		int a = read(),b = read();
		a=find(a);b=find(b);
		if(a==b)continue;fa[a]=b;
	}
	int ans = 0;
	for(int i = 1;i <= n;i++) {
		int a =find(i);
		if(vis[a])continue;ans++;vis[a]=1;
	}
	cout << ans - 1<< endl;
}

Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
long long n,i,nr,x,aux;
int main()
{
    cin>>n;
    i=5;
    if(n%2==0)
        while(i<=n)
            nr=nr+n/(i*2) , i=i*5;
    cout<<nr;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   float av,sum=0,x=0;int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
   {
       cin>>a[i];sum+=a[i];
   }
   av=sum/n;
  ll int d= round(av);
   for(int i=0;i<n;i++)
   {
       x+=(a[i]-d)*(a[i]-d);
   }
   cout<<x;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct Dish {
  int a, b;
};

int n, t, dp[3005][3005][2];
vector<Dish> v;

void init() {
  cin >> n >> t;
  for(int i = 0 ; i < n ; ++i) {
    int a, b; cin >> a >> b; v.push_back((Dish){ a, b });
  }
}
void solve() {
  memset(dp, 0, sizeof(dp));
  int mx = 0;
  for(int i = 1 ; i <= n ; ++i) {
    for(int j = 0 ; j <= t ; ++j) {
      if(j == 0) {
        dp[i][j][0] = dp[i - 1][j][0];
        dp[i][j][1] = dp[i - 1][j][1];
      }
      else if(j < v[i - 1].a) {
        dp[i][j][0] = max(dp[i - 1][j][0], dp[i - 1][j - 1][1] + v[i - 1].b);
        dp[i][j][1] = dp[i - 1][j][1];
      }
      else {
        dp[i][j][0] = max(dp[i - 1][j][0], max(dp[i - 1][j - v[i - 1].a][0], dp[i - 1][j - 1][1]) + v[i - 1].b);
        dp[i][j][1] = max(dp[i - 1][j][1], dp[i - 1][j - v[i - 1].a][1] + v[i - 1].b);
      }

      if(i == n) mx = max(mx, max(dp[i][j][0], dp[i][j][1]));
    }
  }
  cout << mx << '\n';
}

int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  init();
  solve();
}


Measured memory_bytes: 141440
#include<stdio.h>
int main(void)
{
	int a,b,k,c;
	scanf("%d %d",&a,&b);
	
	k = (a+b) / 2;
	c = (a+b) % 2;
	
	if(c!=0){
		printf("IMPOSSIBLE");
	}else{
		printf("%d",k);
	}
	return 0;
}

Measured memory_bytes: 128
_ = input()
aa = input()

west_count = [None for _ in aa]
east_count = [None for _ in aa]

west_count[0] = 0
for i in range(len(aa) - 1):
    if aa[i] == 'W':
        west_count[i + 1] = west_count[i] + 1
    else:
        west_count[i + 1] = west_count[i]

east_count[-1] = 0
for i in range(len(aa) - 1, 0, -1):
    if aa[i] == 'E':
        east_count[i - 1] = east_count[i] + 1
    else:
        east_count[i - 1] = east_count[i]

candidate_count = len(aa)
for i in range(len(aa)):
    candidate_count = min(west_count[i] + east_count[i], candidate_count)

print(candidate_count)


Measured memory_bytes: 17836
W, H, N = map(int, input().split())
L = 0
R = W
D = 0
U = H

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    L = max(L, x)
  if a == 2:
    R = min(R, x)
  if a == 3:
    D = max(D, y)
  if a == 4:
    U = min(U, y)
print(max((R-L),0) * max((U-D),0))

Measured memory_bytes: 3064
# import sys
import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    x = int(input())
    ans = 0
    if x<600:
        ans = 8
    elif x<800:
        ans = 7
    elif x<1000:
        ans = 6
    elif x<1200:
        ans = 5
    elif x<1400:
        ans = 4
    elif x<1600:
        ans = 3
    elif x<1800:
        ans = 2
    else:
        ans = 1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    if(n%2==0){
        rep(i, n){
            if(a.at(i)%2==0){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    else{
        int cnt = 0;
        rep(i, n){
            if(a.at(i)%2!=0){
                cout << 0 << endl;
                return 0;
            }
            if(a.at(i)==0){
                cnt++;
            }
            if(cnt==2){
                cout << 0 << endl;
                return 0;
            }
        }
    }

    ll sum = 1;
    ll mod = 1e9 + 7;
    rep(i, n/2){
        sum *= 2LL;
        sum %= mod;
    }
    cout << sum % mod << endl;
    return 0;
}


Measured memory_bytes: 640
(defun split-and-parse-integer (string)
  (loop for i = 0 then (1+ j)
    as j = (position #\Space string :start i)
    collect (parse-integer (subseq string i j))
    while j))
(defparameter x (read))
(defparameter n (read))
(if (not (= n 0))
(defparameter lst (split-and-parse-integer (read-line)))
(defparameter lst nil)
 )
(defparameter ans x)
(defparameter tmp 100)

(loop for i below 102
     do (if (and lst (not (find i lst)) (> tmp (abs (- x i))))
            (progn
              (setf ans i)
            (setf tmp (abs (- x i))) )
            )
      )

(princ ans)

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string t;
  cin >> t;
  int32 n = t.size();
  
  //取り敢えず1を全部取る
  int32 cnt = 0;
  REP(i,n)if(t[i] == '1')++cnt;
  int64 ans = (1 + cnt/2) * (cnt/2);
  if(cnt % 2)ans += (cnt+1)/2;
  // ANS(ans);

  //前から順に偶数番目になるなら0埋めてく
  int32 cntuse = 0;
  REP(i,n){
    if(t[i] =='1'){
      ++cntuse;
      continue;
    }
    if(cntuse % 2 == 0)continue;
    t[i] = 2; //取った
    ++cntuse;
    ++cnt;
    ans += (cnt+1)/2;
  }
  // ANS(ans);

  //後ろから順に残りの0取ってく
  int32 cntodd1=0,cnteven1=0;
  FORR(i,n-1,0){
    if(t[i] =='1'){
      if(cntuse % 2 == 1){
        ++cntodd1;
      }else{
        ++cnteven1;
      }
    }
    if(t[i] != '0')--cntuse,--cnt;
    if(t[i] == '0'){
      swap(cntodd1,cnteven1);
      // cout << cntodd1 << " " << cnteven1 << " " << (cnt + 1) / 2 + cntodd1 << endl;
      ans += (cnt + 1) / 2 + cntodd1;
    }
  }
  ANS(ans);
}

Measured memory_bytes: 3780
using System;
class main{
    static void Main(string[] args){
        int seconds = 0, minutes = 0, hours = 0;
        int input = int.Parse(Console.ReadLine());
        if (input < 60)
        {
            seconds = input;
        }
        else if (input < 3600)
        {
            seconds = input % 60;
            minutes = ((input % 3600) - seconds) / 60;
        }
        else
        {
            seconds = input % 60;
            minutes = ((input % 3600) - seconds) / 60;
            hours = (input - seconds - minutes * 60) / 3600;
        }
        Console.WriteLine(hours.ToString() + ':' + minutes.ToString() + ':' + seconds.ToString());
    }
}

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

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

  vector<int> check1(26, -1), check2(26, -1);
  for (int i = 0; i < S.size(); i++) {
    int a = S[i] - 'a', b = T[i] - 'a';
    if (check1[a] != -1 || check2[b] != -1) {
      if (check1[a] != b || check2[b] != a) {
        cout << "No" << endl;
        return 0;
      }
    }
    check1[a] = b;
    check2[b] = a;
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 900
#include <iostream>

using namespace std;

int main() {
  int total, book;
  while (true) {
    cin >> total;
    if (total == 0) {
      return 0;
    }
    for (int i = 0; i < 9; ++i) {
      cin >> book;
      total -= book;
    }
    cout << total << endl;
  }
}

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

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First& first, Rest&... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    ll N;
    read(N);
    vector<ll> h(N);
    for(ll i = 0; i < N; i++){
        read(h[i]);
    }
    vector<ll> dp(N + 3, LONG_LONG_MAX);
    dp[1] = 0;
    for(ll i = 1; i <= N; i++){
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i - 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 1] - h[i - 1]));
    }
    write(dp[N]);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First& first, Rest&... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

template<typename T>
T gcd(T a, T b) {
	if( a < b ) swap(a, b);
	
	T r;
	while( r = a % b ) {
		a = b;
		b = r;
	}
	
	return b;
}

int main(void) {
	int m;
	cin >> m;
	
	int ans = 0;
	for(int i = 1; i <= m; ++i) {
		for(int j = 1; j <= m; ++j) {
			for(int k = 1; k <= m; ++k) {
				ans += gcd(i, gcd(j, k));
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000111


using namespace std;
ll n;
ll a[maxn];
ll f[maxn];
ll k;
 main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    f[1]=0;
//    for(int i=1;i<=n;i++)
//    {
//        long long bien=INT_MAX;
//        for (int j=i-k;j<=i-1;j++)
//        {
//            if (f[j]+abs(a[i]-a[j])<bien)
//            {
//                bien=f[j]+abs(a[i]-a[j]);
//            }
//        }
//        f[i]=bien;
//    }
for(int i=2;i<=n;i++)
{
    f[i]=INT_MAX;
    for(int j=1;j<=k;j++)
        if(i-j>0)
    {
        f[i]=min(f[i],f[i-j]+abs(a[i]-a[i-j]));
    }
}
     cout<<f[n];
}



Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#pragma GCC optimize ("O3")

using namespace std;

int main(int argc, char const *argv[])
{
    int h, w;
    cin >> h >> w;
    vector<vector<int> > field(h, vector<int>(w, 0));

    for(int i=0;i<h;++i) {
        for(int j=0;j<w;++j) {
            cin >> field[i][j];
        }
    }

    int count=0;
    vector<vector<bool> > move(h, vector<bool>(w, false));
    for(int i=0;i<h;++i) {
        if(i&1) {
            for(int j=w-2;j>=0;--j) {
                if (field[i][j+1]&1) {
                   move[i][j+1] = true;
                   --field[i][j+1]; ++field[i][j];
                   ++count;
                }
            }
            if (i<h-1 && (field[i][0]&1)) {
                move[i][0] = true;
                --field[i][0]; ++field[i+1][0];
                ++count;
            }
        } else {
            for(int j=1;j<w;++j) {
                if (field[i][j-1]&1) {
                   move[i][j-1] = true;
                   --field[i][j-1]; ++field[i][j];
                    ++count;
                }
            }
            if (i<h-1 && (field[i][w-1]&1)) {
                move[i][w-1] = true;
                --field[i][w-1]; ++field[i+1][w-1];
                ++count;
            }
        }
    }

    cout << count << endl;
    for(int i=0;i<h;++i) {
        if(i&1) {
            for(int j=w-2;j>=0;--j) {
                if (move[i][j+1]) {
                    cout << i+1 << " " << j+2 << " " << i+1 << " " << j+1 << endl;    
                }
            }
            if (move[i][0]) {
                cout << i+1 << " " << 1 << " " << i+2 << " " << 1 << endl;    
            }
        } else {
            for(int j=1;j<w;++j) {
                if (move[i][j-1]) {
                    cout << i+1 << " " << j << " " << i+1 << " " << j+1 << endl;
                }
            }
            if (move[i][w-1]) {
                cout << i+1 << " " << w << " " << i+2 << " " << w << endl;    
            }
        }
    }


    
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  map<int,int> mp;
  vector<int> prime = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
  for(int i=2; i<=n; ++i) for(int j:prime){
    if(i%j == 0){
      int x = i;
      while(x%j == 0){
        x /= j;
        ++mp[j];
      }
    }
  }
  int cnt75 = 0, cnt25 = 0, cnt15 = 0, cnt5 = 0, cnt3 = 0;
  for(auto p:mp){
    if(p.second >= 74) ++cnt75;
    if(p.second >= 24) ++cnt25;
    if(p.second >= 14) ++cnt15;
    if(p.second >= 4) ++cnt5;
    if(p.second >= 2) ++cnt3;
  }
  int ans = cnt5*(cnt5-1)*(cnt3-2) /2;
  ans += cnt75;
  ans += cnt25 *(cnt3-1);
  ans += cnt15 *(cnt5-1);
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
int a, b, c;
int main(){
while(~scanf("%d %d %d", &a, &b, &c)) {
if((a * 100 + b * 10 + c) % 4 == 0) puts("YES");
else puts("NO");
}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
struct E{
	int u,v,val;
	bool operator<(const E& a)const{
		return val<a.val;
	}
};
int main()
{
	int n;
	ll m;
	cin>>n>>m;
	vi a(n);
	vc<ll> suf(n+1);
	for(int i=0;i<n;i++) 
		cin>>a[i];
	sort(a.begin(),a.end());
	for(int i=n-1;i>=0;i--)
		suf[i]=suf[i+1]+a[i];
	ll ans=0;
	int L=2,R=2e5,tar=-1;
	while(L<=R)
	{
		int mid=L+R>>1;
		ll cnt=0;
		for(int i=0;i<n;i++)
		{
			int pos=lower_bound(a.begin(),a.end(),mid-a[i])-a.begin();
			cnt+=n-pos;
		}
	//	dbg(mid,cnt);
		if(cnt>=m)
		{
			L=mid+1;
			tar=mid;
		}
		else R=mid-1;
	}
	assert(tar!=-1);
	//dbg(tar);
	ll cnt=0;
	for(int i=0;i<n;i++)
	{
		int pos=upper_bound(a.begin(),a.end(),tar-a[i])-a.begin();
		cnt+=n-pos;
		ans+=1LL*(n-pos)*a[i]+suf[pos];
	}
	ans+=1LL*tar*(m-cnt);
	cout<<ans<<'\n';
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  string S;
  cin >> S;
  deque<char> M;
  int S2 = S.size();
  for (int i = 0; i < S2; i++) {
    M.push_back(S.at(i));
  }
  int Q;
  cin >> Q;
  bool ok = true;
  for (int i = 0; i < Q; i++) {
    int T;
    cin >> T;
    if (T == 1) {
      if (ok) {
        ok = false;
      }
      else {
        ok = true;
      }
    }
    else {
      int F;
      cin >> F;
      char C;
      cin >> C;
      if (F == 1 && ok) {
        M.push_front(C);
      }
      if (F == 1 && ok == false) {
        M.push_back(C);
      }
      if (F == 2 && ok) {
        M.push_back(C);
      }
      if (F == 2 && ok == false) {
        M.push_front(C);
      }
    }
  }
  if (ok == false) {
    reverse(M.begin(), M.end());
  }
  int M2 = M.size();
  for (int i = 0; i < M2; i++) {
    cout << M.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 3992
n = int(input())
a = list(map(int , input().split()))
even = []
count = 0

for i in a:
    if i%2 == 0:
        even.append(i)

for i in even:
    if i%3 == 0 or i%5 == 0:
        count += 1

if count == len(even):
    print("APPROVED")
else:
    print("DENIED")

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll N;
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 3628