akhauriyash/Code-Regression huggingface dataset:
s = [int(x) for x in list(input())]

def joinstring(s, op1, op2, op3):
  return str(s[0]) + op1 + str(s[1]) + op2 + str(s[2]) + op3 + str(s[3]) + "=7"

p = "+"
m = "-"

if s[0] + s[1] + s[2] + s[3] == 7:
  print(joinstring(s, p, p, p))
elif s[0] + s[1] + s[2] - s[3] == 7:
  print(joinstring(s, p, p, m))
elif s[0] + s[1] - s[2] + s[3] == 7:
  print(joinstring(s, p, m, p))
elif s[0] - s[1] + s[2] + s[3] == 7:
  print(joinstring(s, m, p, p))
elif s[0] + s[1] - s[2] - s[3] == 7:
  print(joinstring(s, p, m, m))
elif s[0] - s[1] + s[2] - s[3] == 7:
  print(joinstring(s, m, p, m))
elif s[0] - s[1] - s[2] + s[3] == 7:
  print(joinstring(s, m, m, p))
elif s[0] - s[1] - s[2] - s[3] == 7:
  print(joinstring(s, m, m, m,))


Measured memory_bytes: 9184
#include <cstdio>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll mod = 1000000007;

ll N;
std::map<P, ll> dp;

ll f( ll S, ll X )
{
  if( dp.count( P( S, X ) ) )
    return dp[P( S, X )];

  ll &ret = dp[P( S, X )];

  // S = 0, X = 0; (1) S = 1, X = 1 (1), S = 2, X = 0 (1)

  if( S == 1 && X == 1 )
    return ret = 2;
  else if( !S || !X )
    return ret = 1;

  return ret = ( ( (S >= 2 && X >= 0 ? f( (S-2)/2, X/2 ) : 0) + (S >= 1 && X >= 1 ? f( (S-1)/2, (X-1)/2 ) : 0) ) % mod + ( S >= 0 && X >= 0 ? f( S/2, X/2 ) : 0 ) ) % mod;
}

int main()
{
  scanf( "%lld", &N );

  printf( "%lld\n", f( N, N ) );
  
  return 0;
}

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

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif




ll s;
const ll e = 1e9;

int main(){
	cin >> s;
	ll a = s / e;
	ll c = s % e;
	ll aa = ( c == 0 ? a : a+1 );
	cout << a << " 0 0 " << c << " " << aa << " 1000000000" << endl;
	
	return 0;
}




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

int main() {
    string s,t;
    int len_s , len_t,i,j;
    getline(cin,s);
    getline(cin,t);
    len_s = s.length();
    len_t = t.length();
    int dp[len_s+1][len_t+1];
    for(i=0;i<=len_s;i++)
    {
        for(j=0;j<=len_t;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(s[i-1]==t[j-1])
            {
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j] = std::max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string LCS = "";
    i=len_s;
    j=len_t;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            LCS = s[i-1]+LCS;
            i--;
            j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
        {
            --i;
        }
        else
        {
            --j;
        }
    }
    cout<<LCS<<endl;
	return 0;
}


Measured memory_bytes: 35456
# -*- coding: utf-8 -*-
N = int(raw_input())
A = []
B = []
for n in range(N):
    A_i = int(raw_input())
    honest_i = set()
    unkind_i = set()
    for i in range(A_i):
        x, y =  map(int, raw_input().split())
        if y == 0:
            unkind_i.add(x-1)
        else:
            honest_i.add(x-1)
    A.append(unkind_i)
    B.append(honest_i)

def check(cand, A, B):
    honest = {i for i,v in enumerate(cand) if v == 1}
    unkind = {i for i,v in enumerate(cand) if v == 0}
    for h in honest:
        if len(honest.intersection(A[h])) != 0:
            return False
        if len(unkind.intersection(B[h])) != 0:
            return False
    return True

best = 0
import itertools
for cand in itertools.product([0,1], repeat=N):
    if check(cand, A, B):
        count = cand.count(1)
        best = max(best, count)

print best


Measured memory_bytes: 2696
#include <stdio.h>
#include <iostream>
using namespace std;

int S;

int main() {
	cin >> S;

	int s = S % 60;
	S = S / 60;

	int m = S % 60;
	S = S / 60;

	int h = S;

	printf("%d:%d:%d\n", h, m, s);
	return 0;
}



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

using namespace std;
#define ll long long
int main() {
    ll a,b,c,d;
    
    cin>>a>>b>>c>>d;
    
    long long res = max(a*c , max(a*d , max(b*c , b*d)));
    
    cout<<res<<endl;
    
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 105;
int num[maxn];
int main(int argc, char const *argv[])
{
	string a;
	long long k;
	cin>>a>>k;
	for(int i = 0;i < a.size(); ++i)
	{
		num[i] = a[i] - '0';
	}
	for(int i = 0;i < a.size(); ++i)
	{
		if(k == i + 1 && num[i] == 1)
		{
			printf("1\n");
			return 0;
		}
		if(num[i] != 1)
		{
			printf("%d\n",num[i]);
			return 0;
		}
	}
	return 0;
}

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

constexpr int INF = 1e9;

void warshall_floyd(vector<vector<int>>& d) {
    const int V = d.size();
    for(int k=0; k<V; ++k) {
        for(int i=0; i<V; ++i) {
            for(int j=0; j<V; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int N, M, L, K, A, H;
    while(cin >> N >> M >> L >> K >> A >> H, N) {
        vector<vector<int>> d(N, vector<int>(N, INF));
        vector<bool> fre(N, false);
        fre[A] = fre[H] = true;
        for(int i=0; i<L; ++i) {
            int l; cin >> l;
            fre[l] = true;
        }
        for(int i=0; i<N; ++i) {
            d[i][i] = INF;
        }
        for(int i=0; i<K; ++i) {
            int x, y, t;
            cin >> x >> y >> t;
            d[x][y] = d[y][x] = t;
        }
        warshall_floyd(d);
        for(int i=0; i<N; ++i) {
            for(int j=0; j<N; ++j) {
                if((!fre[i] || !fre[j]) && i != j) {
                    d[i][j] = INF;
                } else if(fre[i] && fre[j] && i != j && d[i][j] > M) {
                    d[i][j] = INF;
                }
            }
        }
        warshall_floyd(d);
        if(d[A][H] == INF) {
            cout << "Help!" << endl;
        } else {
            cout << d[A][H] + (d[A][H] > M ? d[A][H] - M : 0) << endl;
        }
    }
}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
     
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
const ll MOD2 = 1e9 + 7;
const int MOD = 1e9 + 7;
 
const ull infull = numeric_limits<unsigned long long>::max();
 
void fix(int &x, ll MOD) {
    x = (x % MOD);
    if(x < 0) x += MOD;
    return;
}
 
ll lgput(ll a, ll b, ll MOD) {
    ll ret = 1;
    a %= MOD;
    while(b) {
        if(b&1) ret = ret*a % MOD;
        a = a*a % MOD;
        b >>= 1;
    }
 
    return ret;
}
 
ll inv(ll a, ll MOD) {
    return lgput(a, MOD-2, MOD);
}
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};

using Mint = ModInt<998244353>;

int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    srand(time(NULL));

    int a, b, c;
    cin >> a >> b >> c;

    swap(a, b);
    swap(a, c);

    cout << a << ' ' << b << ' ' << c << '\n';
    return 0; 
}

Measured memory_bytes: 256
from collections import deque, defaultdict
from sys import stdin

input = stdin.readline
def main():
    N, M = map(int, input().split())
    route = defaultdict(list)
    for i in range(M):
        a, b = map(int, input().split())
        route[a-1].append(b-1)
        route[b-1].append(a-1)
    
    arrive_time = [0] + [-1] * (N - 1)
    arrive_route = [0] + [-1] * (N - 1)
    q = deque()
    q.append(0)
    while len(q):
        idx = q.popleft()
        for c in route[idx]:
            if arrive_time[c] >= 0 and arrive_time[c] <= arrive_time[idx]+1:
                continue
            arrive_time[c] = arrive_time[idx]+1
            arrive_route[c] = idx
            q.append(c)
    if min(arrive_time) < 0:
        print("No") 
    else:
        print("Yes")
        for r in arrive_route[1:]:
            print(r+1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 100604
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int n = 0;
    if(1<=a && a<=100){
      for(int i = 1;i<=a;i++){
        if(i%2!=0){
          n = n + 1;
        }
      }
      double m = (double)n/(double)a;
      System.out.println(m);
    }
  }
}



Measured memory_bytes: 23892
#include <iostream>                                                                              
using namespace std;                                                                             
                                                                                                 
int main() {                                                                                     
  int r, g, b, n;                                                                                
  int c = 0;                                                                                     
                                                                                                 
  cin >> r >> g >> b >> n;                                                                       
                                                                                                 
  for (int i = 0;i*r <= n;i++) {                                                                 
    int diff = n - r * i;                                                                        
    for (int j = 0;i*r + j*g <= n; j++) {                                                        
      if ((n - (r * i + g * j))%b == 0) {                                                        
        c++;                                                                                     
      }                                                                                          
    }                                                                                            
  }                                                                                              
  cout << c;                                                                                     
  return 0;                                                                                      
}                                                                                                
       

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,n,x;
  int sum = 0;

  cin >> n;
  vector<int> s(n+1);
  for (i = 0; i < n; i++) {
    s.at(i) = 0;
  }
  for (i = 1; i < n; i++) {
    cin >> x;
    s.at(x)++;
  }
  for (i = 1; i <= n; i++) {
    cout << s.at(i) << endl;
  }

}


Measured memory_bytes: 4020
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 55;

int n,a[maxn],m;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  int ret = 0;
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int l=-1;l<n;l++)
    for(int r=l+1;r<=n;r++){
      if(l+1+n-r>m)continue;
      vector<int>tt;
      for(int i=0;i<=l;i++)tt.push_back(a[i]);
      for(int i=r;i<n;i++)tt.push_back(a[i]);
      if(tt.size()>0){
        sort(tt.begin(),tt.end());
        int sum = 0;
        int lt = m-(l+1+n-r);
        for(int i=0;i<tt.size();i++){
          if(tt[i]>=0)sum+=tt[i];
          else if(lt>0){
            lt--;
          } else sum+=tt[i];
        }
        ret=max(ret,sum);
      }
    }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d %d %d\n" @@ fun n m x ->
  let as_ = Array.to_list @@ Array.init m @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  Printf.printf "%d\n" @@ min
    (List.length @@ List.filter (( <= ) x) as_)
    (List.length @@ List.filter (( >= ) x) as_)



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

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	while( cin >> n ) {
		int count = 0;

		for( int i = 0; i <= 9; ++i ) {
			for( int j = 0; j <= 9; ++j ) {
				for( int k = 0; k <= 9; ++k ) {
					uint32_t x = n - (i+j+k);

					if( x <= 9 ) {
						count += 1;
					}
				}
			}
		}

		cout << count << endl;
	}
}



Measured memory_bytes: 3156
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 1000010
int n,m,k;
char str[N];
int s[N],t[N];
struct Node{
	Node *pre,*suc;
	int s,n;
} *fir,*lst;
Node *ins(Node *p,int s,int n=1){
	Node *nw=new Node;
	*nw={p,p->suc,s,n};
	if (p->suc)
		p->suc->pre=nw;
	else
		lst=nw;
	p->suc=nw;
	return nw;
}
Node *check(Node *p){
	if (p->n==0){
		p->pre->suc=p->suc;
		if (p->suc)
			p->suc->pre=p->pre;
		else
			lst=p->pre;
		return p->pre;
	}
	if (p->pre && p->s==p->pre->s){
		p->pre->n+=p->n;
		p->pre->suc=p->suc;
		if (p->suc)
			p->suc->pre=p->pre;
		else
			lst=p->pre;
		return p->pre;
	}
	return p;
}
int ans[N*2],cnt;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	scanf("%s",str);
	for (int i=0;i<n;++i)
		s[i]=str[n-1-i]-'0';
	scanf("%s",str);
	for (int i=0;i<m;++i)
		t[i]=str[m-1-i]-'0';
	n=max(n,m);	
	fir=lst=new Node;
	*lst=(Node){NULL,NULL,0,1000000000};
	for (int i=n-1;i>=0;--i)
		if (s[i]==1 && t[i]==1){
			int z=k;
			Node *p=lst;
			while (z){
				while (1){
					Node *q=check(p);
					if (q==p) break;
					p=q;
				}
				if (p->n==0){
					p->pre->suc=p->suc;
					if (p->suc) 
						p->suc->pre=p->pre;
					else
						lst=p->pre;
					p=p->pre;
					continue;
				}
				if (p->s==0){
					if (p->n<=z){
						z-=p->n;
						p=p->pre;
						if (z==0)
							ins(p,3,1);
					}
					else{
						p->n-=z;
						Node *q=ins(p,0,z);
						ins(p,3,1);
						break;
					}
				}
				else{
					while (1){
						Node *q=check(p->pre);
						if (q==p->pre) break;
						p->pre=q;
					}
					if (p->s==1){
						if (p->pre->s==0){
							p->s=0,p->n--;
							Node *q=ins(p,2,1),*r=ins(q,0,1);
							p->pre->n--;
							check(p->pre);
							ins(p->pre,1,1);
							check(p);
							break;
						}
						else{
							p->s=0,p->n--;
							Node *q=ins(p,2,1),*r=ins(q,0,1);
							p->pre->n--;
							p=p->pre;
							z--;
							check(p->suc);
							if (z==0)
								ins(p,3,1);
							p=check(p);
						}
					}
					else if (p->s==2){
						if (p->pre->s==0){
							p->s=0,p->n--;
							Node *q=ins(p,1,1),*r=ins(q,0,1);
							p->pre->n--;
							check(p->pre);
							ins(p->pre,2,1);
							check(p);
							break;
						}
						else{
							p->s=0,p->n--;
							Node *q=ins(p,1,1),*r=ins(q,0,1);
							p->pre->n--;
							p=p->pre;
							z--;
							check(p->suc);
							if (z==0)
								ins(p,3,1);
							p=check(p);
						}
					}
//				else
//					printf("fuck\n");
				}
			}
		}
		else{
			int f=s[i]|t[i]<<1;
			if (f==lst->s)
				lst->n++;
			else
				lst=ins(lst,f,1);
		}
	for (Node *p=lst;p!=fir;p=p->pre)
		for (int i=0;i<p->n;++i)
			ans[cnt++]=p->s;
	bool bz=0;
	for (int i=cnt-1;i>=0;--i){
		bz|=ans[i]&1;
		if (bz)
			putchar('0'+(ans[i]&1));
	}
//	if (bz==0)
//		putchar('0');
	putchar('\n');
	bz=0;
	for (int i=cnt-1;i>=0;--i){
		bz|=ans[i]>>1;
		if (bz)
			putchar('0'+(ans[i]>>1));
	}
//	if (bz==0)
//		putchar('0');
	return 0;
}





















Measured memory_bytes: 145244
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <set>
using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
typedef long long LL;

int W, H;
pair<bool, int> S[200001];

bool Comp(const pair<bool, int>& a, const pair<bool, int>& b) {
	return a.second < b.second;
}

int main() {
	cin >> W >> H;
	int buf;
	REP(i, 0, W) {
		cin >> buf;
		S[i] = make_pair(false, buf);
	}
	REP(j, 0, H) {
		cin >> buf;
		S[j + W] = make_pair(true, buf);
	}
	sort(S, S + W + H, Comp);

	int w_n = 0, h_n = 0;
	LL sum = 0;
	REP(k, 0, W + H) {
		if (S[k].first == false) {
			++w_n;
			sum += (LL)S[k].second * (H + 1 - h_n);
		} else {
			++h_n;
			sum += (LL)S[k].second * (W + 1 - w_n);
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv vector<vector<int> >
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}



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

vi a(n,-1);

rep(i,m){
  int s,c;cin>>s>>c;
  if(a.at(s-1)==-1)a.at(s-1)=c;
  else {
    if(a.at(s-1)!=c){
      cout<<"-1"<<endl;
      return 0;
    }
  }
}
if(n==2||n==3){
  if(a.at(0)==0){
    cout<<"-1"<<endl;
      return 0;
  }
}

rep(i,n){
  if(a.at(i)==-1&&i==0){
    if(n==1)cout<<0;
    else cout<<1;
    }
  else if(a.at(i)==-1)cout<<0;
  else cout<<a.at(i);
}
cout<<endl;


 return 0;



}

Measured memory_bytes: 3616
import math

K = int(input())
count = {}
for a in range(1, K + 1):
    for b in range(1, K + 1):
        d = math.gcd(a, b)
        if d in count:
            count[d] += 1
        else:
            count[d] = 1
res = 0
for c in range(1, K + 1):
    for d, cnt in count.items():
        res += math.gcd(c, d) * cnt
print(res)

Measured memory_bytes: 67724
n, q = map(int, input().split())
s = input()
td = [input().split() for _ in range(q)]


def sim(i):
    if i == -1:
        return -1
    if i == n:
        return 1
    for t, d in td:
        if t == s[i]:
            if d == 'L':
                i -= 1
            else:
                i += 1
        if i == -1:
            return -1
        if i == n:
            return 1
    return 0


l =-1
r = n
while l + 1 < r:
    m = (l + r) // 2
    if sim(m) == -1:
        l = m
    else:
        r = m
A = l

l = -1
r = n
while l + 1 < r:
    m = (l + r) // 2
    if sim(m) == 1:
        r = m
    else:
        l = m
B = r

print(B - A - 1)

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

template <class T>
inline bool uin(T& a, T b) { return a > b ? (a = b, true) : false; }
template <class T>
inline bool uax(T& a, T b) { return a < b ? (a = b, true) : false; }

#ifdef LOCAL
#include "pretty.h"
void debug_out() { cerr << endl; }
template <typename head, typename... body>
void debug_out(head H, body... T) {
	cerr << ' ' << H << ' ';
	debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

/**
 * 1D Segment tree: Suppports point update and range queries.
 * f is an associative function. f can be non-commutative.
 * @warning: When f is non-commutative, ensure correct ordering of children!
 * @note: For query function, bounds are inclusive to left and exclusive to right
 */
template <typename T>
struct seg_tree {
	static constexpr T unit = -1;
	vector<T> tree;
	int N;

	inline T f(T a, T b) { return max(a, b); }
	seg_tree(int _N = 0, T def = unit) : tree(2 * _N, def), N(_N) {}
	void update(int pos, T value) {
		for (tree[pos += N] = value; pos > 1; pos >>= 1)
			tree[pos >> 1] = f(tree[pos], tree[pos ^ 1]);
	}
	T query(int l, int r) {
		T ra = unit, rb = unit;
		for (l += N, r += N; l < r; l /= 2, r /= 2) {
			if (l & 1) ra = f(ra, tree[l++]);
			if (r & 1) rb = f(tree[--r], rb);
		}
		return f(ra, rb);
	}
};

const int MOD = 998244353;

int add(const int& a, const int& b) {
	int res = a + b;
	if (res >= MOD) res -= MOD;
	return res;
}

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

	vector<array<int, 2>> P(N);
	for (int i = 0; i < N; ++i) cin >> P[i][0] >> P[i][1];
	sort(P.begin(), P.end());

	seg_tree<int> st(N);
	st.update(N - 1, N - 1);
	vector<int> R(N);
	R[N - 1] = N - 1;
	for (int i = N - 2; i >= 0; --i) {
		int l = i, r = N - 1;
		while (l < r) {
			int m = (l + r + 1) / 2;
			if (P[m][0] < P[i][0] + P[i][1])
				l = m;
			else
				r = m - 1;
		}
		debug(l);
		debug(st.query(i, l + 1));
		R[i] = max(i, st.query(i, l + 1));
		st.update(i, R[i]);
	}
	debug(R);
	vector<long long> dp(N + 10, 0);
	dp[N - 1] = 2, dp[N] = 1;
	for (int i = N - 2; i >= 0; --i)
		dp[i] = add(dp[i + 1], dp[R[i] + 1]);

	cout << dp[0] << '\n';
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    ll N;
    cin >> N;
    vector<ll> A(N);

    for(ll i = 0; i < N; ++i){
        cin >> A[i];
    }

    A.push_back((1<<20)-1);


    ll i_l = 0;
    ll i_r = 0;
    ll ans_l = 0;
    ll ans_r = 0;
    ll tmp_sum = 0;
    ll tmp_xor = 0;
    ll ans = 0;
    while(!((i_l == N) && (i_r == N))){

        if(((tmp_sum + A[i_r]) == (tmp_xor ^ A[i_r])) && (i_r < N)){
            tmp_sum += A[i_r];
            tmp_xor ^= A[i_r];
            i_r++;
        }else{
            ans += (i_r - ans_r);
            ans += (i_r - ans_r) * (ans_r - i_l);
            ans += (i_r - ans_r) * (i_r-ans_r-1) / 2;
            ans_r = i_r;
            ans_l = i_l;
            if(i_r == N) break;
            while((tmp_sum + A[i_r]) != (tmp_xor ^ A[i_r])){
                tmp_sum -= A[i_l];
                tmp_xor ^= A[i_l];
                i_l++;
            }
        }
        
    }

    cout << ans << endl;

    
    return 0;
}



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

int x,y,z[51]={};

int mySet(int d,int e){
	int a=0;
	for(int i=1;i<d;i++){
		if(z[i]>=z[i+1]){
			return 0;
		}
	}
	if(d==x){
		if(e==y){
			return 1;
		}else{
			return 0;
		}
	}
	for(int j=0;j<=9;j++){
		z[d+1]=j;
		a+=mySet(d+1,e+j);
	}
	return a;
}

int main(void){
	while(1){
		cin>>x>>y;
		if(x==0&&y==0){
			break;
		}else{
			cout<<mySet(0,0)<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3012
#include<stdio.h>

int main(void){
	int N,M,C,i,j,ans=0;
	scanf("%d %d %d",&N,&M,&C);
	int B[M],A[N][M];
	for(i=0;i<M;i++) scanf("%d",&B[i]);
	for(i=0;i<N;i++){
		for(j=0;j<M;j++) scanf("%d",&A[i][j]);
	}
	
	for(i=0;i<N;i++){
		int sum=C;
		for(j=0;j<M;j++) sum+=A[i][j]*B[j];
		if(sum>0) ans++;
	}
	
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
	char rank[5][10]={"F","D","C","B","A"};
	int border[6]={0,30,50,65,80,101};
	int m[100],f[100],r[100];
	int idx=0,i,k,sum;
	for(;;){
		scanf("%d %d %d",&m[idx],&f[idx],&r[idx]);
		if(m[idx]==-1 && f[idx]==-1 && r[idx]==-1){
					break;
		}
		idx++;
	}
	for(i=0;i<idx;i++){
		if(m[i]==-1 || f[i]==-1){
			printf("F\n");
			continue;
		}
		sum=m[i]+f[i];
		for(k=0;k<5;k++){
			if(sum>=border[k] && sum<border[k+1]){
				if(k==1 && r[i]>=50){
					printf("C\n");
					break;
				}
				printf("%s\n",rank[k]);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 1756
#include<stdio.h>

int main() {

	int N, K, X, Y, Total;

	scanf("%d", &N);
	scanf("%d", &K);
	scanf("%d", &X);
	scanf("%d", &Y);

	if (N <= K) {
		Total = N*X;
	}
	else {
		Total = K*X + (N - K)*Y;
	}

	printf("%d\n", Total);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, K;
  cin >> N >> K;
  vector<int>Pl(26, 0);
  for (int i = 0; i < N; i ++) {
    string S;
    cin >> S;
    Pl[(int)S[0] - (int)'A'] ++;
  }
  sort(Pl.begin(), Pl.end());
  reverse(Pl.begin(), Pl.end());
  int ans = 0;
  while (true) {
    for (int i = 0; i < K; i ++) {
      if (Pl[i] > 0) Pl[i] --;
      else {
        cout << ans << endl;
        return 0;
      }
    }
    ans ++;
    sort(Pl.begin(), Pl.end());
    reverse(Pl.begin(), Pl.end());
  }
}



Measured memory_bytes: 256
#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>;
ll MOD = 1e9 + 7;

ll modpow(ll x, ll n) {
    if (n==1) return x%MOD;
    if (n%2!=0) return x*modpow(x, n-1)%MOD;
    ll t = modpow(x, n/2);
    return (t*t)%MOD;
}

ll comb(ll n, ll r) {
    ll x = 1, y = 1;
    rep(i, r) {
        x = x*(n-i)%MOD;
        y = y*(1+i)%MOD;
    }
    return x*modpow(y, MOD-2)%MOD;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = modpow(2, n);
    ans -= comb(n, a);
    ans -= comb(n, b);
    ans--;
    cout << (ans%MOD+MOD)%MOD << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  string s; cin >> s;
  map<char, int> cnt;
  rep(i,s.size()) cnt[s[i]]++;
  if (cnt.size()==1){
    if (s.size()==1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
  }
  else if (cnt.size()==2){
    if (s.size()==2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
  }

  int MAX = max({cnt['a'],cnt['b'],cnt['c']});
  int MIN = min({cnt['a'],cnt['b'],cnt['c']});

  if (MAX-MIN<=1) cout << "YES" << endl;
  else cout << "NO" << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}



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


int isOdd(int n) {
	int cnt = 0;
	while(n>0) n/=10, cnt++;
	return cnt%2==1;
}
int main() {
	int n, ans = 0;
	cin>>n;
	int i;
	for (i=1;i<=n;i++) {
		ans += isOdd(i);
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int x,y,z,ans;
 
int main(){
	scanf("%d%d%d",&x,&y,&z);
	if (x<y) swap(x,y);
	if (x<z) swap(x,z);
	if (y<z) swap(y,z);
	for (;y<x;++y,++z,++ans);
	for (;z+2<=y;z+=2,++ans);
	if (z<y) ans+=2;
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

vvi dfs(int n,int m){
	vvi ret;
	if(n==1){
		vi v;
		v.push_back(1);
		ret.push_back(v);
		return ret;
	}else if(n==0){
		return ret;
	}
	for(int i=min(m,n);i>0;i--){
		vvi vv=dfs(n-i,i);
		if(vv.size()==0){
			vi v;
			v.push_back(i);
			ret.push_back(v);
		}else{
			REP(j,vv.size()){
				vi v;
				v.push_back(i);
				v.insert(v.end(),ALL(vv[j]));
				ret.push_back(v);
			}
		}
	}
	return ret;
}

int main(){
	int n;
	while(cin>>n,n){
		vvi ans;
		vvi r=dfs(n,n);
		ans.insert(ans.end(),ALL(r));
		REP(i,ans.size()){
			REP(j,ans[i].size()){
				cout<<ans[i][j]<<(j==ans[i].size()-1?"":" ");
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 1872
//#pragma comment(linker, "/stack:200000000")
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set =
	tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define un(x) x.erase(unique(ALL(x)),x.end())
#define REP(i,x,v)for(int i=x;i<=v;i++)
#define REPD(i,x,v)for(int i=x;i>=v;i--)
#define FOR(i,v)for(int i=0;i<v;i++)
 
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

int dp[1<<21];

int a[22][22];
const int MOD=1e9+7;
	
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	cout << fixed << setprecision(11);
	cerr << fixed << setprecision(6);
	int n;cin>>n;
	REP(i,1,n)REP(j,1,n)cin>>a[i][j];
	dp[0]=1;
	REP(m,1,(1<<n)-1){
		int s=__builtin_popcount(m);
		FOR(j,n) if ((1<<j)&m && a[s][j+1]) dp[m]=(dp[m]+dp[m^(1<<j)])%MOD;
	}
	cout<<dp[(1<<n)-1]<<endl;
		


    return 0;
}










Measured memory_bytes: 8448
class Dice:
 
    def __init__(self, faces):
        self.faces = tuple(faces)
 
    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])
 
    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])
 
    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])
 
    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])
 
    def number(self, face_id):
        return self.faces[face_id - 1]
 
dice = Dice(list(map(int, input().split())))
n = int(input())
for i in range(n):
    (face1, face2) = map(int, input().split())
    if face2 == dice.number(3) or face2 == dice.number(4):
        dice.roll_west()
    while dice.number(2) != face2:
        dice.roll_north()
    while dice.number(1) != face1:
        dice.roll_west()
    print(dice.number(3))

Measured memory_bytes: 7780
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 2e9;
const int mod = 1e9 + 7;

int n, m;
const int MAX = 100000;
int y[MAX];
int l[2 * MAX];
int r[2 * MAX];

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

    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int x, _y;
        cin >> x >> _y;
        y[x] = _y;
    }

    rep(i, n) {
        l[i] = r[i] = i;
    }

    rep(i, MAX) {
        if (!y[i]) continue;
        l[y[i] - 1] = l[y[i]] = min(l[y[i] - 1], l[y[i]]);
        r[y[i] - 1] = r[y[i]] = max(r[y[i] - 1], r[y[i]]);
    }

    rep(i, n) {
        cout << (i != 0 ? " " : "") << r[i] - l[i] + 1;
    }
    cout << endl;

}

Measured memory_bytes: 7056
def resolve():
    import math
    k = int(input())
    ans = 0
    for i in range(1, k+1):
        for j in range(1, k+1):
            gcd1 = math.gcd(i,j)
            for l in range(1, k+1):
                gcd = math.gcd(l, gcd1)
                ans += gcd
    print(ans)
resolve()

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

bool is_prime(int x)
{
	if(x < 2) return false;

	for(int i = 2; i * i <= x; ++i) {
		if(x % i == 0) return false;
	}

	return true;
}

int main()
{
	while(true) {
		int a, d, n;
		cin >> a >> d >> n;
		if(a == 0 && d == 0 && n == 0) break;
			
		int cnt = 0;

		for(int i = a; ; i += d) {
			if(is_prime(i)) {
				cnt++;

				if(cnt == n) {
					cout << i << endl;
					break;
				}
			}
		}
	}
}

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

#define int long long
#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second
const int mod = 1e9 + 7;
int add(int a,int b){
	return (a + b)%mod;
}
int sub(int a,int b){
	return add(a,mod - 1);
}
int mul(int a,int b){
	return (a*b)%mod;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    string s;
    cin >> s;
    if(s[1] == 'B'){
    	cout << "ARC";
    }else{
    	cout << "ABC";
    }
}

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

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
   char c;
   cin >> c;
   if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') cout << "vowel" << endl;
   else cout << "consonant" << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
  #define int long long int
  #define vi vector<int>
  #define pii pair<long long ,long long>
  #define pll pair<int,int>
  #define mod 1000000007
  #define all(x) x.begin(),x.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define eb push_back
  #define ff first
  #define ss second
  #define rep(n) for(int i=0;i<n;i++)
  #define lb lower_bound
  #define up upper_bound
   
  
  using namespace std;
  int dp[100005];
  int h[100005];
  void solve()
  { 
    
     int n;
     cin>>n;
     rep(n)
      cin>>h[i+1];
     
     for(int i=1;i<=n;i++)
       dp[i]=INT_MAX;
     dp[1]=0;
     for(int i=1;i<=n;i++)
     {
       if(i+1<=n)
       dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
     if(i+2<=n)
       dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
     }
     cout<<dp[n];


   
   }

  signed main()
  {
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    T=1;
    
    while(T--)
    {
      solve();
    }
    return 0;
  }

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define lli long long
#define llmax LLONG_MAX   //ranges are defined in climits
#define llmin LLONG_MIN
#define imax INT_MAX
#define imin INT_MIN
#define pb push_back
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
  lli x;cin>>x;
	lli modResult = x%11;
  lli ans=(lli)x/11 * 2;
	if(modResult<7 && modResult>0)
		++ans;
	else if(modResult>=7)
		ans+=2;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,j=0;
  cin>>n;
  vector<ll> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());
  for(int i=1;i<n;i++){
    if(a[i-1]*2<a[i]){
      j=i;
    }
    a[i]+=a[i-1];
  }
  cout<<n-j;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  int e=0,d=0;
  cin>>a>>b>>c;
  reverse(a.begin(),a.end());
  if(a[0]==b[0])d=1;
  reverse(b.begin(),b.end());
  if(b[0]==c[0])e=1;
  if(d==1&&e==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

int del_Recipies(int del,int count,int n,int m,int p[],int Recipies[500][500]);

int main()
{
	int n,m,Recipies[500][500]={0},MAX[500],min_del_Recipies,c,flag,*p,count;
	
	while(1)
	{
		scanf("%d %d",&n,&m);
		if(n==0&&m==0) break;
		min_del_Recipies=-1;
		for(int i=0;i<m;i++) MAX[i]=0;//初期化
		for(int i=0;i<n;i++)
		{
			for(int t=0;t<m;)
			{
				Recipies[i][t]=getchar();
				if(Recipies[i][t] != '\n'&& Recipies[i][t] != ' ')
				{
					Recipies[i][t]-='0';
					MAX[t]+=Recipies[i][t];
					t++;
				}
			}
		}
		flag=1;
		//作る際に必要な材料数がすべての材料で2で割り切れたなら、その時のレシピ数になる
		for(int t=0;t<m;t++)
		{
			if(MAX[t]%2)
			{
				flag=0;
				break;
			}
		}
		if(flag) min_del_Recipies=0;
		else
		{
			p=(int*)malloc(m*sizeof(int));
			//すべて作った時に必要な材料からレシピを減らしていく
			//減らしていく数を順に増やしていき、その減らす数の時のすべての減らし方を試す
			
			for(int del=1;del<n;del++)//何個引くか del個 引いた個数 count
			{
				for(int i=0;i<m;i++) p[i]=MAX[i];
				count=0;
				flag=del_Recipies(del,count,n,m,p,Recipies);//何個引くか del個 引いた個数 count
				//del個減らしたときにすべての材料が2で割り切れるものがあったら 1を返す なかったら 0を返す
				if(flag)
				{
					min_del_Recipies = del;//delで割り切れたとき
					break;
				}
			}
			if(min_del_Recipies==-1)min_del_Recipies=n;//どれも割り切れなかったとき
			free(p);
		}
		printf("%d\n",n-min_del_Recipies);//全体から割り切れるまでに引いた個数を引くと求まる
	}
	return 0;
}

int del_Recipies(int del,int count,int n,int m,int p[],int Recipies[500][500])
{
	//引く個数=del 引いた個数=count何種類目 i
	int flag=1;
	for(;count<n && n-count>=del;count++)
	{
		
		if(del==1)
		{
			flag=1;
			for(int t=0;t<m;t++)
			{
				p[t]-=Recipies[count][t];
				if(p[t]%2!=0)
				{
					flag=0;
					p[t]+=Recipies[count][t];
					break;
				}
				p[t] += Recipies[count][t];
			}
			if(flag) return 1;
			else continue;
		}
		else 
		{
			//残りの引く個数が1になるまで再起
			//pから今回引くRecipiesを引いてから次に渡す
			for(int t=0;t<m;t++) p[t]-=Recipies[count][t];
			//引く個数delを一つ減らす　引いた個数countを一つ増やす
			if(del_Recipies(del-1,count+1,n,m,p,Recipies)) return 1;
			for (int t = 0; t<m; t++) p[t] += Recipies[count][t];
		}
		
	}
	return 0;
}


Measured memory_bytes: 2724
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m=1001,k,l,t,b,a,c;
int main()
{
  for(cin>>n>>t;i<n;i++){
    cin>>a>>b;
    if(b<=t)m=min(m,a);
  }
  if(m==1001)return cout<<"TLE",0;
  cout<<m;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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 main() {
  int a,b,c;
  cin >> a >> b >> c;
  int drop = a-b;
  if(c-drop>=0) cout << c-drop << endl;
  else cout << 0 << endl;

}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    pp = sorted(p, reverse=True)[:X]
    qq = sorted(q, reverse=True)[:Y]
    apples = sorted(pp + qq)
    rr = sorted(r, reverse=True)
    for i, v in enumerate(apples):
        if len(rr) > i and rr[i] > v:
            apples[i] = rr[i]
        else:
            break
    print(sum(apples))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    q = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    r = [int(next(tokens)) for _ in range(C)]  # type: "List[int]"
    solve(X, Y, A, B, C, p, q, r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 28988
X, Y = map(int, input().split())
if (Y%2==1 and (X+Y//2)%3==1) or (Y%2==0 and (X+Y//2)%3==0):
    if X==Y: print("Brown")
    else: print("Alice")
else:
    if abs(X-Y)==1: print("Brown")
    else: print("Alice")

Measured memory_bytes: 61636
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> mp(h);
	rep(i, h) cin >> mp[i];
	ll ans = 0;
	vector<vector<bool>> visit(h, vector<bool>(w));
	rep(i, h) {
		rep(j, w) {
			if (mp[i][j] == '#') {
				queue<pair<int, int>> que;
				visit[i][j] = true;
				ll bl = 1, wh = 0;
				que.push({ i,j });
				while (que.size()) {
					int a = que.front().first;
					int b = que.front().second;
					que.pop();
					rep(k, 4) {
						int c = a + dx[k];
						int d = b + dy[k];
						if (c >= 0 && c < h && d >= 0 && d < w && mp[c][d] != mp[a][b] && !visit[c][d]) {
							if (mp[c][d] == '.') wh++;
							else bl++;
							visit[c][d] = true;
							que.push({ c,d });
						}
					}
				}
				ans += bl * wh;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
count_all = 0
for i in range(N):
    B[A[i]] += 1
for j in range(1, N+1):
    count_all += B[j]*(B[j]-1)/2
for k in range(N):
    if A[k] == 0:
        print(int(count_all))
    else:
        print(int(count_all - B[A[k]] + 1)) 

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

int main() {
	string whether[3] = {"Sunny", "Cloudy", "Rainy"};

	string today;

	cin >> today;

	if (today == "Sunny") {
		cout << "Cloudy";
	}
	else if (today == "Cloudy") {
		cout << "Rainy";
	}
	else {
		cout << "Sunny";
	}

	return 0;
}

Measured memory_bytes: 256