akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int main(void) {
	int d;
	cin >> d;

	cout << "Christmas";
	int i=0;
	for (i; i < 25 - d; i++) {
		cout << " Eve";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int P, Q, R, m;
    scanf("%d %d %d", &P, &Q, &R);
    m=P;
    if (Q>m) m=Q;
    if (R>m) m=R;
    printf("%d", P+Q+R-m);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int MAX = 5000000;

ll mod_pow(ll x, ll e){
  ll v = 1;
  for(;e;e>>=1){
    if(e & 1)v = (v * x) % MOD;
    x = (x * x) % MOD;
  }
  return v;
}

ll f[MAX], finv[MAX];
void init(){
  f[0] = 1;
  for(int i=1;i<MAX;i++)f[i] = f[i-1] * i % MOD;
  finv[MAX-1] = mod_pow(f[MAX-1], MOD-2);
  for(int i=MAX-2;i>=0;i--)finv[i] = finv[i+1] * (i+1) % MOD;
}

ll C(int n, int k){
  return f[n] * finv[k] % MOD * finv[n-k] % MOD;
}

int N, K;

ll dp[2010][2010]; // (i <= j)
ll solve(int i, int j){
  if(i == 0 && j == 0)return 1;
  if(dp[i][j] != -1)return dp[i][j];
  ll res = 0;
  if(i > 0)
    res = (res + solve(i - 1, j)) % MOD;
  if(i <= j - 1){
    int n = i + (j - 1) * (K - 1) + K - 2;
    int k = K - 2;
    ll tmp = solve(i, j - 1) * C(n, k) % MOD;
    res = (res + tmp) % MOD;
  }
  return dp[i][j] = res;
}

int main(){
  init();

  cin >> N >> K;
  if(K == 1){
    cout << 1 << endl;
    return 0;
  }
  
  memset(dp, -1, sizeof(dp));
  ll res = solve(N, N) * f[N] % MOD;
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 110080
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    Rep (i, N) cin >> w[i] >> v[i];

    vector<vector<ll>> dp(N+1, vector<ll>(1e5+1, inf));
    dp[0][0] = 0;
    Rep (i, N) {
        Rep (j, 1e5+1) {
            chmin(dp[i+1][j], dp[i][j]);
            if (j-v[i] >= 0) chmin(dp[i+1][j], dp[i][j-v[i]] + w[i]);
        }
    }

    ll ans = 0;
    Rep (i, 1e5+1) {
        // if (i < 100) cout << dp[N][i] << "\n";
        if (dp[N][i] <= W) chmax(ans, i);
    }

    cout << ans << "\n";

}

Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

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

int main(){
    int n;
    cin >> n;
    rep(i,n){
        cin >> h[i];
        dp[i] = INT_MAX;
    }

    dp[n] = 0;
    dp[n-1] = 0;
    for(int i=n-2; i>=0; i--){
        if(i+2>=n){
            dp[i] = dp[i+1] + abs(h[i+1] - h[i]);
            continue;
        }

        dp[i] = min(dp[i+2] + abs(h[i+2] - h[i]),
                    dp[i+1] + abs(h[i+1] - h[i]));
    }

    cout << dp[0] << endl;
    
}

Measured memory_bytes: 1024
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
void solve()
{
	string s;	cin>>s;
	if(s=="BBB" || s=="AAA")
		cout<<"No";
	else
		cout<<"Yes";	
	
	
	
}
signed main()
{
	fastio;
//	test
		solve();	
}





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

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

typedef struct node *NodePointer;

NodePointer nil;

NodePointer listSerch(int key){
	NodePointer t = nil->next;
	if(t == nil){
		return nil;
	}
	while(1){
		if(t->key == key){
			return t;
		}
		if(t->next == nil){
			return nil;
		}
		t = t->next;
	}
	
}

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

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

void deleteNode(NodePointer t){
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	NodePointer t = nil->next;
	if(t == nil){
		return;
	}
	deleteNode(t);
}

void deleteLast(){
	NodePointer t = nil->prev;
	if(t == nil){
		return;
	}
	deleteNode(t);
}

void delete(int key){
	NodePointer t = nil->next;
	t = listSerch(key);
	if(t == nil){
		return;
	}
	deleteNode(t);
}

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


int main(int argc, char **argv)
{
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;

	scanf("%d", &n);
	init();

	for ( i = 0; i < n; i++ ){
		scanf("%s", com);

		if ( com[0] == 'i' ){
			scanf("%d", &key);
			insert(key); 
			np++; 
			size++;
		}
		else if ( com[0] == 'd' ){
			if (strlen(com) > 6){
				if ( com[6] == 'F' ){
					deleteFirst();
				} 
				else if ( com[6] == 'L' ){
					deleteLast();
				}
			}
			else{
				scanf("%d", &key);
				delete(key); 
				nd++; 
			}
			size--;
		}
	}

	printList();
	return 0;
}


Measured memory_bytes: 32964
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        long ans = 1;
        long mod = (long)Math.Pow(10, 9) + 7;
        for (long i = 2; i <= n; i++)
        {
            ans = ans * i % mod;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(void)
{
    int a, b, c, k;

    cin >> a >> b >> c >> k;
    if(k <= a)
        cout << k << endl;
    else if(k <= a + b)
        cout << a << endl;
    else
        cout << a - (k - (a + b)) << endl;

    return 0;
}


Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0577

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    N = int(input())
    scores = [0] * N            #  ????????¬?????????????????????0??§?????????
    data = [ [int(x) for x in input().split()] for _ in range(N)] #  ?????¬??????????????¨???3??????????????????

    rounds = [[]]                 #  ????????§??¨?????¬???????????????????????°??????????????? (1???????????????????????????????????????????????????)
    rounds.append([d[0] for d in data]) #  1??????
    rounds.append([d[1] for d in data]) #  2??????
    rounds.append([d[2] for d in data]) #  3??????

    # ????????????????¨????
    for i, d in enumerate(data):
        r1, r2, r3 = d
        if rounds[1].count(r1) == 1:
            scores[i] += r1
        if rounds[2].count(r2) == 1:
            scores[i] += r2
        if rounds[3].count(r3) == 1:
            scores[i] += r3

    # ?????¬??????????????¨??????????????¨???
    for s in scores:
        print(s)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7744
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) return b;
    gcd(b, a%b);
}

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int h = gcd(a[0], a[1]);
    if (n == 2) cout << h << endl;
    else {
        for (int i = 2; i < n; ++i) {
            h = gcd(h, a[i]);
        }
        cout << h << endl;
    }
    return 0;
}

Measured memory_bytes: 640
# coding: utf-8
# Your code here!
import copy

class Card:
    def __init__(self, suit, value):
        self.suit = suit
        self.value = value



def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = []
    R = []
    for i in range(n1):
        L.append(A[left + i])
    for i in range(n2):
        R.append(A[mid + i])
    L.append(Card("", 2000000000))
    R.append(Card("", 2000000000))
    
    i = 0
    j = 0
    
    for k in range(left, right):
        if L[i].value <= R[j].value:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = int((left + right) // 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
        
        





def partition(A, p, r):
    x = A[r - 1].value
    i = p - 1
    for j in range(p, r - 1):
        if A[j].value <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r -1] = A[r -1], A[i + 1]
    return i + 1
        
        
def quickSort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q)
        quickSort(A, q + 1, r)
    return
    
    

n = int(input())
A = []
for i in range(n):
    tmp = list(input().split())
    A.append(Card(tmp[0], int(tmp[1])))

B = copy.copy(A)
flg = True

quickSort(A, 0, n)
mergeSort(B, 0, n)

for i in range(n):
    if A[i].suit != B[i].suit:
        flg = False
if flg:
    print("Stable")
else:
    print("Not stable")
        
for i in range(n):
    print(A[i].suit, A[i].value)









Measured memory_bytes: 28544
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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(){
    ll n,k;
    cin >> n >> k;
    ll a;
    if(k%2==1){
        a=k;
        if(n<a){
            cout << 0 << endl;
            return 0;
        }
        ll ans = ((n - a) / k + 1) * ((n - a) / k + 1) * ((n - a) / k + 1);
        cout << ans << endl;
    }
    else{
        a=k/2;
        if(n<a){
            cout << 0 << endl;
            return 0;
        }
        ll ans = ((n - a) / k + 1) * ((n - a) / k + 1) * ((n - a) / k + 1);
        a+=k/2;
        if(a<=n){
            ans += ((n - a) / k + 1) * ((n - a) / k + 1) * ((n - a) / k + 1);
        }
        cout << ans << endl;
    }
}

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

bool NG(string s, string t){
    map<char,int>mp1,mp2;
    rep(i,s.size())mp1[s[i]]++;
    rep(i,t.size())mp2[t[i]]++;
    for(auto&p:mp2){
        if(mp1[p.first]==0)return true;
    }
    return false;
}

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.size();
    if(NG(s,t)){cout<<-1<<endl; return 0;}
    s+=s;
    vector<vector<int>>alp(26);
    ll ans=0;
    rep(i,s.size()){
        alp[s[i]-'a'].push_back(i);
    }
    int now=-1;
    rep(i,t.size()){
        int c=t[i]-'a';
        int x=upper_bound(alp[c].begin(),alp[c].end(),now)-alp[c].begin();
        ans+=alp[c][x]-now;
        now=alp[c][x];
        now%=n;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<int,int> Pi;
const int INF=(ll)(1LL<<31)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m,p,a,b;
int t[10];
int x[500],y[500],z[500];
double dp[1<<8][500];
int d[500][500];
vector<double> ans;
int main(){
	while(1){
		cin>>n>>m>>p>>a>>b;
		if(n==0&&m==0&&p==0&&a==0&&b==0)break;
		REP(i,n)cin>>t[i];
		REP(i,500)
			REP(j,500)
				d[i][j]=-1;
		REP(i,p){
			cin>>x[i]>>y[i]>>z[i];
			d[x[i]][y[i]]=z[i];
			d[y[i]][x[i]]=z[i];
		}
		for(int i=0;i<(1<<8);i++){
			for(int j=0;j<500;j++){
				dp[i][j]=INFd;
			}
		}
	
		dp[(1<<n)-1][a]=0;
		
		for(int i=(1<<n)-1;i>=0;i--){
			for(int v=1;v<=m;v++){
				for(int j=0;j<n;j++){
					if((i>>j)&1){
						for(int k=1;k<=m;k++){
							if(v!=k){
								if(d[v][k]>0){
									dp[i&~(1<<j)][k]=min(dp[i&~(1<<j)][k],dp[i][v]+(double)d[v][k]/t[j]);
								}
							}
						}
					}
				}
			}
		}
		
		double ans1=INFd;
		for(int i=(1<<n)-1;i>=0;i--){
			//printf("%lf\n",dp[i][b]);
			ans1=min(ans1,dp[i][b]);
		}
		
		if(ans1==INFd)ans.push_back(-1);//printf("Impossible\n");
		else ans.push_back(ans1);//printf("%.3f\n",ans);
	}
	
	REP(i,ans.size()){
		if(ans[i]==-1){
			printf("Impossible\n");
		}else{
			printf("%.3f\n",ans[i]);
		}
	}
	return 0;
}


Measured memory_bytes: 5156
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    reds = []
    for _ in range(N):
        a, b = map(int, input().split())
        reds.append((a, b))

    blues = []
    for _ in range(N):
        c, d = map(int, input().split())
        blues.append((c, d))

    reds.sort(key=lambda x: x[0])
    blues.sort(key=lambda x: x[0])
    used = [False] * N

    ans = 0
    for i in range(N):
        b = blues[i]
        max_r = -1
        max_j = None
        for j in range(N):
            r = reds[j]
            if b[0] < r[0]:
                continue
            if b[1] < r[1]:
                continue

            if not used[j] and max_r < r[1]:
                max_r = r[1]
                max_j = j

        if max_j is not None:
            used[max_j] = True
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		if(a%b!=0){
			System.out.println(1);
		}else {
			System.out.println(0);


		}
    }
}
	

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

int c[3][3];

int main(){
    rep(i, 3)rep(j, 3) cin >> c[i][j];
    int a[3];
    for (a[0]=0; a[0]<=100; a[0]++) {
        for (a[1]=0; a[1]<=100; a[1]++) {
            for (a[2]=0; a[2]<=100; a[2]++) {
                bool ok = true;
                int b[3];
                b[0] = c[0][0] - a[0];
                b[1] = c[1][1] - a[1];
                b[2] = c[2][2] - a[2];
                rep(i, 3) {
                    if (b[0] != c[i][0] - a[i] || b[1] != c[i][1] - a[i] || b[2] != c[i][2] - a[i]) {
                        ok = false;
                        break;
                    }
                }

                if (ok) {
                    puts("Yes");
                    return 0;
                }
            }
        }
    }
    puts("No");
    return 0;
}

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

#define PI 3.14159265358979323846264338327950L

int main() {
	long long A, B, C, K;
	long long max = 0, tmp;

	cin >> A >> B >> C >> K;

	if (K <= 0) goto END;
	if (A <= K) max += 1 * A;
	else max += 1 * K;
	
	K -= A;
	if (K <= 0) goto END;

	K -= B;
	if (K <= 0) goto END;

	if (C <= K) max -= 1 * C;
	else max -= 1 * K;

END:	cout << max << endl;
		return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
    long long int n,k=0,ans=0;
    cin>>n;
    for(int i=1;i<100000000;i++){
        k+=i;
        if(n<=k){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define sorted(a_1) sort(a_1.begin(),a_1.end())
#define rsorted(a_1) sort(a_1.rbegin(),a_1.rend())
#define t1(a_1) cout<<a_1<<endl;
#define t2(a_1) for(auto it_test : a_1) cout<<it_test<<" ";
#define end cout<<endl;

const int MAX = 1000001;
vector<long long >isprime(MAX , true); 
vector<long long >prime; 
vector<long long >SPF(MAX); 
void Seive(int N) 
{ 
    isprime[0] = isprime[1] = false ; 
   
    for (long long int i=2; i<N ; i++) 
    { 
        if (isprime[i]) 
        { 
            prime.push_back(i);  
            SPF[i] = i; 
        } 
  
        for (long long int j=0; j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) 
        { 
            isprime[i*prime[j]]=false; 
   
            SPF[i*prime[j]] = prime[j] ; 
        } 
    } 
} 

ll expo(ll a, ll b, ll m) 
{ 
    if (b == 0) 
        return 1; 
    ll p = expo(a, b / 2, m) % m; 
    p = (p * p) % m; 
  
    return (b % 2 == 0) ? p : (a * p) % m; 
} 

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--){
		solve();
	}

return 0;
}

Measured memory_bytes: 19572
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

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

	string O,E; cin >> O>>E;
	int ES = E.size();

	string ans = "";
	FOR(i, 0, ES) {
		ans += {O[i], E[i]};
	}

	int OS = O.size();
	if (ES < OS) ans += O[OS - 1];

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import itertools
import collections
N = int(input())
A = list(map(int, input().split()))

table = collections.defaultdict(int)
A = [0] + A
s = itertools.accumulate(A)
for x in s:
    table[x] += 1
ans = 0
for x in table:
    if table[x] > 1:
        ans += (table[x] * (table[x]-1)) // 2
print(ans)


Measured memory_bytes: 38932
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	char c;
	cin >> c;
	if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		puts("vowel");
	else
		puts("consonant");

	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define INF 1e9 + 7
#define cae cout << ans << endl;
#define cye cout << "Yes" << endl;
#define cne cout << "No" << endl;
#define r0 return 0;
#define ll long long
using namespace std;
typedef pair<int,int>P;
signed main() {
    int n, k;
    int a[100];
    int ans = 0;
    cin >> n >> k;
    rep(i, n) {
        cin >> a[i];
        ans += min(a[i], abs(a[i] - k)) * 2;
    }
    cae
    r0
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int n;
    int a = 100000;
 
    scanf("%d", &n);
    while (n-- > 0) {
        a = a + (a * 5) / 100;
        a = ((a - 1) / 1000 + 1) * 1000;
    }
    printf("%d\n", a);
    return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#include <fstream>
#pragma GCC optimize("O2")
using namespace std;

#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
long long const inf = 1e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 3e5 + 10 ;


ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set <int > s ; 

int main(){
	int n , k ; 
	cin>>n>>k ; 
	for (int i = 1; i <= n ; i ++)
		s.insert(i) ; 
	for(int i = 1 ; i <= k ; i++){
		int t ; 
		cin>>t ; 
		for (int j = 1 ; j <= t ; j++){
			int a ; 
			cin>>a ;
			if (s.find(a)!=s.end())
				s.erase(a) ; 
		}
	}
	cout<<s.size() ; 
}	

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int x=n%10;
  if(x==2||x==4||x==5||x==7||x==9){
    cout<<"hon"<<endl;
  }
  else if(x==3){
    cout<<"bon"<<endl;
  }
  else cout<<"pon"<<endl;
}


Measured memory_bytes: 3612
#include<stdio.h>

int main (void)
{
	
	int a, b, c;
	
	int min, mid, max;

	scanf("%d %d %d",&a, &b, &c);

	if(a >= b && b >= c) {
	min = c;
	mid = b;
	max = a;
	} else if(a >= c && c >= b) {
	min = b;
	mid = c;
	max = a;
	} else if(b >= a && a >=c) {
	min = c;
	mid = a;
	max = b;
	} else if(b >= c && c >= a) {
	min = a;
	mid = c;
	max = b;
	} else if(c >= b && b >= a) {
	min = a;
	mid = b;
	max = c;
	} else if(c >= a && a >= b){
	min = b;
	mid = a;
	max = c;
	}

	printf("%d %d %d\n",min,mid,max);

	return 0;
}
	

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

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




//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}
/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	return (x / tmp) * y;
}


struct Combination {

	vector<ll> fact, rfact;

	Combination(ll sz) : fact(sz + 1), rfact(sz + 1) {

		fact[0] = 1;
		for (ll i = 1; i < fact.size(); i++) {
			fact[i] = fact[i - 1] * i % MOD;
		}
		//逆元
		rfact[sz] = inv(fact[sz]);
		for (ll i = sz - 1; i >= 0; i--) {
			rfact[i] = rfact[i + 1] * (i + 1) % MOD;
		}
	}

	ll inv(ll x) {
		return pow(x, MOD - 2);
	}
	ll pow(ll x, ll n) {
		ll ret = 1;
		while (n > 0) {
			if (n & 1) (ret *= x) %= MOD;
			(x *= x) %= MOD;
			n >>= 1;
		}
		return (ret);
	}
	ll P(ll n, ll r) {
		if (r < 0 || n < r) return (0);
		return (fact[n] * rfact[n - r] % MOD);
	}

	ll C(ll p, ll q) {
		if (q < 0 || p < q) return (0);
		return (fact[p] * rfact[q] % MOD * rfact[p - q] % MOD);
	}

	ll H(ll n, ll r) {
		if (n < 0 || r < 0) return (0);
		return (r == 0 ? 1 : C(n + r - 1, r));
	}
};


/******************************************************************************************/



int main() {

	int n, d;
	cin >> n >> d;

	int x[15][15] = {};

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			int cnt = 0;
			for (int k = 0; k < d; k++)
			{
				cnt += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
			}
			//cout << cnt << endl;
			for (int h = 1; h <= 400; h++)
			{
				if (h*h == cnt) {
					//cout << cnt << endl;
					//cout << i << " " << j << endl;
					ans++;
					break;
				}
			}
		}
	}

	cout << ans << endl;






	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			int[] arrX = new int[n];
			int[] arrY = new int[m];
			for (int i = 0; i < n; i++) {
				arrX[i] = sc.nextInt();
			}
			for (int i = 0; i < m; i++) {
				arrY[i] = sc.nextInt();
			}

			Arrays.sort(arrX);
			Arrays.sort(arrY);

			boolean flg;
			for (int z = x + 1; z <= y; z++) {
				flg = true;
				for (int xi : arrX) {
					if (z <= xi) {
						flg = false;
						break;
					}
				}
				for (int yi : arrY) {
					if (yi < z) {
						flg = false;
						break;
					}
				}
				if (flg) {
					System.out.println("No War");
					return;
				}
			}

			System.out.println("War");
		}
	}
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int h, w;
    cin >> h >> w;
    if (h == 1 or w == 1) {
        dump(1);
    } else {
        dump((h * w + 1) / 2);
    }
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val Array(x1, y1, x2, y2) = io.StdIn.readLine.split(' ').map(_.toInt)

  def next(xx1: Int, yy1: Int, xx2: Int, yy2: Int) = {
    (xx2 - (yy2 - yy1), yy2 + (xx2 - xx1))
  }

  val (x3, y3) = next(x1, y1, x2, y2)
  val (x4, y4) = next(x2, y2, x3, y3)

  val out = s"$x3 $y3 $x4 $y4"

  println(out)
}

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

ll gcd(ll x,ll y){
    if (y==0) return x;
    return gcd(y,x%y);
}

int main(){
  ll n,x;
  cin>>n>>x;
  ll a=gcd(n,x);
  cout<<(n/a-1)*3*a<<endl;
}

Measured memory_bytes: 256
i,h,m,s,a,b,c;
int main()
{
  for(;i++<3;)
    {
      scanf("%d%d%d%d%d%d",&h,&m,&s,&a,&b,&c);
      a-=h;
      b-=m;
      c-=s;
      if(c<0)
	{
	  b--;
	  c+=60;
	}
      if(b<0)
	{
	  a--;
	  b+=60;
	}
      printf("%d %d %d\n",a,b,c);
    }
exit(0);
}

Measured memory_bytes: 0
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9 + 7;

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

    ll arr[n],sum=0;
    for(ll i=0;i<n;i++){
        cin>>arr[i];
        sum = sum + arr[i];
    }

    sum/=2;
    ll a = sum;
    for(ll i=1;i<n;i+=2)
        a = a - arr[i];

    ll ans[n];
    ans[0]=2*a;

    for(ll i=1;i<n;i++)
    {
        ans[i] = 2 * (arr[i-1] - a);
        a = arr[i-1]-a;
    }

    for(ll i=0;i<n;i++)
        cout<<ans[i]<<" ";
}


Measured memory_bytes: 2944
def bisect_right_callable(fn, x, lo, hi):
    """
    lo から hi-1 のうち、fn の結果が x 以下となる、最も右の値 + 1
    bisect.bisect_right と同じ
    https://docs.python.org/ja/3/library/bisect.html
    :param callable fn:
    :param x:
    :param int lo: 最小値
    :param int hi: 最大値 + 1
    :return: lo <= ret <= hi
    """
    while lo < hi:
        mid = (lo + hi) // 2
        if x < fn(mid):
            hi = mid
        else:
            lo = mid + 1
    return lo


N = int(input())
series = list(map(int, input().split()))
series_sorted = sorted(series)

# L と r の選び方の組み合わせ数。1 から N までの和に等しい
lr_size = (N + 1) * N / 2


def count_lr(x):
    """
    x 以上の数を半分以上含む == 中央値が x 以上である、L と r の選び方の数
    :param x:
    :return:
    """
    ret = 0
    # series[i] が x 未満なら 1、x 以上なら -1 を i番目に持つ配列の、i=0 から i までの累積和。
    cumsum = 0
    # counts[i]: cumsum が i に何回なったか
    counts = {i: 0 for i in range(-N, N + 1)}
    counts[cumsum] = 1
    diff = 0
    for i in range(N):
        if series[i] >= x:
            cumsum += 1
            counts[cumsum] += 1
            diff += counts[cumsum]
        else:
            cumsum -= 1
            counts[cumsum] += 1
            diff -= counts[cumsum + 1] - 1
        ret += diff
    return ret


# count_lr(x) の結果が半分以上であれば、中央値は x 以上。
# count_lr(x) が半分以上のうち一番大きい x を探す。
def solve(i):
    if count_lr(series_sorted[i]) >= (lr_size + 1) // 2:
        return 0
    else:
        return float('inf')


ans_i = bisect_right_callable(solve, 0, lo=0, hi=N)
print(series_sorted[max(0, min(N - 1, ans_i - 1))])


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

int main() {
  int N;
  cin >> N;
  int max = 0;
  int min = 1000000001;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (A > max) max = A;
    if (A < min) min = A;
  }
  cout << max - min << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

int min (int x, int y) {
	if (x < y) return x;
	return y;
}

int main () {
	int n, k;
	while (scanf("%d %d", &n, &k) != EOF) {
		int arr[n];
		for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
		//DP
		int DP[n] = {0, abs(arr[1]-arr[0])};
		for (int i = 2; i < n; i++) {
			int m = 2147483647;
			for (int j = 1; j <= k; j++) {
				if (i-j >= 0) m = min(m, DP[i-j] + abs(arr[i] - arr[i-j]));
				else break;
			}
			DP[i] = m;
		}
		printf("%d\n", DP[n-1]);
	}
	return 0;
}

Measured memory_bytes: 896
/*
 * 16-10-1_AGC005_B.cpp
 *
 *  Created on: 2016/10/01
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>
#include<set>

using namespace std;

int N, a[200001],aa[200001];
long long ans;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> a[i];
		aa[a[i]] = i;
	}
	set<int> s;
	s.insert(-1);
	s.insert(N);
	for(int i=1;i<=N;i++){
		set<int>::iterator itr = s.lower_bound(aa[i]);
		int r = *itr;
		itr--;
		int l = *itr;
		ans += (long long)i * (aa[i] - l)*(r - aa[i]);
		s.insert(aa[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11136
n = int(input())
for i in range(n):
    x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))
    a = complex(x1, y1)
    b = complex(x2, y2)
    c = complex(x3, y3)
    a -= c
    b -= c
    z0 = abs(a)**2 * b - abs(b)**2 * a
    z0 /= a.conjugate() * b - a * b.conjugate()
    z = z0 + c
    zx = "{0:.3f}".format(z.real)
    zy = "{0:.3f}".format(z.imag)
    r  = "{0:.3f}".format(abs(z0))
    print(zx, zy, r)


Measured memory_bytes: 5628
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    int n;
    
    double score[1000];
    
    double ans;
    while(1){
        double ava = 0;
        double sum = 0;
        cin >> n;
        if(n == 0){
            break;
        }
        for(int i = 0; i < n; i++){
            cin >> score[i];
        }
        for(int i = 0; i < n; i++){
            ava += score[i];
        }
        ava = ava / n;
        for(int i = 0; i < n; i++){
            sum += (score[i] - ava)*(score[i] - ava);
        }
        ans = sqrt(sum / n);
        printf("%f\n", ans);
    
        
    }
    return 0;
}


Measured memory_bytes: 3204
n = int(input())
sb = 0
a, b, d = [], [], []
for i in range(n):
    av, bv = map(int, input().split())
    a.append(av)
    b.append(bv)
    d.append([i, av + bv])
d = sorted(d, key=lambda x: x[1], reverse=True)
tk, ao = 0, 0
for i in range(n):
    if i % 2 == 0:
        tk += a[d[i][0]]
    else:
        ao += b[d[i][0]]
print(tk - ao)

Measured memory_bytes: 34256
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 4e3+10;
const int INF = 1e12+10;
pair<int,int> a[N];
int arr[N][2],pos[N][2],h[N][N][2],dp[N][N];
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    for(int i=1;i<=2*n;i++){
        char c;cin>>c>>a[i].S;
        a[i].F=(c=='B');
    }
    for(int i=1;i<=2*n;i++){
        pos[a[i].S-1][a[i].F]=i;
        for(int j=a[i].S;j<=2*n;j++)
            arr[j][a[i].F]++;
        for(int j=1;j<=n+1;j++)
            if(!a[i].F)
                h[a[i].S-1][j-1][a[i].F]=arr[a[i].S-1][a[i].F]+arr[j-1][!a[i].F];
            else
                h[j-1][a[i].S-1][a[i].F]=arr[a[i].S-1][a[i].F]+arr[j-1][!a[i].F];
    }
    for(int i=n;i>=0;i--)
        for(int j=n;j>=0;j--)
            dp[i][j]=min({(i!=n)?(dp[i+1][j]-h[i][j][0]+pos[i][0]-1):(INF),(j!=n)?(dp[i][j+1]-h[i][j][1]+pos[j][1]-1):(INF),(i==n&&j==n)?(0):(INF)});
    cout<<dp[0][0];
}






Measured memory_bytes: 190208
#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

int n;

void read()
{
	cin >> n;
}

void solve()
{
	cout << (n - 2) * 180 << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	read();
	solve();
	return 0;
}



Measured memory_bytes: 256
#include <iostream>


using namespace std;


int main() {
    string s;
    int mod = ((int) 'Z' - (int) 'A' + 1);
    int n;
    cin >> n;
    n %= mod;
    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        int sh = (int)s[i] - (int) 'A';
        sh += n;
        sh %= mod;
        int c = (int)'A' + sh;
        cout << (char)c;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

template < class T >
class SegmentTree {
    // 0-indexed Segment Tree
    long long n; // 葉の数
    vector<T> data;  // データを格納する配列
    T def;  // 初期値（単位元）
    function<T(T, T)> operation;  // 区間クエリで使う処理
    function<T(T, T)> update;  // 点更新で使う処理

    // 区間 [a, b) に対する query !!!!!
    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return data[k];  // a,l,r,bの順で含まれる
        else {
            T c1 = _query(a, b, 2*k+1, l, (l+r)>>1);
            T c2 = _query(a, b, 2*k+2, (l+r)>>1, r);
            return operation(c1, c2);
        }
    }

public:
    // _n: 葉の要素の数, _def: 初期値（単位元）, _operation: クエリの関数, _update: 更新用の関数
    SegmentTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
        : n(_n), def(_def), operation(_operation), update(_update) {
            n = 1;
            while (n < _n) n<<=1;
            data = vector<T>(2*n-1, def);
        }
    
    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i>0) {
            i = (i-1)>>1;
            data[i] = operation(data[i*2+1], data[i*2+2]);
        }
    }

    // 区間 [a, b) に対する query !!!!!
    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](int i) {
        return data[i+n-1];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vll a(n), h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int i = 0; i < n; i++) cin >> a[i];
    SegmentTree<ll> seg(n, 0LL,
        [&](ll i, ll j) {return max(i, j);},
        [&](ll i, ll j) {return j;});
    V<int> ord(n); iota(ALL(ord), 0);
    sort(ALL(ord), [&](int i, int j) {return h[i] < h[j];});
    for (int idx: ord) {
        seg.change(idx, seg.query(0, idx) + a[idx]);
    }
    cout << seg.query(0, n) << '\n';
    return 0;
}


Measured memory_bytes: 11132
#include <stdio.h>

int main()
{
  int k,s;
  scanf("%d %d", &k, &s);
  int sum=0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k ;j++){
      if(0 <= s-i-j && s-i-j <= k)
        sum++;
    }
  }
  printf("%d", sum);
  return 0;
}

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

int main() {
    string S;
    cin >> S;
    string result = "No";
    if(S.find('A') != std::string::npos && S.find('B') != std::string::npos) {
        result = "Yes";
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] ary = new String[n];
		for(int i = 0; i < n; i++){
			ary[i] = sc.next();
		}
		Arrays.sort(ary);
		int[] streakAry = new int[n];
		int maxNum = 0;
		int sameNum = 0;
		String before = ary[0];
		streakAry[0] = 0;
		for(int i = 1; i < n; i++){
			if(before.equals(ary[i])){
				sameNum++;
				maxNum = Math.max(maxNum, sameNum);
			}else{
				sameNum = 0;
			}
			before = ary[i];
			streakAry[i] = sameNum;
		}
		for(int i = 0; i < n; i++){
			if(streakAry[i] == maxNum){
				System.out.println(ary[i]);
			}
		}
	}
}


Measured memory_bytes: 79720
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int e = sc.nextInt();
    e = sc.nextInt();
    e = sc.nextInt();
    e = sc.nextInt();
    int k = sc.nextInt();
    if(e-a <= k )
      System.out.println("Yay!");
    else
      System.out.println(":(");
  }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const int MAX_N=5e3;
const ll INF=1e18;
int N;
ll A[MAX_N];
vector<int> G[MAX_N];
vector<ll> dp[2][MAX_N];	

void dfs(int v,int p){
	if (A[v]>0){
		dp[0][v]={A[v]};
	}else{
		dp[0][v]={INF};
	}
	dp[1][v]={A[v]};
	for(auto e:G[v]){
		if (e!=p){
			dfs(e,v);
			vector<ll> vec[2];
			REP(i,2)vec[i].resize(dp[i][v].size()+dp[i][e].size());
			REP(i,2){
				for(auto &j:vec[i]){
					j=INF;
				}
			}
			REP(a,2){
				REP(i,(int)dp[a][v].size()){
					REP(b,2){
						REP(j,(int)dp[b][e].size()){
							if (dp[a][v][i]==INF || dp[b][e][j]==INF) continue;
							if (b==0 || dp[b][e][j]<0){
								if (a==0){
									vec[0][i+j+1]=min(vec[0][i+j+1],dp[a][v][i]);
								}
								vec[1][i+j+1]=min(vec[1][i+j+1],dp[a][v][i]);
							}
							if (a==0 && b==0){
								vec[0][i+j]=min(vec[0][i+j],dp[a][v][i]+dp[b][e][j]);
							}
							vec[1][i+j]=min(vec[1][i+j],dp[a][v][i]+dp[b][e][j]);
						}
					}
				}
			}
			REP(i,2){
				dp[i][v]=vec[i];
			}
		}
	}
}
int main(){
	cin>>N;
	REP(i,N)cin>>A[i];
	REP(i,N-1){
		int u,v;
		cin>>u>>v;
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(0,-1);
	int ans=N;
	REP(i,(int)dp[0][0].size()){
		if (dp[0][0][i]!=INF){
			ans=min(ans,i);
		}
	}
	REP(i,(int)dp[1][0].size()){
		if (dp[1][0][i]<0){
			ans=min(ans,i);
		}
	}
	cout<<ans<<endl;
	/*
	REP(i,2){
		REP(j,(int)dp[i][2].size()){
			cout<<"dp["<<i<<"][2]["<<j<<"]="<<dp[i][2][j]<<endl;
		}
	}
	*/
	return 0;
}

Measured memory_bytes: 164608
#include <bits/stdc++.h>
using namespace std;
int n;
inline int bits(int x) {
	return __builtin_popcount(x);
}
void printbin(int n, int b = 31) {
	for(int i=b-1; i>=0; i--) printf("%d", n>>i&1);
}
void f(int a, int b, int mask) {
	//printf("a:%d, b:%d, mask:%d\n", a, b, mask);
	if(bits(mask) == 1) {
		printf("%d ", b);
		//printbin(b,n);puts("");
		return;
	}
	int ra = a & mask;
	int rb = b & mask;
	int c = ra ^ rb;
	if(bits(c) == 1) {
		mask ^= c;
		f(a, a ^ (mask & -mask), mask);
		printf("%d ", a ^ (mask & -mask) ^ c);
		//printbin(a^mask^c, n); puts("");
		f(a ^ (mask & -mask) ^ c, b, mask);
	} else {
		int d = c & -c;
		mask ^= d;
		//printf("d:%d\n", d);
		int t;
		if(bits(c ^ d) == 1) {
			int e = mask ^ c ^ d;
			t = e & -e;
		} else {
			int e = c ^ d;
			t = e & -e;
		}
		f(a, a ^ t, mask);
		printf("%d ", a ^ t ^ d);
		//printbin(a^t^d, n);puts("");
		f(a ^ t ^ d, b, mask);
	}
}
int main() {
	int a, b;
	scanf("%d%d%d", &n, &a, &b);
	if(bits(a) % 2 == bits(b) % 2) {
		puts("NO");
		return 0;
	}
	// a -> b. assume c be a position that differs a and b
	// a=...1.....  00001000
	// b=...0.....  0000
	printf("YES\n%d ", a);
	//printbin(a,n);puts("");
	f(a, b, (1<<n)-1);
	return 0;
}

Measured memory_bytes: 1024
#include <utility>
#include <bitset>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <ios>
#include <iomanip>
#include <sstream>
#include <climits>
#include <cmath>

using namespace std;

#ifdef USE_LOG
#define LOG(str)  cout << str << endl
#define DMP(var)  cout << #var << " = " << var << endl
#else
#define LOG(...)
#define DMP(...)
#endif

#define FOR(v, b, e)   for (int v = (b); v < (e); ++v)
#define RFOR(v, b, e)  for (int v = (e) - 1; (b) <= v; --v)
#define REP(v, n)      FOR(v, 0, n)
#define RREP(v, n)     RFOR(v, 0, n)

#define ALL(c)         (c).begin(), (c).end()

typedef long long           ll;
typedef unsigned long long  ull;

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

	int N;
	cin >> N;
	cout << (int)(N / 3) << endl;
}

Measured memory_bytes: 888
#include<iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  //整数の時はint
  int a,b,c;
  //文字の時はstring
  //string a;

 

  cin>>a>>b>>c;

  if(a==b && a!=c)
    cout<<"Yes"<<endl;
  else if(c==b && a!=c)
    cout<<"Yes"<<endl;
  else  if(a==c && b!=c)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
s = list(input())
r = ''
if s[0] == '0':
  r = ['0' if i % 2 == 0 else '1' for i in range(len(s))]
elif s[0] == '1':
  r = ['1' if i % 2 == 0 else '0' for i in range(len(s))]

mul = [str(int(s[i]) + int(r[i])) for i in range(len(s))]

print(mul.count('1'))

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

int n;

int main() {
  cin >> n;
  vector<int> a(n - 1);
  vector<int> ans(n,0);
  rep (i, n - 1) {
    cin >> a.at(i);
  }
  rep (i, n - 1) {
    ans.at(a.at(i) - 1)++;
  }
  rep (i, n) {
    cout << ans.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 4792