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

const long long int INF = 1e12;

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

    vector<long long int> x(n);
    for(int i=0; i<n; i++){
        cin >> x[i];
    }

    long long int ans = INF;
    for(int i=0; i<n-k+1; i++){
        if(ans > min(abs(x[i])     + abs(x[i+k-1] - x[i]),
                     abs(x[i+k-1]) + abs(x[i+k-1] - x[i]))
        ){
            ans = min(abs(x[i])     + abs(x[i+k-1] - x[i]),
                      abs(x[i+k-1]) + abs(x[i+k-1] - x[i]));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<29)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        if (t % 2 != 0) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}


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

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

template <class T> void get_max(T& a, const T b) { a = max(a, b); }
template <class T> void get_min(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


struct E { int to, cost; };
vector<vector<E> > edge;
int n;
int dijkstra(int from, int to)
{
	ll d[100];
	const ll INF = INT_MAX;
	fill(d, d + n, INF);

	priority_queue<pint, vector<pint>, greater<pint> > q;
	d[from] = 0;
	q.push(pint(0, from));
	while (!q.empty())
	{
		pint t = q.top(); q.pop();
		int cost = t.first, v = t.second;
		if (v == to)
			return cost;
		else if (cost > d[v])
			continue;

		foreach (it, edge[v])
		{
			if (cost + it->cost < d[it->to])
			{
				d[it->to] = cost + it->cost;
				q.push(pint(cost + it->cost, it->to));
			}
		}
	}
	return -1;
}
int main()
{
	int k;
	while (scanf("%d%d", &n, &k), n | k)
	{
		edge = vector<vector<E> >(n);
		while (k--)
		{
			int w;
			scanf("%d", &w);
			if (w == 0)
			{
				int a, b;
				scanf("%d%d", &a, &b);
				--a, --b;
				printf("%d\n", dijkstra(a, b));
			}
			else
			{
				int c, d, e;
				scanf("%d%d%d", &c, &d, &e);
				--c, --d;
				E x = { d, e }, y = { c, e };
				edge[c].push_back(x);
				edge[d].push_back(y);
			}
		}
	}
}

Measured memory_bytes: 956
#include <bits/stdc++.h>
#define s second
using T=std::pair<int,int>;
T*P=new T[1<<19],*p;
int BIT[1<<17],j,k,l,r,x,M;
int main(){
	p=P;
	while(~scanf("%d%d",&p->first,&p->s)) p++;
	M=P->s;
	++P;
	sort(P,p,[](T a,T b){return a.s-a.first<b.s-b.first;});
	--p;
	//for(int d=0;d<p;d++)printf("%d ",P[i].first);puts("");
	while(x++<M){
		while(std::tie(l,r)=*P, l&&r-l<x){
			for(j=l; j<=M; j+=j&-j) BIT[j]++;
			for(j=r+1; j<=M; j+=j&-j) BIT[j]--;
			P++;
		}
		k=p-P;
		for(j=0; j<=M; j+=x) {
			for(l=j; l; l-=l&-l)
				k+=BIT[l];
		}
		printf("%d\n",k+1);
	}
	j=0;
}

Measured memory_bytes: 5376
/*
   Created by Rahul Goel.
*/
/*******************************************************************************/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
/*******************************************************************************/
using namespace std;
typedef long long ll;
typedef long double ld;
ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
/* For PBDS */
/*Two new methods X.order_of_key() and X.find_by_order()*/
/*
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*******************************************************************************/
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define pii             pair < ll, ll >
#define vi              vector < ll >
#define vb              vector < bool >
#define vvi             vector < vector < ll > >
#define vvb             vector < vector < bool > >
#define vpii            vector < pair < ll, ll > >
#define vvpii           vector < vector < pair < ll, ll > > >
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/
ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_prod() { return 1LL; }
template<typename T, typename... Args>
T mod_prod(T a, Args... args) { return (a*mod_prod(args...))%mod; }
/*******************************************************************************/

/*
    Code begins after this.
*/


ll solve(){
    ll n;
    cin >> n;
    vi vec(n), dp(n);
    for(ll &x : vec)
        cin >> x;
    dp[0] = 0;
    dp[1] = llabs(vec[1] - vec[0]);
    for(ll i=2; i<n; i++)
        dp[i] = min(llabs(vec[i] - vec[i-1]) + dp[i-1], llabs(vec[i] - vec[i-2]) + dp[i-2]);
    cout << dp[n-1] << endl;
    return 0;
}


int main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}



Measured memory_bytes: 1792
N, K = map(int, input().split())

edges = [(1, to) for to in range(2, N + 1)]
M = (N - 1) * (N - 2) // 2

if K > M:
    print(-1)
    exit()

for fr in range(2, N + 1):
    for to in range(fr + 1, N + 1):
        if M == K:
            break
        edges.append((fr, to))
        M -= 1

print(len(edges))
for fr ,to in edges:
    print(fr ,to)


Measured memory_bytes: 3992
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>
#include <map>

using namespace std;

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

	int N;
	cin >> N;

	vector<long long> A(N, 0);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	map<long long, int> count;
	for (int i = N - 1; i >= 0; i--)
	{
		count[i - A[i]]++;
	}

	long long result = 0;
	for (int i = N - 1; i >= 0; i--)
	{
		long long val = i + A[i];
		if (count.find(val) != count.end())
		{
			result += count[val];
		}
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 16396
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair




int main(){
    ll a[10][10];
    ll h,w;
    cin>>h>>w;
    for(int i=0;i<10;i++){
        for(int t=0;t<10;t++){
            cin>>a[i][t];
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int t=0;t<10;t++){
                a[i][t]=min(a[i][t],a[i][k]+a[k][t]);
            }
        }
    }
    ll count=0;
    for(int i=0;i<h;i++){
        for(int t=0;t<w;t++){
            ll k;
            cin>>k;
            if(k!=-1){count+=a[k][1];}
        }
    }
    cout<<count<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    long long ans = 1;
    if(abs(N-M) > 1) cout << 0 << endl;
    else if(abs(N-M) == 1){
        int X = max(N,M);
        int Y = min(N,M);
        while(X != 1){
            ans *= X;
            ans %= 1000000007;
            ans *= Y;
            ans %= 1000000007;
            X--;
            Y--;
        }
        cout << ans << endl;
    }
    else{
        ans *= 2;
        while(N != 1){
            ans *= N;
            ans %= 1000000007;
            ans *= M;
            ans %= 1000000007;
            N--;
            M--;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)


int main()
{
    int N;
    cin >> N;
    multiset<int> S;
    REP(_, 1 << N)
    {
        int t;
        cin >> t;
        S.insert(t);
    }
    vector<int> T{*max_element(S.begin(), S.end())};
    S.erase(prev(S.end()));

    REP(_, N)
    {
        int n = T.size();
        REP(i, n)
        {
            auto itr = S.lower_bound(T[i]);
            if (itr == S.begin())
            {
                cout << "No" << endl;
                return 0;
            }
            itr = prev(itr);
            T.push_back(*itr);
            S.erase(itr);
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 13816
#include <stdio.h>

/* 選択ソート (0オリジン) */
int selectionSort(int A[], int N) {
  int i, j, t, sw = 0, mini;
  for(i=0; i<N-1; i++) {
    mini = i;
    for(j=i; j<N; j++) {
      if(A[j] < A[mini]) mini = j;
    }

  	t = A[i];
  	A[i] = A[mini];
  	A[mini] = t;

  	if(i != mini) sw++;
  }
  return sw;
}

int main(void) {
  int A[100], N, i, sw;
  scanf("%d", &N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  sw = selectionSort(A,N);

  for(i=0;i<N;i++) {
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  string s; cin >> s; 
  int n = s.size();
  if(s[n-1] == 's') {
    cout << s << "es" << endl;
  }
  else {
    cout << s << "s" << endl;
  }
}


Measured memory_bytes: 3624
#coding:utf-8
#1_7_C
def preorder(i):
    if i == -1:
        return
    (l, r) = tree[i]
    print(" {}".format(i), end = "")
    preorder(l)
    preorder(r)

def inorder(i):
    if i == -1:
        return
    (l, r) = tree[i]
    inorder(l)
    print(" {}".format(i), end = "")
    inorder(r)

def postorder(i):
    if i == -1:
        return
    (l, r) = tree[i]
    postorder(l)
    postorder(r)
    print(" {}".format(i), end = "")

n = int(input())
tree = [None for i in range(n)]
root = set(range(n))
for i in range(n):
    i, l, r = map(int, input().split())
    tree[i] = (l, r)
    root -= set([l, r])

root_node = root.pop()

print("Preorder")
preorder(root_node)
print()

print("Inorder")
inorder(root_node)
print()

print("Postorder")
postorder(root_node)
print()

Measured memory_bytes: 7748
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int n;
vector<bitset<26>> seg;
string s;

void init(int n_)
{
    n = 1;

    while (n < n_)
    {
        n *= 2;
    }
}

void update(int i, char x)
{
    seg[i + n - 1].reset(s[i] - 'a');
    s[i] = x;
    seg[i + n - 1].set(s[i] - 'a');

    i += n - 1;

    while (i > 0)
    {
        i = (i - 1) / 2;
        seg[i] = seg[2 * i + 1] | seg[2 * i + 2];
    }
}

bitset<26> query(int a, int b, int k, int l, int r)
{
    if (r <= a || b <= l)
    {
        bitset<26> bit(0ll);
        return bit;
    }

    if (a <= l && r <= b)
    {
        return seg[k];
    }
    else
    {
        bitset<26> bit1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        bitset<26> bit2 = query(a, b, 2 * k + 2, (l + r) / 2, r);

        return bit1 | bit2;
    }
}

int main(void)
{
    int q;
    int i, j;
    int n_;
    vector<int> ans;

    cin >> n_ >> s >> q;

    init(n_);

    seg.resize(2 * n - 1);

    rep(i, 0, n_)
    {
        update(i, s[i]);
    }

    init(n_);

    rep(i, 0, q)
    {
        int x;

        cin >> x;

        if (x == 1)
        {
            int iq;
            char c;

            cin >> iq >> c;
            iq--;

            update(iq, c);
        }
        else
        {
            int l, r;
            int an = 0;

            cin >> l >> r;
            l--;

            bitset<26> bit = query(l, r, 0, 0, n);

            an = bit.count();

            ans.push_back(an);
        }
    }

    for (auto &z : ans)
    {
        cout << z << endl;
    }
}

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

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

  int ans;
  bool flag = false;
  for (int i = 0; i < 50000; i++) {
    if ((int)(i * 1.08) == n ) {
      ans = i;
      flag = true;
      break;
    }
    else if (i * 1.08 > n) {
      break;
    }
  }

  if (flag) {
    cout << ans << endl;
  }
  else {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
import Data.List
import Data.Maybe
import Control.Applicative ((<$>))
data DataBase = DB { pid :: Int
                   , ans :: Int }

main = do
    dbs <- getData
    let rank = zip (nub.reverse.sort.map ans $ dbs) [1..]
    rankChecker rank dbs

getData :: IO [DataBase]
getData = do
    [p,s] <- map read.splitByComma<$>getLine
    if p == 0 && s == 0 then return []
                        else do
                            dbs <- getData
                            return $ (DB p s) : dbs

splitByComma :: String -> [String]
splitByComma xs
    | rest == "" = pre : []
    | otherwise = pre : splitByComma (tail rest)
    where
        (pre, rest) = break (== ',') xs

rankChecker :: [(Int, Int)] -> [DataBase] -> IO ()
rankChecker ranks dbs = do
    ids <- fmap ((map read).lines) getContents
    let pts = concat.map (\pID -> map ans.filter (\x -> pid x == pID) $ dbs) $ ids
        rank = map (fromMaybe 0.(\x -> lookup x ranks)) pts
    mapM_ print rank

Measured memory_bytes: 4104
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	int ans = (a+b)%24;
	cout << ans << endl;
	return 0;
	
}


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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

const int INF=1<<29;
const double EPS=1e-9;

const int dx[6]={1,1,0,-1,-1,0};
const int dy[6]={1,0,-1,-1,0,1};
int board[1500][1500];
int t,n;//ターン数、障害物の数
typedef pair<int,int> P;
queue<P> que;
queue<int> cost;
int main(){
  int x;
  int y;
  int sx,sy;
  while(cin>>t>>n,n||t){
    
    for(int i =0;i <= 1000;i++){
      for(int j = 0;j <= 1000;j++){
	board[i][j] = 0;
      }
    }
    for(int i = 0;i <n;i++){
      cin>>x>>y;
      board[y+200][x+200] = 1;
    }
    cin>>sx>>sy;
    sx+=200;
    sy+=200;
    que.push(P(sy,sx));
    cost.push(0);
    int ans = 0;
    while(!que.empty()){
      P p =que.front();
      que.pop();
      int turn = cost.front();
      cost.pop();
      if(turn >t){
	continue;
      }
      int px = p.second;
      int py = p.first;
      if(board[py][px]==1){
	continue;
      }
      board[py][px] =1;
      ans++;
      for(int i = 0;i < 6;i++){
	int nx = px +dx[i];
	int ny = py +dy[i];
	if(board[ny][nx]==0){
	  cost.push(turn+1);
	  que.push(P(ny,nx));
	}
      }
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 7360
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = new int[N];
        int Max = 0, secondMax = 0 ;
        for(int i = 0; i < N; i++) {
            A[i] = int.Parse(Console.ReadLine());
            if (A[i] >= Max) { secondMax = Max; Max = A[i]; }
            else if (A[i] >= secondMax) { secondMax = A[i]; }
        }
        for(int i = 0; i < N; i++)
        {
            if (A[i] == Max) { Console.WriteLine(secondMax); }
            else { Console.WriteLine(Max); }
        }
    }
}


Measured memory_bytes: 17108
<?php
define('MOD', 10 ** 9 + 7);
list($n) = ints();
$a = ints();
$cnt = [0, 0, 0];
$ans = 1;
for ($i = 0; $i < $n; ++$i) {
    $tmp = 0;
    for ($k = 0; $k < 3; ++$k) {
        if ($a[$i] === $cnt[$k]) {
            $tmpk = $k;
            ++$tmp;
        }
    }
    ++$cnt[$tmpk];
    $ans = ($ans * $tmp) % MOD;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

using namespace std;
#define ll long long 
#define endl '\n'
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=1 && a<=9 && b>=1 && b<=9)
        cout<<a*b<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int cnt = 0, flag = 0;
    for (int i = 1; i < 4; i++)
    {
        if (s[i - 1] == s[i])
        {
            cnt++;
            if (cnt > 1)
            {
                flag = 1;
                break;
            }
        }
        else
            cnt = 0;
    }
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

#define PI acos(-1)
#define all(a) a.begin(), a.end()
#define full(a, n) a, a + n
#define ma(type, size) (type *)malloc(sizeof(type) * size)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define f0n(i, n) for (i = 0; i < (n); i++)
#define f1n(i, n) for (i = 1; i <= (n); i++)
#define fab(i, a, b) for (i = (a); i <= (b); i++)
#define fr(i, b, a) for (i = (b); i >= (a); i--)

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
	tree_order_statistics_node_update> indexed_set;
//*/
typedef long long int ll;
typedef long int lo;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

//* utility function
inline bool compare(ll i, ll j)
{
    return i < j;
}
//*/

//* function prototypes

//*/

//int row, column;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
#ifdef DEBUG
#endif // DEBUG

vector<bool>visited;
void dfs(ll node, ll increment);

vector<vector<ll>>adj;
vector<ll>mp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll n, q;
    cin >> n >> q;
    ll i, j;
    adj.resize(n+1);
    mp.resize(n+1, 0);

    ll t1, t2;

    f0n(i, n-1)
    {
        cin >> t1 >> t2;
        adj[t1].PB(t2);
        adj[t2].PB(t1);
    }
    f0n(i, q)
    {
        cin >> t1 >> t2;
        mp[t1] += t2;
    }
    visited.resize(n+1, 0);
    dfs(1, 0);
    for(i = 1; i <= n; i++)
    {
        if (i > 1)cout << " ";
        cout << mp[i];
    }
    cout << endl;


    return 0;
}
void dfs(ll node, ll increment)
{
    visited[node] = true;
    mp[node] += increment;
    for (auto a : adj[node])
    {
        if (visited[a] == false)
            dfs(a, mp[node]);
    }
}


Measured memory_bytes: 24320
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v){os << " [" << i++ << "]" << x; if (i % 5 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 5 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, A;
  std::cin >> N >> A;

  ll ans = N * N - A;
  print(ans);
  return 0;
}


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

int main(){
	int l,a,b,c,d;
	scanf("%d%d%d%d%d",&l,&a,&b,&c,&d);
	printf("%d\n",l-max(a/c+(a%c!=0),b/d+(b%d!=0)));
}

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

const int MAX = 400005;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  rep(i, MAX) {
    if (i==0||i==1) continue;
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll COM(int n, int k) {
  if (n<k) return 0;
  if (n<0||k<0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main() {
  int n,k; cin>>n>>k;
  COMinit();
  ll res=0;
  int X=min(k, n-1);
  rep(i, X+1) {
    res+=COM(n-1, i)*COM(n, i);
    res%=MOD;
  }
  cout<<res<<endl;
}


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

using namespace std;

typedef long long ll;
const int MOD = 2019;
int f[MOD], p10 = 1, suf;
long long ans;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  f[0]++;
  for (auto &x : s) {
    suf = (suf + (x - '0') * p10) % MOD;
    p10 = p10 * 10 % MOD;
    ans += f[suf]++;
  }
  cout << ans << "\n";
  return 0;
}


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

using namespace std;

using ll = long long;
using db = double;
using vi = vector<int>;
#define pb push_back

int n, s; 

int main() {
	cin>>n; 
	int ans = 0, mind = 1000000000; 
	for (int i = 1; i <= n; ++i) {
		cin>>s; 
		ans += s; 
		if (s % 10 != 0) mind = min(mind, s); 
	}
	if (ans % 10 == 0) 
		if (mind == 1000000000) puts( "0" ); 
		else cout<<ans-mind<<endl; 
	else cout<<ans<<endl;  
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long n,i,k=0,l=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        k=((k*10)+7)%n;
        if(k==0)
        {
            l++;
            cout<<i<<endl;
            break;
        }
    }
    if(l==0)
    {
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
//コピーここから
struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n,-1) {}
  void init(int n) { par.assign(n,-1); }
  //木の根であれば連結する頂点数×(-1),そうでなければ親ノードのID
  int root(int x){
    if(par[x]<0) return x;
    else return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x==y) return;//既に連結
    
    if(par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return;
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  int size(int x){
    return -par[root(x)];
  }
};
//コピーここまで
int main(void){
  ll n,m,i,j,k,result=0,q;
  int t,a,b;
  
  cin >> n >> q;
  UnionFind uf(n+1);
  uf.init(n+1);
  rep(i,q){
    cin >> t >> a >> b;
    if(t==0) uf.unite(a,b);
    else cout << (uf.same(a,b) ? 1 : 0) << endl;
  }
    
  return 0;
}

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

char a,b,c,d;

int main(){
    cin>>a>>b>>c>>d;
    if(a==b&&b==c)cout<<"Yes"<<endl;
    else if(b==c&&c==d)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------
		int n = Integer.parseInt(sc.next());
		ArrayList<Integer> a = new ArrayList<Integer>();
		ArrayList<Integer> b = new ArrayList<Integer>();
		ArrayList<Integer> c = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			a.add(Integer.parseInt(sc.next()) - 1);
		}
		for (int i = 0; i < n; i++) {
			b.add(Integer.parseInt(sc.next()));
		}
		for (int i = 0; i < n - 1; i++) {
			c.add(Integer.parseInt(sc.next()));
		}
		int pre = -999;
		int ret = 0;
		for (int i = 0; i < n; i++) {
			ret += b.get(a.get(i));
			if (pre == a.get(i) - 1) {
				ret += c.get(pre);
			}
			pre = a.get(i);
		}
		out.println(ret);

		// ------------------------------------------------
		sc.close();
		out.flush();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

bool cmp(const ii& a, const ii& b) {
	return (a.ff*b.ss < b.ff*a.ss);
}
signed main(void)
{
	// IOS;
	int h,n; cin>>h>>n;
	vii a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i].ff>>a[i].ss;
		// a[i].ff=a[i].ss.ff/a[i].ss.ss;
	}
	sort(all(a), cmp);
	// cout<<1<<endl;
	int dp[h+1][n];
	for(int i = 0; i < n; i++)
	dp[0][i]=0;
	for(int i = 1; i<=h; i++) {
		// cout<<i<<endl;
		dp[i][0]=(h/a[0].ff)*a[0].ss;
		if(h%a[0].ff) dp[i][0] += a[0].ss;
	}
	// cout<<1<<endl;
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j < n; j++) {
			int mx1=inf,mx2=inf;
			mx1=dp[i][j-1];
			mx2=a[j].ss;
			if(i-a[j].ff >=0)
				mx2 += dp[i-a[j].ff][j];
			dp[i][j]=min(mx1,mx2);
			// dp[i][j]=(h/a[j].ff)*a[j].ss;
			// int rem=h%a[j].ff;
			// if(rem) {
			// 	int mx1=a[j].ss;
			// 	int mx2=dp[rem][j-1];
			// 	dp[i][j] += min(mx1,mx2);
			// }
		}
	}
	// for(int i = 0; i < n; i++)
	// 	cout<<a[i].ff<<" "<<a[i].ss<<endl;
	// for(int i = 0; i <= h; i++) {
	// 	for(int j = 0; j < n; j++) {

	// 	}
	// }
	cout<<dp[h][n-1]<<endl;
	return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  int N,H,W;
  cin>>N>>H>>W;
  int cnt=0;
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    if(a>=H&&b>=W){cnt++;}
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3632
x, n = map(int, input().split())
if n==0:
    print(x)
if n > 0:
    P = list(map(int, input().split()))
    for i in range(0,102):
        if x-i not in P or x+i not in P:
            if x-i not in P:
                print(x-i)
                exit(0)
            if x+i not in P:
                print(x+i)
                exit(0)

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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define lim 100010
#define mod 1e9 + 7
#define INF 1e9
#define REP(i, n) for (int i = 0; i < n; i++)

ll GCD(int x, int y) { return x % y == 0 ? y : GCD(y, x % y); }

int main() {
  int H, N;
  scanf("%d%d", &H, &N);
  int A[N], B[N];
  for (int i = 0; i < N;i++){
    scanf("%d%d", &A[i], &B[i]);
  }
  ll hituyou[H+1];
  hituyou[0] = 0;
  for (int i = 1; i <= H;i++){
    hituyou[i] = INF;
  }
  for (int i = 1; i <= H; i++) {
    ll tmp;
    for (int j = 0; j < N; j++) {
      int hp = i - A[j];
      if (hp >= 0) {
        tmp = hituyou[hp] + B[j];
        hituyou[i] = tmp < hituyou[i] ? tmp : hituyou[i];
      }else{
        tmp = B[j];
        hituyou[i] =  tmp < hituyou[i] ? tmp : hituyou[i];
      }
    }

  }
  ll ans = hituyou[H];
  printf("%lld", ans);

  return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String sl[];

    sl = r.readLine().split(" ");
    int n = Integer.parseInt(sl[0]);

    long a[] = new long[n];
    long v[] = new long[n];
    
    sl = r.readLine().split(" ");
    for(int i = 0; i < n; i++)
    {
      a[i] = Long.parseLong(sl[i]);
    }
    
    long sig = 1;
    long v0 = 0;
    for(int i = 0; i < n; i++)
    {
      v0 += a[i] * sig;
      sig = - sig;
    }
    v[0] = v0;
    
    for(int i = 1; i < n; i++)
    {
      v[i] = (a[i - 1] - v[i - 1] / 2) * 2;
    }
    
    for(int i = 0; i < n; i++)
    {
      System.out.println(v[i]);
    }
    
  }

}

Measured memory_bytes: 52744
#include <iostream>

using namespace std;

int main()
{
    int a,b,sum,diff,product;
    cin >> a >> b;
    sum=a+b;
    diff=a-b;
    product=a*b;
    if ((sum>diff || sum==diff) && (sum>product || sum==product)){
        cout << sum;
    }else if ((diff>sum || diff==sum) && diff>product){
        cout << diff;
    }else{
        cout << product;
    }
    return 0;
}


Measured memory_bytes: 256
import math
import sys
a,b,h,m = map(int,input().split())
h_ = h*30 + (m/60) * 30
m_ = m*6
alpha = h_ - m_
if 0 < alpha < 180:
    pass
elif alpha == 180:
    print(a+b)
    sys.exit()
elif alpha == 0 or alpha == 360:
    print(abs(a-b))
    sys.exit()
else:
    alpha = 360 - alpha
ans_2 = a**2 + b**2 - 2 * b * a * math.cos(math.radians(alpha))
print(ans_2 ** 0.5)

Measured memory_bytes: 9528
#include <cstdio>
#include <cstring>
using namespace std;
inline int read(){
    int x(0),w(1); char c = getchar();
    while(c^'-' && (c<'0'||c>'9')) c = getchar(); if(c == '-') w = -1, c = getchar();
    while(c>='0' && c<='9') x = (x<<3) + (x<<1) + c - '0', c = getchar();
	return x*w;
}
int n,k;
char s[110];
int main(){
//	freopen(".in","r",stdin);
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	s[k-1] += 'a'-'A';
	printf("%s",s);
	return 0;
}

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

int main() {
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        mp[p[i]]++;
    }
    vector<set<int> > sub(1000);
    for (int i = -110; i < 110; i++) {
        if (mp[i] != 0) continue;
        sub[abs(i - x)].insert(i);
    }
    int ans = x;
    for (int i = 0; i < 1000; i++) {
        if (sub[i].size() == 0) continue;
        ans = *sub[i].begin();
        break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <iomanip>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdlib>

using namespace std;

#define PB push_back
#define MP make_pair
#define L first
#define R second

typedef pair<int, int> pie;

int a[222];
int dis[222][222];

int main() {
    ios_base::sync_with_stdio(false);
    int n, m, r;
    cin >> n >> m >> r;
    for (int i = 0; i < r; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            dis[i][j] = 1e9;
    for (int i = 0; i < m; i++) {
        int fi, se, we;
        cin >> fi >> se >> we;
        dis[fi][se] = we;
        dis[se][fi] = we;
    }
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
    sort(a, a + r);
    int ans = 1e9;
    do {
        int ts = 0;
        for (int i = 1; i < r; i++)
            ts += dis[a[i - 1]][a[i]];
        ans = min(ans, ts);
    } while(next_permutation(a, a + r));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextLong();
        long D = scanner.nextLong();

        int R = 0;
        for (int i = 0; i < N; i++) {
            long X = scanner.nextLong();
            long Y = scanner.nextLong();

            if (X*X + Y*Y <= D*D){
                R++;
            }
        }

        System.out.println(R);
    }

    public static void main(String[] args) {
        new Main();
    }
}

Measured memory_bytes: 59544
#include <iostream>
#include <iomanip>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

int col[100001];
bool used[100001];
vector<int> paths[100001];
vector<int> costs[100001];

int main(void)
{
    int N;
    cin >> N;
    for (int i = 0; i < N - 1; i++)
    {
        int u, v;
        long w;
        int c = 0;
        cin >> u >> v >> w;
        if (w % 2 == 1) c = 1;
        paths[u].push_back(v);
        paths[v].push_back(u);
        costs[u].push_back(c);
        costs[v].push_back(c);
    }
    for (int i = 1; i <= N; i++)
    {
        col[i] = 0;
        used[i] = false;
    }

    queue<int> vertices;
    vertices.push(1);

    while (vertices.size() > 0)
    {
        int num = vertices.size();
        for (int i = 0; i < num; i++)
        {
            int vert = vertices.front();
            vertices.pop();
            used[vert] = true;
            for (int j = 0; j < paths[vert].size(); j++)
            {
                int to = paths[vert][j];
                if (used[to]) continue;
                int cost = costs[vert][j];
                if (cost == 1)
                {
                    if (col[vert] == 1)
                    {
                        col[to] = 0;
                    }
                    else
                    {
                        col[to] = 1;
                    }
                }
                else
                {
                    col[to] = col[vert];
                }
                vertices.push(to);
            }
        }
    }
    for (int i = 1; i <= N; i++)
    {
        cout << col[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 11904
import java.util.Scanner;

public class  Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();
    
    int sum = 0;
    
    if(A+B>C*2){
      int temp = Math.min(X, Y);
      sum += temp*C*2;
      X -= temp;
      Y -= temp;
    }
    
    if(A>C*2){
      sum += X*C*2;
    } else {
      sum += X*A;
    }
    
    if(B>C*2){
      sum += Y*C*2;
    } else {
      sum += Y*B;
    }
    
    System.out.println(sum);
  }
}
        

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

using namespace std;
const int mod = 1e9+7;
int n;
ll a[(int)3e5+100];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int i,j;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	ll ans=0;
	for(i=0;i<60;i++)
	{
		int c[2]={0,0};
		for(j=1;j<=n;j++)
			c[(a[j]>>i)&1]++;
		ans=(ans+(1LL<<i)%mod*c[0]%mod*c[1]%mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

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


void solve(long long A, long long B){
    ll ans=1;
    ll a=A;
    if(B==1){cout<<0<<endl; return;}
    while(a<B){
        if(a<B)a+=A-1;
        ans++;
    }
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::cout<<std::fixed<<std::setprecision(10);//誤差小数10桁まで
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

int maxA = 1000001;

int main() {
	ll N;
	cin >> N;
	vector<int> C(maxA,0);
	vector<int> A(N,0);
	for(int i = 0; i< N; i++){
		cin >> A[i];
		C[A[i]]++;
	}

	bool pc = true;
	for(int i = 2; i < maxA; i++){
		int c = 0;
		for(int j = i; j < maxA; j +=i){
			c += C[j];
		}
		if(c > 1) pc = false;
	}
	if(pc){
		cout << "pairwise coprime" << endl;
		return(0);
	}


	int g = A[0];
	for(int i = 1; i < N; i++){
		g = gcd(g,A[i]);
	}

	if(g == 1){
		cout << "setwise coprime" << endl;
	}else{
		cout << "not coprime" << endl;
	}
	return(0);
}


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

int main(void){
    int T, N;
    long long Abuf;
    vector<long long> A;
    string S;
    cin >> T;
    for(int itestcase=0; itestcase<T; itestcase++){
        cin >> N;
        A.clear();
        for(int i=0; i<N; i++){
            cin >> Abuf;
            A.push_back(Abuf);
        }
        cin >> S;
        vector<long long> DP;
        DP.push_back(0);
        for(int i=N-1; i>=0; i--){
            Abuf = A[i];
            for(long long v: DP)Abuf = min(Abuf, Abuf^v);
            if(S[i]=='0'){
                DP.push_back(Abuf);
            }else if(Abuf != 0LL){
                DP.clear();
                break;
            }
        }
        if(DP.empty()){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
            DP.clear();
        }
    } 
    return 0;
}

Measured memory_bytes: 3572
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2603"

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

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#endif
//BEGIN CUT HERE
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#endif
//BEGIN CUT HERE
namespace MonotoneMinima{
  template<typename T,typename F>
  void induce(int l,int r,int a,int b,vector<int> &dp,F dist){
    if(l==r) return;
    int m=(l+r)>>1;
    int &idx=(dp[m]=a);
    T res=dist(m,idx);
    for(int i=a;i<b;i++){
      T tmp=dist(m,i);
      if(tmp<res) res=tmp,idx=i;
    }
    induce<T>(l,m,a,idx+1,dp,dist);
    induce<T>(m+1,r,idx,b,dp,dist);
  }

  // p < q -> argmin f(p, *) < argmin f(q, *)
  template<typename T,typename F>
  vector<int> args(int n,int m,F dist){
    vector<int> dp(n,-1);
    induce<T>(0,n,0,m,dp,dist);
    return dp;
  }
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed COLOPL2018FINAL_C(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  using ll = long long;

  int n;
  cin>>n;
  vector<ll> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  auto dist=[&](int i,int j){return as[j]+(ll)(i-j)*(i-j);};
  auto res=MonotoneMinima::args<ll>(n,n,dist);

  for(int i=0;i<n;i++) cout<<dist(i,res[i])<<"\n";
  cout<<flush;
  return 0;
}
/*
  verified on 2019/10/29
  https://atcoder.jp/contests/colopl2018-final-open/tasks/colopl2018_final_c
*/
signed main(){
  //COLOPL2018FINAL_C();
  return 0;
}
#endif

#undef call_from_test

signed main(){
  int s,n,m;
  cin>>s>>n>>m;
  vector<int> xs(s);
  for(int i=0;i<s;i++) cin>>xs[i];

  vector<int> ts(n),ps(n);
  for(int i=0;i<n;i++) cin>>ts[i]>>ps[i],ps[i]--;

  vector<int> vs(n);
  for(int i=0;i<n;i++) vs[i]=ts[i]-xs[ps[i]];
  sort(vs.begin(),vs.end());

  vector<int> sm(n+1,0);
  for(int i=0;i<n;i++) sm[i+1]=sm[i]+vs[i];

  const int INF = 1e9;
  vector<int> dp(n+1,INF);
  dp[0]=0;
  for(int k=0;k<m;k++){
    auto dist=
      [&](int i,int j){
        return i<j?INF:dp[j]+(i?vs[i-1]:0)*(i-j)-(sm[i]-sm[j]);
      };
    auto res=MonotoneMinima::args<int>(n+1,n+1,dist);
    vector<int> nx(n+1);
    for(int i=0;i<=n;i++) nx[i]=dist(i,res[i]);
    swap(dp,nx);
  }
  cout<<dp[n]<<endl;
  return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <string>

using namespace std;

int main(){
        string s;
        int sum = 0;
        while(cin >> s){
                int n = 0;
                int idx = 0;
                for(int i = 0; i < s.size(); i++){
                        if('0' <= s[i] && s[i] <= '9') n = n*10+s[i]-'0';
                        else if(n){
                                sum += n;
                                n = 0;
                        }
                }
                sum += n;
        }
        cout << sum << endl;
}

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

int main(){
  int n,m,a,ans=0;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> a;
    ans += a;
  }
  if(ans <= n) n -= ans;
  else n = -1;
  
  cout << n << endl;
  
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int N; cin >> N;
    vector<int>H(N);
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    sort(H.begin(),H.end(),greater<int>());
    int sum = 0;
    for(int j = 0; j < N; j++){
        if(j == 0){
            sum += H[j] / 2;
        }else{
            sum += H[j];
        }
    }
    cout << sum << endl;    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long gcd(long a, long b);

int main(void) {
    long A, B, C, D;

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

    A--;

    long lcm = C * D / gcd(D, C);

    cout << B - B / C - B / D + B / lcm - A + A / C + A / D - A / lcm << endl;

    return 0;
}

long gcd(long a, long b) {
    long r;
    while (a % b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int l, r, d;
int main(){
	scanf("%d%d%d", &l, &r, &d);
	
	int ans = 0;
	for (int i = l; i <= r; ++i)
		if (i % d == 0) ++ans;
	
	printf("%d\n", ans);
	
	return 0;
}

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

using namespace std;

int huiwen(string s)
{
    string t;
    t = s;
    reverse(s.begin(),s.end());
    if(t == s)
        return 1;
    else
        return 0;
}

int main()
{
    int n,i;
    string s,n1,n2;
    cin >> s;
    
    if(huiwen(s))
    {
        n = s.size();
        for(i = 0;i < (n-1)/2 ;i++)
            n1 += s[i];
        for(i = (n+3)/2-1; i < n ;i++)
            n2 += s[i];
        if(huiwen(n1) && huiwen(n2))
            cout << "Yes" <<endl;
        else
            cout << "No" <<endl;
    }
    else
        cout << "No" << endl;
        
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s1,s2,s="";
    cin>>s1>>s2;
    int a,b,l=0,x,y,i,j;
    a=s1.length();
    b=s2.length();
    int t[a+1][b+1];
    for(i=0;i<=b;i++)
    {
        t[0][i]=0;
    }
    for(i=1;i<=a;i++)
    {
        t[i][0]=0;
    }
    for(i=1;i<=a;i++)
    {
        for(j=1;j<=b;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                t[i][j]=t[i-1][j-1]+1;
                if(t[i][j]>l)
                {
                    l=t[i][j];
                    x=i;
                    y=j;
                }
            }
            else{
                t[i][j]=max(t[i-1][j],t[i][j-1]);
            }
        }
    }
    //cout<<x<<" "<<y<<endl;
    while(t[x][y]!=0)
    {
        if(t[x][y]!=t[x-1][y]&&t[x][y]!=t[x][y-1])
        {
            s=s1[x-1]+s;
            x--;y--;
            //cout<<"step1 "<<x<<" "<<y<<endl;


        }
       else if(t[x-1][y]>t[x][y-1])
        {
            x--;
            //cout<<"step2 "<<x<<" "<<y<<endl;


        }
        else{y--;}
        //cout<<"step3 "<<x<<" "<<y<<endl;}
    }
    //cout<<t[a][b]<<endl;
    cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 35456