akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N, Q;
	while (true) {
		cin >> N >> Q;
		if (N == 0 && Q == 0) break;
		vector<vector<int>> mem(N);
		for (int i = 0; i < N;i++) {
			int M; cin >> M;
			for (int j = 0; j < M;j++) {
				int D; cin >> D;
				mem[i].push_back(D);
			}
		}

		int ans = 0;
		int C_Max = 0;
		int cnt = 0;
		for (int i = 1; i <= 100; i++) {
			cnt = 0;
			for (int j = 0; j < N;j++) {
				if (!mem[j].empty()) {
					if (mem[j][0] == i) {
						cnt++;
						mem[j].erase(mem[j].begin());
					}
				}
			}
			if (cnt > C_Max && cnt >= Q) {
				C_Max = cnt;
				ans = i;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

long long N, L;

int main() {
	long long pre;
	int spot = -1;
	scanf("%lld%lld", &N, &L);
	pre = -1;
	for (int i = 0; i < N; i++) {
		long long val;
		scanf("%lld", &val);
		if (spot == -1 && pre > 0 && val + pre >= L) {
			spot = i - 1;
		}
		pre = val;
	}
	
	if (spot == -1) puts("Impossible");
	else {
		puts("Possible");
		for (int i = 1; i <= spot; i++) printf("%d\n", i);
		for (int i = N - 1; i > spot; i--) printf("%d\n", i);
	}
	
	return 0;
}


Measured memory_bytes: 768
n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]

xyh.sort(key=lambda x: x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        x = xyh[0][0]
        y = xyh[0][1]
        h = xyh[0][2]
        ans = [cx, cy, h + abs(x - cx) + abs(y - cy)]
        for i in range(1, n):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            if h != max(ans[2] - abs(x - cx) - abs(y - cy), 0):
                break
        else:
            print(*ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  char c; cin>>c;
  if ('A' <= c && c <= 'Z') {
    cout << 'A' << endl;
  } else {
    cout << 'a' << endl;
  }

  return 0;
}


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

struct unionfind{
    vector<int> par,rank;
    unionfind(int x){
        par.resize(x);
        rank.resize(x);
        for(int i=0; i<x; i++)par[i]=i,rank[i]=0;
    }
    int root(int x){
        if(par[x]==x)return x;
        return par[x]=root(par[x]);
    }
    void uni(int x,int y){
        x=root(x),y=root(y);
        if(x==y)return;
        if(rank[x]<rank[y])par[x]=y;
        else{
            par[y]=x;
            if(rank[x]==rank[y])rank[x]++;
        }
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

int main(){
    int n,m;cin>>n>>m;
    vector<int> p(n);
    for(int i=0; i<n; i++){
        cin>>p[i];
        p[i]--;
    }
    unionfind u(n);
    for(int i=0; i<m; i++){
        int x,y;cin>>x>>y;
        u.uni(x-1,y-1);
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        ans+=u.same(i,p[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll h;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> h;
  ll ans = 1;
  ll now = 1;
  while(h > 1) {
    h /= 2;
    now *= 2;
    ans += now;
  }

  cout << ans << endl;
}


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

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    int X;
    X = 100 * r + 10 * g + b;
    if (X % 4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 3628
from heapq import *

N=int(input())
a=[int(input()) for i in range(N)]
s=[]
for i in a:
    heappush(s,i)
k=sum(a)
if k % 10 == 0:
    for j in range(N):
        i= heappop(s)
        if i % 10 != 0:
            print(k-i)
            break
else:
    print(k)
if len(s)==0:
    print(0)


Measured memory_bytes: 38384
n=gets.to_i
x=gets.split.map &:to_i
y=gets.split.map &:to_i
z=(0...n).map{|i|(x[i]-y[i]).abs}
d1=z.inject{|a,b|a+b}
d2=(z.map{|i|i**2}.inject{|a,b|a+b})**(1/2.0)
d3=(z.map{|i|i**3}.inject{|a,b|a+b})**(1/3.0)
d4=z.max
p d1,d2,d3,d4


Measured memory_bytes: 6928
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll a[3][3],c[3][3];
  for(ll i=0;i<3;i++)
  {
    for(ll j=0;j<3;j++)
    {
      cin>>a[i][j];
      c[i][j]=0;
    }
  }
  ll n,f=0;
  cin>>n;
  ll b[n];
  for(ll i=0;i<n;i++)
  {
    cin>>b[i];
  }
for(ll k=0;k<n;k++)
{
    for(ll i=0;i<3;i++)
  {
    for(ll j=0;j<3;j++)
    {
      if(b[k]==a[i][j])
      {
        c[i][j]=1;
      }
    }
  }
}
ll k=0,m=0;
    for(ll i=0;i<3;i++)
  {
  	ll s=0,l=0;
    for(ll j=0;j<3;j++)
    {
      s+=c[i][j];
      l+=c[j][i];
      if(i==j)
      {
      	m+=c[i][j];
      }
      if(2-i==j)
      {
      	k+=c[i][j];
      }
    }
    if(s==3)
    {
    	f=1;
    	break;
    }
     if(l==3)
    {
    	f=1;
    	break;
    }
     if(m==3)
    {
    	f=1;
    	break;
    }
     if(k==3)
    {
    	f=1;
    	break;
    }
  }
  if(f==1)
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;
}
  

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
			       c > 0 ? i < b : i > b; \
			       i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define dump(x) cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else
const bool test = false;
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
	v.push_back(buffer);
    }
    return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}
 
void solve();
 
signed main()
{
    cout << fixed << setprecision(20);
    solve();
    while (true)
    {
	char s[MAX];
	if (scanf("%s", s) == EOF)
	    break;
	int n = strlen(s);
	for (int i = n - 1; i > -1; i--)
	{
	    ungetc(s[i], stdin);
	}
	solve();
    }
    return 0;
}
 
int N, T;
int t[MAX];

void solve()
{
	cin >> N >> T;
	rep(i, N) cin >> t[i];
	int res = T;
	rep(i, N-1) {
		if (t[i + 1] > t[i] + T) res += T;
		else {
			res += t[i + 1] - t[i];
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  string s;
  cin >> s;
  s = s + 'T';
  ll N = s.size();
  ll x, y;
  cin >> x >> y;
  set<ll> xs;
  set<ll> ys;
  xs.insert(0);
  ys.insert(0);
  ll way = 0;
  ll cnt = 0;
  // bool first_time = true;
  for (ll i = 0; i < N; ++i) {
    if (s[i] == 'T') {
      if (cnt != 0) {
        if (way % 2 == 1) {
          set<ll> new_ys;
          for (auto j = ys.begin(); j != ys.end(); ++j) {
            new_ys.insert(*j + cnt);
            new_ys.insert(*j - cnt);
          }
          ys = new_ys;
        }
        else {
          set<ll> new_xs;
          if (way != 0) {
            for (auto j = xs.begin(); j != xs.end(); ++j) {
              new_xs.insert(*j + cnt);
              new_xs.insert(*j - cnt);
            }
          }
          else {
            // first_time = false;
            for (auto j = xs.begin(); j != xs.end(); ++j) {
              new_xs.insert(*j + cnt);
            }
          }
          xs = new_xs;
        }
      }
      way += 1;
      cnt = 0;
    }
    else {
      cnt += 1;
    }
  }
  auto x_itr = xs.find(x);
  auto y_itr = ys.find(y);
  if ((x_itr != xs.end()) && (y_itr != ys.end())) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
typedef long long ll;
const int xmax=1e5+7;
const int INF=1e9+7;
using namespace std;
int main()
{
    char s[100007];
    scanf("%s",s);
    int ans1=0,ans2=0;
    for(int i=0;i<strlen(s);i++)
    {
        if(s[i]=='0')
            ans1++;
        else
            ans2++;
    }
    if(ans1==0||ans2==0)
        printf("0");
    else
        printf("%d",min(ans1,ans2)*2);
    return 0;
}


Measured memory_bytes: 384
t= list(input())
if t[-1] == '?':
  t[-1] = 'D'

if t[0] == '?':
  if t[1] == 'D':
    t[0] = 'P'
  elif t[1] == 'P':
    t[0] = 'D'
  else:
    t[0] = 'P'
    t[1] = 'D'

for i in range(1, len(t)-1):
  if t[i] == '?':
    if t[i-1] == 'P':
      t[i] = 'D'
    elif t[i-1] == 'D':
      if t[i+1] == 'P':
        t[i] = 'D'
      elif t[i+1] == 'D':
        t[i] = 'P'
      else:
        t[i] = 'P'
        t[i+1] = 'D'
    
    
print(''.join(t))
  

Measured memory_bytes: 10632
#include<stdio.h>
#define MAX 200000
#define SENTINEL 2000000000

int L[MAX/2+2],R[MAX/2+2];

long long merge(int A[],int n,int left,int mid,int right){
	int i,j,k;
	long cnt=0;
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++){
		L[i]=A[left+i];
	}
	for(int i=0;i<n2;i++){
		R[i]=A[mid+i];
	}
	L[n1]=SENTINEL;
	R[n2]=SENTINEL;
	i=0,j=0;
	for(int k=left;k<right;k++){
		if(L[i]<=R[j]){
			A[k]=L[i++];
		}
		else{
			A[k]=R[j++];
			cnt+=n1-i;
		}
	}
	return cnt;
}

long long mergeSort(int A[],int n,int left,int right){
	int mid;
	long long v1,v2,v3;
	if(left+1<right){
		mid=(left+right)/2;
		v1=mergeSort(A,n,left,mid);
		v2=mergeSort(A,n,mid,right);
		v3=merge(A,n,left,mid,right);
		return v1+v2+v3;
	}
	else{
		return 0;
	}
}

int main(void){
	int A[MAX],n,i;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	
	long long ans=mergeSort(A,n,0,n);
	printf("%ld\n",ans);
	
	return 0;
}



Measured memory_bytes: 4264
import java.util.*;

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

    if(X==1){
	System.out.println("Hello World");  
  }else{
    int A = sc.nextInt();
    int B = sc.nextInt();
    System.out.println(A+B);
      }
    }
}


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

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

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vl v(3*n);
	REP(i, 3*n)cin >> v[i];
	sort(ALL(v),greater<ll>());
	ll ans = 0;
	REP(i, n)ans += v[2 * i + 1];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include<string>
#include<iomanip>
#define N 100
using namespace std;
int main(void) {
	int n;
	int i;
	int l[10];
	int b = 0;
	int g = 0;

	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> l[i];
		if (b < l[i]) {
			b = l[i];
		}
		g = g + l[i];
	}
	g = g - b;

	if (b < g) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

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

using namespace std;

int N, nr, v[20009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
if (N == 3)
{
    printf ("2 5 63\n");
    return 0;
}
long long S = 0;
for (int i=30000; i>1; i--)
    if (i % 2 == 0 || i % 3 == 0)
    {
        if (nr < N - 1) v[++nr] = i, S += i;
        else
        {
            if ((S + i) % 6 == 0)
            {
                v[++nr] = i;
                break;
            }
        }
    }
if (nr != N)
{
    nr = 0, S = 0;
    for (int i=2; i<=30000; i++)
        if (i % 2 == 0 || i % 3 == 0)
        {
            if (nr < N - 1) v[++nr] = i, S += i;
            else
            {
                if ((S + i) % 6 == 0)
                {
                    v[++nr] = i;
                    break;
                }
            }
        }
    assert (nr == N);
}
for (int i=1; i<=nr; i++)
    printf ("%d ", v[i]);
printf ("\n");
return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main() {
  // ========================================================
  int n, m, sum = 0, cnt = 0;
  cin >> n >> m;
  vector<int> a(n);
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  REP(i, n) {
    if (a[i] >= sum / (double)(4 * m)) {
      cnt++;
      if (cnt >= m) {
        yOUT;
        return 0;
      }
    }
  }
  nOUT;
}

//最大公約数
ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

Measured memory_bytes: 256
N,K=map(int,input().split())
h=list(map(int,input().split()))
cost=[0,abs(h[1]-h[0])]

for i in range(2,N):
    cand=10**10
    for j in range(K):
        if j==i:
            break
        cand=min(cand,cost[i-j-1]+abs(h[i]-h[i-j-1]))
    cost.append(cand)

print(cost[-1])

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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (const T& x : v)
    o << x << ",";
  return o << "]";
}

const int INF = 1e18;

int n;
const int MAXCITYNUM = 50;
const int MAXCOST = 2500;
inline int vind(int v, int c) {
  assert(c >= 0);
  return min(c,MAXCOST) * n + v;
}

void dijkstra(const vvpii& g, int start, vi& dists) {
  vi pred(g.size(), -1);
  pred[start] = -2;
  dists[start] = 0;
  set<pii> prioq;
  prioq.insert({0, start});
  while (!prioq.empty()) {
    int curr;
    int currd;
    tie(currd, curr) = *prioq.begin();
    prioq.erase(prioq.begin());
    if (currd > dists[curr])
      continue;

    for (const auto& p : g[curr]) {
      int w;
      int t;
      tie(w, t) = p;
      if (currd + t < dists[w]) {
        prioq.erase({dists[w],w});
        dists[w] = currd + t;
        prioq.insert({dists[w],w});
      }
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int m, s;
  cin >> n >> m >> s;
  assert(n <= MAXCITYNUM);

  vvpii g(n*(MAXCOST+1));
  
  for (int i=0; i<m; ++i) {
    int ui, vi, ai, bi;
    cin >> ui >> vi >> ai >> bi;
    --ui; --vi;
    assert(ai <= 50);
    for (int c=0; c<=MAXCOST; ++c) {
      if (c-ai < 0)
        continue;
      g[vind(ui,c)].pb({vind(vi,c-ai), bi});
      g[vind(vi,c)].pb({vind(ui,c-ai), bi});
      //if (c <= 10) { 
      //  cerr << "DBG ins e " << vind(ui,c) << " " << vind(vi,c-ai) << " " << bi << endl;
      //  cerr << "DBG ins e " << vind(vi,c) << " " << vind(ui,c-ai) << " " << bi << endl;
      //}
    }
  }

  for (int i=0; i<n; ++i) {
    int ci, di;
    cin >> ci >> di;
    for (int c=0; c<=MAXCOST; ++c) {
      g[vind(i, c)].pb({vind(i, c+ci), di});
    }
  }

  //for (int i=0; i<n; ++i) {
  //  for (int c=0; c<=10; ++c) {
  //    cerr << "DBG adjl " << vind(i,c) << endl;
  //    for (const auto& p : g[vind(i,c)]) {
  //      cerr << "DBG adjl " << vind(i,c) << " " << p.first << " " << p.second << endl;
  //    }
  //  }
  //}

  vi dists(g.size(), INF);
  dijkstra(g, vind(0,s), dists);

  vi realdists(n, INF);
  for (int i=0; i<n; ++i) {
    for (int c=0; c<=MAXCOST; ++c) {
      //if (c < 20)
      //  cerr << "DBG " << i << " " << c << " " << vind(i,c) << " " << dists[vind(i,c)] << endl;
      realdists[i] = min(realdists[i], dists[vind(i,c)]);
    }
  }
  for (int i=1; i<n; ++i)
    cout << realdists[i] << "\n";
}


Measured memory_bytes: 26060
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

    int n;
    cin >> n;
    set<ll> s;
    rep(i,n){
        int a;
        cin >> a;
        s.insert(a);
    }
    if(s.size() == n)cout << "YES" << endl;
    else cout << "NO" << endl; 
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc154.contest.atcoder.jp/tasks/abc154_b

Measured memory_bytes: 9600
import math

def main():
    a, b, x = map(int, input().split())
    if a*a*b == x:
        print(0)
        return
    mid = a**2*b/2
    c = x/(a**2)
    if mid == x:
        ans = 90 - math.degrees(math.atan(a/b))
    elif mid < x:
        d = 2*x/(a**2) - b
        ans = 90 - math.degrees(math.atan(a/(b-d)))
    else:
        d = 2*a*c/b
        ans = 90 - math.degrees(math.atan(d/b))

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9252
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()

  l=[LI() for _ in range(n-1)]

  for i in range(n-1):
    t=0
    for x in l[i:]:
      c,s,f=x
      if t<=s:
        t=s
      else:
        _t=t-s
        if _t%f==0:
          pass
        else:
          t+=f-(_t%f)
      t+=c
    print(t)
  print(0)

main()
# print(main())


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

using namespace std;

int a[3][111];
int dp[3][111];
void solve() {
    int m; cin >> m;
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    memset(dp, 0, sizeof dp);
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = a[i][j] + max(dp[i-1][j], dp[i][j-1]);
        }
    }
    cout << dp[2][m];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
A=list(input())
B=list(input())
C=list(input())
s=""
s=A.pop(0)
while(1):
    if s=="b":
        if B!=[]:
            s=B.pop(0)
        else:
            print("B")
            break
    elif s=="c":
        if C != []:
            s=C.pop(0)
        else:
            print("C")
            break
    elif s=="a":
        if A !=[]:
            s =A.pop(0)
        else:
            print("A")
            break

Measured memory_bytes: 3064
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    s = s.split("><")
    ans_lst = []

    for part in s:
        lnum = part.count("<")
        rnum = part.count(">")      
        ans_lst.append(lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1)


    if len(s) == 1:
        lnum = s[0].count("<") -1
        rnum = s[0].count(">") -1
        ans_lst[0] = lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1
    else:
        lnum = s[0].count("<") -1
        rnum = s[0].count(">")
        ans_lst[0] = lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1

        lnum = s[-1].count("<")
        rnum = s[-1].count(">") -1
        ans_lst[-1] = lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1

    ans = sum(ans_lst)
    print(ans)

main()


Measured memory_bytes: 92300
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;

int s[110]={0};
int main()
{
	int i,a,b,c,d,sum=0;
	cin>>a>>b>>c>>d;
	for(i=0;i<=110;i++)
	{
		if(i>=a&&i<b)
			s[i]++;
		if(i>=c&&i<d)
			s[i]++;
	}
	for(i=0;i<=110;i++)
	{
		if(s[i]==2) sum++;
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 256
using System;

namespace Beginner101
{
    class Program
    {
        static void Main(string[] args)
        {
            var hoge = Console.ReadLine();
            var ans ="";
            
            var sum = 0;
            for(int i=0; i < hoge.Length; i++) {
                sum += int.Parse(hoge[i].ToString());
            }
            ans = (int.Parse(hoge) % sum== 0)?"Yes":"No";
            Console.WriteLine(ans);
        }
    }
}


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

int main() {
  int N, K, l[50];
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> l[i];
  
  sort(l, l + N, greater<int>());
  
  int res = 0;
  for (int i = 0; i < K; i++) res += l[i];
  
  cout << res << endl;
  
}

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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  int x = 0;
  for(int i = 0; i < n; ++i){
    if(s[i] == 'I') {
      x++;
      ans = max(ans, x);
    } else{
      x--;
    }
  }
  cout << ans << endl;
  return 0; 
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 100

int compare(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int main()
{
    int i, n, last, r = 0;
    int a[N];
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    qsort(a, n, sizeof(int), compare);

    for (i = 0; i < n; i++)
    {
        if (i == 0)
            r++;
        else if (a[last] < a[i])
            r++;
        last = i;
    }
    printf("%d\n", r);
}

Measured memory_bytes: 128
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] inputString = new string[N];
        for(int i = 0; i < N; i++)
		{
            inputString[i] = Console.ReadLine();
		}
        string[] repatoriString = inputString.Distinct().ToArray();
        int countGacha = repatoriString.Length;

        Console.WriteLine(countGacha);
    }
}

Measured memory_bytes: 49812
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String t= sc.next();
		String buff= "";
		//double n = sc.nextInt()/1000.0;
		int m = sc.nextInt();
		//int k = sc.nextInt();
		//String s=sc.next();
		long count=0,flag=0;
		long count1=0,count2=0;
		int count3=0;
		int[] array = new int[100];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		//Arrays.sort(array);

		for(int i=0;i<m;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=0;i<m-1;i++) {
			for(int j=i+1;j<m;j++) {
				count+=array[i]*array[j];
			}
		}

		/*if(count==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}*/

		System.out.println(count);
	}
}




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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;
map<llong, llong> m;
vector<llong> l;


llong dfs(llong n){

	if(n == 1)return 0;
	if(m.find(n) != m.end())return m[n];
	m[n] = -1;
	for(auto e : l){
		if(e > n)break;
		if(n%e == 0){
			llong val = dfs(n/e);
			if(val < 0) continue;
			m[n] = max(m[n], 1+val);
	
		}
	}
	if(m[n] == 0)return -1;
	return m[n];
}

/*
llong dfs(llong n){
	if(n == 1)return 0;
	if(m.find(n) != m.end())return m[n];
	llong ret = 
	for(auto e : l){
		if(e > n)break;
		if(n%e == 0)m[n] = max(m[n], 1+dfs(n/e));
	}
	if(m[n] == 0)return -1;
	return m[n];
}
*/
signed main(){
	llong n; cin >> n;
	for(llong i = 1; i < 19; i++){
		for(llong j = 0; j < (1 << i); j++){
			llong tmp = 0;
			llong t = 1;
			for(llong k = 0; k < i; k++){
				if(j & (1 << k)){
					tmp += 8*t;
				}
				else{
					tmp += 2*t;
				}
				t *= 10;
			}
			l.push_back(tmp);
		}
	}
//	for(int i = 0; i < 20; i++)cerr << l[i] << " ";
//	cerr << endl;
	if(n == 1){
		cout << -1 << endl;
		return 0;
	}
	m[1] = 0;
	cout << dfs(n) << endl;


	return 0;
}




Measured memory_bytes: 7076
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    int input, ans = 0, flag;
    int ans2, ans3 = 0;
    cin >> input;

    vector<int> side(input);
    for (int i = 0; i < input; i++) {
        cin >> side.at(i);
    }

    sort(side.begin(), side.end());
    reverse(side.begin(), side.end());

    vector<int> num;
    num.push_back(0);
    num.push_back(1);
    for (int i = 0; i < input; i++) {
        flag = 0;
        for (int j = i + 1; j < input; j++) {
            for (int k = j + 1; k < input; k++) {
                if (side.at(i) < side.at(j) + side.at(k) && side.at(j) < side.at(k) + side.at(i) && side.at(k) < side.at(i) + side.at(j)) {
                    ans++;
                    ans2++;
                    //ans3++;
                }
                else {
                    break;
                    flag++;
                }
            }
            if (flag != 0) {
                break;
            }
        }
    }

    cout << ans << endl;

}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

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

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;


signed main(){
    int N;
    double v, w;
    priority_queue<double, vector<double>, greater<double>> que;
    cin >> N;
    REP(i, N){
        cin >> v;
        que.push(v);
    }
    REP(i, N - 1){
        v = que.top(); que.pop();
        w = que.top(); que.pop();
        que.push((v + w) / 2);
    }
    PRINT(que.top());
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n=II()
	A=LI()
	A.sort()
	ans=0

	for i in range(n-2):
		for j in range(i+1,n-1):
			for k in range(j+1,n):
				if A[i]==A[j] or A[j]==A[k]:
					continue
				if A[i]+A[j]>A[k]:
					ans+=1

	print(ans)








if __name__ == "__main__":
	main()


Measured memory_bytes: 9292
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 30;
const int N = (int)3e5 + 7;
const int MAXN = (int)3e6 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e17;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

void solve() {
	int k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK";
			return;
		}
	}
	cout << "NG";
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    bool f = (abs(a-b) <= d && abs(b-c) <= d) || abs(a-c) <= d;
    cout << (f?"Yes":"No") << endl;
}


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

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            //

            var S1 = GetStr();
            var S2 = GetStr();
            var ans = YESNO(S1[0] == S2[2] && S1[1] == S2[1] && S1[2] == S2[0]);

            Console.WriteLine(ans);

            //
            Console.Out.Flush();
            Console.ReadKey();
        }

        static void Solve()
        {

        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c, out V d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]);
        }
    }
}

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

signed main() {
	ll l; cin >> l;
	double L = l / 3;
	printf("%lf\n" , (double)l * l * l  / 27);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define pi pair<int, int>
#define l first
#define r second
#define all(x) x.begin(), x.end()
#define fori(a, b, step) for (int i = a; i < b; i += step)
#define forj(a, b, step) for (int j = a; j < b; j += step)

const int maxn = 5e5 + 1, CC = 10001;

using namespace std;

short a[100];
short dp[100][10001];
short sm[10001], pm[10001];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    fori (0, n, 1)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < CC; j++)
            dp[i][j] = 1e9;
    for (int i = 0; i < CC; i++)
        dp[0][i] = 1;
    dp[0][a[0]] = 0;
    pm[0] = sm[CC - 1] = 1e9;
    for (int i = 1; i < CC; i++)
        pm[i] = min(pm[i - 1], dp[0][i]);
    for (int i = CC - 1; i > 0; i--)
        sm[i - 1] = min(sm[i], dp[0][i]);
    for (int i = 1; i < n; i++) {
        for (int j = 1; j < CC; j++) {
            dp[i][j] = (j != a[i]) + min(pm[j - 1], sm[j]);
        }
        for (int j = 1; j < CC; j++)
            pm[j] = min(pm[j - 1], dp[i][j]);
        for (int j = CC - 1; j > 0; j--)
            sm[j - 1] = min(sm[j], dp[i][j]);
    }
    cout << sm[0];
    return 0;
}


Measured memory_bytes: 5520
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	ll n;
	cin>>n;
	ll a[n];
	ll ans = 1;
	ll left_lim=1;
	// ll maxi = 1000000000000000000;	// not a good practise.
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}

	for(ll i=0;i<n;i++)
	{
		if(a[i]==0)
		{
			cout<<0<<endl;
			return 0;
		}
	}

	for(ll i=0;i<n;i++)
	{
		ans = (ans)*(a[i]);
		if(ans>(ll)1e18)   // imp type casting dgt.   
		{				   //  1e18  representation of 10^18.
			cout<<-1<<endl;
			return 0;
		}
		if(ans<left_lim)
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4420
#include<stdio.h>
int main(void){
    int a,b,c,d,n,ans;

    while(scanf("%d",&n)!=EOF){
        ans=0;
        for(a=0;a<10;a++){
            for(b=0;b<10;b++){
                for(c=0;c<10;c++){
                    for(d=0;d<10;d++){
                        if(a+b+c+d==n)ans++;
                    }
                }
            }

        }
        printf("%d\n",ans);
    }
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int n;
  cin >> n;
  vector<ll> a(n+1);
  vector<ll> b(n);
  rep(i, n+1) {
    cin >> a[i];
  }
  ll ans = 0;
  rep(i, n) {
    cin >> b[i];
    rep(j, 2) {
      ll atack = min(a[i+j], b[i]);
      a[i+j] -= atack;
      b[i] -= atack;
      ans += atack; 
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
  /* your code */
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  if(t == nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  /* your code */
  deleteNode(nil->prev);
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev =x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 32984
import statistics
n=int(input())
l=list(map(int,input().split()))
l=[l[i]-(i+1) for i in range(n)]
a=statistics.median_low(l)
b=0
if n%2==0:b=statistics.median_high(l)
print(min(sum([abs(i-a) for i in l]),sum([abs(i-b) for i in l])))

Measured memory_bytes: 27264
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n; cin >> n;
	int w[101];

	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		sum += w[i];
	}

	int mini = sum;
	int prefix_sum = 0;
	for (int i = 0; i < n; i++) {
		prefix_sum += w[i];
		mini = min(mini, abs(prefix_sum - (sum - prefix_sum)));
	}

	cout << mini << endl;
	return 0;
}

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

using namespace std;

struct UnionFind{
    vector <int> par;
    vector <int> height;
    vector <int> card;

    UnionFind(int N){
        par.assign(N, 0);
        height.assign(N, 0);
        card.assign(N, 1);
        for(int i = 0; i < N; i++){
            par[i] = i;
        }
    }
    int set_size(int x){
        return card[root(x)];
    }
    int root(int x){
        if(x == par[x]){
            return x;
        }
        par[x] = root(par[x]);
        return par[x];
    }

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

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y){
            return;
        }
        if(height[x] >= height[y]){
            par[y] = x;
            if(height[x] == height[y]){
                height[x] ++;
            }
            card[x] += card[y];
        } else {
            par[x] = y;
            card[y] += card[x];
        }
    }
};

vector <int> x_ids[100000];
vector <int> y_ids[100000];
int x[100000];
int y[100000];
int main(){
    int N;
    cin >> N;
    int x_max = 0;
    int y_max = 0;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i];
        x_max = max(x_max, x[i]);
        y_max = max(y_max, y[i]);
        x_ids[x[i] - 1].push_back(i);
        y_ids[y[i] - 1].push_back(i);
    }
    
    UnionFind uf(N);
    for(int i = 0; i < x_max; i++){
        for(int j = 1; j < x_ids[i].size(); j++){
            uf.unite(x_ids[i][0], x_ids[i][j]);
        }
    }

    for(int i = 0; i < y_max; i++){
        for(int j = 1; j < y_ids[i].size(); j++){
            uf.unite(y_ids[i][0], y_ids[i][j]);
        }
    }

    map <int, int> group_to_x_num;
    map <int, int> group_to_y_num;
    for(int i = 0; i < N; i++){
        int rt = uf.root(i);
        if(group_to_x_num.find(rt) == group_to_x_num.end()){
            group_to_x_num[rt] = uf.set_size(rt);
        }
        if(group_to_y_num.find(rt) == group_to_y_num.end()){
            group_to_y_num[rt] = uf.set_size(rt);
        }
    }

    for(int i = 0; i < x_max; i++){
        if(x_ids[i].size() > 0){
            int rt = uf.root(x_ids[i][0]);
            group_to_x_num[rt] -= ((x_ids[i].size()) - 1);
        }
    }

    for(int i = 0; i < y_max; i++){
        if(y_ids[i].size() > 0){
            int rt = uf.root(y_ids[i][0]);
            group_to_y_num[rt] -= ((y_ids[i].size()) - 1);
        }
    }

    long long ans = 0;
    for(auto it = group_to_x_num.begin(); it != group_to_x_num.end(); it++){
        int group = it->first;
        int x_num = it->second;
        int y_num = group_to_y_num[group];
        ans += (long long) x_num * (long long) y_num - uf.set_size(group);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10112
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define QUEUE_NUM (20386)

struct Data{
	char color[15];
	int cnt;
};

typedef struct {
	int top,bottom;
	Data data[QUEUE_NUM];
}Queue;

//QÉdataðÇÁ
void push(Queue* Q, Data data){
	Q->data[Q->bottom] = data;
	Q->bottom = (Q->bottom +1);
}

//QÌæªvfðæ¾
Data front(Queue* Q)
{
	return Q->data[Q->top];
}

//QÌæªvfðí
void pop(Queue* Q)
{
	Q->top = (Q->top + 1) %QUEUE_NUM;
}

int check(char str[],int n){
	int i,number,tem=1,temp;
	for(i=0;i<n;i++){
		if(str[i]=='r'){
			str[i]='0';
		}
		else if(str[i]=='g'){
			str[i]='1';
		}
		else if(str[i]=='b'){
			str[i]='2';
		}
		else{
			str[i]='\0';
		}
	}
	
	number = atoi(str);
//	puts("\n--in--");
//	printf("%d  ",number);
	number=0;
	while(i!=-1){
		temp = (str[i]-48);
		number += tem*temp;
		tem*=3;
		i--;
	}
//	printf("%d\n",number);
//	puts("--o--");
	return number;
}

int main(void)
{
	while(1){
		int i,j,n,ans=-1;
		char col[4]={'r','g','b'},str[16];
		int temp;
		bool visited[178000]={0};
		Queue Q = {0,0,{0}};
		Data bag;
		
		scanf("%s",bag.color);
		if(bag.color[0]=='0')break;
		n = strlen(bag.color);
		bag.cnt=0;
		push(&Q,bag);
		
		while(!(Q.bottom==Q.top)){
			int flg=0,flag=0;
			Data d = front(&Q); 
			pop(&Q);
			
			
			for(i=0;i<n-1;i++){
				if(d.color[i]!=d.color[i+1])flg=1;
			}
			if(flg==0){
				ans=d.cnt;
				break;
			}
			
			for(i=0;i<n-1;i++){
				if(d.color[i] != d.color[i+1]){
					int used[4]={0};
					Data next;
					flg=0;
					strcpy(next.color ,d.color);
					
					for(j=0;j<3;j++){
						if(col[j]==next.color[i])used[j]=1;
						if(col[j]==next.color[i+1])used[j]=1;
					}
					
					for(j=0;j<3;j++){
						if(used[j]==0){
							next.color[i]=col[j];
							next.color[i+1]=col[j];
						}
					}
					
					/**/
					strcpy(str,next.color);
					temp=check(str,n);
					
					if(visited[temp]==1){
				//		printf("d¡\n");
						continue;
					}
					else {
						visited[temp]=1;
					}
					
					/**/
	//				printf("now%d == %s\n",next.cnt,next.color);
				//	Sleep(100);
					next.cnt = d.cnt+1;
					push(&Q,next);
				}
			}
		}
		if(ans==-1){
			puts("NA");
		}
		else {
			printf("%d\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 1344
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

const int bound = 200100;
ll fact[bound], fact_inv[bound];

ll power( ll a, ll b ){
	ll res = 1;
	while( b > 0 ){
		if( b & 1 ) res = res*a % mod;
		a = a*a % mod;
		b >>= 1;
	}
	return res;
}

void init(){
	fact[0] = 1;
	int b = bound-10;
	for( int i = 0; i < b; ++i ){
		fact[i+1] = fact[i]*(i+1) % mod;
	}
	fact_inv[b] = power(fact[b], mod-2);
	for( int i = b-1; i >= 0; --i ){
		fact_inv[i] = fact_inv[i+1]*(i+1) % mod;
	}
}

ll comb( ll n, ll r ){
	if( n < r or r < 0 ) return 0;
	return ( fact[n]*fact_inv[r] ) % mod * fact_inv[n-r] % mod;
}

int main(){
	init();
	ll n, k; cin >> n >> k;
	ll ans = 0;
	for( ll x = 0; x <= min(k, n-1); ++x ){
		ans += ( comb(n, x) * comb(n-1, n-x-1) ) % mod;
		ans %= mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 6756