akhauriyash/Code-Regression huggingface dataset:
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

int a, b;

int main() {
	scanf("%d %d",&a,&b);
	if (a > 0) puts("Positive");
	else if (a <= 0 && b >= 0) puts("Zero");
	else (b - a + 1) % 2 ? puts("Negative") : puts("Positive");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Maxn 100007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m;
int a[Maxn],b[Maxn],cnt=0;
int fa[Maxn],rk[Maxn],pos[Maxn];
bool flag[Maxn];
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
void mdf(int x,int y)
{
	x=find(x),y=find(y);
	if (x==y) return;
	if (rk[x]<rk[y]) swap(x,y);
	rk[x]+=rk[y];
	fa[y]=x;
	if (a[pos[y]]<a[pos[x]]) pos[x]=pos[y];
}
int main()
{
	n=read(),m=read();
	if (m==n-1)
	{
		printf("%d\n",0);
		return 0;
	}
	if (n<2*(n-m-1))
	{
		printf("Impossible\n");
		return 0;
	}
	for (int i=1;i<=n;i++)
		a[i]=read();
	for (int i=1;i<=n;i++)
		fa[i]=i,rk[i]=1,pos[i]=i;
	for (int i=1;i<=m;i++)
	{
		int a=read()+1,b=read()+1;
		mdf(a,b);
	}
	long long ans=0;
	int tot=0;
	for (int i=1;i<=n;i++)
		if (!flag[pos[find(i)]])
		{
			ans+=a[pos[find(i)]];
			++tot;
			flag[pos[find(i)]]=true;
		}
	for (int i=1;i<=n;i++)
		if (!flag[i]) b[++cnt]=a[i];
	sort(b+1,b+cnt+1);
	for (int i=1;i<=cnt;i++)
		if (tot<2*(n-m-1))
		{
			++tot;
			ans+=b[i];
		}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int D;
  cin>>D;
  vector<int> c(26);
  for(int &i:c)
    cin>>i;
  vector<vector<int>> s(D,vector<int>(26));
  for(vector<int> &v:s)
    for(int &i:v)
      cin>>i;
  vector<int> t(D);
  vector<int> A(26,0);
  int mzint=0;
  for(int i=0;i<D;i++){
    int mzi=mzint,mzin=0,k;
    for(int j=0;j<26;j++)
      mzi-=(i+1-A[j])*c[j];
    for(int j=0;j<26;j++){
      int l=mzi+s[i][j]-(i+1-A[j])*c[j];
      if(l>mzin){
        k=j;
        mzin=l;
      }
    }
    A[k]=i+1;
    mzint=mzin;
    t[i]=k+1;
  }
  int M=1000000,ans=mzint;
  while(M--){
    vector<pair<int,int>> AAA={make_pair(rand()%D,rand()%26),make_pair(rand()%D,rand()%26),make_pair(rand()%D,rand()%26)};
    vector<int> BBB={t[AAA[0].first],t[AAA[1].first],t[AAA[2].first]};
    int ans2=ans;
    for(int aaa=0;aaa<3;aaa++){
    int d=AAA[aaa].first,q=AAA[aaa].second;
    ans+=s[d][q]-s[d][t[d]-1];
    int mae=-1,ato=D;
    for(int i=d-1;i>=0;i--){
      if(t[i]==t[d]){
        mae=i;
        break;
      }
    }
    for(int i=d+1;i<D;i++){
      if(t[i]==t[d]){
        ato=i;
        break;
      }
    }
    ans-=(ato-d)*(d-mae)*c[t[d]-1];
    mae=-1,ato=D;
    for(int i=d;i>=0;i--){
      if(t[i]==q+1){
        mae=i;
        break;
      }
    }
    for(int i=d;i<D;i++){
      if(t[i]==q+1){
        ato=i;
        break;
      }
    }
    ans+=(ato-d)*(d-mae)*c[q];
    t[d]=q+1;
    }
    if(ans2>ans){
      ans=ans2;
      t[AAA[0].first]=BBB[0];
      t[AAA[1].first]=BBB[1];
      t[AAA[2].first]=BBB[2];
    }
  }
  for(int i:t)
    cout<<i<<endl;
}

Measured memory_bytes: 3736
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
const ll INF = 1LL << 60;


void solve(std::vector<long long> M, std::vector<long long> D){
    if(M[0]==M[1]){
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }
}

int main(){
    std::vector<long long> M(2);
    std::vector<long long> D(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&M[i]);
        scanf("%lld",&D[i]);
    }
    solve(std::move(M), std::move(D));
    return 0;
}


Measured memory_bytes: 256
n=int(input())
res_list=list()
for i in range(n):
  name, score = map(str, input().split())
  ll = {"index": i, "name": name, "score": int(score)}
  res_list.append(ll)

sorted_items = sorted(
  res_list,
  key = lambda x: (x['name'], -x['score'])
)

for s in sorted_items:
  print(s['index']+1)

Measured memory_bytes: 38512
import sys
from itertools import product

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
resp = s
resp = resp.replace('o', '1')
resp = resp.replace('x', '0')
resp = [None] + [int(x) for x in resp]

def restore(pattern):
    for i in range(1, n):
        if resp[i] ^ pattern[i]:
            pattern[i+1] = 1 if pattern[i-1] ^ 1 else 0
        else:
            pattern[i+1] = pattern[i-1]
    return pattern

def contradicting(pattern):
    if pattern[0] != pattern[-1]:
        return True
    if resp[-1] ^ pattern[-1]:
        if not pattern[-2] ^ pattern[1]:
            return True
    else:
        if pattern[-2] ^ pattern[1]:
            return True   
    return False

def main():
    res = [None] * (n + 1)
    for i in range(4):
        pattern = res.copy()
        pattern[0] = i >> 0 & 1
        pattern[1] = i >> 1 & 1
        ans = restore(pattern)
        if not contradicting(ans):
            t = ''
            for i in range(1, n+1):
                t += 'S' if ans[i] & 1 else 'W'
            return t
    return -1

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 6372
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from collections import defaultdict
INF = float("inf")
MOD = 10**9+7


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, f, t, w=1):
        self.E[f].append((t, w))
        self.E[t].append((f, w))


N = int(input())
c = [x-1 for x in map(int, input().split())]
A = [None]*(N-1)
B = [None]*(N-1)
for i in range(N-1):
    A[i], B[i] = map(int, input().split())

g = Graph(N)
for a, b in zip(A, B):
    g.add_edge(a-1, b-1)

# k=1, 2, ..., Nに対して
# 色kが塗られている頂点を一度以上通るような単純パスの数を求める
# 全パスの個数 - 色kが塗られている頂点を一度も通らない単純パスの数
# 全パスの個数はN*(N+1)/2

# グラフを色kのノードで分割して、部分グラフ内での単純パスの総数を求めれば良い
# 各ノードに状態として辞書をもたせる。
# x辞書は色iを通らずに到達可能な頂点の数を持つ。
# o辞書は色iを通らずに到達不可能な頂点の数を持つ。

# 回答用
ans = [0]*N


def f(curr, par=-1):
    # 再帰関数
    # curr: 現在の節点
    # par : 親節点の番号
    ret = defaultdict(int)
    size = 1
    for dest, w in g.E[curr]:
        if dest == par:
            continue
        sz, child = f(dest, curr)
        size += sz

        # 自身の色と同じ場合、子の頂点の数から加算
        n = sz-child[c[curr]]
        ans[c[curr]] += n*(n+1)//2

        # マージ
        if len(ret) < len(child):
            child, ret = ret, child
        for key in child:
            ret[key] += child[key]

    ret[c[curr]] = size
    return size, ret


sz, ret = f(0)
for color in range(N):
    if color != c[0]:
        n = sz-ret[color]
        ans[color] += n*(n+1)//2

tot = N*(N+1)//2
for a in ans:
    print(tot-a)


Measured memory_bytes: 383576
fun main(args: Array<String>){
    val (a, b, c, d) = readLine()!!.split(' ').map{ it.toInt() }
    when {
        Math.abs(a-b) <= d && Math.abs(c-b) <= d || Math.abs(a-c) <= d-> {
            println("Yes")
        }
        else -> {
            println("No")
        }
    }

}

Measured memory_bytes: 36396
#include <bits/stdc++.h>
using namespace std;
int main(){
 	int n, k, h, cnt = 0;
 	cin >> n >> k;
 	for(int i = 0; i < n; ++i){
 	 	cin >> h;
 	 	if(h >= k)cnt++;
 	}
 	cout << cnt << endl;
}

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> count(n,0);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        count[a[i]-1]++;
    }

    vector<ll> comb(n);
    ll combsum=0;
    for(int i = 0; i < n; i++) {
        ll ref=count[i];
        comb[i]=ref*(ref-1)/2;
        combsum+=comb[i];
    }

    for(int i = 0; i < n; i++) {
        ll ref=count[a[i]-1];
        ll tcomb=(ref-1)*(ref-2)/2;
        cout << combsum-comb[a[i]-1]+tcomb << "\n";
    }

    return 0;
}

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

int main(){
    int day=0;
    cin>>day;

    switch(day%7){
        case 0:
        cout<<"thu"<<endl;
        break;
        case 1:
        cout<<"fri" <<endl;
        break;
        case 2:
        cout<<"sat"<<endl;
        break;
        case 3:
        cout<<"sun"<<endl;
        break;
        case 4:
        cout<<"mon"<<endl;
        break;
        case 5:
        cout<<"tue"<<endl;
        break;
        case 6:
        cout<<"wed"<<endl;
        break;
    }
return 0;
}


Measured memory_bytes: 3104
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
string s;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>s;
	for(ll i=2; i<s.size(); i++)
	{
	    if(s[i]==s[i-1]&&s[i-1]==s[i-2])
	    {
	        cout<<"Yes";
	        return 0;
	    }
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  ll a[N];
  for(int i = 0; i < N; i++) cin >> a[i];

  ll ans[N];
  fill(ans, ans + N, 0);
  for(int i = 0; i < N; i++){
    if(i % 2 == 0) ans[0] += a[i];
    else ans[0] -= a[i];
  }

  for(int i = 1; i < N; i++){
    ans[i] = 2 * a[i - 1] - ans[i - 1];
  }

  for(int i = 0; i < N; i++){
    cout << ans[i] << " ";
  }

  cout << endl;
  return 0;
}

Measured memory_bytes: 2816
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{



    public class Program
    {
        static void Main(string[] args)
        {
            var kx = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var k = kx[0];
            var x = kx[1];
            Console.WriteLine(k * 500 >= x ? "Yes" : "No");

        }
    }
}


Measured memory_bytes: 11348
use std::collections::VecDeque;

pub fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let hw = readn::<usize>(" ");
    let h = hw[0];
    let w = hw[1];
    let mut s = Vec::with_capacity(h);
    for _ in 0..h {
        s.push(read1::<String>().chars().collect::<Vec<char>>());
    }

    let sharp = s.iter().map(|v| v.iter().map(|&c| {
        if c == '#' { 1 }
        else { 0 }
    }).sum::<usize>()).sum::<usize>();
    
    let mut q = VecDeque::new();
    q.push_back((0, 0, 0));
    loop {
        if q.len() == 0 {
            println!("-1");
            return;
        }
        let tyx = q.pop_front().unwrap();
        let t = tyx.0;
        let y = tyx.1;
        let x = tyx.2;

        if y + 1 == h && x + 1 == w {
            println!("{}", h * w - sharp - t - 1);
            return;
        }

        if y + 1 < h && s[y + 1][x] == '.' {
            q.push_back((t + 1, y + 1, x));
            s[y + 1][x] = '#';
        }
        if y >= 1  && s[y - 1][x] == '.' {
            q.push_back((t + 1, y - 1, x));
            s[y - 1][x] = '#';
        }
        if x + 1 < w && s[y][x + 1] == '.' {
            q.push_back((t + 1, y, x + 1));
            s[y][x + 1] = '#';
        }
        if x >= 1  && s[y][x - 1] == '.' {
            q.push_back((t + 1, y, x - 1));
            s[y][x - 1] = '#';
        }
    }
}

Measured memory_bytes: 4352
#include <stdio.h>

int A[100000];

int partition(int [],int,int);
int main(){
  int i,j,n,p=0,r;

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

  r = n-1;
  j = partition(A,p,r);

  for(i=0;i<n-1;i++){
    if(i==j){
      printf("[%d] ",A[i]);
    }else{
      printf("%d ",A[i]);
    }
  }
  printf("%d\n",A[n-1]);

  
  return 0;
}

int partition(int A[],int p,int r){
  int x,i,j,change;

  x = A[r];
  i = p-1;

  for(j=p;j<r;j++){
    if(A[j]<=x){
      i = i+1;
      change = A[i];
      A[i] = A[j];
      A[j] = change;
    }
  }
  change = A[i+1];
  A[i+1] = A[r];
  A[r] = change;

  return i+1;
}



Measured memory_bytes: 2104
n=gets.to_i
d,x=gets.split.map(&:to_i)
cnt=0
1.upto(n) do |i|
  a=gets.to_i
  tabetahi=[1]
  1.upto(d) do |j|
    tmp=((j*a) + 1)
    tabetahi << tmp if tmp <= d
  end
  cnt+= tabetahi.size
end
puts cnt + x

Measured memory_bytes: 1788
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# define MOD 1000000000+7
# define INF 1000000000
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> b;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		b.emplace_back(a);
	}
	int pos = 0,ans=0;
	for (int i = 0; i <= n * 2; i++) {
		ans++;
		if (b[pos] == 2) {
			break;
		}
		pos = b[pos]-1;
	}
	if (ans >= n * 2) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
}



Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,  x,  y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ll unsigned long long
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define ls rt << 1
#define rs rt << 1 | 1
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
inline ll read()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
char ch[200010];
int main()
{
	scanf("%s", ch + 1);
	int n = strlen(ch + 1);
	rep(i, 1, n) ch[i] -= '0';
        rrep(i, n + 1, 1) ch[i] ^= ch[i - 1];
	int ans = n;
	rep(i, 0, n + 1)
		if(ch[i]) ans = min(ans, max(i - 1, n + 1 - i));
    cout << ans;
	return 0;
}


Measured memory_bytes: 384
import sys
def input():
  return list(map(int, sys.stdin.readline().strip().split()))

n, m = input()
h = input()
tmp = [[] for i in range(n)]
for i in range(m):
  a, b = input()
  tmp[b - 1].append(a - 1)
  tmp[a - 1].append(b - 1)
ans = 0
for i in range(n):
  flag = True
  for ele in tmp[i]:
    if(h[i] <= h[ele]): flag = False
  if(flag): ans += 1
print(ans)

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

using namespace std;

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

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

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

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL a,b,c,k;
    cin>>a>>b>>c>>k;
    LL ans = 0;
    if(a > k){
        ans += k;
        PUTS(ans);
        return 0;
    }
    ans += a;
    k -= a;

    if(b > k){
        PUTS(ans);
        return 0;
    }
    k -= b;
    PUTS(ans - k);
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main()
{
	int h,w,c=0;
	char a[100][100];
	int b[100][100];
	cin>>h>>w;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			cin>>a[i][j];
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			{
				if(a[i][j]=='#')
				continue;
			if(a[i-1][j]=='#')
				b[i][j]++;
			if(a[i-1][j-1]=='#')
				b[i][j]++;
			if(a[i-1][j+1]=='#')
				b[i][j]++;
			if(a[i][j-1]=='#')
				b[i][j]++;
			if(a[i][j+1]=='#')
				b[i][j]++;
			if(a[i+1][j+1]=='#')
				b[i][j]++;
			if(a[i+1][j-1]=='#')
				b[i][j]++;
			if(a[i+1][j]=='#')
				b[i][j]++;
			}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			{
				if(a[i][j]=='#')
				cout<<"#";
				else
				cout<<b[i][j];
			}
			cout<<endl;
	}
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = a+b;
	boolean isEven = (a+b)%2==0;

	if(isEven){
		System.out.println((a+b)/2);
	}else{
		System.out.println("IMPOSSIBLE");
	}
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
int main(){
 int a,b,r=0;
  scanf("%d%d",&a,&b);
  for(int i=0;i<2;i++){
    if(a>b){
      r+=a;
      a--;
    }else{
      r+=b;
      b--;
    }
  }
  printf("%d",r);
 return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;

string str;
ll k;
int main(){
	cin>>str;
	cin>>k;
	k--;

	ll pos = 0;
	for(int i =0 ; i < str.length(); i++){
		if(str[i] != '1'){
			pos = i;
			break;
		}
	}

	if(k < pos){
		puts("1");
	}
	else{
		printf("%d",str[pos]-'0');
	}


}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] x=new int[n];
    for(int i=0;i<n;i++) x[i]=sc.nextInt();
    Arrays.sort(x);
    long[] p=new long[201];
    long min=999999999999999999L;
    for(int i=-100;i<=100;i++){
      for(int j=0;j<n;j++){
        p[i+100]+=(long)Math.pow((double)x[j]-(double)i,2.0);
      }
      min=Math.min(min,p[i+100]);
    }
    System.out.println(min);
  }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	LOOP(N){
		auto V=vecin(10);
		vector<int> B,C;
		bool success = true;
		REP(i,10){
			if(B.empty() || B.back()<V[i]){
				B.push_back(V[i]);
			}
			else if(C.empty() || C.back()<V[i]){
				C.push_back(V[i]);
			}
			else{
				success = false;
				break;
			}
		}

		out(success?"YES":"NO");
	}
	return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
 
int main(void) {
	int y, m, d;
	char c, cc;
	cin >> y >> c >> m >> cc >> d;
	if(y < 2019)
		cout << "Heisei" << endl;
	else if(y == 2019){
		if(m <= 4)
			cout << "Heisei" << endl;
		else
			cout << "TBD" << endl;
	}
	else
		cout << "TBD" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int cnt=1;
void depth(vector< vector<int> > &vv,vector<int> &f,vector<int> &c,int num){
	f[num]=cnt;
	cnt++;
	for(int i=0; i<vv[num].size(); i++){
		if(vv[num][i]!=0 && f[i]==0){
			depth(vv,f,c,i);
		}
	}
	if(c[num]==0){
		c[num]=cnt;
		cnt++;
	}
}
int main(){
	int n;
	cin>>n;
	vector< vector<int> > v(n,vector<int> (n,0));
	vector<int> ft(n,0);
	vector<int> ct(n,0);
	int u[n];
	for(int i=0; i<n; i++){
		int k;
		cin>>u[i]>>k;
		for(int j=0; j<k; j++){
			int x;
			cin>>x;
			v[i][x-1]=1;
		}
	}
	for(int i=0; i<n; i++){
		if(ft[i]==0){
			depth(v,ft,ct,i);
		}
	}
	for(int i=0; i<n; i++){
		cout<<u[i]<<" "<<ft[i]<<" "<<ct[i]<<endl;
	}
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2])cout << "Yes" << endl;
    else if(s[1] == s[2] && s[2] == s[3])cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
    ll n;
    cin >> n;
    vector<ll> v (n);
    for(ll i=0; i<n; i++){
        ll a;
        cin >> a;
        v.at(i) = a;
    }
    ll ans = 0;
    ll mi = 200010;
    for(int i=0; i<n; i++){
        if(v.at(i) < mi){
            ans++;
            mi = v.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
def input(): return sys.stdin.readline().rstrip()

mod = 998244353
N, K = map(int, input().split())

L = []
for i in range(K):
    l, r = map(int, input().split())
    L.append((l,r))

L.sort()

dp = [0] * (N+1)
dp[1] = 1

for i in range(2,N+1):
    count = 0
    for l,r in L:
        if l >= i:
            break
        elif l < i and i - r > 1:
            count += dp[i-l] - dp[i-r-1]
        else:
            count += dp[i-l]
    dp[i] = (dp[i-1] + count) % mod

print((dp[N] - dp[N-1])% mod)

Measured memory_bytes: 16880
n, a, b = map(int, input().split())
s = input()
passed = 0
sea = 0
for cha in s:
    if cha == 'a':
        if passed < a+b:
            print('Yes')
            passed += 1
        else:
            print('No')
    elif cha == 'b':
        if passed < a+b and sea < b:
            print('Yes')
            passed += 1
            sea += 1
        else:
            print('No')
    elif cha == 'c':
        print('No')


Measured memory_bytes: 4016
n=int(input())
preorder=[int(i)for i in input().split()]
inorder=[int(i)for i in input().split()]
post=[]
pos=0
def recon(left,right):
    global inorder
    global pos
    if left>=right:
        return
    root=preorder[pos]
    pos+=1
    mid=inorder.index(root)
    recon(left,mid)
    recon(mid+1,right)
    post.append(str(root))

recon(0,n)
print(" ".join(post))


Measured memory_bytes: 5604
#include <iostream>
using namespace std;
const int N_MAX = 100;
int main (void) {
    int N;
    int T[N_MAX];
    int M;
    int sum = 0;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> T[i];
        sum += T[i];
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        int P;
        int X;
        cin >> P >> X;
        P--;
        sum = sum - T[P] + X;
        cout << sum << endl;
        sum = sum - X + T[P];
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string szLine = Console.ReadLine();
            szLine = Console.ReadLine();
            string[] szArr = szLine.Split(' ');
            int[] arr = new int[szArr.Length];

            int[] xArr = new int[100000+10];

            for (int i=0;i<szArr.Length;++i)
            {
                int val = int.Parse(szArr[i]);
                arr[i] = val;// 0 ~ 10^5

                val += 1;
                xArr[val - 1] += 1;
                xArr[val] += 1;
                xArr[val + 1] += 1;
            }

            // 一番数の多いのをxとする
            int max = xArr.Max();
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 17376
#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
#ifndef CrafterKolyan
#define endl '\n'
#endif

int a[200000];

signed main() {
#ifndef CrafterKolyan
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] -= i;
    }
    sort(a, a + n);
    int b = a[n / 2];
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += abs(a[i] - b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
"""#################################################################
【ABC111】
B_AtCoder_Beginner_Contest_111
#################################################################"""

#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N = IS()
for i in range(int(N),999+1):
    if str(i).count(str(i)[0]) == 3:
        print(i)
        break

Measured memory_bytes: 3316
d = [[[-1, -1], [0, -1], [1, -1], [1, 0], [0, 1], [-1, 0]],
     [[-1,  0], [0, -1], [1,  0], [1, 1], [0, 1], [-1, 1]]]

w, h = gets.split.map(&:to_i)
fld = (h+2).times.map{ [false]*(w+2) }
(1..h).each do |i|
  gets.split(" ").each_with_index{ |e, j| fld[i][j+1] = true if e == "1" }
end

tmp = (h+2).times.map{ [false]*(w+2) }
arr = []
arr << [0, 0]
tmp[0][0] = true
until arr.empty?
  y, x = arr.pop
  d[y%2].each do |dy, dx|
    u = y + dy; v = x + dx
    next if u < 0 || u > h+1 || v < 0 || v > w+1
    if !fld[u][v] && !tmp[u][v]
      tmp[u][v] = true
      arr << [u, v]
    end
  end
end
fld = fld.flatten.zip(tmp.flatten).map{|f,p| !(!f&p) }
p fld.map.with_index{|e, i| i if e}.compact.map{ |i| d[(i/(w+2))%2].count{ |y, x| !fld[i+y*(w+2)+x]}}.compact.reduce(:+)

Measured memory_bytes: 9556
import math

n,m = map(int, input().split())


ans = 0
if abs(n-m) <= 1:
  if n == m:
    ans = (math.factorial(n) * math.factorial(m) * 2) % (10**9 + 7)
  else:
    ans = (math.factorial(n) * math.factorial(m)) % (10**9 + 7)
    
print(ans)

Measured memory_bytes: 5184
// https://atcoder.jp/contests/abc122/tasks/abc122_c

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 1e5;
const int Q_MAX = 1e5;

int N, Q;
char S[N_MAX + 1];
int l[Q_MAX];
int r[Q_MAX];

int acc[N_MAX];

void solve() {
  REP(i, N - 1) {
    acc[i + 1] = acc[i];
    if (S[i] == 'A' && S[i + 1] == 'C') acc[i + 1]++;
  }

  REP(i, Q) {
    int a = l[i] - 1;
    int b = r[i] - 2;
    printf("%d\n", acc[b + 1] - acc[a]);
  }

  // int ans = 0;
  // printf("%d\n", ans);
}

void input() {
  scanf("%d%d", &N, &Q);
  scanf("%s", S);
  REP(i, Q) scanf("%d%d", l + i, r + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 2048
import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
class Main{
    public static void main(String[] a){
    	int kotae = 0;
    	for(int i = 1; i <= 9; i++){
    		for (int k = 1; k <= 9; k++){
    			kotae = i*k;
    			System.out.println(i + "x" + k + "=" + kotae);
    		}
    		
    	}

    }
}

Measured memory_bytes: 23980
A, B, M = map(int, input().split())
Frz = list(map(int, input().split()))
Mic = list(map(int, input().split()))
C = []

for _ in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    C.append((x,y,c))

minF = min(Frz)
minM = min(Mic)
ans = minF + minM

for x, y, z in C:
    tmp = Frz[x] + Mic[y] - z
    if tmp < ans:
        ans = tmp

print(ans)

Measured memory_bytes: 33884
#include <stdio.h>

int main(void){
    int a[3][3],i,j,n,tmp,k,ans=0;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d",&a[i][j]);
        }
    }

    scanf("%d",&n);
    for(k=0;k<n;k++){
    scanf("%d",&tmp);
        for(i=0;i<3;i++){
            for(j=0;j<3;j++){
                if(tmp == a[i][j]) a[i][j] = 0;
            }
        }
    }

    //ヨコ
    if((a[0][0]==0) && (a[0][1]==0) && (a[0][2]==0)) ans = 1;
    if((a[1][0]==0) && (a[1][1]==0) && (a[1][2]==0)) ans = 1;
    if((a[2][0]==0) && (a[2][1]==0) && (a[2][2]==0)) ans = 1;

    //タテ
    if((a[0][0]==0) && (a[1][0]==0) && (a[2][0]==0)) ans = 1;
    if((a[0][1]==0) && (a[1][1]==0) && (a[2][1]==0)) ans = 1;
    if((a[0][2]==0) && (a[1][2]==0) && (a[2][2]==0)) ans = 1;

    //ナナメ
    if((a[0][0]==0) && (a[1][1]==0) && (a[2][2]==0)) ans = 1;
    if((a[2][0]==0) && (a[1][1]==0) && (a[0][2]==0)) ans = 1;

    if(ans==1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    
    return 0;
}

Measured memory_bytes: 1604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

int main() {
	int N;
	cin >> N;
	vector<ll> L(N);
	for (int i = 0;i < N;i++)cin >> L[i];

	int ans = 0;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < N;j++) {
			for (int k = 0;k < N;k++) {
				if (L[i] < L[j] && L[j]<L[k] && L[i] + L[j] > L[k]) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

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

vector<ll> G[26];

int main(){	
	string t;
	string s;
	cin >> s;
	cin >> t;
	rep(i, s.length()) {
		G[s[i]-'a'].push_back(i);
	}
	rep(i, t.length()) {
		if(G[t[i]-'a'].size() == 0) {
			cout << "-1" << endl;
			return 0;
		}
	}
	// rep(i, 26) {
	// 	if (G[i].size() != 0) {
	// 		cout << i << ": ";
	// 		rep(j, G[i].size()) {
	// 			cout << G[i][j];
	// 		}
	// 		cout << endl;
	// 	}
	// }
	ll res = 0, piv = 0;
	rep(i, t.length()) {
		// cout << G[t[i]-'a'][POSL(G[t[i]-'a'], piv)] << endl;
		// cout << endl;
		if(lower_bound(G[t[i]-'a'].begin(),G[t[i]-'a'].end(),piv) != G[t[i]-'a'].end()) {
			piv = G[t[i]-'a'][POSL(G[t[i]-'a'], piv)]+1;
		} else {
			res++;
			piv = G[t[i]-'a'][0]+1;
		}
		// cout << piv << " " << res << endl;
	}
	cout << res*s.length()+piv << endl;
	return 0;
}



Measured memory_bytes: 1724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) {
        long n = readLong(System.in);
        System.out.println(n * n * n);
    }

    private static long readLong(InputStream in) {
        long n = 0;
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(new InputStreamReader(in));
            String line = reader.readLine();
            n = Long.parseLong(line);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return n;

    }
}

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

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define MSET(m,v) memset((m),(v),sizeof(m))
#define UB(c,v) (upper_bound((c).begin(),(c).end(),(v)))
#define LB(c,v) (lower_bound((c).begin(),(c).end(),(v)))
#define INREP int TC;cin>>TC;while(TC--)
#define CPPIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

// SOLUTION

int main () {
	CPPIO;
	int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort (arr, arr + n);
    int r = arr[n - 1] >> 1;
    int x = lower_bound (arr, arr + n, r) - arr;
    vi pv;
    if (x - 1 >= 0) pv.EB (arr[x - 1]);
    pv.EB (arr[x]);
    if (x + 1 < n) pv.EB (arr[x + 1]);
    int md = arr[n - 1] + 10, ans = arr[x];
    for (auto i : pv) {
        int diff = arr[n - 1] - i;
        if (abs (diff - r) < md) md = abs (diff - r), ans = i;
        if (arr[n - 1] & 1 && abs (diff - (r + 1)) < md) md = abs (diff - (r + 1)), ans = i;
    }
    cout << arr[n - 1] << " " << ans;
	return 0;
}


Measured memory_bytes: 640
#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 mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF (1<<30)
#define LLINF (1LL<<60)
//#define MOD 998244353
#define MOD 1000000007
#define PI 3.14159265358979
using ll = long long;
using namespace std;

int main(){
    int AC = 0, WA = 0, TLE = 0, RE = 0;
    int n;
    cin >> n;
    rep(i,n){
        string t;
        cin >> t;
        if(t=="AC")
            AC++;
        else if(t=="WA")
            WA++;
        else if(t=="TLE")
            TLE++;
        else
            RE++;
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
    return 0;
}



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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> S(m), C(m);
    for(int i=0; i<m; i++){
        cin >> S.at(i) >> C.at(i);
    }
    bool a = true;

    if(m==0){
        a = false;
    }

    if(n!=1){
        for(int i=0; i<m; i++){
            if(S.at(i)==1 && C.at(i)==0){
                a = false;
                break;
            }
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
            if(S.at(i)==S.at(j) && C.at(i)!=C.at(j)){
                a = false;
                break;
            }
        }
    }

    if(a){
        vector<int> ans(n);
        for(int i=0; i<m; i++){
        ans.at(S.at(i)-1)=C.at(i);
        }
        if(n!=1 && ans.at(0)==0){
            ans.at(0) = 1;
        }
        for(int i=0; i<n; i++){
            cout << ans.at(i);
        }
    } else if(n==1 && m==0){
        cout << 0;
    } else if(m==0){
        cout << pow(10, n-1);

    }else{ 
        cout << -1;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
 
using namespace std;
 
int main(){
  stack<int> trains;
  int p;
  while(cin >> p){
    if(p == 0){
      cout << trains.top() << endl;
      trains.pop();
    }else{
      trains.push(p);
    }
  }
  return 0;
}

Measured memory_bytes: 1196
using System;
public class Program{
    public static void Main(){
        int kazu = int.Parse(Console.ReadLine());
        string[] word = new string[kazu];
        int count =0;
        for(int i=0;i<kazu;i++){
            word[i] = Console.ReadLine();
            for(int j=0;j<i;j++){
                if(word[i] == word[j]){
                    count++;
                }
            }
        }
        if(count == 0){
            for(int i=0;i<kazu-1;i++){
                int temp = word[i].Length;
                string last = word[i].Substring(temp-1);
                string first = word[i+1].Substring(0,1);
//                Console.WriteLine("{0} {1}",last,first);
                if(last != first){
                    count++;
                    i = kazu;
                }
            }
        }
        if(count==0){
            Console.WriteLine("Yes");
        }else{
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int n = s.length();
    loop(i,0,n) cout << 'x';
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
signed main(){
    int H;
    int cnt = 1;
    cin >> H;
    int num = 1;
    while(H > 1){
        if(H % 2 == 1)H = (H-1)/2;
        else H /= 2;
        num *= 2;
        cnt+=num;
    }
    cout << cnt;
}

Measured memory_bytes: 256
// たてなが
#include <iostream>
#include <string>
using namespace std;
int main(){
    int H,W;
    char C[100][101];
    cin>>H>>W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>C[i][j];
        }
    }
    for(int i=0;i<2*H;i++){
        for(int j=0;j<W;j++){
            cout<<C[i/2][j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  string s;
  cin >> s;
  rep(i,25000) {
    if (s == "") {
      cout << "YES" << '\n';
      return 0;
    }
    else if (s[0] == 'e') {
      if (s.substr(0,5) == "erase") {
        if (s[5] ==  'r') s.erase(0,6);
        else s.erase(0,5);
      }
    }
    else if (s[0] == 'd') {
      if (s.substr(0,5) == "dream") {
        if (s.substr(5,5) == "erase") s.erase(0,5);
        else if (s.substr(5,2) == "er") s.erase(0,7);
        else s.erase(0,5);
      }
    }
  }
  cout << "NO" << '\n';
}

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

struct fentree {
  vector<int> bit;  // binary indexed tree
  int n;

  fentree(int n) {
    this->n = n;
    bit.assign(n, 0);
  }

  fentree(vector<int> a) : fentree(a.size()) {
    for (size_t i = 0; i < a.size(); i++) 
      add(i, a[i]);
  }

  int sum(int r) {
    if (r < 0) return 0;
    int ret = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1)
      ret += bit[r];
    return ret;
  }

  void add(int idx, int delta) {
    for (; idx < n; idx = idx | (idx + 1))
      bit[idx] += delta;
  }
};

const int mod = 998244353;

void add(int &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
}

int sub(int x, int y) {
  x -= y;
  if (x < 0)
    x += mod;
  return x;
}

int mult(int x, int y) {
  return (1LL * x * y) % mod;
}

int powmod(int a, int b) {
  int res = 1;
  a %= mod;
  assert(b >= 0);
  for ( ; b; b >>= 1) {
    if (b & 1)
      res = 1LL * res * a %mod;
    a = 1LL * a * a % mod;
  }
  return (int) res;
}

const int N = 2e5 + 10;

int n;
vector<int> a[N];

void compress() {
  vector<int> xc, yc;
  for (int i = 0; i < n; i++) {
    xc.push_back(a[i][0]);
    yc.push_back(a[i][1]);
  }

  sort(xc.begin(), xc.end());
  sort(yc.begin(), yc.end());

  map<int, int> mpx, mpy;
  int cur = 1;
  for (int i = 0; i < n; i++)
    mpx[xc[i]] = cur++;
  cur = 1;
  for (int i = 0; i < n; i++)
    mpy[yc[i]] = cur++;

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

int f(int x) {
  return sub(powmod(2, x), 1);
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    a[i] = vector<int>(6);
    scanf("%d %d", &a[i][0], &a[i][1]);
  }
  sort(a, a + n);
  compress();

  fentree ft(n + 1);
  for (int i = 0; i < n; i++) {
    int bawah = ft.sum(a[i][1]);
    a[i][5] = i - bawah;
    a[i][4] = i - a[i][5];
    ft.add(a[i][1], 1);
  }

  ft = fentree(n + 1);
  for (int i = n - 1; i >= 0; i--) {
    int bawah = ft.sum(a[i][1]);
    a[i][2] = n - 1 - i - bawah;
    a[i][3] = n - 1 - i - a[i][2];
    ft.add(a[i][1], 1);
  }
  
  int ans = mult(n, powmod(2, n - 1));
  for (int i = 0; i < n; i++) {
    int z = f(n - 1);
    for (int j = 2; j < 5; j++)
      z = sub(z, f(a[i][j] + a[i][j + 1]));
    z = sub(z, f(a[i][2] + a[i][5]));
    for (int j = 2; j < 6; j++)
      add(z, f(a[i][j]));
    add(ans, z);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 31596
#include <bits/stdc++.h>
#include <sys/time.h>
#include <unistd.h>
using namespace std;
#define i64         unsigned long long 
#define rep(i, n)   for(i64 i = 0; (i) < ((i64)(n)); ++(i))
#define bit(n)      (((i64)1)<<((i64)(n)))
#define sz(v)       ((i64)((v).size()))



void kill()
{
  cout << -1 << endl;
  exit(0);
}

int main()
{
  i64 n;
  cin >> n;
  vector<i64> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  priority_queue<pair<i64, i64>> q;
  rep(i, n) q.push(make_pair(b[i], i));

  i64 ans = 0;
  while(0 < sz(q)){
    // DEBUG(q);
    i64 i = q.top().second;
    q.pop();
    if(b[i] == a[i]) continue;
    if(b[i] < a[i]) kill();

    i64 prev = (i - 1 + n) % n;
    i64 next = (i + 1 + n) % n;
    i64 total = b[prev] + b[next];
    i64 times = (b[i]- a[i]) / total;
    // DEBUG(b[i], total, times);
    if(times == 0) kill();
    ans += times;
    b[i] -= total * times;
    q.push(make_pair(b[i], i));
  }

  cout << ans << endl;
}


Measured memory_bytes: 9456
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int r;

int main(){
	cin >> r;
	
	cout << r*r << endl;
	
	return 0;
}

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

using namespace std;
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; }
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL << 60;
ll dp[100010][3];

int main(){

  int n;cin>>n;
  int a[100010][3];
  rep(i,0,n){
    rep(j,0,3){
      cin>>a[i][j];
    }
  }

  rep(i,0,n){
    rep(j,0,3){
      rep(k,0,3){
        if(j==k)continue;
        chmax(dp[i+1][j],dp[i][k]+a[i][j]);
      }
    }
  }

  ll ans=0;
  rep(j,0,3)chmax(ans,dp[n][j]);

  out(ans);

  return 0;
}


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

int main(void){
    string S; cin >> S;
    int length=1;
    int t;
    if(S.size()%2==0) t=S.size()/2-1;
    else t=S.size()/2;

    for(int l=1; l<=t; l++){
        bool flag=true;
        for(int i=0; i<l; i++){
            if(S[i]!=S[l+i]) flag=false;
        }
        if(flag) length=l;
    }

    cout << length*2 << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

void solve() {
	int n; cin >> n;
	vector<int> vec(n), dp(n, INT_MAX);
	for (int i = 0; i < n; ++i) {
		cin >> vec[i];
	}
	dp[0] = 0, dp[1] = abs(vec[0] - vec[1]);
	for (int i = 2; i < n; ++i) {
		dp[i] = min(abs(vec[i] - vec[i - 1]) + dp[i - 1], abs(vec[i] - vec[i - 2]) + dp[i - 2]);
	}
	cout << dp[n - 1];
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 1024