akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
#include <boost/any.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto i:v)output(i);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define sum(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
int main(){
    lint n,m,p;
    cin>>n>>m>>p;
    vec a(m),b(m),c(m);
    rep(i,m)cin>>a[i]>>b[i]>>c[i];
    rep(i,m){
        a[i]--;
        b[i]--;
        c[i]-=p;
    }
    vec diff(n,INF);
    diff[0]=0;
    rep(j,n-1)rep(i,m){
        if(diff[a[i]]!=INF)diff[b[i]]=min(diff[b[i]],diff[a[i]]-c[i]);
    }
    rep(j,n)rep(i,m){
        if(diff[a[i]]!=INF && diff[a[i]]-c[i]<diff[b[i]])diff[b[i]]=-INF;
    }
    if(diff[n-1]==-INF)cout<<-1;
    else cout<<max(0LL,-diff[n-1]);
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;

int k;
string s;
set<string> g;

int main(void) {
  cin >> s;
  scanf("%d", &k);
  for (int l = 0; l < s.length(); ++l)
    for (int r = l + 1; r <= s.length() && r <= l + k; ++r)
      g.insert(s.substr(l, r - l));
  set<string>::iterator it = g.begin();
  for (; it != g.end(); ++it) {
    if (k == 1) {
      cout << *it << '\n';
      break;
    } else --k;
  }

  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int main(){
  int a,b; string s,t,u;
  cin>>s>>t>>a>>b>>u;
  if(u==s) a--;
  else b--;
  cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int n;
int a[15],b[15],c[15];
int flag;
void dfs(int i,int j,int x)
{
    if(i + j == 12){
        flag = 1;
        return ;
    }
    if(flag == 1)
        return ;
    if(a[x] > b[i - 1]){
        b[i] = a[x];
        dfs(i + 1,j,x + 1);
    }
    else
    {
        if(a[x] > c[j - 1]){
            c[j] = a[x];
            dfs(i,j + 1,x + 1);
        }
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        while(n --){
            for(int i = 0; i < 10; i++)
                scanf("%d",&a[i]);
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            flag = 0;
            dfs(1,1,0);
            if(flag == 1)
                printf("YES\n");
            else
                printf("NO\n");
            /*for(int i = 0; i < 10; i++)
                printf("%d",b[i]);
            //printf("\n\n\n\n");
            /*for(int i = 0; i < 10; i++)
                printf("%d",c[i]);
            printf("\n");*/

        }
    }
    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main(){
	string s,t;
	cin>>s>>t;
	int f=0;
	r(i,t.size()){
		if(t==s)f++;
		string tm="";
		r(i,s.size()-1)tm+=s[i];
		s=s[s.size()-1]+tm;

	}
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<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 repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 long long INF = 1LL << 60;

int main(){
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  sort(all(a));

  cout << a[0] + a[1] << endl;

  return 0;
}


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


public class Test
{	
    public static void Main()
	{
	    string s1 = Console.ReadLine();
	    string s2 = Console.ReadLine();
	    string s3 = Console.ReadLine();
	    Console.WriteLine(s1[0]+""+s2[1]+""+s3[2]);
	} 
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
int get(PI a){
	return a.se>=0?a.fi:a.fi-a.se;
}
bool cmp(PI a,PI b){
	int A=get(a),B=get(b);
	return A<B;
}
const int N=100005;
int n,k;
PI a[N];
ll sum,s[N];
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	n=read();
	For(i,1,n){
		a[i].fi=read(); a[i].se=read()-a[i].fi;
		a[i].fi+=a[i].se;
		if(a[i].se>=0){
			sum+=a[i].se;
		}
	}
	sort(a+1,a+n+1,cmp);
	//cout<<sum<<" "<<get(a[1])<<" "<<get(a[2])<<endl;
	For(i,1,n)s[i]=s[i-1]+get(a[i]);
	int k=upper_bound(s+1,s+n+1,sum)-s-1;
	PI ans=mp(0,1);
	For(i,1,n){
		PI zs;
		if(i>k){
			ll t=sum-s[k];
			if(a[i].se>=0)zs=mp(t,a[i].fi);
			else zs=mp(t+a[i].se,a[i].fi);
		}else{
			ll t=sum+get(a[i])-s[k+1];
			if(a[i].se>=0)zs=mp(t,a[i].fi);
			else zs=mp(t+a[i].se,a[i].fi);
		}
		if(zs.fi*ans.se>ans.fi*zs.se)ans=zs;
	}
	ans.fi+=k*ans.se; ans.se*=n;
	ll t=__gcd(ans.fi,ans.se); ans.fi/=t; ans.se/=t;
	cout<<ans.fi<<" "<<ans.se<<endl;
}


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

int main(void){
  string a,b,c;
  cin>>a>>b>>c;
  char dif='A'-'a';
  printf("%c%c%c\n",a[0]+dif,b[0]+dif,c[0]+dif);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
namespace fio{
	streambuf*in=cin.rdbuf();
	char bb[1000000], *s=bb,*t=bb;
	#define gc() (s==t&&(t=(s=bb)+in->sgetn(bb,1000000),s==t)?EOF:*s++)
	inline int read(){
		int x=0;
		char ch=gc();
		while(ch<48)ch=gc();
		while(ch>=48)x=x*10+ch-48,ch=gc();
		return x;
	}
}using fio::read;
int n,m;
vector<int>road[5005];
long long dp[5005], tmp[5005][5005], siz[5005], stk[5005];
void dfs(int x, int p){
	siz[x]=tmp[x][1]=1;
	for(int it:road[x])if(it!=p){
		dfs(it, x);
		memset(stk, 0, sizeof(stk));
		for(int i=1;i<=siz[x];i++)for(int u=0;u<=siz[it];u++)stk[i+u]=(stk[i+u]+1ll*tmp[x][i]*tmp[it][u])%1000000007;
		siz[x]+=siz[it];
		for(int i=1;i<=siz[x];i++)tmp[x][i]=stk[i];
	}
	for(int i=2;i<=siz[x];i+=2)tmp[x][0]=(tmp[x][0]-1ll*tmp[x][i]*dp[i]%1000000007+1000000007)%1000000007;
}
int main(){
	n=read();
	for(int i=1,x,y;i<n;i++)x=read(), y=read() ,road[x].push_back(y), road[y].push_back(x);
	dp[0]=1,dp[1]=0;
	for(int i=2;i<=n;i++)dp[i]=1ll*dp[i-1-1]*(i-1)%1000000007;
	dfs(1, 0);
	cout<<(1000000007-tmp[1][0]);
}

Measured memory_bytes: 196608
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

double res;

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

    int R;
    cin >> R;
    res = 2 * PI * R;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3808
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

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

  int n;
  cin >> n;

  int a[2][100];
  for (int i = 0; i < n; i++)
  {
    cin >> a[0][i];
  }
  for (int i = 0; i < n; i++)
  {
    cin >> a[1][i];
  }
  int dp[2][100] = {{0}};

  dp[0][0] = a[0][0];
  dp[1][0] = dp[0][0] + a[1][0];
  for (int i = 1; i < n; i++)
  {
    dp[0][i] += dp[0][i - 1] + a[0][i];
  }

  for (int i = 1; i < n; i++)
  {
    dp[1][i] = max(dp[0][i], dp[1][i - 1]) + a[1][i];
  }

  // for (int i = 0; i < 2; i++)
  // {
  //   for (int j = 0; j < n; j++)
  //   {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  cout << dp[1][n - 1] << endl;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int sz = 1e5+1;
ll mod=1e9+7;

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t;
    t=1;
    // cin>>t;
    //sieve();
    for(int cs=1;cs<=t;cs++)
    {
        
        ll n;
        cin>>n;
        // 
        string s;
        ll cnt[4]={0};
        for(int i=0;i<n;i++)
        {
            cin>>s;
            if(s=="AC")
            cnt[0]++;
            else if(s=="WA")
            cnt[1]++;
        else if(s=="TLE")
            cnt[2]++;
        else
            cnt[3]++;

        }

        cout<<"AC x "<<cnt[0]<<endl;
        cout<<"WA x "<<cnt[1]<<endl;
        cout<<"TLE x "<<cnt[2]<<endl;
        cout<<"RE x "<<cnt[3]<<endl;
        // sort(ar,ar+n);
         
        // for(int i=1;i<n;i++)
        // {

        // }

        
 
    }
    return 0;
} 

Measured memory_bytes: 3652
N, Y=map(int, input().split()) 
x, y, z= -1, -1, -1 
for i in range(N+1): 
    for k in range(N+1): 
        if i*10000+k*5000+(N-i-k)*1000==Y: 
            x, y, z= i, k ,N-i-k 
        else: 
            pass
if z<0: 
    x, y, z= -1, -1, -1 
else: 
    pass
print(x, y, z)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,S,n;
    cin>>N;
    n=N;
    S=0;
    //cout<<n<<endl;
    for (int i=0;i<10;i++){
        S=S+n%10;
        n=n/10;
     }
    //cout<<S<<endl;
    if (N%S==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const LL INF = 1e18;
const LL MOD = 998244353;

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

LL modpow(LL a, LL b, LL mod)
{
  // a^b を mod で割った余りを計算する。
    LL res = 1;
    while (b > 0)
    {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  cout << (n-1)/2 << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import deque

S = deque(input())
Q = int(input())

sign = 1
head = ""
tail = ""
for i in range(Q):
    Q = input().split()
    if Q[0] == "1":
        sign *= -1
    else:
        if int(Q[1]) * sign == 1:
            S.appendleft(Q[2])
        elif int(Q[1]) * sign == -1:
            S.append(Q[2])
        elif int(Q[1]) * sign == 2:
            S.append(Q[2])
        elif int(Q[1]) * sign == -2:
            S.appendleft(Q[2])

if sign==1:
    print("".join(S))
elif sign==-1:
    S.reverse()
    print("".join(S))


Measured memory_bytes: 75480
#include<stdio.h>
#include<stdlib.h>

void scanArrayInt(int N, int* A){
    int i;
    for(i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }
}

void printArray(int N, int* A){
    int i;
    for(i = 0; i < N - 1; i++){
        printf("%d ", A[i]);
    }
    printf("%d\n", A[N - 1]);
}

void bubbleSort(int N, int* A, int* count){
    int flag = 1;
    int i, v;
    while(flag){
        flag = 0;
        for(i = N - 1; i > 0; i--){
            if(A[i] < A[i - 1]){
                v = A[i];
                A[i] = A[i - 1];
                A[i - 1] = v;
                flag = 1;
                *count = *count + 1;
            }
        }
    }
}

int main(){
    int N;
    scanf("%d", &N);
    int* A;
    A = (int*)malloc(sizeof(A[0]) * N);
    scanArrayInt(N, A);
    int i = 0;
    int* count = &i;
    bubbleSort(N, A, count);
    printArray(N, A);
    printf("%d\n", *count);
    return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
int col[100005];
vector<int> v[100005];
bool dfs(int node,int c)
{
	if (col[node]!=-1)
	return (col[node]==c);
	col[node]=c;
	bool ok=1;
	for (int u:v[node])
	ok&=dfs(u,!c);
	return ok;
}
int main()
{
	int n,m,c=0,b=0;
	scanf("%d%d",&n,&m);
	while (m--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	memset(col,-1,sizeof(col));
	int nn=n;
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		if (v[i].empty())
		{
			ans+=2*nn-1;
			nn--;
			continue;
		}
		if (col[i]==-1)
		{
			c++;
			b+=dfs(i,0);
		}
	}
	printf("%lld",ans+1LL*c*c+1LL*b*b);
}

Measured memory_bytes: 9984
import java.io.PrintWriter

@JvmField val OUTPUT = System.out
@JvmField val _writer = PrintWriter(OUTPUT, false)
fun main(args: Array<String>) { _writer.solve(); _writer.flush() }
fun PrintWriter.solve() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }

    val ans = IntArray(n){0}
    repeat(a.size) {
        ans[a[it]-1]++
    }

    ans.forEach {
        println(it)
    }
}


Measured memory_bytes: 65804
// https://atcoder.jp/contests/dwacon5th-prelims/tasks/dwacon5th_prelims_e
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const MOD: i64 = 998244353;

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a%b)
    }
}


fn main() {
    input! {
        n: usize,
        a: [i64; n]
    };
    let mut a = a;
    a.sort();

    let mut total = 1;
    for i in 0..n {
        if i == 0 {
            total *= a[i];
        } else {
            total *= gcd(a[i], i as i64);
        }
        total %= MOD;
    }
    println!("{}", total);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define ol(c, s, e) for(int pos=s; pos<e; pos++)cout << c[pos] << " ";cout <<"\n";
#define PI acos(-1LL)

const int M = 1000000007;
const int N = 2e6 + 5;
const long long INF = 1e18 + 37;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n+1), dp(n+1,INF);
    for(int i=1; i<=n; i++){
        cin >> v[i];
    }
    dp[1] = 0;
    for(int i=2; i<=n; i++){
        for(int j=1;j<=k;j++){
            if(i-j < 1) continue;
            dp[i] = min(dp[i], dp[i-j] + abs(v[i] - v[i-j]));
        }
    }
    cout << dp[n] << endl;
}

signed main(){
    FAST
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}


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

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

  map<int, int> odd_mp, even_mp;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    if (i % 2 == 0) {
      even_mp[v]++;
    } else {
      odd_mp[v]++;
    }
  }

  vector<pair<int, int>> vpe;
  for (auto x : even_mp) {
    vpe.push_back({x.second, x.first});
  }

  vector<pair<int, int>> vpo;
  for (auto x : odd_mp) {
    vpo.push_back({x.second, x.first});
  }
  vpe.push_back({0, 0});
  vpo.push_back({0, 0});


  sort(vpe.rbegin(), vpe.rend());
  sort(vpo.rbegin(), vpo.rend());

  int ans;
  if (vpe.at(0).second == vpo.at(0).second) {
    int tmp_a = n - vpe.at(0).first - vpo.at(1).first;
    int tmp_b = n - vpe.at(1).first - vpo.at(0).first;
    ans = min(tmp_a, tmp_b);
  } else {
    ans = n - vpe.at(0).first - vpo.at(0).first;
  }
  cout << ans << endl;
}

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

typedef long long ll;

const int N = 200 * 1000 + 20;
int a[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  	ll n, k, ans = 0;
  	cin >> n >> k;
  	for (int i = 0; i < n; i++)
      	cin >> a[i];
 	sort(a, a + n);
  	for (int i = n - 1; ~i; i--) {
		if (k)
          	k--;
      	else
          	ans += a[i];
    }
  	cout << ans << "\n";
}


Measured memory_bytes: 1024
const main = (input) => {
  input = input.trim();
  input = input.split(' ');
  const a = parseInt(input[0], 10);
  const b = parseInt(input[1], 10);
  
  if(a<9&&b<9){
    console.log("Yay!");
  }else{
    console.log(":(");
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

bool  cmp(int  a, int  b)
{
	return  a>b;
}

int  main()
{
	int  n,k,i,s=0,x;
	cin>>n>>k;
	int  a[200000+5]={0};
	
	for(i=0; i<n; i++)
	{
		cin>>x;
		a[x]++;
	}
	
	sort(a+1,a+200000+1,cmp);
	
	for(i=k+1; i<=200000; i++)
	   s+=a[i];
	   
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int64_t> r(N), g(N), b(N);
  for (int i = N - 1; 0 < i; --i) {
    if (S[i] == 'R') {
      r[i - 1] = r[i] + 1;
      g[i - 1] = g[i];
      b[i - 1] = b[i];
    } else if (S[i] == 'G') {
      r[i - 1] = r[i];
      g[i - 1] = g[i] + 1;
      b[i - 1] = b[i];
    } else {
      r[i - 1] = r[i];
      g[i - 1] = g[i];
      b[i - 1] = b[i] + 1;
    }
  }
  int64_t result = 0;
  for (int i = 0; i < N - 2; ++i) {
    for (int j = i + 1; j < N - 1; ++j) {
      if (((S[i] == 'R') && (S[j] == 'G')) ||
          ((S[i] == 'G') && (S[j] == 'R'))) {
        result += b[j];
        if ((2 * j - i < N) && (S[2 * j - i] == 'B')) --result;
      } else if (((S[i] == 'G') && (S[j] == 'B')) ||
                 ((S[i] == 'B') && (S[j] == 'G'))) {
        result += r[j];
        if ((2 * j - i < N) && (S[2 * j - i] == 'R')) --result;
      } else if (((S[i] == 'R') && (S[j] == 'B')) ||
                 ((S[i] == 'B') && (S[j] == 'R'))) {
        result += g[j];
        if ((2 * j - i < N) && (S[2 * j - i] == 'G')) --result;
      }
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>
 
using namespace std;
 
typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i, n) rep (i, n)
#define F first
#define S second
#define mp(a,b) make_pair((a),(b))
#define list3(a,b,c) mp((a),mp((b),(c)))
#define list4(a,b,c,d) mp((a),list3((b),(c),(d)))
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
template<typename T,typename U> ostream& operator<< (ostream& out, const pair<T,U>& val){return out << "(" << val.F << ", " << val.S << ")";}
template<class T> ostream& operator<< (ostream& out, const vector<T>& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";}
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int w,h;
string in[100];
bool ok;
bool vis[100][100];

pair<double,int> dfs(int x,int y){
  int wesum=0;
  double xsum=0;
  queue<PI> q;
  q.push(mp(x,y));
  int miny=y,maxy=y;
  while(!q.empty()){
    int cx=q.front().F;
    int cy=q.front().S;
    q.pop();
    if(vis[cx][cy]) continue;
    vis[cx][cy]=true;
    ++wesum;
    xsum += cy;
    rep(i,4){
      int nx=cx+dx[i];
      int ny=cy+dy[i];
      if(nx==h){
	miny=min(miny,cy);
	maxy=max(maxy,cy);
      }

      if(min(nx,ny)<0 || nx>=h || ny>=w) continue;
      if(in[nx][ny]=='.') continue;
      if(dx[i]==-1 && in[nx][ny]!=in[cx][cy] && !vis[nx][ny]){
	pair<double,int> t(dfs(nx,ny));
	wesum += t.S;
	xsum += t.F*t.S;
	continue;
      }

      if(dx[i]==1  && in[nx][ny]!=in[cx][cy]){
	miny=min(miny,cy);
	maxy=max(maxy,cy);
      }      

      if(in[nx][ny]==in[cx][cy])
	q.push(mp(nx,ny));
    }
  }
  
  ok&= miny-0.5+EPS < xsum/wesum && xsum/wesum < maxy+0.5-EPS;
  //cout << x << ' ' << y << ' ' << xsum/wesum << ' ' << wesum << endl;
  //cout << miny << ' ' << maxy << endl;
  return mp(xsum/wesum,wesum);
}

void solve(){
  CLR(vis);
  ok=true;
  rep(i,h) cin >> in[i];
  rep(i,w) if(in[h-1][i]!='.' && !vis[h-1][i]) dfs(h-1,i);
  cout << (ok?"STABLE":"UNSTABLE") << endl;
}

int main(){
  while(cin >> w >> h && w) solve();
}

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

#define MOD 1000000007

int n;
string s[2];
long long memo[60][4][4];


long long dfs(int i, int one, int two){
  if(i == n){
    return 1;
  }

  if(memo[i][one][two] != -1) return memo[i][one][two];

  long long ans = 0;
  if(s[0][i] == s[1][i]){
    for(int j = 1;j < 4;j++){
      if(one != j && two != j){
        ans = (ans + dfs(i+1,j,j)) % MOD;
      }
    }
  }else{
    for(int j = 1;j < 4;j++){
      for(int k = 1;k < 4;k++){
        if(one != j && k != two && j != k){
          ans = (ans + dfs(i+2,j,k)) % MOD;
        }
      }
    }
  }

  return memo[i][one][two] = ans;
}

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

  memset(memo,-1,sizeof(memo));

  cout << dfs(0,0,0) << endl;

  return 0;
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    int counter=0;
    if(s[0]=='o') ++counter;
    if(s[1]=='o') ++counter;
    if(s[2]=='o') ++counter;
    cout << 700 + 100*counter << endl;
}

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

const int nax = 1e6 + 5;
int child[nax][26];
bitset<nax> is_end;
int nxt = 1;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; 
    cin >> n;
    vector<string> in(n);
    vector<vector<int>> paths(n);
    memset(child, 0, sizeof child);
    for (int i = 0; i < n; ++i) {
        auto &s = in[i];
        cin >> s;
        reverse(begin(s), end(s));
        int node = 0;
        for (char ch : s) {
            paths[i].push_back(node);
            if (child[node][ch-'a'] == 0) {
                child[node][ch-'a'] = nxt++;
            }
            node = child[node][ch-'a'];
        }
        is_end[node] = 1;
    }
    long long ans = 0;
    
    for (int i = 0; i < n; ++i) {
        auto &s = in[i];
        set<int> suffix;
        
        for (int j = (int)s.size() - 1; j >= 0; --j) {
            int node = paths[i][j];
            suffix.insert(s[j]);
            for (char ch : suffix) {
                ans += is_end[child[node][ch-'a']];
            }
        }
    }
    
    cout << ans - n;
}


Measured memory_bytes: 123968
n, x = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
if A[0] > x:
    eat = A[0] - x
    ans += eat
    A[0] -= eat
for i in range(1, n):
    s = A[i-1] + A[i]
    if s > x:
        eat = s - x
        A[i] -= eat
        ans += eat
print(ans)


Measured memory_bytes: 14468
<?php
/*
    Problem URL : http://arc065.contest.atcoder.jp/tasks/arc065_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */
// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%s", $s);
$arrayMoji = array('dream', 'dreamer', 'erase', 'eraser');

$jobs = array(0);

while ($jobs) {
    // echo implode(" ", $jobs) . PHP_EOL;
    $pos = array_pop($jobs);
    $partial = substr($s, $pos);
    foreach ($arrayMoji as $moji) {
        $len = strlen($moji);
        $partial_partial = substr($partial, 0, $len);
        if ($partial_partial == $moji) {
            $newLoc = $pos + $len;
            if ($newLoc == strlen($s)) {
                exit("YES\n");
            }
            array_push($jobs, $pos + $len);
        }
    }
}

echo "NO\n";


Measured memory_bytes: 3448
#include<iostream>
#include<deque>
using namespace std;
typedef long long LL;
LL N;
int tot=0;
deque <int> le,re;
inline void solve(LL n){
	if(n==1)
		return;
	solve(n>>1);
	le.push_front(++tot);
	re.push_front(tot);
	if(n&1){
		le.push_front(++tot);
		re.push_back(tot);
	}
}

int main(){
	cin>>N;
	solve(N+1);
	cout<<le.size()+re.size()<<endl;
	for(int i=0;i<le.size();i++)
		cout<<le[i]<<" ";
	for(int i=0;i<re.size();i++)
		cout<<re[i]<<" ";
	cout<<endl;
	return 0;
} 

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

int main()
{
  int a, b, t, cnt;
  while (cin>>a>>b, a||b) {
    if (a < b) {
      a ^= b;
      b ^= a;
      a ^= b;
    }
    cnt = 0;
    while (b > 0) {
      t = a;
      a = b;
      b = t%b;
      cnt++;
    }
    cout<<a<<" "<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import statistics as stat
import math
N = int(input())
A = list(map(int, input().split()))
linear = [i+1 for i in range(N)]
B = [x-y for (x, y) in zip(A, linear)]
med = stat.median(B)
med_up = math.ceil(med)
med_low = math.floor(med)
count_up = 0
count_low = 0
for i in range(N):
    count_up += abs(B[i] - med_up)
    count_low += abs(B[i] - med_low)
print(min(count_up, count_low))

Measured memory_bytes: 31232
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
//cout.precision(9);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
		lli n,i,z,c,count=0;
		cin>>n;
		vector<lli> v;
		v.pb(0);
		for(i=0;i<n;i++)
		{
			cin>>z;
			v.pb(z);
		}
		for(i=1;i<=n;i++)
		{
			//what_is(v[i]);
			//what_is(v[v[i]]);
			if(v[i]!=i)
			{
				//what_is(i);
				if(v[v[i]]==i)
				{
					c=v[i];
					//what_is(c);
					v[i]=i;
					v[c]=c;
					count++;
				}
				else
				{
					cout<<"NO"<<endl;
					return 0;
				}
			}
			if(count==2)
			{
				cout<<"NO"<<endl;
				return 0;
			}
			//for(j=1;j<=n;j++)
			//what_is(v[j]);
		}
		if(i==n+1)
		cout<<"YES"<<endl;
    }
}


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

ll dp[202][202];
const int inf = 1e9;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, s.size()) {
            if (s[j] == '1') {
                dp[i][j] = 1;
            } else {
                dp[i][j] = inf;
            }
        }
    }

    rep(k, n) rep(i, n) rep(j, n) if (i != j) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    }

    // rep(i, n) rep(j, n) {
//        cout << i << " " << j << " " << dp[i][j] << endl;
    //}

    int ans = 1;
    auto d = dp[0];
    while(true) {
        vi v;
        rep(i, n) if (d[i] == ans) v.push_back(i);
        if (v.size() == 0) break;
        else if (v.size() >= 1) {
            rep(i, v.size()) for (int j = i + 1; j < v.size(); j++) {
                if (dp[v[i]][v[j]] == 1) {
                    cout << "-1" << endl;
                    return 0;
                }
            }
        }
        ans++;
    }

    ans = 0;
    rep(i, n) rep(j, n) if (dp[i][j] != inf) {
        ans = max((ll)ans, dp[i][j]);
    }
    cout << ans + 1 << endl;

    return 0;
}


Measured memory_bytes: 640
num = []
m = 10
for _ in range(5) :
    n = int(input())
    if n % 10 == 0 :
        num.append(n)
        continue
    num.append(n + 10 - (n % 10))
    m = min(m, n % 10)

print(sum(num) - 10 + m)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	private static final int BALLS = 10;

	public static void main(String[] args) {
		int dataSet = Integer.parseInt(sc.nextLine()); //???????????????????????°?????\?????????????????????

		for(int $ = 0; $ < dataSet; $++) {
			int box1 = 0;
			int box2 = 0;
			boolean flag = true;

			//????????????????????????
			String[] numBall = sc.nextLine().split(" ");

			//?????????????????????????????????
			//YES???NO??????
			for(int count = 0; count < BALLS; count++) { //??????????????°????????°?????????
				int ball = Integer.parseInt(numBall[count]);
				int between1 = ball - box1;
				int between2 = ball - box2;

				if(between1 < 0 && between2 < 0) { //?????????????????????2????????±?????\??£???????????????????°?????????¨???
					flag = false;
					break;
				} else if(between1 > 0 && between2 < 0) { //1?????±???????????????????????????????°????????????????2?????±????????????????????????????????§??????
					box1 = ball;
				} else if(between1 < 0 && between2 > 0) { //1?????±????????????????????????????????§???????????????2?????±???????????????????????????????°???????
					box2 = ball;
				} else if(between1 < between2) { //??????????????????2????????±??????????????§?????????1?????±????????????????????????????????????????????¨???
					box1 = ball;
				} else {
					box2 = ball;
				}
			}

			if(flag) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
				flag = true;
			}

		}

	}

}

Measured memory_bytes: 26032
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vi vector<int>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vvi vector< vector<int> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<ll, ll>, ll > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define pi pair<int, int>
#define ppi pair<pair<int, int>, int>
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
#define INF (ll)1e18
#define s(v) v.size()
#define e(v) v.empty()

using namespace std;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
// bool sortbysec(const pll &a, const pll &b){return (a.second < b.second);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll l, m;
        float a, b;
        cin>>l>>m;
        a = (float)l;
        b = (float)m;
        float lowa, lowb, higha, highb;
        lowa = a/0.08;
        lowb = b*10;
        higha = (a+1)/0.08;
        highb = (b+1)/0.08;
        ll x, y, z, w;
        x = ceil(lowa);
        y = ceil(lowb);
        z = floor(higha);
        w = floor(highb);
        w--;
        ll ans = 0;
        if((ll)higha == z) z--;
        if(x > w || y > z)  {cout<<-1;return 0;}
        else{
            if(x<= w && x >= y) ans = x;
            else ans = y;
        }
        if((ll)((float)ans*0.08) == l && (ll)((float)ans*0.1) == m) cout<<ans;
        else cout<<-1;
    }   
}

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

using namespace std;

#define int long long

int n,k;
vector<int>v(200005);

bool calc(int x)
{
    int cnt=0;
    for(int i=0;i<n;i++){
        if(v[i]%x==0)cnt+=(v[i]/x)-1;
        else cnt+=(v[i]/x);
    }
    return cnt<=k;
}

int32_t main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>v[i];
   }
   int lo=1,hi=*max_element(v.begin(),v.begin()+n),ans;
   while(lo<=hi){
      int mid=(lo+hi)/2;
      if(calc(mid))hi=mid-1,ans=mid;
      else lo=mid+1;
   }
   cout<<ans<<endl;
}


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

int main(){
	long long n;
	cin>>n;
	long long s1=0,s2=0,ans=0;
	long long a[n+1],b[n+1],c[n+1];
	long long h=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		s1+=a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
		s2+=b[i];
		if(b[i]>a[i]){
			h+=b[i]-a[i];
			ans++;
		}
		c[i]=a[i]-b[i];
	}
	if(s2>s1){
		cout<<-1<<endl;
		return 0;
	}
	sort(c+1,c+n+1);
	if(h<=0){
		cout<<0<<endl;
		return 0;
	}
	for(int i=n;i>=1;i--){
		h-=c[i];
		//cout<<c[i]<<endl;
		if(h<=0){
			cout<<++ans<<endl;
			return 0;
		}
		++ans;
	}
}


Measured memory_bytes: 2560
n, x, y = map( int, input().split() )

def distance( i, j ):
  wapu =  abs( x - i )
  wapu += 1
  wapu += abs( y - j )
  return min( ( j - i ), wapu )

ret_list = [ 0 ] * n
for i in range( 1, n + 1 ):
  for j in range( i+1, n + 1 ):
    ret_list[ distance( i, j ) ] += 1

for i in range( 1, n ):
  print( ret_list[ i ] )

Measured memory_bytes: 3444
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	ps := make([]int, n)
	for i := range ps {
		sc.Scan()
		p, _ := strconv.Atoi(sc.Text())
		ps[i] = p
	}

	mp := make([]int, n+1)
	ans := make([]byte, 0)
	var pp, max int
	for _, p := range ps {
		mp[p] = 1
		if p < pp {
			if mp[p+1] != 1 {
				fmt.Println(":(")
				return
			}
			ans = append(ans, ')')
		} else {
			for i := max; i < p-1; i++ {
				ans = append(ans, '(')
			}
			ans = append(ans, '(')
			ans = append(ans, ')')
		}
		if p > max {
			max = p
		}
		pp = p
	}
	fmt.Println(string(ans))
}



Measured memory_bytes: 5184
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b, c, x, y, z = mod;
    cin >> a >> b >> c >> x >> y;
    for (int i = 0; i <= 200000; i++, i++) {
        int d = x - i / 2, e = y - i / 2;
        z = min(z, max(0, d) * a + max(0, e) * b + i * c);
    }
    cout << z;
}


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

typedef long long LL;
const int INF=0x3f3f3f3f;

int main(){
    string s;
    cin>>s;
    int len=s.size();
    for(int i=0;i<len-1;i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
lia = list(map(int,input().split()))
lib = list(map(int,input().split()))
ans = 0
tmp = 0
for i in range(n):
  if tmp > lia[i]:
    ans += lia[i]
    tmp = lib[i]
  elif lia[i] <= lib[i] + tmp:
    ans += lia[i]
    tmp = lib[i] - lia[i] + tmp
  else:
    ans += lib[i] + tmp
    tmp = 0
ans += min(tmp,lia[n])
print(ans)

Measured memory_bytes: 18468
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
set<char> ST[N];
ll n;
set<char> combine(set<char> a, set<char> b)
{
    set<char> s;
    s.insert(a.begin(), a.end());
    s.insert(b.begin(), b.end());
    return s;
}
void build()
{
    for (ll i = n - 1; i; i--)
        ST[i] = combine(ST[i << 1], ST[i << 1 | 1]);
}
void modify(ll p, char val)
{
    for (ST[p += n] = {val}; p > 1; p >>= 1)
        ST[p >> 1] = combine(ST[p], ST[p ^ 1]);
}
set<char> query(ll l, ll r)
{
    set<char> res;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1)
    {
        if (l & 1)
            res.insert(ST[l].begin(), ST[l].end()), l++;
        if (r & 1)
            r--, res.insert(ST[r].begin(), ST[r].end()), l++;
    }
    return res;
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string s;
    ll q;
    cin >> n >> s >> q;
    for (ll i = 0; i < n; i++)
        ST[i + n] = {s[i]};
    build();
    while (q--)
    {
        ll a, b;
        cin >> a >> b;
        b--;
        if (a == 1)
        {
            char c;
            cin >> c;
            modify(b, c);
        }
        else
        {
            ll c;
            cin >> c;
            cout << query(b, c).size() << '\n';
        }
    }
}

Measured memory_bytes: 186396
let (h, w, a, b) = Scanf.sscanf (read_line ()) "%d %d %d %d" @@ fun h w a b -> (h, w, a, b)

let () =
  Array.iter (fun arr ->
    Array.iter print_int arr;
    print_newline ()
  ) @@ Array.init h @@ fun i -> Array.init w @@ fun j -> 
    if i < b then
      if j < a then 0 else 1
    else
      if j < a then 1 else 0

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

struct Dice {
  int top, front, right, left, back, bottom;
  // constructor
  //
  //         top:1
  //           |
  // left:4--front:2--right:3--back:5
  //           |
  //         bottom:6
  //
  Dice(vector<int> v) {
    top    = v.at(0);
    front  = v.at(1);
    right  = v.at(2);
    left   = v.at(3);
    back   = v.at(4);
    bottom = v.at(5);
  }

  void roll(char c) {
    int old_top = top;
    if (c == 'E') {
      top    = left;
      left   = bottom;
      bottom = right;
      right  = old_top;
    } else if (c == 'N') {
      top    = front;
      front  = bottom;
      bottom = back;
      back   = old_top;
    } else if (c == 'S') {
      top    = back;
      back   = bottom;
      bottom = front;
      front  = old_top;
    } else if (c == 'W') {
      top    = right;
      right  = bottom;
      bottom = left;
      left   = old_top;
    }
  }
};

int main() {
  // 各面の整数
  vector<int> v(6);
  for (int i = 0; i < 6; i++) {
    cin >> v.at(i);
  }
  Dice dice(v);

  // 質問の数
  int q;
  cin >> q;

  for (int i = 0; i < q; i++) {
    int q_top, q_front;
    cin >> q_top >> q_front;

    // 上面を質問の整数（上面）にする
    // NOTE: dice.top == q_top の場合は操作不要のため何もしない
    if (dice.back == q_top) {
      dice.roll('S');
    } else if (dice.right == q_top) {
      dice.roll('W');
    } else if (dice.left == q_top) {
      dice.roll('E');
    } else if (dice.front == q_top) {
      dice.roll('N');
    } else if (dice.bottom == q_top) {
      dice.roll('N');
      dice.roll('N');
    }

    // 質問の整数（前面）の位置を把握し、その面の右側の面を出力する
    int ans = 0;
    if (dice.left == q_front) {
      ans = dice.front;
    } else if (dice.front == q_front) {
      ans = dice.right;
    } else if (dice.right == q_front) {
      ans = dice.back;
    } else if (dice.back == q_front) {
      ans = dice.left;
    }
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, y;
    cin >> n >> y;
    y /= 1000;
    for (int i = 0; i <= n; ++i)
    {
        for (int j = 0; i + j <= n; ++j)
        {
            int k = y - 10 * i - 5 * j;
            if (k >= 0 && i + j + k == n)
            {
                cout << i << " " << j << " " << k;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)

struct N001 {
  std::vector<long> parents;
  std::vector<long> numbers;
  long n, q;
};
void init(N001& s, long n) {
  s.parents.resize(n+1, -1);
  s.numbers.resize(n+1, -1);
}
long find(N001& s, long x) {
  if( s.parents[x] == -1 ) return x;
  return s.parents[x] = find(s, s.parents[x]);
}
bool same(N001& s, long x, long y) {
  return find(s, x) == find(s, y);
}
void unite(N001& s, long x, long y) {
  long x2 = find(s, x);
  long y2 = find(s, y);
  if( x2 == y2 ) return;
  if( not ( s.numbers[x2] <= s.numbers[y2] ) )
    std::swap(x2, y2);
  s.parents[x2] = y2;
  s.numbers[y2] += s.numbers[x2];
}

struct Solver {
  Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
  ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
  N001 u;
  void solve() {
    long n, q;
    if( scanf("%ld %ld", &n, &q) < 0 ) exit(0);
    init(u, n);
    for(long i = 0; i < q; ++i) {
      long c, x, y;
      scanf("%ld %ld %ld", &c, &x, &y);
      if( c == 0 ) 
        unite(u, x, y);
      else
        puts(same(u, x, y) ? "1" : "0");
    }
  }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}  

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

struct Mystruct {
  int x;
  int y;
  int c;

  Mystruct(long long input_a, long long input_b, long long input_c) {
    x = input_a;
    y = input_b;
    c = input_c;
  }
  bool operator<(const Mystruct &another) const {
    // if(cost == another.cost){
    //     return mp < another.mp;
    // }
    return c < another.c;
  };
};

int main() {
  int a, b, m;
  cin >> a >> b >> m;

  VI priceA(a);
  VI priceB(b);

  REP(i, a) {
    cin >> priceA[i];
  }
  REP(i, b) {
    cin >> priceB[i];
  }

  int ans = *min_element(priceA.begin(), priceA.end()) +
            *min_element(priceB.begin(), priceB.end());
  int x, y, c;
  REP(i, m) {
    cin >> x >> y >> c;
    x--;
    y--;
    int price = priceA[x] + priceB[y] - c;
    ans = min(ans, price);
  }

  ANS(ans);

  return 0;
}


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

unsigned long long func(long long n, unsigned long long x)
{
  if (n >= 0) {
    return n/x + 1;
  } else {
    return 0;
  }
}

int main()
{
  unsigned long long a, b, x;
  cin >> a >> b >> x;
  unsigned long long num = func(b, x) - func (a-1, x);
  cout << num << endl;
}
    


Measured memory_bytes: 256