akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	ll n, c, ans=0, m=0;
	cin >> n;
	for (ll i=0; i<n; i++)
	{
		cin >> c;
		m = max(m, c);
		ans += m - c;

	}
	cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>

using namespace std;

int main(){
    int n;
    cin >> n;
    long long int ans = 0;
    for(int i = 0; i < n; i++){
        long long int x;
        cin >> x;
        if(x % 2 == 0){
            while (x % 2 == 0) {
                x /= 2;
                ans++;
            }
        }
    }
    cout << ans;
}

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

using namespace std;
int N, X, Y, ans[23333];

int main(){
    cin >> N >> X >> Y;
    for (int i = 1; i <= N; i++){
        for (int j = i+1; j <= N; j++){
            int a = j-i;
            int b = 1+abs(i-X)+abs(j-Y);
            int d = min(a, b);
            ans[d]++;
        }
    }
    for (int i = 1; i < N; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 256
import java.util.*;

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


        boolean b = false;
        int n1=0, n2=0;
        for(int i=1; i<1000; i++){
            if(i * (i+1) == n * 2){
                b = true;
                n1 = i;
                n2 = i+1;
                break;
            }
        }

        if(!b){
            System.out.println("No");
            return;
        }

        int[][] ans = new int[n2][n1];
        for(int i=0; i<n1; i++){
            ans[0][i] = i+1;
        }
        int c = n1+1;
        for(int i=1; i<n2; i++){
            for(int j=0; j<i; j++){
                ans[i][j] = ans[j][i-1];
            }
            for(int j=i; j<n1; j++){
                ans[i][j] = c;
                c++;
            }
        }

        System.out.println("Yes");
        System.out.println(n2);
        for(int i=0; i<n2; i++){
            System.out.print(n1);
            for(int j=0; j<n1; j++){
                System.out.print(" " + ans[i][j]);
            }
            System.out.println("");
        }

    }
}

Measured memory_bytes: 47976
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
template<class T>
inline T ab(T a){
	return (a > 0) ? a : -a;
}
template<class T>
inline void swa(T &a, T &b){
	a ^= b ^= a ^= b;
	return ;
}
ll cnt, x, y, n, m;
ll h[maxn];
bool f[maxn];
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	qread(n);
	qread(m);
	for(int i = 1;i <= n;i++){
		qread(h[i]);
	}
	for(int i = 1;i <= m;i++){
		qread(x);
		qread(y);
		if(h[x] <= h[y]){
			f[x] = 1;
		}
		if(h[y] <= h[x]){
			f[y] = 1;
		}
	}
	for(int i = 1;i <= n;i++){
		if(!f[i]){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;

  vector<pair<int, int>> ps(N);
  rep(i, N){
    int X, L;
    cin >> X >> L;
    ps.at(i) = make_pair(X+L, X-L);
  }

  sort(ps.begin(), ps.end());
  int cur = -1e9;
  int ans = 0;

  rep(i, N){
    if(cur <= ps.at(i).second){
      ans++;
      cur = ps.at(i).first;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int N;
  ci(N);
  ve<int> a(N);
  rep(i, N){
    ci(a.at(i));
  }
  sort allr(a);
  int c = 0, b = 0;
  rep(i, N){
    if(i % 2 == 1){
      c += a.at(i);
    }
    else{
      b += a.at(i);
    }
  }
  co(abs(c - b));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<bool>check(n+1,false);
  vector<int>was(n+1,0);
  int wa = 0;
  int ac = 0;
  int i;
  int p;
  string s;
  for(i=0;i<m;i++){
    cin >> p >> s;
    if(check[p]==false){
      if(s=="WA")was[p]++;
      else{
      check[p]=true;
      ac++;
    }
  }
  }
  for(i=1;i<=n;i++){
    if(check[i])wa += was[i];
  }
  cout << ac << " " << wa << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1e5+10;
inline char get() {
	static char buf[10000], *S = buf, *T = buf;
	if (S == T) {
		T = (S = buf) + fread(buf, 1, 10000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}
inline void read(int &x) {
	static char c; x = 0; int sgn = 0;
	for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
	for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
	if (sgn) x = -x;
}

int n, m;
vector<int> adj[N];
int deg[N];
int dp[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read(n); read(m);
  for (int i = 0; i < m; i++) {
    int u, v; read(u); read(v); u--; v--;
    adj[u].push_back(v);
    deg[v]++;
  }
  stack<int> q;
  for (int i = 0; i < n; i++) {
    if (!deg[i]) q.push(i);
  }
  while (!q.empty()) {
    int u = q.top(); q.pop();
    for (int v : adj[u]) {
      dp[v] = max(dp[v], dp[u]+1);
      if (!--deg[v]) q.push(v);
    }
  }
  cout << *max_element(dp, dp + N) << nl;
  return 0;
}


Measured memory_bytes: 6528
package main

import "fmt"

func main() {
  var s string

  start := -1
  end := -1
  fmt.Scanf("%s", &s)
  for i, _ := range s {
    if s[i:i+1] == "A" && start == -1 {
      start = i
    }
    if s[i:i+1] == "Z" {
      end = i
    }
  }
  fmt.Println(end-start+1)
}

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

bool linearSearch(int key, int n, int S[]) {
    int i = 0;
    S[n] = key;
    while(key != S[i]) i++;
    return i != n;
}

int main() {
    int n, q, cnt = 0;
    int S[20000], T[1000];
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> S[i];
    }
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> T[i];
        if(linearSearch(T[i], n, S)) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3108
N = int(input())

e_list = [[] for i in range(N)]
for i in range(N-1):
    a,b,c = list(map(int,input().split()))
    a=a-1
    b=b-1
    e_list[a].append([b,c])
    e_list[b].append([a,c])

Q,K = list(map(int,input().split()))
q = []
for i in range(Q):
    x,y=list(map(int,input().split()))
    x=x-1
    y=y-1
    q.append([x,y])

vi = K-1 #時と場合によってここを変える
from collections import deque
Q = deque([vi])
checked_list = [False for i in range(N)]
checked_list[vi]=True
min_path_list = [10**27 for i in range(N)] #問題によりここを変える
min_path_list[vi] = 0
while len(Q)>0:
    v = Q.pop()
    for e in e_list[v]:
        v1,c=e
        if not checked_list[v1]:
            checked_list[v1]=True
            Q.append(v1)
            min_path_list[v1]=min(min_path_list[v1],min_path_list[v]+c) #問題によりここを変える

for a in q:
    x,y=a
    print(min_path_list[x]+min_path_list[y])

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define mem(a,b) memset(a,b,sizeof(a))
#define shutdown ios::sync_with_stdio(false)
#define MAX 10e18+1000
#define INF 0x3f3f3f3f

int math[100][100];
struct aa{
    int x;
    int y;
}flag[3000];

int main()
{
    shutdown;
    mem(math,0);
    mem(flag,0);
    int a,b,k=0,ff=0;
    char temp;
    scanf("%d%d",&a,&b);
    scanf("%*c");
    for(int i=1;i<=a;i++){
        for(int j=1;j<=b;j++){
            scanf("%c",&temp);
            if(temp=='#')
                math[i][j]=1000;
            else{
                math[i][j]=0;
                ff=1;
                flag[k].x=i,flag[k].y=j;
                k++;
            }
        }
        scanf("%*c");
    }
    if(ff){
    for(int i=0;i<k;i++){
        int ta=flag[i].x;
        int tb=flag[i].y;
        math[ta][tb]=math[ta-1][tb-1]+math[ta][tb-1]+math[ta+1][tb-1]+math[ta-1][tb]+math[ta+1][tb]+math[ta-1][tb+1]+math[ta][tb+1]+math[ta+1][tb+1];
        math[ta][tb]/=1000;
    }
    }
    for(int i=1;i<=a;i++){
        for(int j=1;j<=b;j++){
            if(math[i][j]==1000)
                printf("#");
            else
                printf("%d",math[i][j]);
        }
        printf("\n");
    }
	return 0;
}



Measured memory_bytes: 384
while(1):
    [n,m]=map(int,raw_input().split())
    if n==0:    break
    D=[[] for i in range(n+1)]
    D[0]=range(1,n+1)
    nflg=0
    for i in range(m):
        [u,v]=map(int,raw_input().split())
        D[u].append(v)
        D[v].append(u)
        if len(D[u])>2 or len(D[v])>2:
            nflg=1
    if nflg:
        print 'no'
    else:
        bkf=0
        while (len(D[0])>0):
            st=D[0].pop()
            if len(D[st])==2:
                D[0].append(st)
            st0=st
            while len(D[st])!=0:
               nxt=D[st].pop()
               if nxt!=st0:
                   D[0].remove(nxt)
                   D[nxt].remove(st)
                   st=nxt
               else:
                   print 'no'
                   bkf=1
                   break
            if bkf:    break
        else:
            print 'yes'
            

Measured memory_bytes: 29308
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int N,M; cin >>N >>M;
  vector<vector<bool>> S(M, vector<bool>(N, false));
  vector<int> P(M, 0);
  rep(i, M){
    int k; cin >>k;
    rep(j, k){
      int s; cin >>s; s--;
      S[i][s] = true;
    }
  }
  rep(i, M) cin >>P[i];

  int res = 0;

  for (int bit=0; bit<(1<<N); bit++){
    bool ok = true;
    rep(i, M){
      int p = 0;
      rep(j, N){
        if (S[i][j]) if (bit & (1<<j)) p++;
      }
      p %= 2;
      if (p != P[i]){ ok = false; break;}
    }
    if (ok) res++;
  }
  cout <<res <<endl;
}


Measured memory_bytes: 256
from collections import deque

N = int(input())
G = [[] * N for _ in range(N)]
for _ in range(N - 1):
  a, b, c = map(int, input().split())
  G[a - 1].append((b - 1, c))
  G[b - 1].append((a - 1, c))

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

D = [-1] * N
D[K - 1] = 0

q = deque([K - 1])
while q:
  n = q.popleft()
  for i, c in G[n]:
    if D[i] < 0:
      q.append(i)
      D[i] = D[n] + c

for _ in range(Q):
  x, y = map(int, input().split())
  print(D[x - 1] + D[y - 1])

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

int jou(int x,int y){
  int ans = 1,i;

  for(i = 0;i < y;i++){
    if(y != 0) ans *= x;
  }
  if(y == 0) ans = 1;
  return ans;
}


int main(){
  int keta = 0,n;
  int bin[999];

  while(1){
    cin >> n;
    if(n == -1) break;
    int sum = n;
    //keta
    while(1){
      if(n < 4 )break;
      keta++;   
      n /= 4;
    }

    keta ++;
    // cout << "keta = " << keta << endl;

    for(int i = keta - 1;i > 0;i--){
      bin[i] = sum / jou(4,i);
      // cout << "bin[i] = " << bin[i] << "jou(4,1) = " << jou(4,i) << endl;
      sum = sum - jou(4,i) * bin[i];
    }

    bin[0] = sum;

    for(int i = keta - 1;i >= 0 ;i--){
      cout  << bin[i]  ;
    }
    cout << endl;
    keta = 0;
  }
 
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

long long cnt;

struct SSS
{
	string str;
	int val;
	SSS(string s = "", int v = 0) :str(s), val(v){};
};

void print(vector<SSS> &data){
	for (int i = 0; i < data.size(); ++i){
		cout << data[i].str << " " << data[i].val << endl;
	}
}

void print(vector<int> &data){
	for (int i = 0; i < data.size(); ++i) {
		cout << data[i];
		if (i == data.size() - 1) cout << endl;
		else cout << " ";
	}
}

void print_endl(vector<int> &data){
	for (int i = 0; i < data.size(); ++i) {
		cout << data[i] << endl;
	}
}

vector<SSS> tmp;
void mer(vector<SSS> &data, int l, int m, int r){
	for (int i = l; i < r; ++i) tmp[i] = data[i];
	cnt += (r - l);

	int p1(l), p2(m);
	while (p1 < m && p2 < r) {
		if (tmp[p1].val <= tmp[p2].val) data[l++] = tmp[p1++];
		else data[l++] = tmp[p2++];
	}
	while (p1 < m) data[l++] = tmp[p1++];
	while (p2 < r) data[l++] = tmp[p2++];
}

void merS(vector<SSS> &data, int l, int r){
	if (l + 1 < r){
		int m = l + (r - l) / 2;
		merS(data, l, m);
		merS(data, m, r);
		mer(data, l, m, r);
	}
}

int part(vector<SSS> &data, int l, int r){
	SSS v = data[r];

	int p1 = l - 1;
	int p2 = l;
	while (p2 < r) {
		if (data[p2].val <= v.val) swap(data[++p1], data[p2]);
		p2++;
	}
	swap(data[++p1], data[r]);
	return p1;
}

void quiS(vector<SSS> &data, int l, int r){
	if (l < r){
		int piv = part(data, l, r);
		quiS(data, l, piv - 1);
		quiS(data, piv + 1, r);
	}
}

int main()
{
	int n; cin >> n;
	vector<SSS> data(n);
	for (int i = 0; i < n; ++i) {
		SSS s;
		cin >> s.str >> s.val;
		data[i] = s;
	}
	vector<SSS> d1(data), d2(data);
	tmp.resize(n);
	merS(d1, 0, n);
	//print(d1);
	//cout << cnt << endl;

	quiS(d2, 0, n - 1);

	string str = "Stable";
	for (int i = 0; i < n; ++i){
		if (d1[i].str != d2[i].str) str = "Not stable";
	}
	cout << str << endl;
	print(d2);

	return 0;
}

Measured memory_bytes: 13640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,m,i,f,t;
	cin>>n>>m;
	vector<vector<int>> g(n);
	for (i=0;i<m;i++){
		cin>>f>>t;
		f--;t--;
		g[f].push_back(t);
		g[t].push_back(f);
	}
	for (i=0;i<n;i++){
		cout<<g[i].size()<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int insertionSort(int *A, int n){
  int i,j,v,k;

  for(i=0;i<n;i++) {
    if(i==n-1)printf("%d",A[i]);
    else printf("%d ",A[i]);
  }
  
    printf("\n");
  
  for(i=1 ; i<n ; i++){
    v = A[i];
    j = i-1;
    while(j>=0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    
    for(k=0;k<n;k++) {
      if(k==n-1) printf("%d",A[k]);
      else printf("%d ", A[k]);
      }
    
    printf("\n");
  
  }
  return *A;
}
  

int main(){

  int i,j,n;
  int A[N];

  scanf("%d",&n);

  for(i=0 ; i<n ; i++) scanf("%d",&A[i]);
  
  

    insertionSort(A, n);

  
  return 0;
}


Measured memory_bytes: 2072
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

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

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  ll ans = 0;
  cin >> n;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    ans += (a-1);
  }
  cout<< ans <<endl;
}


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

using namespace std;

long long int sum[10][10];

int main(){
    long long int N,ans=0;
    cin >> N;
    for(int i=1;i<=N;i++){
        string S = to_string(i);
        sum[S[0]-'0'][S.back()-'0']++;
    }

    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            ans += sum[i][j]*sum[j][i];
        }
    }

    cout << ans << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    s.push_back('#');
    s.push_back('#');

    if(c < d){
        for(int i=b;i<d;i++){
            if(s[i-1]=='#' && s[i]=='#'){
                cout << "No" << endl;
                return 0;
            }
        }
        for(int i=a;i<c;i++){
            if(s[i-1]=='#' && s[i]=='#'){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }else{
        for(int i=a;i<c;i++){
            if(s[i-1]=='#' && s[i]=='#'){
                cout << "No" << endl;
                return 0;
            }
        }
        for(int i=b;i<d;i++){
            if(s[i-1]=='#' && s[i]=='#'){
                cout << "No" << endl;
                return 0;
            }
        }
        for(int i=b-1;i<=d-1;i++){
            if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#include <string>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;


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

  int count = 0;

  while(!H == 0) {
    H /= 2;
    count++;
  }


  ll ans = 1;
  REP(i, count) {
    ans *= 2;
  }
  ans -= 1;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		
		long count = 0;
		for(int i = 1; i < n; i++) {
			long s = a[i-1] - a[i];
			if(s > 0) {
				a[i] += s;
				count += s;
			}
		}

		System.out.println(count);
	}

}


Measured memory_bytes: 62872
def gcd(a,b):
    a,b = max(a,b),min(a,b)
    while a%b!=0:
        a,b = b,a%b
    return b

a,b,c,d=map(int,input().split())

e = c*d//gcd(c,d)

b_c = b//c
b_d = b//d
b_e = b//e
a_c = (a-1)//c
a_d = (a-1)//d
a_e = (a-1)//e

print(b-a+1 - (b_c - a_c) - (b_d - a_d) + (b_e - a_e))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int X1, X2, Y1, Y2;

int main() {
	cin >> X1 >> X2;
	cout << X1 - X2 + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
  n = int(input())
  s = input()
  s_l = [s[0]]
  if n == 0:
    print(0)
  else:
    for i in range(1,n):
      if s[i] != s_l[-1]:
        s_l.append(s[i])
        #print(s_l)
    print(len(s_l))
      
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_N 100005
ll mod=1e9+7;
int N,T,x=0;
int d[MAX_N];
ll dp[MAX_N];
int main(){
  cin>>N>>T;
  for(int i=0;i<N;i++)cin>>d[i];
  sort(d,d+N);
  dp[0]=1;
  for(int i=1;i<N;i++){
    while(d[x]<d[i]-T)x++;
    dp[i]=(dp[i-1]*(i-x+1))%mod;
  }
  cout<<dp[N-1]<<endl;
  return 0;
}

Measured memory_bytes: 2344
#include<stdio.h>
int A,B,C,X[105][105],Y[105][105],i,j,k;
long long t;
int main()
{
    scanf("%d%d%d",&A,&B,&C);
    for(i=0;i<A;i++)
        for(j=0;j<B;j++)
            scanf("%d",&X[i][j]);
    for(i=0;i<B;i++)
        for(j=0;j<C;j++)
            scanf("%d",&Y[i][j]);
    for(i=0;i<A;i++)
    {
        for(j=0;j<C;j++)
        {
            for(k=t=0;k<B;k++)
                t+=X[i][k]*Y[k][j];
            printf("%lld%s",t,j==C-1?"\n":" ");
        }
    }
    return 0;
}


Measured memory_bytes: 2104
k,n = map(int,input().split())
a = [int(x) for x in input().split()]

diff=0
for i in range(1,n):
  if(a[i]-a[i-1]>diff):
    diff=a[i]-a[i-1]
    
last = k-a[-1]+a[0]
diff= max(diff,last)
print(k-diff)

Measured memory_bytes: 26420
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

// naive
ll solve(int N, map<int,int>& M) {
    int res = 0;
    ll wa = 0;
    for (auto x = M.begin(); x != M.end(); x++) {
        wa += x->first * x->second;
        auto n = next(x);
        if (n == M.end()) { // right next is not there
            res += x->second;
            break;
        }
        ll cur = wa; // You can eat every smaller animals
        while (n != M.end()) {
            if (cur * 2 >= n->first) cur += n->first;
            else goto LOOP;
            n = next(n);
        }
        res += x->second;
LOOP: ;
    }
    return res;
}

// right answer
ll solve2(int N, map<int,int>& M) {
    int res = 0;
    ll wa = 0;
    for (auto x : M) wa += (ll)x.first * x.second;

    for (auto x = M.rbegin(); x != M.rend(); x++) {
        wa -= (ll)x->first * x->second;
        res += x->second;
        if (wa *2 < x->first) break;
    }
    return res;
}

int main() {
    int N; cin >> N;
    map<int, int> M;
    rep(i,N) {
        int a; cin >> a;
        M[a]++;
    }

    cout << solve2(N, M) << endl;
}


Measured memory_bytes: 8204
#include<stdio.h>

int main(void){

	int a[5];
	int work;
	int i,j;

	for(i=0;i<5;i++)
		scanf("%d",&a[i]);

	for(i=0;i<5;i++){
		for(j=i;j<5;j++){
			if(a[i] < a[j]){
				work = a[i];
				a[i] = a[j];
				a[j] = work;
			}
		}
	}

	printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);

	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
int main(void)
{
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    if (a<b)
        printf("a < b\n");
    else if (a>b)
        printf("a > b\n");
    else
        printf("a == b\n");
    
    return 0;
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;cin >> n;
    vl v(n);rep(i,n)cin >> v[i];
    ll m=*max_element(all(v));
    vl z(m+1);
    rep(i,n)z[v[i]]++;
    bool ok=true;
    if(m%2){
        rep(i,(m+1)/2){
            z[m-i]-=2;
            if(z[m-i]<0)ok=false;
        }
    }
    else{
        rep(i,m/2){
            z[m-i]-=2;
            if(z[m-i]<0)ok=false;
        }
        z[m/2]--;
        if(z[m/2]<0)ok=false;
    }
    //if(!ok)cout << "Impossible" <<endl,exit(0);
    ll end=m-(m/2)+1;
    //cout << end <<endl;
    rep(i,end)if(z[i])ok=false;
    if(!ok)cout << "Impossible" <<endl;
    else cout << "Possible" <<endl;
}


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

ll N;
vector<ll> capacity(5);
ll mincapa;

int main() {
    scanf("%Ld", &N);
    for (int i = 0; i < 5; i++) scanf("%Ld", & capacity[i]);
    vector<ll>::iterator mincapa = min_element(capacity.begin(), capacity.end());
    int mincapindex = distance(capacity.begin(), mincapa);

    ll count = 0;
    for (int i = 0; i < 5; i++){
        if (i == mincapindex) count += N/capacity[i] + !!(N%capacity[i]);
        else count++;
    }

    printf("%Ld\n", count);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
		}
		bubbleSort(a, n);
	}

	static void bubbleSort(int[] a, int n) {
		boolean flg = true;
		int cnt = 0;
		while(flg) {
			flg = false;
			for(int j = n - 1 ; j >= 1 ; j--) {
				if(a[j - 1] > a[j]) {
					int v = a[j - 1];
					a[j - 1] = a[j];
					a[j] = v;
					cnt++;
					flg = true;
				}
			}
		}
		for(int i = 0 ; i < n ; i++) {
			if(i != n - 1) {
				System.out.print(a[i] + " ");
			} else {
				System.out.println(a[i]);
			}
		}
		System.out.println(cnt);
	}

}

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

typedef long long ll;

int main(){
 int n;
 cin >> n;
 int a, b;
 a = n/1.08;
 b = n/1.08+1;

 int aa = a * 1.08, bb = b * 1.08;

 if(aa == n){
   cout << a;
 }
else if(bb == n){
  cout << b;
}
else{
  cout << ":(";
}

}


Measured memory_bytes: 3624
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a - 2 * b < 0){
      System.out.println(0);
    }else{
      System.out.println(a-2*b);
    }
  }
}

Measured memory_bytes: 21844
N=int(input())
import math

XY=[[int(x) for x in input().rstrip().split()] for i in range(N)]

ans=0
for i in range(N):
  for j in range(N):
    if i<j:
      ans+=math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)
bb=1
for i in range(1,N+1):
  bb*=i

print(2*ans/N)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
int mod = 1e9+7;

vector<P> prime_factorize(int N){
	vector<P> ans;
	for(int a = 2; a*a <= N; a++){
		if(N%a == 0){
			int ex = 0;
			while(N%a == 0){
				ex++;
				N /= a;
			}
			ans.push_back(P(a, ex));
		}
	}
	if(N != 1) ans.push_back(P(N, 1));
	return ans;
}

signed main(){
	int N, Q; cin >> N >> Q;
	/*
	for(int i = 0; i < map.size(); i++){
        for(int j = 0; j < map[i].second/N; j++){
			 ans *= map[i].first;
		}
	} */
	vector<P> map = prime_factorize(Q);
    int ans = 1;
    for (auto p : map) {
        for (int j = 0; j < p.second/N; ++j) ans *= p.first;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <complex> 
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)


typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int MOD =  1e9 + 7; 
 
ll power(ll a, ll b){
	if(b == 0) return 1;
	else {
		ll x = power(a,b/2);
		x = (x*x)%MOD;
		if(b&1) return (x*a)%MOD;
		else return x;
	}
}

ll& Mod(ll& a) {
    if (a >= MOD) {
        return Mod(a -= MOD);
    } else if (a < 0) {
        return Mod(a += MOD);
    } else {
        return a;
    }
}

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



int main() {
	fast_cin();
	ll k;
	cin >> k;
	ll sum = 0;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= k; j++){
			for(int l = 1; l <= k; l++){
				 sum += gcd(i, gcd(l, j));
			  }
		}
	 }
	 
	 cout << sum << '\n';
	  
}


Measured memory_bytes: 3620
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
      
        int a = sc.nextInt();
        int n = 0;
        int ans = 0;
      
        do {
          n++;
          ans = n*100 + n*10 + n;
        } while(a > ans);

          System.out.println(ans);
    }
}

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

int main() {
  int L, R;
  cin >> L >> R;

  ll ans = 2020;
  if (2020 < R - L) ans = 0;
  else {
    rep(i,L,R) {
      rep(j,i+1,R) {
        ans = min(ans, i * j % 2019);
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

string S;

int main() {
    cin >> S;
    ll N = S.length();

    ll ans = N, cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'S') {
            ++cnt;
        }
        if (S[i] == 'T' && cnt) {
            ans -= 2;
            --cnt;
        }
    }
    cout << ans << endl;
}

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

//const ll MAX = 200000;
const ll MOD = 1000000007;

/*
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/

// 累積積でa^nを計算
ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1) res = res*a%MOD;
        a = a*a%MOD;
        n >>= 1;
    }
    return res;
}

// kの逆元(k^{-1} mod 10^9+7)を計算
ll modinv(ll k){
    return modpow(k, MOD-2);
}

// 愚直な二項係数計算
ll nCk(ll n, ll k){
    ll res = 1;
    for(ll i=1; i<=k; i++){
        res = (res*(n-i+1)%MOD)*modinv(i)%MOD;
    }
    return res;
}

void solve(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll res = (modpow(2, n) - 1 - nCk(n, a) - nCk(n, b))%MOD;
    if(res<0) res += MOD;
    cout << res << endl;

}

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

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> //tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric>
using namespace std;

int main() {
    float N;
    const float Pi = 3.1415926535;
    cin >> N;
    cout << 2.0f * N * Pi << endl;
}

Measured memory_bytes: 3788
w,h,n = map(int, input().split())

x1, x2, y1, y2 = 0, w, 0, h

for _ in range(n):
    x,y,a=map(int, input().split())

    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    elif a == 4:
        y2 = min(y2, y)

x2 = max(x1, x2)
y2 = max(y1, y2)

print((y2 - y1) * (x2 - x1))


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

int main()
{
	int x,temp,k,j,i,m;
	char s[100];
	char t[100];
	while(scanf("%s%s",s,t)!=EOF)
	{
		x=strlen(s);
		
			for(i=0;i<x;i++)
			{
				temp=s[x-1];
				for(j=x-1;j>=0;j--)
				{
					s[j]=s[j-1];
					if(j==0)
					{
						s[j]=temp;
					}
					
				}
				if(strcmp(s,t)==0)
				{
					printf("Yes\n");
					break;
				}
			}
			//printf("%s\n",s);
			if(i>=x)
			{
				printf("No\n");	
			}
		
	}
	return 0;
	
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	long long a, b, v, w, t;
	cin >> a >> v >> b >> w >> t;
	
	if (w >= v) {
		cout << "NO" << endl;
	} else {
		long long dist = abs(a - b);
		if (abs(v - w) * t >= dist) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)|(1<<(i)))
#define togglebit(n,i) ((n)^(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
//int a[200005];
vector<pair<int,int> >v[200];
int main()
{
    fastread;
    string s;
    int i,j,k,l,sz;
    cin>>s;
    sz=s.size();
    int co=0;
    for(i=0;i<sz/2;i++)
    {
    	if(s[i]!=s[sz-i-1])
    	co++;
	}
	cout<<co;
	return 0;	 
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

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

		int n = stdIn.nextInt();
		int k = stdIn.nextInt();

		Set<Integer> hasOkashiSet = new HashSet<>();

		for (int i = 0; i < k; i++) {
			int d = stdIn.nextInt();
			IntStream.range(0, d).forEach(j -> hasOkashiSet.add(stdIn.nextInt()));

		}

		System.out.println(n - hasOkashiSet.size());

		stdIn.close();
	}
}


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

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int A, B, M;
	cin >> A >> B >> M;
	
	vector<ll> a(A), b(B);
	for(int i = 0; i < A; ++i) {
		cin >> a[i];
	}
	
	for(int i = 0; i < B; ++i) {
		cin >> b[i];
	}
	
	ll amin = *min_element(a.begin(), a.end());
	ll bmin = *min_element(b.begin(), b.end());
	ll ans = amin + bmin;
	
	for(int i = 0; i < M; ++i) {
		int x, y;
		ll c;
		cin >> x >> y >> c;
		x--;
		y--;
		
		ans = min(ans, a[x] + b[y] - c);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
           int n,k;
           string s;
           cin>>n>>s>>k;
           for(int i=0;i<n;i++)if(s[i]!=s[k-1])s[i]='*';
           cout<<s;
           return 0;

        }


Measured memory_bytes: 256
/*
Author: Sanskar Agarwal
Nick: sanskarag
Birla Institute Of Technology, Mesra
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define INF 100009
#define mod 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define test while(t--)solve();

void solve()
{
	ll n;
	cin >> n;
	ll arr[n + 1];
	for (ll i = 1; i <= n; ++i)
		cin >> arr[i];
	ll dp[n + 1];
	dp[1] = 0;
	dp[2] = abs(arr[2] - arr[1]);
	for (ll i = 3; i <= n; ++i)
	{
		ll one = dp[i - 1] + abs(arr[i] - arr[i - 1]);
		ll two = dp[i - 2] + abs(arr[i] - arr[i - 2]);
		dp[i] = min(one, two);
	}
	cout << dp[n] << endl;
}

int main()
{
// #ifndef ONLINE_JUDGE
// 	freopen("../input.txt", "r", stdin);
// 	freopen("../output.txt", "w", stdout);
// #endif
	fast
	ll t;
	// cin >> t;
	t = 1;
	test
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#define N 2000

int C[N];

extern int search(int n,int C[],int i,int h){
  if(h==0){
    return 1;
  }
  else if(i>=n){
    return 0;
  }

  return (search(n, C, i + 1 ,h) || search(n, C, i + 1, h - C[i]));
}

extern void solve(int n,int C[],int q,int H[]){
  int i;
  for(i=0;i<q;i++){
    if(search(n,C,0,H[i])==1)
      printf("yes\n");
    else
      printf("no\n");
  }
}

int main(){
  int n,*H,q,i;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&C[i]);
  }
  scanf("%d",&q);
  H=(int*)malloc(sizeof(q));
  for(i=0;i<q;i++){
    scanf("%d",&H[i]);
  }
  
  solve(n,C,q,H);
  
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>

using namespace std;

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {  // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  int sum_digits = findSumOfDigits(N);
  if (N % sum_digits == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N1, N2, N3, N4 = map(int, input().split())
a = list()
a.append(N1)
a.append(N2)
a.append(N3)
a.append(N4)
a.sort()

if a[0] == 1 and a[1] == 4 and a[2] == 7 and a[3] == 9:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9032
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.1415926535

int main() 
{
    FAST;
    ll n;
    cin>>n;
	string s;
	cin>>s;
	ve<ll> r,g,b;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R')
			r.pb(i);
		if(s[i]=='G')
			g.pb(i);
		if(s[i]=='B')
			b.pb(i);
	}
	ll ans=0;
	for(int i=0;i<(int)r.size();i++)
	{
		for(int j=0;j<(int)g.size();j++)
		{
			ll x1=(2*max(r[i],g[j]))-min(r[i],g[j]),x2=r[i]+g[j],x3=(2*min(r[i],g[j]))-max(r[i],g[j]),y1=b.size();
			if(x1<n && s[x1]=='B')
				y1--;
			if(x3>=0 && s[x3]=='B')
				y1--;
			if(x2%2==0 && s[x2/2]=='B')
				y1--;
			ans+=y1;
		}
	}
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3676
#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;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[30000];
int main(){
	ll n,K;cin>>n>>K;
	rep(i,n)scanf("%d",&a[i]);
	ll ans=0;
	rep(i,n){
		ll c1=0,c2=0;
		for(int j=0;j<i;j++){
			if(a[j]>a[i])c1++;
		}
		rep(j,n){
			if(a[j]>a[i])c2++;
		}
		ll d=(K-1)*K/2%MOD*c2+c1*K;
		(ans+=d)%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> s(n+1);
    s[0] = 0;
    for(int i = 0; i < n; i++){
        s[i+1] = s[i] + a[i];
    }

    int ans = INF;
    for(int q = 2; q <= n-2; q++){
        int l = 0;
        int r = q;
        while(r - l > 1){
            int m = (l + r) / 2;
            if(s[q] / 2 > s[m]){
                l = m;
            }else{
                r = m;
            }
        }
        int p = l;
        if(p == 0){
            p++;
        }

        l = q;
        r = n;
        while(r - l > 1){
            int m = (l + r) / 2;
            if((s[n] - s[q]) / 2 > s[m] - s[q]){
                l = m;
            }else{
                r = m;
            }
        }
        int t = l;
        if(t == q){
            t++;
        }

        vector<int> x1 = {s[p], s[q]-s[p], s[t]-s[q], s[n]-s[t]};
        int tmp;
        tmp = abs(*max_element(x1.begin(), x1.end()) - *min_element(x1.begin(), x1.end()));
        if(tmp < ans){
            ans = tmp;
        }

        if(p + 1 < q){
            vector<int> x2 = {s[p+1], s[q]-s[p+1], s[t]-s[q], s[n]-s[t]};
            tmp = abs(*max_element(x2.begin(), x2.end()) - *min_element(x2.begin(), x2.end()));
            if(tmp < ans){
                ans = tmp;
            }
        }
        if(t + 1 < n){
            vector<int> x3 = {s[p], s[q]-s[p], s[t+1]-s[q], s[n]-s[t+1]};
            tmp = abs(*max_element(x3.begin(), x3.end()) - *min_element(x3.begin(), x3.end()));
            if(tmp < ans){
                ans = tmp;
            }
        }
        if(p + 1 < q && t + 1 < n){
            vector<int> x4 = {s[p+1], s[q]-s[p+1], s[t+1]-s[q], s[n]-s[t+1]};
            tmp = abs(*max_element(x4.begin(), x4.end()) - *min_element(x4.begin(), x4.end()));
            if(tmp < ans){
                ans = tmp;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std; 
int N,ptr,res;
int A[100000]; 
int main (){
  scanf("%d",&N);
  for(int i=0;i<N;i++) scanf("%d",&A[i]); 
  sort(A,A+N);
  while(ptr<N){
    int cc=A[ptr],f=0;
    while(ptr<N&&A[ptr]==cc) f++,ptr++;
    res+=f%2;
  }
  printf("%d\n",res);
}

Measured memory_bytes: 640
N = int(input())
A = 0
B = 0
AB = 0
ans = 0

for _ in range(N):
    S = list(input())

    for i in range(len(S)):
        try:
            if S[i] == 'A' and S[i+1] == 'B':
                ans += 1
        except:
            pass
    if S[0] == 'B':
        B += 1
        if S[-1] == 'A':
            A += 1
            AB += 1
    elif S[-1] == 'A':
        A += 1

if A == B and A == AB and AB != 0:
    print(A-1+ans)
else:
    print(min(A,B)+ans)

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

double calc_distance(vector<int> vec1, vector<int> vec2) {
    double sum = 0;
    for (int i = 0; i < vec1.size(); i++) {
        sum += (vec1.at(i) - vec2.at(i)) * (vec1.at(i) - vec2.at(i));    
    }
    return sqrt(sum);
}

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> vec(n);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            int num;
            cin >> num;
            vec.at(i).push_back(num);
        }
    }

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            double distance = calc_distance(vec.at(i), vec.at(j));
            if (ceil(distance) == floor(distance)) count++;
        }
    }

    cout << count << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

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

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, res = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int x;
		cin >> x;
		if (i == 0)
			res = x;
		else
			res = gcd(res, x);

		if (res == 1)
			break;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256