akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define MAX 100005
#define NIL -1

typedef struct
{
  int parent;
  int left; //左の子
  int right; //右の兄弟
}node;

node T[MAX];
int D[MAX];

void print(int u)
{
  int i,c;

  printf("node %d: parent = %d, depth = %d, ",u,T[u].parent,D[u]);

  if(T[u].parent == NIL) printf("root, ");
  else if(T[u].left == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i = 0,c = T[u].left ; c != NIL ; i++,c = T[c].right)
    {
      if(i) printf(", ");
      printf("%d",c);
    }
  printf("]\n");

  return;
}

void depth(int u,int p)
{
  D[u] = p;

  if(T[u].right != NIL) depth(T[u].right,p);
  if(T[u].left != NIL) depth(T[u].left,p+1);

  return;
}

int main()
{
  int i,j,k,n,id,sib,child,root=NIL;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) //データの初期化
    {
      T[i].parent = NIL;
      T[i].left = NIL;
      T[i].right = NIL;
    }

  for(i = 0 ; i < n ; i++)
    {
      scanf("%d %d",&id,&k);

      for(j = 0,sib = NIL ; j < k ; j++)
	{
	  scanf("%d",&child);
	  T[child].parent = id;
	  if(j == 0) T[id].left = child; //一番左
	  else T[sib].right = child; //左の兄弟と繋ぐ

	  sib = child; //次の子の左の兄弟
	}
    }

  for(i = 0 ; i < n ; i++) //root の探索 (初期化した値)
    {
      if(T[i].parent == -1) root = i;
    }

  depth(root,0); //depth

  for(i = 0 ; i < n ; i++) //表示
    {
      print(i);
    }
    
  return 0;
}



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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N;
    Scd(N);
    using pii = pair<ll,ll>;
    vector<pii> a(N);

    int x,y;
    Rep(i,N){
        Scd2(x,y);
        a[i] = pii(y,x);
    }

    sort( a.begin(), a.end() );

    ll t = 0;
    bool fail = false;
    Rep(i,N){
        t += a[i].second;
        if( t > a[i].first ) fail = true;
    }

    YesNo(!fail);


    return 0;
}


Measured memory_bytes: 3328
from math import ceil
n=int(input())
p=list(map(int,input().split()))
m=[]
l=[0]*n
for i in range(n):
    if p[i]==i+1:
        l[i]=1
# print(l)
t=0
for i in range(n):
    if i==n-1:
        if l[i]==1:
            t+=1
        m.append(t)
        break

    if l[i]==1:
        t+=1
        if l[i+1]==1:
            continue
        m.append(t)
        t=0
# print(m)
ans=0
for mm in m:
    ans+=ceil(mm/2)
print(ans)


Measured memory_bytes: 13812
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
S=[0]*N
for i in range(N):
  S[i]=S[i-1]+A[i]
S=[0]+S
S=Counter(S)
a=[S[s]*(S[s]-1)//2 for s in S]
print(sum(a))

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

template<typename T>
static inline void chmin(T & ref, const T  value) {
	if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
	if (ref < value) ref = value;
}

int main() {
	ll n;
	cin >> n;
	vector<ll> as(n+2);
	as[0] = 300;
	as[n + 1] = 0;
	rep(i, n) cin >> as[i+1];
	vector<int> act(n + 2, 0);
	for (int i = 0; i < n; i++) {
		if (as[i + 1] <= as[i] and as[i + 1] <= as[i + 2]) {
			act[i + 1] = 1;
		}
		else if (as[i + 1] >= as[i] and as[i + 1] >= as[i + 2]) {
			act[i + 1] = -1;
		}
	}
	ll own = 1000;
	for (int i = 1; i <= n; i++) {
		if (act[i] == 1) {
			bool found = false;
			for (int j = i + 1; j <= n; j++) {
				if (act[j] == -1) {
					ll has = own / as[i];
					own -= has * as[i];
					own += has * as[j];
					i = j;
					found = true;
					break;
				}
			}
			if (found) continue;
		}
	}
	cout << own << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n, k;
	bool ans = false;
	cin >> n >> k;
	vector<int>a(n);
	rep(i,n)cin >> a[i];
	rep(i, n - k) {
		if (a[i] < a[i + k])ans = true;
		else ans = false;

		if (ans) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 4048
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

t = [(x + l, x - l) for x, l in XL]
t.sort()
max_r = -float('inf')
result = 0
for i in range(N):
    r, l = t[i]
    if max_r <= l:
        result += 1
        max_r = r
print(result)

Measured memory_bytes: 41044
N = int(input())
ans = "No"
tmp = 0
for i in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        tmp += 1
        if tmp == 3:
            ans = "Yes"
            break
    else:
        tmp = 0
print(ans)

Measured memory_bytes: 62356
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


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

    int x, y;
    cin >> x >> y;
    for (int i = 0; i <=100; i++)
    {
        for (int j = 0; j <=100; j++)
        {
            if(i+j==x && 2*i +4*j==y){
                cout << "Yes" << endl;
                return 0;
            }
        }
        
    }
    cout << "No" << endl;
    return 0;

    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
void insertionSort(int *a,int n){
    int j,v;
    for(int i=1;i<n;i++){
        v = a[i];
        j = i - 1;
        while (j >= 0 && a[j] > v)
        {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        for (int i = 0; i < n; i++)
        {
            if(i > 0) printf(" ");
            printf("%d",a[i]);
        }
        printf("\n");
        
    }
}
int main(){
    int n;
    scanf("%d",&n);
    int a[100];
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for (int i = 0; i < n; i++)
        {
            if(i > 0) printf(" ");
            printf("%d",a[i]);
        }
        printf("\n");
    insertionSort(a,n);

}


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

#define int long long

using namespace std;

const int maxn = 1e7 + 9, mod = 998244353;
int fac[maxn], tw[maxn], ifac[maxn], n;

int pw(int base, int power)
{
    int res = 1;
    while (power) {
        if (power & 1)
            (res *= base) %= mod;
        (base *= base) %= mod;
        power >>= 1;
    }
    return res;
}

int C(int n, int k) { return fac[n] * ifac[k] % mod * ifac[n - k] % mod; }

signed main()
{
    ios::sync_with_stdio(false);
    cin >> n;

    fac[0] = 1;
    for (int i = 1; i < maxn; i++)
        fac[i] = fac[i - 1] * i % mod;
    ifac[maxn - 1] = pw(fac[maxn - 1], mod - 2);
    for (int i = maxn - 2; ~i; i--)
        ifac[i] = ifac[i + 1] * (i + 1) % mod;
    tw[0] = 1;
    for (int i = 1; i < maxn; i++)
        tw[i] = tw[i - 1] * 2 % mod;

    int ans = pw(3, n);
    for (int i = n / 2 + 1; i <= n; i++) {
        (ans += mod - C(n, i) * tw[n - i + 1] % mod) %= mod;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 234624
#include<iostream>
using namespace std;
int main(){
	int s[20]={0,1,3,1,2,1,2,1,1,2,1,2,1};
	int a,b;
	cin>>a>>b;
	if(s[a]==s[b]){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


/*
--------------------------------------------

	type

--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;

/*
--------------------------------------------

	container

--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())

/*
--------------------------------------------

	repetition

--------------------------------------------
*/
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

/*
--------------------------------------------

	constant

--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

/*

	Optimizer

*/
//#pragma GCC optimize("Ofast")


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

  int N,K;
  cin >> N >> K;

  int x;
  int ans = 0;
  REP(N) {
    cin >> x;
    if(x < abs(x - K)) {
      ans += (2*x);
    }
    else {
      ans += (2*abs(x-K));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// AOJ 2020: Princess's Japanese
// 2017.12.12 bal4u@uu

#include <stdio.h>
#include <string.h>

char bo['z'+1]; char *sbo = "aiueo";
char mu['z'+1]; char *smu = "ksthp";
char buf0[110], *buf = buf0 + 5;
char ans[103];

int main()
{
	int f, g;
	char *p, *q;

	p = sbo; while (*p) bo[*p++] = 1;
	p = smu; while (*p) mu[*p++] = 1;
	while (1) {
		memset(buf0, 0, sizeof(buf));
		fgets(buf, 103, stdin);
		if (*buf == '#') break;

		q = ans, f = 0;
		for (p = buf; *p > ' '; p++) {
            if (f && bo[*p]) { *q++ = *p, f = 0; continue; }
            g = mu[*(p-1)] || (*(p-1) == 'y' && (mu[*(p-2)]));
            if (g && (*p == 'i' || *p == 'u') && (*(p+1) < ' ' || mu[*(p+1)])) {
				*q++ = '(', *q++ = *p, *q++ = ')', f = 1; continue;
			}
            if (g && (*p == 'a' || *p == 'o') && mu[*(p+1)] && 
				(*(p+2) == *p || *(p+2) == 'y' && *(p+3) == *p)) {
				*q++ = '(', *q++ = *p, *q++ = ')', f = 1; continue;
            }
            *q++ = *p;
        }
		*q = 0;
        puts(ans);
    }
    return 0;
}

Measured memory_bytes: 1676
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    long int n;
    cin >> n;
    long int t[n], a[n];
    rep(i, n) cin >> t[i] >> a[i];
    long int ans1 = t[0], ans2 = a[0];
    for(int i = 1; i < n; i++){
        long int m;
        if(ans1 % t[i] == 0) m = ans1 / t[i];
        else m = ans1 / t[i] + 1;

        if(ans2 % a[i] == 0) m = max(m, ans2 / a[i]);
        else m = max(m, ans2 / a[i] + 1);

        ans1 = t[i] * m;
        ans2 = a[i] * m;
    }
    cout << ans1 + ans2 << endl;
}


Measured memory_bytes: 256
using System;
namespace ConsoleApplication1{
    class Program{
        static void Main(string[] args){
            int n=int.Parse(Console.ReadLine());
            for(int i=0;i<n;i++){
                string[] str=Console.ReadLine().Split();
                double xa=double.Parse(str[0]);
                double ya=double.Parse(str[1]);
                double ra=double.Parse(str[2]);
                double xb=double.Parse(str[3]);
                double yb=double.Parse(str[4]);
                double rb=double.Parse(str[5]);
                double ab=Math.Sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya));
                Console.WriteLine(ab > ra + rb ? 0 : ab >= Math.Abs(ra - rb) ? 1 : ra > rb ? 2 : -2);
            }
        }
    }
}

Measured memory_bytes: 5692
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#define MOD 1000000007
using namespace std;
int main()
{
	int q;
	string s, s_front, s_back;
	//vector<short> query;
	bool reverse_ = false;
	int f;
	string c;
	cin >> s >> q;
	for (size_t i = 0; i < q; i++)
	{
		int query;
		cin >> query;
		if (query == 1) {
			reverse_ = !reverse_;
		}
		else {
			cin >> f >> c;
			if (f == 1&&!reverse_||f==2&&reverse_) {
				s_front = c + s_front;
			}
			else {
				s_back += c;
			}
		}
	}

	s = s_front + s + s_back;
	if (reverse_) {
		//reverse(s.begin(), s.end());
		//reverse(s_front.begin(), s_front.end());
		//reverse(s_back.begin(), s_back.end());
		reverse(s.begin(), s.end());
	}
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 1360
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  int k,s; cin >> k >> s;
  int ans = 0;
  rep(i,k+1){
    rep(j,k+1){
      if(0 <= s-i-j && s-i-j <= k) ans++;
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define int long long

#define TASKNAME ""

using namespace std;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("1.txt", "w", stdout);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());
    int ans = 0;
    if (n%2==1){
        for (int i=0; i <= n/2-2; i++){
            ans -= 2*v[i];
        }
        for (int i=n/2-1; i <= n/2; i++) ans -= v[i];
        for (int i=n/2+1; i < n; i++) ans += 2*v[i];
        int kek = 0;
        for (int i=0; i <= n/2-1;i++) kek -= 2*v[i];
        for (int i=n/2; i < n/2+2; i++) kek += v[i];
        for (int i=n/2+2; i < n; i++) kek += 2*v[i];
        ans = max(ans, kek);
    }
    else{
        for (int i=0;i<n/2-1;i++) ans -= 2*v[i];
        ans -= v[n/2-1];
        ans += v[n/2];
        for (int i=n/2+1; i < n; i++) ans += 2*v[i];
    }
    cout << ans;

}


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

int main() {
    int x;
    cin >> x;
    vector<bool>b(x+1);
    b[1]=1;
    for(int i=2;i<=x;i++){
        int v=i*i;
        while(v<=x){
            b[v]=1;
            v=v*i;
        }
    }
    for(int i=x;i>=1;i--){
        if(b[i]==1){
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define per(i,a,b) for (int i=(b)-1;i>=a;i--)
#define sz(a) (int) a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
//-----
int e[5][5];
int main() {
    int a[5];
    memset(a,0,sizeof(a));
    rep(i,0,3) {
        int u,v;scanf("%d%d",&u,&v);
        a[u]++;
        a[v]++;
    }
    int one = 0,two = 0;
    rep(i,1,5) {
        if(a[i] == 1) one++;
        else if(a[i] == 2) two++;
    }
    if(one == two &&one == 2) printf("YES\n");
    else printf("NO\n");
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  long double L;
  cin>>L;

  long double x=L/3.0;
  long double ans=x*x*x;

  cout<<fixed<<setprecision(10)<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import math

def cc(n, r):

    if n < r or n < 0 or r < 0:

        return 0

    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))




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

for i in range(K):

    i += 1

    if N - K < i - 1:
        print (0)

    else:

        ans = 0

        ans += cc(K-1,i-1)

        ans *= cc(N-K+1,i)

        print (ans % (10**9 + 7))

    

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

int main(void){
    int x;
    cin >> x;
    
    string s = "NO";
    if(x == 3 || x == 5 || x == 7) s = "YES";
    
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

r_cnt = S.count('R')
g_cnt = S.count('G')
b_cnt = S.count('B')

ans = r_cnt * g_cnt * b_cnt

for i in range(N):
    for d in range(N):
        j = i+d
        k = j+d
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    string s;
    string t;
    cin >> s;
    cin >> t;
    int ans = 0;
    REP(i, s.size()) {
        if (s[i] != t[i]) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3920
#include <iostream>
#include <cstring>
#include <cmath>

using namespace std;

const int N = 30005;
string endString = {"\0"};


// int lcs ( char* a, char* b, int da, int db ){
//   if ( da == 0 || db == 0 )
//     return 0;
//   if ( a[da - 1] == b[db - 1] ){
//     return 1 + lcs ( a, b, da - 1, db - 1);
//   }
//   return max ( lcs ( a, b, da - 1, db), lcs ( a, b, da, db - 1));
// }


string lcs ( string& a, string& b, int da, int db ){
   int dp[da + 1][db + 1];

   for (int i = 0; i <= da; i++ )
    for (int j = 0; j <= db; j++ ){
      if ( i == 0 || j == 0 )
        dp[i][j] = 0;
      else{
        if (a[i - 1] == b[j - 1])
         dp[i][j] = dp[i - 1][j - 1] + 1;
       else
         dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
    int i = da, j = db;
    char lcs[dp[da][db] + 1];
    lcs[dp[da][db]] = '\0';
    while ( i > 0 && j > 0 ){
      if ( a[i - 1] == b[j - 1]){
        lcs[dp[da][db] - 1] = a[i - 1];
        i --;
        j --;
        dp[da][db] --;
      }
      else{
        if ( dp[i - 1][j] > dp[i][j - 1])
          i --;
        else j --;
      }
    }
    string r = (string) lcs;
    return r;
}

int main (){

  string a, b;

  cin >> a >> b;

  string rez =  lcs ( a, b, a.size(), b.size());
  cout << rez;

  return 0;
}


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


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

    int length = S.size();

    int ans = 0;
    for (int i = 0; i < S.size(); ++i) {
        --length;
        if (length % 2 != 0) continue;
        else {
            int cnt = 0;
            for (int j = 0; j < length/2; ++j) {
                if (S[j] == S[j+length/2]) ++cnt;
                else break;
            }
            if (cnt == length/2) {ans = cnt*2; break;}
        }
    }

    cout << ans << endl;

}

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

int main()
{
	double x, h, s;

	cout<<setprecision(6);
	cout<<setiosflags(ios::fixed);
	while (cin>>x>>h, x||h) {
		s = 4.0*x*sqrt(x*x/2.0/2.0+h*h)/2.0 + x*x;
		cout<<s<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
class Trie():
	def __init__(self,arrRev):
		self.node = [ [] for _ in range(len(arrRev)) ]
		# self.children = [ [ -1 for _ in range(ord('z')-ord('a'))] for _ in range(10**6+1) ]
		self.children = [ {} for _ in range(10**6+1) ]
		self.isHeadCharNode = [ False for _ in range( 10**6+1 ) ]
		nodeNumbering = 1
		for i,s in enumerate(arrRev):
			currentNode = 0
			for j,c in enumerate(list(s)):
				self.node[i].append( currentNode )
				if c not in self.children[currentNode]:
					self.children[currentNode][c] = nodeNumbering
					# print( currentNode, c, self.children[currentNode][c] )
					nodeNumbering += 1
				currentNode = self.children[currentNode][c]

			self.isHeadCharNode[currentNode] = True
			# print(currentNode, True)

	def getAnsCount(self,arrRev):

		ret = 0
		for i,s in enumerate(arrRev):
			prefixListOfLonger = set()
			for j in range( len(s)-1, -1, -1 ):
				# loop from leaf to root
				c = s[j]
				prefixListOfLonger.add(c)
				currentNode = self.node[i][j]

				for prefix in prefixListOfLonger:
					if prefix in self.children[currentNode] and self.isHeadCharNode[self.children[currentNode][prefix]]:
						# print(self.isHeadCharNode[self.children[currentNode][prefix]])
						ret += 1

		return ret



if __name__ == "__main__":
	ans=""
	N = int(input())
	lstW=[]

	for n in range(N):
		lstW.append(input()[::-1])

	# create Trie
	trie=Trie(lstW)
	ans = trie.getAnsCount(lstW) - N

	print( ans )



Measured memory_bytes: 536928
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    double t, x;
    cin >> t >> x;
    printf("%.10lf\n", t / x);
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll;
#define pb push_back
#define endl        '\n'
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    ll N;
    cin>>N;
    int a[2005];
    for(int i=0; i<N; i++)
    {
        cin>>a[i];
    }
    int ans=0;
    sort(a,a+N);
    for(int i=0; i<N-2; i++)
        for(int j=i+1; j<N-1; j++)
        {
            int x=a[i]+a[j];
            for(int t=j+1; t<N; t++)
            {
                if(x>a[t])
                {
                    ans++;
                }
            }
        }
        cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  string s;cin>>s;
  print(s.substr(0,3));
  return 0;
}


Measured memory_bytes: 3608
n = int(input())
h = list(map(int,input().split()))
ans = "Yes"

h[0]-=1

for i in range(1,n):
    if h[i-1]<h[i]:
        h[i]-=1
    elif h[i-1]==h[i]:
        pass
    else:
        ans = "No"
        break

print(ans)

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

int main() {
    int n, m;
    cin >> n >> m;
    int a[n][m] = {}, b[m] = {};
    int c[n] = {};
    for(int z = 0; z < n; z ++) {
        for (int b = 0; b < m; b ++) {
            cin >> a[z][b];
        }
    }
    for(int c = 0; c < m; c++){
        cin >> b[c];
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            c[i] = c[i] + a[i][j]*b[j];
        }
    }
    for(int k = 0; k < n; k++){
        cout << c[k] << endl;
    }
}


Measured memory_bytes: 3108
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	tt := make([]int64, n)
	for i := 0; i < n; i++ {
		tt[i] = getNextInt64(scanner)
	}
	var lcm int64
	g := tt[0]
	lcm = g
	for i := 1; i < n; i++ {
		g = gcd64(lcm, tt[i])
		lcm = lcm / g * tt[i]
	}
	fmt.Fprintln(writer, lcm)

	writer.Flush()
}

func gcd64(m, n int64) int64 {
	if n == 0 {
		return m
	}
	return gcd64(n, m%n)
}


Measured memory_bytes: 640
N=int(input())
l_b=list(map(int,input().split()))
l_a=[l_b[-1]]
for i in range(N-2):
  l_a.append(min(l_b[N-2-i],l_b[N-3-i]))
l_a.append(l_b[0])
print(sum(l_a))

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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 60;
const int maxN = 400;

void solve() {
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}

	vector<int> dp(1 << n);
	dp[0] = 1;
	for (int mask = 1; mask < (1 << n); mask++) {
		int cnt = -1;
		for (int i = 0; i < n; i++) {
			if ((mask >> i) & 1) cnt++;
		}
		for (int i = 0; i < n; i++) {
			if ((mask >> i) & 1) {
				if (a[cnt][i]) dp[mask] += dp[mask ^ (1 << i)];
				dp[mask] %= MOD;
			}
		}
	}
	cout << dp[(1 << n) - 1];
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}


Measured memory_bytes: 16640
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(X, Y, Z, K, A, B, C):
    q = []

    for a in A:
        for b in B:
            heapq.heappush(q, a+b)
            if len(q) > K:
                heapq.heappop(q)

    qq = []
    for c in C:
        for d in q:
            heapq.heappush(qq, d+c)
            if len(qq) > K:
                heapq.heappop(qq)
    qq.sort(reverse=True)
    return qq

def main():
    X, Y, Z, K = read_int_n()
    A = read_int_n()
    B = read_int_n()
    C = read_int_n()
    print(*slv(X, Y, Z, K, A, B, C), sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 82240
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  string s; cin>>s;
  if(s[0]==s[2])
  puts("Yes");
  else
  puts("No");

  return 0;
}


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

int a[60];

int main(void)
{
    int N, K;
    cin >> N >> K;

    for(int i = 0; i < N; i++) cin >> a[i];
    sort(a, a + N, greater<int>());

    int sum = 0;
    for(int i = 0; i < K; i++) sum += a[i];

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000

int n;
vi adj[2005];

vi runBFS(int v) {
    qii q;
    vi dst(n);
    bool vis[n];
    memset(vis, false, sizeof vis);
    q.push({v, 0});
    while (q.size() > 0) {
        ii ns = q.front();
        q.pop();
        int vt = ns.first;
        if (vis[vt]) {
            continue;
        }
        int ds = ns.second;
        dst[vt] = ds;
        vis[vt] = true;
        for (int a : adj[vt]) {
            if (vis[a]) {
                continue;
            }
            q.push({a, ds + 1});
        }
    }
    return dst;
}

void solve() {
    int x, y;
    cin >> n >> x >> y;
    x--; y--;
    for (int i = 0 ; i < n - 1 ; i++) {
        adj[i].pb(i + 1);
        adj[i + 1].pb(i);
    }
    adj[x].pb(y);
    adj[y].pb(x);
    int counts[n - 1];
    memset(counts, 0, sizeof counts);
    rep(i, n) {
        vi dsts = runBFS(i);
        rep(j, i) {
            counts[dsts[j] - 1]++;
        }
    }
    rep(i, n - 1) {
        cout << counts[i] << endl;
    }
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

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


Measured memory_bytes: 384
n = int(input())
s = int(input())

def f(b, n) :
    ret = 0
    while n != 0 :
        ret += n % b
        n //= b
        
    return ret

def solve(n, s) :
    if n == s :
        return n + 1
    if s > n :
        return -1
    
    b = 2
    while b * b <= n :
        if f(b, n) == s :
            return b
        b += 1
            
    p = int(-(-(n ** 0.5 - 1) // 1))
    while p > 0 :
        if (n - s) % p == 0 :
            b = 1 + (n - s) // p
            if p < b and 0 <= s - p < b :
                return b
            
        p -= 1
        
    return -1
            
print(solve(n, s))

Measured memory_bytes: 40684
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
vector<int>g[55];
bool vis[55];
int dfs(int now,int cur,int mask)
{
	if(mask==(1<<n)-1)
	{
		return 1;
	}
	int ans=0;
	for(int i=0;i<g[cur].size();i++)
	{
		int x=g[cur][i];
		int bit=1<<x;
		if(!(mask&bit))
		{
			ans+=dfs(now+1,x,mask|bit);
		}
	}
	return ans;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cout<<dfs(0,0,1)<<endl;
	return 0;
}

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

using namespace std;

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

    int x=a+b;
    int y=a-b;
    int z=a*b;


    if(x>=y && x>=z){
        cout << x << endl;
    }else if(y>=x && y>=z){
        cout << y << endl;
    }else if(z>=x && z>=y){
        cout << z << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ll x;
	cin >> x;
	ll q = (x / 1000) + (x % 1000 != 0);
	q *= 1000;
	cout << q - x << '\n';





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3632
from collections import deque
postorder = list()

def reconstruction(preorder, inorder, l, r):
    if l >= r:
        return

    c = preorder.popleft()
    m = inorder.index(c)
    reconstruction(preorder, inorder, l, m)
    reconstruction(preorder, inorder, m + 1, r)
    postorder.append(str(c))

def Main():
    N = int(input())
    preorder = deque(map(int, input().split()))
    inorder = deque(map(int, input().split()))
    reconstruction(preorder, inorder, 0, N)
    print(*postorder)

Main()


Measured memory_bytes: 6000
n=int(input())
if n==4 or n==6 or n==9 or n==10 or n==14 or n==21 or n==22 or n==25 or n==26:
  print(2)
elif n==32:
  print(51)
elif n==8 or n==12 or n==18 or n==20 or n==27:
  print(5)
elif n==28 or n==30:
  print(4)
elif n==16:
  print(14)
elif n==24:
  print(15)
else:
  print(1)

Measured memory_bytes: 3064
import java.util.*; 
import java.lang.*; 


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                int N = scan.nextInt();
                int K = scan.nextInt();
                
                int[] ans = new int[N];
                
                for(int i=0; i<N; i++){
                    ans[i]  = scan.nextInt();
                }
                Arrays.sort(ans);
                
                int answer = 0;
                for(int i=0; i<K; i++){
                    answer = answer + ans[i];
                }
                
                System.out.println(answer);
        }
                
}


Measured memory_bytes: 38888
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

bool isInGroup(vector<int> g, int x, int y) {
    bool inx = false, iny = false;
    rep(i,g.size()) {
        if (x == g[i]) inx = true;
        if (y == g[i]) iny = true;
    }
    return (inx && iny);
}
int main() {
    int x,y; cin >> x >> y;
    vector<int> a = {1,3,5,7,8,10,12};
    vector<int> b = {4,6,9,11};
    vector<int> c = {2};
    if (isInGroup(a,x,y) || isInGroup(b,x,y) || isInGroup(c,x,y)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative

main :: IO ()
main = do
    xs <- map read . lines <$> getContents
    mapM_ print $ solve xs []

solve :: [Int] -> [Int] -> [Int]
solve [] _ = []
solve (x:xs) [] = solve xs [x]
solve (x:xs) q'@(q:qs)
    | x == 0    = q:(solve xs qs)
    | otherwise = solve xs (x:q')

Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long N, std::vector<std::vector<long long>> A){
    for(int i = 0; i < N; ++i) for(int j = 0; j < N - 1; ++j) {
        A[i][j]--;
    }

    vector<int> p(N);

    int res = 0;

    for(;;) {
        ++res;
        vector<int> v;

        for(int i = 0; i < N; ++i) {
            if (p[i] == N - 1) continue;
            int o = A[i][p[i]];

            if (p[o] == N - 1) continue;

            if (A[o][p[o]] == i) {
                v.push_back(i);
            }
        }

//        cerr << v.size() << "," << res << endl;

        for(auto a: v) {
            p[a]++;
        }

        if (v.empty()) break;
    }

    bool f = true;
    for(auto a: p) {
//        cerr << ">" << a << endl;
        f = f && a == N - 1;
    }
    if (!f) res = 0;

    cout << res - 1 << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::vector<long long>> A(N, std::vector<long long>(N-1));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < N-1 ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    solve(N, std::move(A));
    return 0;
}


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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

int main()
{
    int H, W;
    cin >> H >> W;
    int ans = H * W;
    int a, b;
    cin >> a >> b;
    cout << ans - (a * W + b * H - a * b) << endl;
    return 0;
}

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

const int MAX=100005;
vector<int> S(MAX),h(MAX);
int N;

void DP(int u){
    for(int i=2;i<=u;i++){
    if(i==2) S[2]=abs(h[2]-h[1]);
    else if(i==3) S[3]=abs(h[3]-h[1]);
    else S[i]=min(S[i-1]+abs(h[i]-h[i-1]),S[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<S[u]<<endl;
}

int main(){
    
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>h[i+1];
    }
    DP(N);
    
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>

map<int,int> a;
map<int,int> mul;
map<int,int> one;

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

  int n,m;
  cin>>n>>m;
  rep(i,n){
    int x;
    cin>>x;
    a[x]++;
  }
  for(P x:a){
    mul[x.F%m]+=x.S/2;
    one[x.F%m]+=x.S%2;
    //cout<<x.F<<' ';
  }
  //cout<<endl;

  int ans=0;
  for(P p:one){
    int x=p.F,y=p.S;
    //cout<<x<<' '<<y<<' '<<endl;
    if(x==0||x==m-x){
      ans+=y/2;
    }else{
      int res=min(y,one[m-x]);
      ans+=res;
      //cout<<res<<' '<<y<<' '<<one[m-x]<<endl;
      y-=res;
      one[x]-=res;
      one[m-x]-=res;
      //cout<<one[x]<<' '<<one[m-x]<<endl;
      //cout<<x<<' '<<y<<endl;
      if(y>0){
        res=min(y,mul[m-x]*2);
        //cout<<res<<endl;
        ans+=res;
        one[x]-=res;
        mul[m-x]-=(res+1)/2;
      }
    }
    //cout<<ans<<endl;
  }

  for(P p:mul){
    //cout<<p.F<<' '<<p.S<<endl;
    ans+=p.S;
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 19072
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll N,sum=0;
    cin >>N;
    for(ll i =0;i<N;i++){
        if((i+1)%3!=0 && (i+1)%5!=0){
            sum+=(i+1);
        }
    }
    cout << sum << endl;
    return 0;    
}


Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<map>
#include<string>

using namespace std;

const int INF=200000000;

int data[51][11];
int pena[51];
int ac[51];
int main(){
	int t,p,r;
	while(cin>>t>>p>>r &&t){
		for(int i=0;i<51;i++){
			for(int j=0;j<11;j++)data[i][j]=0;
		}
		fill(pena,pena+51,0);
		fill(ac,ac+51,0);

		for(int i=0;i<r;i++){
			int tID,pID,time;
			string str;
			cin>>tID>>pID>>time>>str;
			if(str=="CORRECT"){
				pena[tID]+=data[tID][pID]*1200+time;
				ac[tID]++;
			}
			else{
				data[tID][pID]++;
			}
		}
		for(int i=0;i<t;i++){
			int tmp[2]={-1,INF};
			int ans=-1;
			for(int j=1;j<=t;j++){
				if(ac[j]>tmp[0] || (ac[j]==tmp[0] && pena[j]<tmp[1])){
					tmp[0]=ac[j];
					tmp[1]=pena[j];
					ans=j;
				}
			}
			cout<<ans<<" "<<ac[ans]<<" "<<pena[ans]<<endl;
			ac[ans]=-1;pena[ans]=INF;
		}

	}
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, ans, l[2005];
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%d", l+i);
	sort(l, l+n);
	rep(i,n) rep(j,i){
		ans += (int)(lower_bound(l, l+n, l[i]+l[j]) - l) - i - 1;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int	main(void)
{
  	int	N;
  	char S[100];
    int flag;
  	int	num;
  	int	i;
  
 	num = scanf("%d", &N);
  	if (num != 1)
      	return (0);
  
  	num = scanf("%s", S);
  	if (num != 1)
      	return (0);
  
  	if (N % 2 != 0)
    {
      	printf("No");
      	return (0);
    }
  	
  	flag = 0;
  	for (i=0; i<N/2; i++)
    {
      	if (S[i] == S[i + N / 2])
          	flag = 1;
      	else
        {
          	flag = 0;
          	printf("No");
          	return (0);
        }
    }
  	if (flag == 1)
      	printf("Yes");
  	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PP;

int num[1101][1101];
bool saw[2000000], fact[2000000];
int m, n;

void init(){
	rep(i,1101) rep(j,1101) num[i][j] = -1;
	num[550][550] = 1; num[550][551] = 2;
	int y = 550, x = 551;
	for(int i = 3; i <= 1010*1010; i++){
		if(num[y][x-1] != -1 && num[y-1][x] == -1) y--;
		else if(num[y+1][x] != -1 && num[y][x-1] == -1) x--;
		else if(num[y][x+1] != -1 && num[y+1][x] == -1) y++;
		else if(num[y-1][x] != -1 && num[y][x+1] == -1) x++;
		num[y][x] = i;
	}
	rep(i,2000000) fact[i] = false;
	rep(i,2000000) saw[i] = false;
	for(int i = 2; i <= 2000000; i++){
		if(saw[i] == false) fact[i] = true;
		for(int j = i*2; j <= 2000000; j += i) saw[j] = true; 
	}
}

P cnt[1101][1101];

void solve(){
	rep(i,1101) rep(j,1101) cnt[i][j] = P(-1,0);
	int y, x;
	rep(i,1101) rep(j,1101){
		if(num[i][j] == n){
			y = i;
			x = j;
			cnt[i][j] = P(0,0);
			break;
		}
	}
	if(fact[n]){
		cnt[y][x] = P(1,n);
	}
	
	rep(yy,1101) rep(xx,1101){
		if(cnt[yy][xx].first == -1) continue;
		for(int i = -1; i <= 1; i++){
			if(num[yy+1][xx+i] == -1 || num[yy+1][xx+i] > m) continue;
			P tmp = cnt[yy][xx];
			if(fact[num[yy+1][xx+i]]){
				tmp.first++;
				tmp.second = num[yy+1][xx+i];
			}
			if(cnt[yy+1][xx+i] > tmp) continue;
			cnt[yy+1][xx+i] = tmp;
		}
	}
	P ans = P(-1,-1);
	rep(i,1101) rep(j,1101) ans=max(ans,cnt[i][j]);
	cout << ans.first << " " << ans.second << endl;
}

int main(){
	init();
	while(true){
		cin >> m >> n;
		if(m == 0 && n == 0) break;
		solve();
	}
}

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

// main
int main(){
    int n;
    cin >> n;
    map<string, int> dict;

    string command, key;

    for(int i =0; i < n; ++i){
        cin >> command;
        if(command == "insert"){
            cin >>key;
            //pair<string, int> p =  make_pair(key, 1);
            //dict.insert(p);
            dict.emplace(key, 1);
        }else if(command == "find"){
            cin >> key;
            auto iter = dict.find(key);
            if( iter != dict.end() ) {
                cout << "yes" << "\n";
            }else{
                cout << "no" << "\n";
            }
        }

    }
    return 0;
}



Measured memory_bytes: 36940
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

int n,x,y,t,ti,xi,yi;

int main()
{
    scanf("%d",&n);
    x = 0, y = 0, t = 0;
    bool ans = 1;
    for (int i=0;i<n;i++)
    {
        scanf("%d %d %d",&ti,&xi,&yi);

        int ned = abs(x-xi)+abs(y-yi);
        if (ned > ti-t) ans = 0;

        int tag = (ti-t)-ned;
        if (tag % 2) ans = 0;

        x = xi, y = yi, t = ti;
    }
    if (ans) printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

int main() {
	int x, y;
	while (std::cin >> x >> y && (x != 0 || y != 0)) {
		x > y ?
			std::cout << y << " " << x << std::endl :
			std::cout << x << " " << y << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3092