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

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> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll k;
  cin >> n >> k;
  vector<P> p;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p.emplace_back(a, b);
  }
  sort(all(p));
  int ans;
  ll count = 0;
  rep(i, n) {
    if(count >= k) break;
    ans = p[i].first;
    count += p[i].second;
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
  int i, check_c = 0;
  char str[11];
  scanf("%s", str);
  if(str[0] != 'A') {
    printf("WA\n");
  } else {
    for(i = 2; i < strlen(str) - 1; i++) {
      if(str[i] == 'C') check_c++;
    }
    if(check_c != 1) {
      printf("WA\n");
    } else {
      for(i = 1; i < strlen(str); i++) {
        if(islower(str[i]) || str[i] == 'A' || str[i] == 'C') {
          continue;
        } else {
          printf("WA\n");
          break;
        }
      }
      if(i == strlen(str)) printf("AC\n");
    }
  }
  return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)


class UnionFind:
    def __init__(self, n):
        self.p = [-1]*n
        self.r = [1]*n

    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def union(self, x, y):
        rx, ry = self.find(x), self.find(y)
        if rx != ry:
            if self.r[rx] > self.r[ry]:
                rx, ry = ry, rx
            if self.r[rx] == self.r[ry]:
                self.r[ry] += 1
            self.p[ry] += self.p[rx]
            self.p[rx] = ry

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.p[self.find(x)]


n, m = map(int, input().split())
uf = UnionFind(n)
edges = [tuple(map(lambda x: int(x)-1, input().split()))for _ in range(m)]


ans_inv = [n*(n-1)//2]
for a, b in reversed(edges):
    if uf.same(a, b):
        ans = ans_inv[-1]
    else:
        x = uf.size(a)
        y = uf.size(b)
        ans = ans_inv[-1]-x*y
    ans_inv.append(ans)
    uf.union(a, b)

print(*reversed(ans_inv[:-1]), sep='\n')

Measured memory_bytes: 24792
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N,M = cin.mapInt()
    A = cin.intListList(N)
    ans = 0
    A.sort()
    for i in range(N):
        b = min(M,A[i][1])
        ans += b * A[i][0]
        M-=b
    print(ans)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 57052
#include<iostream>
using namespace std;
int main() {
    string n;
    cin>>n;
    int sum = 0;
    for (char c : n) {
        sum += c - '0';
    }
    if (sum % 9 == 0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF (ll)1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

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

//constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

#define P pair<int,int>
//struct edge { int to, cost; };
using edge = tuple<int, int, int>;
using obj = tuple<int, double, int, int>;

class CompareDist
{
public:
	bool operator()(obj n1, obj n2) {
		return get<1>(n1) > get<1>(n2);
	}
};

void solve(int n, int m) {

	vector<vector<edge>> G(n);
	int s, g ;
	cin >> s >> g; s--;g--;
	vi x(m), y(m), dd(m), c(m);
	rep(i, m) {
		cin >> x[i] >> y[i] >> dd[i] >> c[i];
		x[i]--; y[i]--;
	}
	rep(i, m) {
		edge ed = make_tuple(y[i], dd[i], c[i]);
		G[x[i]].push_back(ed);
		ed = make_tuple(x[i], dd[i], c[i]);
		G[y[i]].push_back(ed);
	}

	priority_queue<obj, vector<obj>, CompareDist> q;
	//fill(d,d+V,INT_MAX);
	vector<vector<vector<double>>> d(n, vector<vector<double>>(30,vector<double>(31,INF)));
	rep(i, n) {
		d[s][i][0] = 0;
	}
	obj o = make_tuple(s, 0, -1, 0);
	q.push(o);

	while (!q.empty()) {
		obj p = q.top(); q.pop();
		int node = get<0>(p);
		double time = get<1>(p);
		int prev = get<2>(p);
		int velo = get<3>(p);

		//if (ans < time)continue;

		for (int i = 0; i<G[node].size(); i++) {
			edge e = G[node][i];
			int to = get<0>(e);
			int cos = get<1>(e);
			int lim = get<2>(e);
			if (get<0>(e) == prev)continue;
			range(j, -1, 2) {
				int newvel = velo + j;
				if (newvel < 1 || newvel>lim)continue;
				double dt = cos / (double)newvel;

				if (time + dt < d[to][node][newvel]){//////d[to]>d[node] + dt) {
					//cout <<node<<" "<<to << " " << time << " "<<time + dt << " " << newvel << " " << endl;
					d[to][node][newvel] = time + dt;
					obj o = make_tuple(to, time + dt, node, newvel);
					q.push(o);
				}
			}
		}
	}
	double ans = INF;
	rep(i, n) {
		//cout << d[g][i][1] << endl;
		//ans = min(d[g][i][1],ans);
		if (ans > d[g][i][1])ans = d[g][i][1];
	}
	if (ans != INF)printf("%.7lf\n", ans);
	else cout << "unreachable" << endl;
}

int main(void) {
	int n, m;
	while (cin >> n >> m, n) {
		solve(n, m);
	}
}




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

typedef long long ll;

ll X,Y,Z,K,a[1009],b[1009],c[1009];
vector<ll> ans;


int main()
{
	ios_base::sync_with_stdio(false);
	cin>>X>>Y>>Z>>K;
	
	for(int i=0;i<X;i++)
		cin>>a[i];
	for(int i=0;i<Y;i++)
		cin>>b[i];
	for(int i=0;i<Z;i++)
		cin>>c[i];
	sort(a,a+X,greater<ll>());
	sort(b,b+Y,greater<ll>());
	sort(c,c+Z,greater<ll>());
	
	for(int i=0;i<X;i++)
	{
		for(int j=0;j<Y;j++)
		{
			for(int k=0;k<Z;k++)
			{
				if((i+1)*(j+1)*(k+1)<=K)
					ans.push_back(a[i]+b[j]+c[k]);
			}
		}
	}
	
	sort(ans.begin(),ans.end(),greater<ll>());
	for(int i=0;i<K;i++)
		cout<<ans[i]<<"\n";
	
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;

typedef string::const_iterator Iterator;

struct evaluator
{
  vector<int> all;
  vector<int> sets[5];

  vector<int> factor(Iterator& it, const Iterator& last) const
  {
    if (*it == '(') {
      ++it;
      const vector<int> r = expr(it, last);
      ++it;
      return r;
    } else {
      const int i = *it-'A';
      ++it;
      return sets[i];
    }
  }

  vector<int> term(Iterator& it, const Iterator& last) const
  {
    if (*it == 'c') {
      ++it;
      const vector<int> s = factor(it, last);
      vector<int> r;
      set_difference(all.begin(), all.end(), s.begin(), s.end(), back_inserter(r));
      return r;
    } else {
      return factor(it, last);
    }
  }

  vector<int> expr(Iterator& it, const Iterator& last) const
  {
    vector<int> r = term(it, last);
    while (it != last && (*it == 'u' || *it == 'i' || *it == 'd' || *it == 's')) {
      const char op = *it;
      ++it;
      const vector<int> l = term(it, last);
      vector<int> o;
      switch (op) {
        case 'u':
          set_union(r.begin(), r.end(), l.begin(), l.end(), back_inserter(o));
          break;
        case 'i':
          set_intersection(r.begin(), r.end(), l.begin(), l.end(), back_inserter(o));
          break;
        case 'd':
          set_difference(r.begin(), r.end(), l.begin(), l.end(), back_inserter(o));
          break;
        case 's':
          set_symmetric_difference(r.begin(), r.end(), l.begin(), l.end(), back_inserter(o));
          break;
      }
      swap(r, o);
    }
    return r;
  }
};

int main()
{
  while (!cin.eof()) {
    string name;
    int n;
    evaluator e;
    while (cin >> name >> n && name != "R") {
      vector<int>& s = e.sets[name[0]-'A'];
      for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        e.all.push_back(x);
        s.push_back(x);
      }
      sort(s.begin(), s.end());
    }
    sort(e.all.begin(), e.all.end());
    e.all.erase(unique(e.all.begin(), e.all.end()), e.all.end());

    string s;
    cin >> s;
    Iterator it = s.begin(), last = s.end();
    const vector<int> r = e.expr(it, last);
    if (r.empty()) {
      cout << "NULL" << endl;
    } else {
      for (vector<int>::const_iterator it = r.begin(); it != r.end(); ++it) {
        if (it != r.begin()) {
          cout << ' ';
        }
        cout << *it;
      }
      cout << endl;
    }

    cin.ignore();
    cin.peek();
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
  stack<int> S1;
  stack< pair < int,int> > S2;
  char ch;
  int sum = 0;
  for (int i=0; cin >> ch; i++ ) {
    if (ch == '\\' ) S1.push(i);
    else if ( ch =='/' && S1.size() > 0) {
      int j = S1.top(); S1.pop();
      sum += i-j;
      int a = i-j;
      while ( S2.size() > 0 && S2.top().first > j ){
        a += S2.top().second; S2.pop();
      }
      S2.push(make_pair(j,a));
    }
  }
  vector<int> ans;
  while (S2.size() > 0){ ans.push_back(S2.top().second); S2.pop(); }
  reverse( ans.begin(), ans.end() );
  cout << sum << endl;
  cout <<ans.size();
  for ( int i = 0; i<ans.size(); i++ ){
    cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3256
using System;

public class Test
{
	public static void Main()
	{
		int stps = 0;
		int a = 0;
		do{
			stps++;
			string line = System.Console.ReadLine();
			string[] ab = line.Split(' ');
			a = int.Parse(ab[0]);
			if(a == 0) break;
			Console.WriteLine("Case {0}: {1}",stps,a);
		}while(a!=0 );
	}
}

Measured memory_bytes: 9308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] w = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			w[i] = Integer.parseInt(sc.next());
			sum += w[i];
		}
		sc.close();

		int s1 = w[0];
		int s2 = sum - w[0];
		int ans = Math.abs(s2 - s1);
		for (int i = 1; i < N - 1; i++) {
			s1 += w[i];
			s2 -= w[i];
			ans = Math.min(ans, Math.abs(s2 - s1));
		}
		System.out.println(ans);

	}

}


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

using namespace std;

const int N = (int)1e5;

int n, k;
long long a[N+5], ans = (long long)2e15;

int main() {
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i+k-1 <= n; i++) {
		int l = i, r = i+k-1;
		ans = min(ans, a[r]-a[l]+min(abs(a[l]), abs(a[r])));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		
		long ans=n+(n*n)+(n*n*n);
		
		System.out.println(ans);
		
	}
	
}

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

#define N 100000

int head=0,tail=0;
int Qi[N];
char Qc[N][10];

void enq(char *s,int x){
  int i=0;
  if(isFull()){
    fprintf(stderr,"over flow\n");
    exit(1);
  }
  Qi[tail] = x;
  /*
  while(i<10&&s[i]!=NULL){
    printf("%s\n",s);
    Qc[tail][i]=s[i];
    i++;
  }*/
  strcpy(Qc[tail],s);
  
  if(tail+1 == N){
    tail = 0;
  }else{
    
    tail++;
  }
}

int deq(){
  int x;
  if(isEmpty()){
    fprintf(stderr,"empty\n");
    exit(2);
  }
  x = head;
  if(head + 1 == N){
    head = 0;
  }else{
    head++;
  }
  return x;
}

int isEmpty(){
  return head == tail;
}

int isFull(){
  return head == (tail + 1) % N;
}

void roundschedule(int n,int q){
  int i,num,sum=0,over;
  char name[10];
  for(i=0;i<n;i++){
    scanf("%s ",name);
    scanf("%d",&num);
    enq(name,num);
  }
 
  while(!isEmpty()){
     num=deq();
    if(q>=Qi[num]){
      sum+=Qi[num];
      printf("%s %d\n",Qc[num],sum);
    }else{
      over=Qi[num]-q;
      sum+=q;
      enq(Qc[num],over);
    }

  }
}

int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  roundschedule(n,q);
  return 0;
}



Measured memory_bytes: 3156
NN = 2020202
MOD = 10**9+7
INF = float("inf")

N = input()
K = int(input())
len_n = len(N)

dp0 = [[0] * 4 for _ in range(len_n)]  # not fixed
dp1 = [[0] * 4 for _ in range(len_n)]  # fixed
dp0[0][1] = 1
dp1[0][1] = int(N[0]) - 1
for i in range(len_n):
    dp1[i][0] = 1

for i in range(1, len_n):
    cur = int(N[i])
    for k in range(1, 4):
        if cur == 0:
            dp0[i][k] = dp0[i - 1][k]
            dp1[i][k] = dp1[i - 1][k] + 9*dp1[i - 1][k-1]

        else:
            dp0[i][k] = dp0[i - 1][k - 1]
            dp1[i][k] = dp1[i - 1][k] + 9*dp1[i - 1][k-1] + (cur - 1)*dp0[i - 1][k-1] + dp0[i - 1][k]

print(dp0[-1][K] + dp1[-1][K])

Measured memory_bytes: 38256
import sys
sys.setrecursionlimit(10**7)
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N = II()
    A = LI()

    rain = [None]*N
    rain[0] = 0
    for i in range(1,N):
        rain[i] = A[i-1] - rain[i-1]
    looped_ans = A[N-1] - rain[N-1]
    difference = looped_ans//2
    for i in range(N):
        if i%2 == 0:
            rain[i] += difference
        else:
            rain[i] -= difference

    print(' '.join([str(i*2) for i in rain]))


main()

Measured memory_bytes: 19084
#include <bits/stdc++.h>
 
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<long long int,long long int>
#define vi vector<long long int>
#define vll vector<ll>
#define vii vector<ii>
#define debug cout << "Ok" << endl;

using namespace std;
long long int group[100010];
bitset<100010>verified;
vector<long long int>val;
vector<vector<long long int>>f(100010);
vector<vector<long long int>>b(100010);

void dfs(long long int i, long long int gr){
	if(verified[i]==true) return;
	verified[i]=true;
	val[gr]++;
	group[i] = gr;

	for(long long int j=0;j<f[i].size();j++){
		dfs(f[i][j], gr);
	}


	return;
}



int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	long long int n,m,k,a,c;

	cin >> n >> m >> k;

	while(m--){
		cin >> a >> c;
		f[a].push_back(c);
		f[c].push_back(a);
	}

	while(k--){
		cin >> a >> c;
		b[a].push_back(c);
		b[c].push_back(a);
	}

	long long int cont=0;
	for(long long int i=1;i<=n;i++){
		if(verified[i]==false){
			val.push_back(0);
			dfs(i,cont);
			cont++;
		}
	}

	for(long long int i=1;i<=n;i++){
		cont = val[group[i]] - f[i].size();
		long long int g = group[i];

		for(long long int j=0;j<b[i].size();j++){
			if(g == group[b[i][j]])
				cont--;
		}

		cout << cont-1 << (i==n ? "\n": " ");
	}

	return 0;
}

Measured memory_bytes: 17088
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <map>
#include <cmath>
#include <math.h>

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

using namespace std;

int main(void)
{
	int j= 0; 
	char S[100]={0};
  ULL K;
	
	cin >> S;
	
	cin >> K;

	
	do{
	
		if(S[j] == '1'){
			K--;
			if(K == 0) break;
		}
		else {
			break;
		}
		j++;
	}while(S[j]!= 0);

	printf("%c\n",S[j]);

	return 0;
}

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

using namespace std;

int main()
{
  string s;
  int m = 0;

  while ( cin >> s && s != "-" )
    {
      int sn = s.size();
      int n, m, l;
      int sum = 0;
      
      s += s;
      
      cin >> n;
      
      for ( int i = 0; i < n; i++ )
        {
          cin >> m;
          sum += m;
        }

      l = sum % sn;

      cout << s.substr(l, sn) << endl;
    }
  
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>

using namespace std;

int main()
{
	int w;
	while (cin >> w) {
		bool first_output = true;
		for (int weight = 1; w>0; w>>=1, weight<<=1) {
			if ((w&1)==1) {
				if (!first_output) cout << " ";
				cout << weight;
				first_output = false;
			}
		}
		cout << endl;
	}
	
	return 0;
}

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

int main()
{
  string s; cin >> s;

  int bucket[26] = {0};
  char ans;
  bool is_all = true;
  bool is_fetched = false;

  rep(i, s.size()) {
    bucket[s[i]-'a'] += 1;
  }
  rep(i, 26) {
    if (!bucket[i] && !is_fetched) {
      ans = i+97;
      is_all = false;
      break;
    }
  }

  if (is_all) {
    cout << "None" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) (v.begin(),v.end())
#define ff first
#define ss second


int main(){
	fast;
	ll n,i,j,k;
	cin>>n;
	set<ll> d1,a;
	for(i=1;i*i<=(n-1);++i){
		if((n-1)%i==0){
			d1.insert(i);
			d1.insert((n-1)/i);
		}
		
	}
	for(ll x : d1){
		if(n%x==1)
			a.insert(x);
	}
	set<ll> d2;
	for(i=1;i*i<=n;++i){
		if(n%i==0){
			d2.insert(i);
			d2.insert(n/i);
		}
			
	}
	for(ll x : d2){
		ll t=n;
		//cout<<x<<" ";
		while(true){
			if(t%x!=0 || x==1)
				break;
			t/=x;
		}
		if(t%x==1)
			a.insert(x);
	}
	cout<<a.size();
	
}

Measured memory_bytes: 512
#include <stdio.h>
 
int main() {
  int n;
  int b, f, r, v;
  int i, j, k;
 
  int t[4][3][10] = {{{}}};
 
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d %d %d %d", &b, &f, &r, &v);
    t[b-1][f-1][r-1] += v;
  }
 
  for(i = 0; i < 4; i++) {
    for(j = 0; j < 3; j++) {
      for(k = 0; k < 10; k++) {
    printf(" %d", t[i][j][k]);
      }
      printf("\n");
    }
    if(i != 3) printf("####################\n");
  }
 
  return 0;
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define all(x) x.begin(), x.end()

typedef pair<int, int> pi;
typedef long long ll;
const int MAX_INT = 2000000000;

int dp[100001];
int h[100001];

int cost(int i, int j)
{
    return abs(h[i] - h[j]);
}

int main()
{
    int N;
    cin >> N;
    FOR(i, 1, N)
    {
        cin >> h[i];
    }

    dp[N] = 0;
    dp[N - 1] = cost(N - 1, N);

    for (int i = N - 2; i >= 1; i--)
    {
        dp[i] = min(cost(i, i + 1) + dp[i + 1], cost(i, i + 2) + dp[i + 2]);
    }

    cout << dp[1];

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(c>=a&&c<=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    REP(i, N) { REP(j, D) cin >> X[i][j]; }
    int ans = 0;
    REP(n1, N) {
        FOR(n2, n1 + 1, N) {
            int sum = 0;
            REP(j, D) {
                sum += abs(X[n1][j] - X[n2][j]) * abs(X[n1][j] - X[n2][j]);
            }
            REP(i, 1000) {
                int po = i * i;
                if (po == sum) {
                    ans++;
                    break;
                }
            }
        }
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

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

    using P = pair<ll, int>;
    vector<P> v(n);
    rep(i, n) cin >> v[i].second >> v[i].first;

    sort(rall(v));

    ll ans = 0;
    vector<int> c(n+1);
    priority_queue<P, vector<P>, greater<P>> s;
    rep(i, k){
        ans += v[i].first;
        if(c[v[i].second] == 0){
            c[v[i].second] = 1;
        } 
        else s.push({v[i].first, v[i].second});
    }

    ll sum = ans;

    ll kind = 0;
    rep(i, n+1) kind += c[i];
    ans += kind*kind;

    for(int i=k; i<n; i++){
        if(s.size() == 0) break;
        ll d, t;
        tie(d, t) = s.top();
        if(c[v[i].second] != 1){
            s.pop();
            sum += v[i].first - d;
            c[v[i].second] = 1;
            kind++;
            ans = max(ans, sum + kind*kind);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3320
#include <cstdio>

int main(void) {
	char s[5];

	scanf("%s", s);
	for(int i = 0; i < 4; i++) {
		if(s[i] == s[i + 1]) {
			printf("Bad\n");
			return 0;
		}
	}
	printf("Good\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>; // グラフ型

int main()
{
    int n, d; cin >> n >> d;
    int cnt = 0;

    rep(i,n){
        ll x,y;
        cin >> x >> y;
        if( sqrt(x*x+y*y) <= d) cnt++;
    }
    
    cout << cnt << endl;
}



/*
g++ b.cpp
./a.out

oj d https://atcoder.jp/contests/abc172/tasks/abc172_c
oj t
*/


Measured memory_bytes: 3672
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
cnt1=0
cnt2=0
j=1
import itertools
for i in itertools.permutations(range(1,n+1)):
    if list (i)==p:
        a=j
    if list(i)==q:
        b=j
    j+=1
print(abs(a-b))

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

using namespace std;

using ll = long long;

const ll INF = 2e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, K;
    cin >> n >> m >> K;
    vector<ll> a(n);
    vector<ll> dp(n, -INF);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        dp[i] = a[i];
    }

    for (int i = 2; i <= K; i++) {
        vector<ll> ndp(n, -INF);
        deque<int> q;
        for (int j = 0; j < n; j++) {
            while (!q.empty()) {
                if (j - q.front() > m) q.pop_front();
                else break;
            }
            if (!q.empty()) {
                ndp[j] = dp[q.front()] + i * a[j];
            }

            while (!q.empty()) {
                if (dp[q.back()] <= dp[j]) q.pop_back();
                else break;
            }
            q.push_back(j);
        }
        dp = move(ndp);
    }
    
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}

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

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

    ll a = n%10;
    ll b = n/10;
    ll c = b%10;
    ll d = b/10;

    if((a==7||c==7)||d==7){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }


    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int n, m, u, v, deg[100007], dp[100007], ans = 0;
vector <int> edge[100007];
queue <int> q;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		edge[u].pb(v);
		deg[v]++;
	}
	for(int i = 1; i <= n; i++){
		if(deg[i] == 0){
			q.push(i);
		}
	}
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v : edge[u]){
			dp[v] = max(dp[v], dp[u] + 1);
			deg[v]--;
			if(deg[v] == 0) q.push(v);
		}
		ans = max(ans, dp[u]);
	}
	cout << ans;
}


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

int main() {
  long N, X, M;
  cin >> N >> X >> M;

  vector next(60, vector(M, 0L));
  auto sum = next;
  for (int i = 0; i < M; i++) {
    next.at(0).at(i) = (long) i * i % M;
    sum.at(0).at(i) = i;
  }

  for (int i = 0; i + 1 < 60; i++) {
    for (int j = 0; j < M; j++) {
      next.at(i + 1).at(j) = next.at(i).at(next.at(i).at(j));
      sum.at(i + 1).at(j) = sum.at(i).at(j) + sum.at(i).at(next.at(i).at(j));
    }
  }

  long ans = 0;
  for (int i = 0; i < 60; i++) {
    if (N >> i & 1) {
      ans += sum.at(i).at(X);
      X = next.at(i).at(X);
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 97172
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    string N;
    cin >> N;
    for(int i=0; i<3; i++){
        if(N[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

string a;

int read() {
    int ret, fl = 1;
    char ch;
    while(!isdigit(ch = getchar())) (ch == '-') && (fl = -1);
    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');
    return ret * fl;
}

void print(int x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

int main() {
    read();
    cin >> a;
    int num = 0, l = 0, r = 0;
    for(auto i : a) {
        // if(i == '(' && num >= 0) ++r;
        if(i == ')' && !num) ++l;
        num += i == '(' ? 1 : -1;
        num = max(0, num);
    }
    for(int i = 1; i <= l; ++i) putchar('(');
    cout << a;
    for(int i = 1; i <= num; ++i) putchar(')');
    return 0;
}

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

int main() {
	int w, h;
	do {
		cin >> h >> w;
		if (h == 0 && w == 0)
			break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	} while (w != 0 || h != 0);
	return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
// const ll MOD = 1e9+7;
const ll mod =998244353;
#define REP(i,j,n) for(int i=j;i<n;i++)
#define rep(i,n) REP(i,0,n)


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,k;
    cin >> n >> k;
    int lr[k][2];

    rep(i,k) 
    {
        cin >> lr[i][0] >> lr[i][1];
    }
    ll dp[n+2];
    ll wa[n+2];
    rep(i,n+2)
    {
        dp[i] = 0;
        wa[i] = 0;
    }
    dp[0] = 1;

    REP(i,1, n+2)
    {
        wa[i] = wa[i-1] + dp[i-1];
        wa[i] += mod;
        wa[i]%=mod;
        rep(j,k)
        {
            dp[i] += wa[max(0, i-lr[j][0]+1)] - wa[max(0, i-lr[j][1])];
            dp[i]+=mod;
            dp[i]%=mod;
        }
    }

    // rep(i,n)
    // {
    //     cout << dp[i] << endl;
    // }
    // cout << "wa" << endl;
    // rep(i,n+1)
    // {
    //     cout << wa[i] << endl;
    // }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 6740
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int A,B,X;
    cin>>A>>B>>X;
    if(A>X) cout<<"NO"<<endl;
    else if(A==X) cout<<"YES"<<endl;
    else if(A<X) {
        if((A+B)<X) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
}

Measured memory_bytes: 256
/*
AUTHOR: Aman Raj
LANG: C++
*/

using namespace std;

typedef   long long  ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
#define mod 998244353
#define inf 1e9
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, ll, hash<ll> > ht;

// find_by_order()  // order_of_key
typedef tree<
    int,
    null_type,
    less<long long int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c=c%mod;if(b%2==1) c*=a;c=c%mod;
        return c;
   }
  /* ll mi(ll a,ll m)
   { ll c= power1(a,m-2,mod);

     return c;
   }
*/


  int main()
{    fast;
     ll n,m,x;cin>>n>>m>>x;
      vector<ll> vcost(n);
       vector<vector<ll> > vval(n);
        for(ll i=0;i<n;i++)
        {
            cin>>vcost[i];
             for(ll j=0;j<m;j++)
             {  ll a;cin>>a;
                vval[i].push_back(a);

             }
        }
         ll ans=1e12;
         for(ll a=0;a<power1(2,n);a++)
         {  ll tans=0;
           vector<ll> vgyan(m);
             for(ll books=0;books<n;books++)
             {
                  if(((1<<books)&a)!=0)
                  { //if(a==6)cout<<books<<endl;
                      tans+=vcost[books];
                       for(ll i=0;i<m;i++)
                        vgyan[i]+=vval[books][i];

                  }
             }
             bool ok=true;
             for(ll i=0;i<m;i++){ if(vgyan[i]<x)ok=false; }
             //if(a==6)for(auto x:vgyan)cout<<x<<" ";
             if(ok)ans=min(ans,tans);
         }
         if(ans==1e12)cout<<-1<<endl;
         else cout<<ans<<endl;

      return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;
#define mp make_pair
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=1612345678;
const ll LLINF=1012345678012345678LL;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int b[2005],w[2005];
int cb[2005][4005],cw[2005][4005]; //number of b/w that is >i but position <j
int dp[2005][2005];

int main(){
	int n;
	scanf("%d",&n);
	char c[5]; int arr[2*n];
	for(int i=0;i<2*n;i++){
		scanf(" %s%d",c,&arr[i]);
		if(c[0]=='B'){b[arr[i]]=i;arr[i]*=-1;}
		else w[arr[i]]=i;
	}
	for(int i=0;i<=n;i++){
		int xb=0,xw=0;
		for(int j=0;j<2*n;j++){
			cb[i][j]=xb;cw[i][j]=xw;
			if(arr[j]<0&&-arr[j]>i)xb++;
			if(arr[j]>0&&arr[j]>i)xw++;
		}
	}
	//for(int i=0;i<=n;i++){for(int j=0;j<2*n;j++)printf("%d ",cb[i][j]);printf("\n");}printf("\n");
	//for(int i=0;i<=n;i++){for(int j=0;j<2*n;j++)printf("%d ",cw[i][j]);printf("\n");}
	for(int i=0;i<2005;i++)for(int j=0;j<2005;j++)dp[i][j]=INF;
	//taken 1 to i black and 1 to j white
	dp[0][0]=0;//printf("0 ");
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(i==0&&j==0)continue;
			if(i==0){
				dp[i][j]=dp[i][j-1]+cb[i][w[j]]+cw[j-1][w[j]];
			}else if(j==0){
				dp[i][j]=dp[i-1][j]+cb[i-1][b[i]]+cw[j][b[i]];
			}else{
				dp[i][j]=min(dp[i-1][j]+cb[i-1][b[i]]+cw[j][b[i]],dp[i][j-1]+cb[i][w[j]]+cw[j-1][w[j]]);
			}
			//printf("%d ",dp[i][j]);
		}
		//printf("\n");
	}
	printf("%d",dp[n][n]);
}


Measured memory_bytes: 78592
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

typedef long long LL;
const int MaxN = 1e5;
LL sum;
int n;
LL a[2 * MaxN + 5];
LL q[2 * MaxN + 5];

int main()
{
	while(~scanf("%d",&n)){
		sum = 0;
	LL ans = 1LL << 60;
	LL fir,sec,num;
	for(int i = 1;i <= n;i++){
		scanf("%lld",&a[i]);
		sum += a[i];
	}
	for(int i = 1;i <= n;i++)
		q[i] = q[i-1] + a[i];
	if(n == 2)printf("%lld\n",abs(a[1] - a[2]));
else if(n > 2){
	for(int i = 2;i <= n-1;i++)
	{
		num = abs((sum - q[i]) - q[i]);
		ans = min(ans,num);
	}
	printf("%lld\n",ans);
}
	memset(a,0,sizeof(a));
	memset(q,0,sizeof(q));
}
return 0;
}

Measured memory_bytes: 3328
import java.util.ArrayList;
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    int n,m;
    ArrayList<Integer> score = new ArrayList<>();
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    m = sc.nextInt();
    int x;
    double border = 0;
    for(int i=0;i<n;i++){
      score.add(sc.nextInt());
      border+=score.get(score.size()-1);
    }
    border/=4*m;
    int list = 0;
    for(int i=0;i<score.size();i++){
      if(score.get(i)>=border)
        list++;
    }
    if(list>=m)
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}

Measured memory_bytes: 23892
#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=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

static const double INF = 1e20;
static const double EPS = 1e-7;

typedef complex<double> P;

inline double dot(P a, P b) { return real(conj(a)*b); }

struct L : public vector<P> {
	L(P a, P b) {
		push_back(a); push_back(b);
	}
};

inline bool intersectSP(const L &s, const P &p) {
	return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS;
}

inline P projection(const L &l, const P &p) {
	double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}

inline double distanceSP(const L &s, const P &p) {
	const P r = projection(s, p);
	if (intersectSP(s, r)) return norm(r - p);
	return min(norm(s[0] - p), norm(s[1] - p));
}

inline P in(){
	double x,y;
	cin >>x >>y;
	return P(x,y);
}

signed main() {
	int N, M;
	cin >> N >> M;
	vector<P> p(N + 1);
	p[0] = in();
	rep2(i, 1, N + 1) {
		p[i] = in();
	}
	vector<bool> is_kyoten(N + 1);
	is_kyoten[0] = true;
	rep(i, N) is_kyoten[i + 1] = false;

	vector<double> d_points(N + 1);
	vector<double> d_seg(N + 1);

	rep(i, N + 1) {
		d_points[i] = 0;
		d_seg[i] = 0;
	}

	double ans = 0;

	double mi = INF;
	int id_mi = 0;
	rep2(i, 1, N + 1) {
		d_points[i] = norm(p[i] - p[0]);
		if (d_points[i] < mi -EPS ) {
			mi = d_points[i];
			id_mi = i;
		}
	}

	ans += abs(p[id_mi] - p[0]);

	is_kyoten[id_mi] = true;
	L l = L(p[0], p[id_mi]);
	rep2(i, 1, N + 1) {
		d_seg[i] = distanceSP(l, p[i]);
	}

	rep(t, M - 1) {
		// ?¶????????????????????????¢???
		double mi = INF;
		int id_food = 0;
		rep2(i, 1, N + 1) {
			if (!is_kyoten[i] && d_seg[i] < mi -EPS ) {
				mi = d_seg[i];
				id_food = i;
			}
		}

		mi = INF;
		int id_kyoten = -1;
		rep(i, N + 1) {
			if (is_kyoten[i]) {
				double dist = norm(p[i] - p[id_food]);
				if (dist < mi -EPS ) {
					mi = dist;
					id_kyoten = i;
				}
			}
		}

		ans += abs(p[id_kyoten] - p[id_food]);

		L l = L(p[id_kyoten], p[id_food]);
		rep(i, N + 1) {
			d_seg[i] = min(d_seg[i], distanceSP(l, p[i]));
		}

		is_kyoten[id_food] = true;


	}

	printf("%.10f\n", ans);

}

Measured memory_bytes: 3396
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node{
  int key;
  struct Node *right, *left, *parent;
}; 
struct Node *root, *NIL; 
struct Node * treeMinimum(struct Node *x){
  while(x->left != NIL) x = x->left;
  return x;
}
struct Node * find(struct Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
} 
struct Node * treeSuccessor(struct Node *x){
  if(x->right != NIL) return treeMinimum(x->right);
  struct Node *y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}
void treeDelete(struct Node *z){
  struct Node *y;
  struct Node *x;
 
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
 
  if(y->left != NIL) x = y->left;
  else x = y->right;
 
  if(x != NIL) x->parent = y->parent;
 
  if(y->parent == NIL) root = x;
  else{
    if(y == y->parent->left) y->parent->left = x;
    else y->parent->right = x;
  }
 
  if(y != z) z->key = y->key;
 
  free(y);
}
void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;
 
  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}
 
void inorder(struct Node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
 
void preorder(struct Node *u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
 
int main(){
  int n, i, x;
  char com[10];
 
  scanf("%d", &n);
 
  for(i = 0; i < n; i++){
    scanf("%s", com);
    if(com[0] == 'f'){
      scanf(" %d", &x);
      struct Node *t = find(root, x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com[0] == 'i'){
      scanf(" %d", &x);
      insert(x);
    }
    else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com[0] == 'd'){
      scanf(" %d", &x);
      treeDelete(find(root, x));
    }
  }
  return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

bool ac_flg = false;

int count_ac(vector<string> &vec)
{
    for (const auto& s : vec) {
        if (s == "AC") {
            ac_flg = true;
            return 1;
        }
    }
    return 0;
}

int count_wa(vector<string> &vec)
{
    if (ac_flg) {
        int wa_cnt = 0;
        for (const auto& s : vec) {
            if (s == "AC") return wa_cnt;
            ++wa_cnt;
        }
        return wa_cnt;
    }
    return 0;
}

int main()
{
    int N, M; cin >> N >> M;
    map<int, vector<string>> map;
    rep (i, 0, M) {
        int p;
        string S;
        cin >> p >> S;
        map[p].push_back(S);
    }

    int ac_cnt = 0, wa_cnt = 0;
    for (auto mp : map) {
        ac_flg = false;
        ac_cnt += count_ac(mp.second);
        wa_cnt += count_wa(mp.second);
    }

    cout << ac_cnt << " " << wa_cnt << endl;
}

Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{

	int A, B;
	cin >> A >> B;
	
	int coin = 0;

	if (A >= B) {
		coin = A;
		A = A - 1;
	}
	else {
		coin = B;
		B = B - 1;
	}

	if (A >= B) {
		coin = coin + A;
		A = A - 1;
	}
	else {
		coin = coin +B;
		B = B - 1;
	}


	std::cout << coin; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
#define ma 500000
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                             //n is odd
        return x*power(x*x,(n-1)/2);
}
int highestPowerof2(int n)
{
   int p = (int)log2(n);
   return (int)pow(2, p);  
}
ll powermod(ll x, ll y, ll p)  
{  
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;  
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}
 
int main()
{
    ll n,i,c=0;
    cin>>n;
    ll a[n+1];
    for(i=1;i<=n;i++)
    cin>>a[i];
    
    for(i=1;i<=n;i++)
    {
        if(i%2!=0&&a[i]%2!=0)
        {
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3676
n = int(input())
c = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
  p = int(str(i)[0])
  q = int(str(i)[-1])
  c[p][q] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans += c[i][j] * c[j][i]

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 25
typedef struct node{
  int p;//parents
  int left;
  int right;
  int sib;
  int deg;
}Node;
void depth(int,int);
int height(int,int);
Node node[MAX];//nodeの大きさ
int D[MAX];
int H[MAX];
int main(){
  int n,i,num,j,tmp;
 scanf("%d",&n);//節の入力
  for(i=0;i<n;i++){//初期化
    node[i].p=-1;
    node[i].left=-1;
    node[i].right=-1;
    node[i].sib=-1;
    node[i].deg=0;
  }
  for(i=0;i<n;i++){
    scanf("%d",&num);
    for(j=0;j<2;j++){
      scanf("%d",&tmp);
      if(j==0){
	if(tmp!=-1){
	node[num].left=tmp;
	node[num].deg++;
	}
      }
      else{
	if(tmp!=-1){
	 node[num].right=tmp;
	 node[num].deg++;
	}
	if(node[num].left!=-1){//左側の要素が存在するとき	 
	  node[node[num].left].sib=node[num].right;
	}
	if(node[num].right!=-1){//右側の要素が存在するとき
	  node[node[num].right].sib=node[num].left;
	}

	
      }
      if(tmp!=-1){
      node[tmp].p=num;
      }
    }
    
  }
for(i=0;i<n;i++){
    if(node[i].p==-1){
      
      depth(i,0);
   
     
    }
  H[i]=  height(i,0);
 }

  
   for(i=0;i<n;i++){
     printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,node[i].p,node[i].sib,node[i].deg,D[i],H[i]);
     if(node[i].left==-1 && node[i].right==-1 && node[i].p!=-1){
       printf("leaf\n");
     }
     else if(node[i].p==-1){
       printf("root\n");
     }
     else {
       printf("internal node\n");
     }
     
   }
   return 0;
}
void depth(int u,int p){
  D[u]=p;
   if(node[u].left !=-1){
    depth(node[u].left,p+1);
   
    }
    if(node[u].right!=-1){
    depth(node[u].right,p+1);
   
     }
}
int height(int u, int p){
  int i=0,j=0;
  if(node[u].left==-1 &&node[u].right==-1){//reafの時高さ0
    return 0;
  }
  if(node[u].left!=-1){//左に移動
      i=height(node[u].left,p+1);
    }
  if(node[u].right!=-1){//右に移動
      j= height(node[u].right,p+1);     
    }
  if(i>=j)return i+1;//i+1,j+1を返すことでその時の高さが分かる
    else return j+1;
    
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

int main(){
	ll N,Q;
	cin >> N >> Q;
	ll a[N];
	FOR(i,0,N)cin >> a[i];
	FOR(q,0,Q){
		ll x,ans=0,sum=a[0],l=0,r=1;
		cin >> x;
		FOR(i,0,N){
			while(sum<=x && r<N){
				sum += a[r];r++;
			}
			if(sum>x){
				ans += r-l-1;
			}else{
				ans += r-l;
			}
			sum -= a[l];
			l++;
		}
		cout << ans << endl;
	}



}


Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
int My_Abs(int data[],int t,int n){
    
    int r=0,l=0;
    for(int i = 0;i<t;i++) l+= data[i];
    for(int i = t;i<n;i++) r+= data[i];
    return abs(r-l);
}
int main(void){
   
    int N,ans = 0;
    cin >> N;
    int data[N];
    
    for(int i=0;i<N;i++) cin >> data[i];
    
    for(int t=0;t<N;t++){
        if(t == 1) ans = My_Abs(data,t,N);
        else{
            int v = My_Abs(data,t,N);
            if(ans > v) ans = v;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){

  int a,b,c;
  cin >> a >> b >> c;
  bool flag = false;
  for(ll i = 1;i <= b+1;i++){
    if(a*i%b == c)flag = true;
  }
  flag ? cout << "YES" << endl : cout << "NO" << endl;




  

  return 0;
}


Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))

ps = sorted(p)

if p == ps:
    print('YES')
else:
    count = 0
    for i in range(len(ps)):
        if ps[i] != p[i]:
            count += 1

    if count == 2:
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 2940