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

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long

const int upper = 1e5 + 20;
const int M = (int) 1e9 + 7;
const int inf = (int) 1e15;
const double eps =  1e-8;

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif		

	int x, y;
	cin >> x >> y;

	cout << x + y / 2;
 	end_routine();	
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int maxd=1000000007,N=100000;
const double pi=acos(-1.0);
typedef long long ll;

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int main()
{
	int a=read(),b=read();
	printf("%0.10lf",(double)a/(double)b);
	return 0;
}


Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**4
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,A,B,C = LI()
    l = [NI() for _ in range(N)]
    m = [i for i in range(N)]
    x = [0, 0, 0]
    ans = INF
    for p in itertools.combinations(m,3):
        q = []
        for i in range(N):
            if not i in p: q.append(i)
        for i in range(4**(N-3)):
            for j in range(3): x[j] = l[p[j]]
            mp = 0
            r = i
            for j in range(N-3):
                k = r % 4
                if k > 0:
                    x[k-1] += l[q[j]]
                    mp += 10
                r //= 4
            for a,b,c in itertools.permutations(x):
                ans = min(ans,mp+abs(A-a)+abs(B-b)+abs(C-c))

    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 45544
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using lli = long long;

lli X;

lli foo(lli v) { return v * v * v * v * v; }

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> X;
	for (lli a = -1000; a <= 1000; ++a)
	{
		for (lli b = -1000; b <= 1000; ++b)
		{
			if (foo(a) - foo(b) == X) { cout << a << " " << b; return 0; }
		}
	}

}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0)cout << "Alice" << endl;
	else cout << "Borys" << endl;
}

Measured memory_bytes: 256
import sys, heapq

def calcScores(D, complaints, satisfications, HoldedContestDays):
    TotalSatisfications = [0]
    ContestDays = [1] * 26
    complaint_all = 0
    for i in range(26):
        complaint_all += complaints[i]

    complaint_sum = 0
    for i in range(D):
        complaint_sum += complaint_all
        Contest = HoldedContestDays[i]
        complaint_sum -= ContestDays[Contest] * complaints[Contest]
        ContestDays[Contest] = 0

        satisfication_day_i = TotalSatisfications[-1] + satisfications[i][Contest] - complaint_sum
        TotalSatisfications.append(satisfication_day_i)
        for j in range(26):
            ContestDays[j] += 1
    return TotalSatisfications

def calccontestnumbers(D, complaints, satisfications):
    ContestDays = [1] * 26
    HoldedContests = [-1] * D
    for i in range(D):
        Demands = []
        for j in range(26):
            Demand_j = ContestDays[j] * complaints[j] + satisfications[i][j]
            heapq.heappush(Demands, (-Demand_j, j) )
            ContestDays[j] += 1
        print("Day", i, ":", Demands)
        Demand_Contest = heapq.heappop(Demands)
        Contest = Demand_Contest[1]
        ContestDays[Contest] =1
        HoldedContests[i] = Contest+1
    return HoldedContests



"""
13: 19922, 89
20: 19830, 80

20: 19830 - 80 * 5 = 19430
13: 19922 - 89 * 2 = 19744
毎日1つのコンテスト
満足度をあげるようにコンテスト
ci * (最後にコンテストを行ってからの経過日数)満足度低下
上昇値はs_d_i

"""
if(__name__ == "__main__"):
    D = int(input().strip())
    complaints = list(map(int, input().split() ) )

    satisfications = []
    for i in range(D):
        satisfication = list(map(int, input().split() ) )
        satisfications.append(satisfication)
    HoldedContestDays =[0] * D
    for i in range(D):
        HoldedContestDays[i] = int(input().strip())
        HoldedContestDays[i] -= 1
    Scores = calcScores(D, complaints, satisfications, HoldedContestDays)
    for i in range(D):
        print(Scores[i+1])


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

int main() {
	int n, m;
	while(1){
		cin >> n >> m;
		if(n==0 && m==0) break;
		int p[1000], sum, max=0;
		for(int a=0; a<n; a++)
			cin >> p[a];
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				sum = p[i]+p[j];
				if(max<sum && sum<=m) max = sum;
			}
		}
		if(max==0) cout << "NONE" << endl;
		else cout << max << endl;
	}
	return 0;
}


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

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


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n; 
  cin>>n;  
  vector<int>vec(n); 
  rep(i,n) cin>>vec[i];
  
  vector<pair<int,int>> a1;
  vector<pair<int,int>> a2;
  
  rep(i,100000){
    a1.push_back(make_pair(0,i));
    a2.push_back(make_pair(0,i));
  }  
  for(int i=0;i<n;i+=2){
    a1[vec[i]-1].first++;
  }
  for(int i=1;i<n;i+=2){
    a2[vec[i]-1].first++;
  }
  
  sort(a1.begin(),a1.end());
  sort(a2.begin(),a2.end());
  
  int sum1=a1[100000-1].first;
  int sum2=a2[100000-1].first;
  
  int sum3=a1[100000-1-1].first;
  int sum4=a2[100000-1-1].first;
  
  
  if(a1[100000-1].second==a2[100000-1].second){
    cout<<n-max(sum1+sum4,sum2+sum3)<<endl;
  }
  else cout<<n-(sum1+sum2)<<endl;
}



Measured memory_bytes: 2420
#include<iostream>
#include<algorithm>
#include<math.h>
#include <iterator>
#include <map>
using namespace std;


int main (){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b)
    cout<<c<<endl;
  else{
      if(b==c){
        cout<<a<<endl;
      }else
            cout<<b<<endl;
  }
return 0;
}

















Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  char a,b;
  scanf("%c %c",&a,&b);
  if((a=='H'&&b=='H')||(a=='D'&&b=='D')){
    printf("H\n");
  }
  else{
    printf("D\n");
  }
  return 0;
}

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

int main(){
  int a, b;
  char s;
  while(1){
    cin >> a >> s >> b;
    if(s == '?') break;
    else if(s == '+') cout << a + b << "\n";
    else if(s == '-') cout << a - b << "\n";
    else if(s == '*') cout << a * b << "\n";
    else if(s == '/') cout << a / b << "\n";
  }
  return 0;
}



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

#define ll long long
#define endl "\n"
#define vi vector<int>
#define pb push_back
#define F first
#define S second

void solve() {

}

int main() {
#ifndef ONLINE_JUDGE
	freopen("manish.txt", "r", stdin);
	//freopen("ps.txt", "w", stdout);
#endif
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		ll ans = (-1ll) * 1e18;

		ans = max(ans, a * c);
		ans = max(ans, a * d);
		ans = max(ans, b * c);
		ans = max(ans, b * d);

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int x;
string s;
int main()
{
    cin>>s;
    for (int i=0;i<s.size();i++)
    {
        if (s[i]=='+')
            x++;
        else
            x--;
    }
    cout<<x;
    return 0;
}


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

flag=False

for i in range(N+1):
  for j in range(N+1):
    if(9000*i+4000*j==Y-1000*N):
      flag=True
      x=i
      y=j
      z=N-i-j
      
if(flag==True and z>=0):
  print(str(x)+" "+str(y)+" "+str(z))
else:
  print("-1 -1 -1")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>

#define RED 1
#define GREEN 2
#define TRANSPARENT 0

using namespace std;
int main(void){
    int x,y,a,b,c,i,v;
    long long sum=0;
    cin >> x >> y >> a >> b >> c;
    pair<int,unsigned char> z[a+b+c];
    int n_to_take=x+y;
    for(i=0;i<a;i++){
        cin >> v;
        z[i]=make_pair(v,RED);
    }
    for(i=0;i<b;i++){
        cin >> v;
        z[i+a]=make_pair(v,GREEN);
    }
    for(i=0;i<c;i++){
        cin >> v;
        z[i+a+b]=make_pair(v,TRANSPARENT);
    }
    sort(z,z+(a+b+c),greater<pair<int, unsigned char>>());
    for(v=0,i=0;v<n_to_take;i++){
        if(z[i].second==RED && x>0){
            x--; v++; sum+=(long long)z[i].first;
        }else if(z[i].second==GREEN && y>0){
            y--; v++; sum+=(long long)z[i].first;
        }else if(z[i].second==TRANSPARENT){
            v++; sum+=(long long)z[i].first;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main (){
int a;
  cin >> a;
  if (a == 0){
    cout << 0 << endl;
  }else if (a == 1 || a == 10 || a == 100){
    cout << 1 << endl;
  }else if(a == 11 || a == 101 || a == 110){
    cout << 2 << endl;
  }else{
    cout << 3 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			string s = cin.Next();
			int n = s.Length;
			int[] ans = new int[n];

			//RRLLLLRLRRLL
			bool isR = false;
			int count = 0;
			int L = 0;
			for (int i = 0; i < n; i++) {
				if (isR) {
					if (s[i] == 'R') {
						++count;
					} else {
						++count;
						L = i;
						isR = false;
					}
				} else {
					if (s[i] == 'R') {
						if (count > 0) {
							//RRRRLLR
							for (int j = i - count; j < L; ++j) {
								if ((L - j) % 2 == 0) {
									ans[L]++;
								} else {
									ans[L - 1]++;
								}
							}

							for (int j = L; j < i; ++j) {
								if ((L - j) % 2 == 0) {
									ans[L]++;
								} else {
									ans[L - 1]++;
								}
							}
						}

						count = 1;
						isR = true;
					} else {
						++count;
					}
				}
			}

			if (count > 1) {
				for (int j = n - count; j < L; ++j) {
					if ((L - j) % 2 == 0) {
						ans[L]++;
					} else {
						ans[L - 1]++;
					}
				}

				for (int j = L; j <= n - 1; ++j) {
					if ((L - j) % 2 == 0) {
						ans[L]++;
					} else {
						ans[L - 1]++;
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < n; i++) {
				sb.Append($"{ans[i]} ");
			}

			Console.WriteLine(sb.ToString());
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;
		
		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  for(int i=2;i<s.size();i++){
    if(s.at(i-2) == 'A' && s.at(i-1) == 'B' && s.at(i) == 'C') cnt ++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from fractions import gcd


def main():
  A,B = map(int, input().split())
  AB = gcd(A,B)
  divs = set([])
  for i in range(1,int(AB**0.5)+1):
    if AB % i == 0:
      divs.add(i)
      divs.add(AB//i)
  divs = sorted(list(divs))

  rets = set([])
  for d in divs[1:]:
    chk = True
    for r in rets:
      if d%r == 0:
        chk = False
        continue
    if chk:
      rets.add(d)
  return len(rets)+1

if __name__ == "__main__":
  ret = main()
  print(ret)

Measured memory_bytes: 65516
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, Q = mi()
    a, b = i2(N-1)
    p, x = i2(Q)

    d = [[] for i in range(N)]
    for i in range(N-1):
        d[a[i]-1].append(b[i]-1)
        d[b[i]-1].append(a[i]-1)

    child = [[] for i in range(N)]
    parent = [None]*N

    q = deque([0])
    while q:
        now = q.pop()
        for v in d[now]:
            if parent[now] == v:
                continue
            parent[v] = now
            q.appendleft(v)

    c = [0]*N
    for i in range(Q):
        c[p[i]-1] += x[i]

    @lru_cache(maxsize=None)
    def dfs(i):
        if parent[i] == None:
            return c[i]
        
        return c[i]+dfs(parent[i])

    print(*[dfs(i) for i in range(N)])

if __name__ == '__main__':
    main()


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

using namespace std;

#define ll long long
#define ld long double

signed main() {
	ll n; cin >> n;
	if (n & 1LL) 
		cout << 0 << endl;
	else{
		ll ans = 0;
		ll nx = 5;
		while (nx <= n) {
			ans += n / nx / 2;
			nx *= 5;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort
#include <math.h>

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

int main(){
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N,C;
    cin >> N >> C;
    vector < vector<int> > d(C,vector<int>(C, 0));
    vector < vector<int> > t(3,vector<int>(C, 0));

    REP(i,C)
    {
        REP(j,C)
        {
            cin >> d[i][j];
        }
    }
    REP(i,N)
    {
        REP(j,N)
        {
            int c;
            cin >> c;
            --c;
            ++t[(i+j) % 3][c];
        }
    }

    ll res = INF;
    for(int i = 0; i < C; ++i)
    {
        for(int j = 0; j < C; ++j)
        {
            if(i == j)continue;
            for(int k = 0; k < C; ++k)
            {
                if(i == k || j == k)continue;
                ll tmp = 0;
                for(int l = 0; l < C; ++l)
                {
                    tmp += d[l][i] * t[0][l];
                }
                for(int l = 0; l < C; ++l)
                {
                    tmp += d[l][j] * t[1][l];
                }
                for(int l = 0; l < C; ++l)
                {
                    tmp += d[l][k] * t[2][l];
                }

                res = min(res, tmp);
            }
        }
    }

    cout << res << endl;



    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();
      int X = sc.nextInt();
      long[] x = new long[N];
      for (int i = 0; i < N; i++) {
        x[i] = sc.nextLong();
      }
      System.out.println(solve(X, x));
    }
  }

  public static long solve(int X, long[] x) {
    long init = Math.abs(X - x[0]);
    for (int i = 1; i < x.length; i++) {
        init = gcd(init,  Math.abs(X - x[i]));
    }
    return init;
  }

  private static long gcd(long m, long n) {
    if (m < n) {
      return gcd(n, m);
    }
    if (n == 0) {
      return m;
    }
    return gcd(n, m % n);
  }
}

Measured memory_bytes: 48444
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,q;
    cin>>n>>q;
    string s;
    int t[n+1]={};
    cin>>s;
    if(s[0]=='A'&&s[1]=='C')
    t[0]=1;
    for(int i=1;i<n-1;i++)
    {
        if(s[i]=='A'&&s[i+1]=='C')
        t[i]=t[i-1]+1;
        else
        t[i]=t[i-1];
    }
    int l[q],r[q],ans[q];
    for(int i=0;i<q;i++)
    {
        cin>>l[i]>>r[i];
        if(l[i]!=1)
        ans[i]=t[r[i]-2]-t[l[i]-2];
        else
        ans[i]=t[r[i]-2]-0;
    }
    for(int i=0;i<q;i++)
    cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 2560
//
//  main.cpp
//  ITP1_7-C
//
//  Created by Saicj on 2015/07/14.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, const char * argv[])
{


    int r;
    int c;
    
    cin >> r >> c;
    
    int newForm[r][c];
    int resultForm[r+1][c+1];
    
    // ?????????
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            newForm[i][j] = 0;
        }
    }
    
    for (int i = 0; i < r+1; i++) {
        for (int j = 0; j < c+1; j++) {
            resultForm[i][j] = 0;
        }
    }
    
    
    // ????????\???
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            
            cin >> newForm[i][j];
            
            resultForm[i][j] = newForm[i][j];
            
            // ???????¨????
            resultForm[i][c] += newForm[i][j];
        }
        
    }
    
    
//    // ???????¨????
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < r; j++) {
            
            resultForm[r][i] += resultForm[j][i];
        }
        
    }
    
    
    // ??????????????????
    for (int i = 0;  i < c; i++) {
        resultForm[r][c] += resultForm[r][i];
    }
    
    
    
    // ??¨????????????
    for (int i = 0; i <= r ; i++) {
        for (int j = 0; j <= c; j++) {
            
            printf("%d", resultForm[i][j]);
            
            if (j == c){
                continue;
            }
            
            printf(" ");
        }
        
        printf("\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 1224
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();	
    if(-a + b <= 0) {
      System.out.println("delicious");
    } else if(-a + b <= x) {
      System.out.println("safe");
    } else {
      System.out.println("dangerous");
    }
  }
}

Measured memory_bytes: 21844
def isp(n):
    c=n**0.5
    if c%1==0:
        return True
    else:
        return False
s=input()
a=s.split()[0]
b=s.split()[1]
s=int(a+b)
if isp(s)==True:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  if ( (a+b) % 2 == 0 ) {
    cout << (a+b) / 2 << endl;
  }
  else {
    cout << (a+b)/2+1 << endl;
  }
}

Measured memory_bytes: 256
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
 
    
    
def solve(N):
    arr = [chr(ord('a')+i) for i in range(26)]
    num_digit = 1
    tmp = N
    while tmp-26**num_digit>=0:
        tmp -=26**num_digit
        num_digit+=1
    ans = ''
    while num_digit:
        idx = tmp // 26**(num_digit-1)
        tmp = tmp % 26**(num_digit-1)
        ans+= arr[idx]
        num_digit-=1
    print(ans)
N = rri()
solve(N-1)

Measured memory_bytes: 64812
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

int a[105];
int ans,ansa,ansb,n;

bool cmp(int a,int b){
	return a > b;
}

int main()
{
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
	}
	sort(a,a+n,cmp);
	for(int i = 0 ; i < n ; i++){
		if(i % 2 == 0) ansa += a[i];
		else ansb += a[i];
	}
	ans = ansa - ansb;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def high(i):
    return max(H - abs(x[i] - Cx) - abs(y[i] - Cy), 0)

N = int(input())
x = []
y = []
h = []
for _ in range(N):
    a, b, c = map(int, input().split())
    x.append(a)
    y.append(b)
    h.append(c)

for i in range(N):
    if h[i] != 0:
        non_zero = i
        break

found = False
for Cx in range(0, 101):
    for Cy in range(0, 101):
        H = h[non_zero] + abs(x[non_zero] - Cx) + abs(y[non_zero] - Cy)
        if all([h[i] == high(i) for i in range(N)]):
            print('{} {} {}'.format(Cx, Cy, H))
            found = True
            break
    if found:
        break

Measured memory_bytes: 3064
n = int(input())
I = [[0,1]]
while n < I[-1][0] or I[-1][1] < n:
  if len(I)%2 != 0:
    I += [[I[-1][0]-2**(len(I)),I[-1][1]]]
  else:
    I += [[I[-1][0],I[-1][1]+2**(len(I))]]
ans = ''
for i in range(len(I)):
  if abs((I[-i-1][0]+I[-i-1][1])/2) < abs(n) and n * (-1)**(len(I)-i-1) > 0:
    ans += '1'
    n -= (-2)**(len(I)-i-1)
  else:
    ans += '0'
print(int(ans))

Measured memory_bytes: 3316
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, m = wi()
ks = [None] * m
for i in range(m):
    ks[i] = wi()

p = wi()

nums = [0, 1]
for balls in itertools.product(nums, repeat=n):#3**2
    tmp = 0
    for i in range(m):
        tmp = 0
        for j in range(1, len(ks[i])):
            tmp += balls[ks[i][j] - 1]
        if tmp % 2 == p[i]:
            pass
        else:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 67308
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>  
#include <iterator>    
#include <set>
#include <iomanip>
using namespace std;

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

    vector <long long > A(N);
    double count = 0.0;
    for(int i= 0 ; i< N ; i++){
        cin >> A[i];
        count +=  (1.0 / A[i]);
    }

    cout <<  1.0 / count  << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int a, b, c;
	scanf("%d%d%d",&a,&b,&c);
	if (b -c  >= 0) {
		printf("delicious");
	}else if (c - b <= a) {
		printf("safe");
	}
	else { 
		printf("dangerous");
	}
	return 0;
}

Measured memory_bytes: 128
using System;

namespace ABC093C
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            int a = int.Parse(target[0]);
            int b = int.Parse(target[1]);
            int c = int.Parse(target[2]);
            int m = Math.Max(a , b); m = Math.Max(m , c); 
            int d = 0;
            while(d < 200){
                int tmp = a + b + c + 2 * d;
                if(tmp >= 3*m && tmp % 3 == 0) break;
                d++;
            }
            Console.WriteLine(d);
        }
    }
}


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

#define MAX_N 100000

int main() {
  std::string s;
  std::getline(std::cin, s);

  int zero = 0, one = 0;
  for(int i = 0; i < s.length(); ++i) {
    if(s[i] == '0') {
      zero++;
    } else {
      one++;
    }
  }

  std::cout << 2 * ((one < zero) ? one : zero) << std::endl;
  return 0;
}


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

#define pb push_back
#define all(a) (a).begin(), (a).end()

using ll = long long;
using pii = pair<int, int>;

// BGR
char flip(char x, char y) {
    if (x > y)
        swap(x, y);
    if (x == 'B' && y == 'G')
        return 'R';
    else if (x == 'B' && y == 'R')
        return 'G';
    return 'B';
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> pos(3);
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') 
            pos[0].pb(i);
        else if (s[i] == 'G')
            pos[1].pb(i);
        else
            pos[2].pb(i);
    }
    map<char, int> mp = {{'R', 0}, {'G', 1}, {'B', 2}};

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        char x = s[i];
        for (int j = i + 1; j < n; ++j) {
            char y = s[j];
            if (x == y)
                continue;
            char z = flip(x, y);
            int k = mp[z];
            int it = lower_bound(all(pos[k]), j) - pos[k].begin();
            if (it != (int)pos[k].size()) {
                ans += (int)pos[k].size() - it;
                if (binary_search(all(pos[k]), j + (j - i)))
                    --ans;
            }
        }
    }

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

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

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

    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;

        if (c == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }

    cout << "Three" << endl;

    return 0;
}


Measured memory_bytes: 256
/***
*   author:   ashikur rahman
*   created:  29.08.2020 20:04:01
***/

#include<bits/stdc++.h>

using namespace std;

const int N = 1e6 + 2;
bool vis[N + 5];
vector<int> primes;
int sz;
void seive(){
  for (int i = 4; i < N; i += 2) {
    vis[i] = true;
  }       
  for (int i = 3; i * i < N; i += 2){
    if (vis[i] == false){
      for (int j = i * i; j < N; j += (i << 1)) {
        vis[j] = true;
      }
    }
  }
  primes.push_back(2);
  for (int i = 3; i < N; i += 2){
    if (vis[i] == false){
      primes.push_back(i);
    }
  }
  sz = primes.size();
}
int cnt[N + 5];
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  seive();
  int n;
  cin >> n;
  vector<int>ar(n);
  for (int i = 0; i < n; i++){
    cin >> ar[i];
  }
  int gg = 0;
  for (int i = 0; i < n; i++){
    gg = __gcd(gg, ar[i]);
  }
  if (gg > 1) {
    cout << "not coprime\n";
    return 0;
  }
  for (int v : ar){
    int x = v;
    for (int i = 0; i < sz && primes[i] * primes[i] <= x; i++){
      if (x % primes[i] == 0){
        while (x % primes[i] == 0){
          x /= primes[i];
        }
        cnt[primes[i]]++;
        if (cnt[primes[i]] > 1){
          cout << "setwise coprime\n";
          return 0;
        }
      }
    }
    if (x > 1){
      cnt[x]++;
      if (cnt[x] > 1){
        cout << "setwise coprime\n";
        return 0;
      }
    }
  }
  cout << "pairwise coprime\n";
  return 0;
}

Measured memory_bytes: 8836
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const ll INF = 1LL << 60;

struct edge{
	int to; ll cost;
};
class Graph{
	public:
	vector<vector<edge> > adj;
	Graph(int V){
		adj.resize(V);
	}
	void add_edge(int s, edge e){
		adj[s].push_back(e);
	}
	vector<ll> dijkstra(int s){
		priority_queue<pair<ll, int> , vector<pair<ll, int> > , greater<pair<ll, int> > > pqa;
		vector<ll> dist(adj.size(), INF);
		dist[s] = 0;
		pqa.push(make_pair(0, s));
		while(!pqa.empty()){
			pair<ll, int> p = pqa.top(); pqa.pop();
			int u = p.second;
			if(dist[u] < p.first) continue;
			for(int v = 0; v < adj[u].size(); v++){
				edge e = adj[u][v];
				if(dist[e.to] > dist[u] + e.cost){
					dist[e.to] = dist[u] + e.cost;
					pqa.push(make_pair(dist[e.to], e.to));
				}
			}
		}
		return dist;
	}
};

int main(){
	int V, E;
	cin >> V >> E;
	Graph G(V);
	vector<vector<ll> > adj(V, vector<ll>(V, INF));
	for(int i = 0; i < E; i++){
		int s, t, d;
		cin >> s >> t >> d;
		s--; t--;
		G.add_edge(s, (edge){t, d});
		G.add_edge(t, (edge){s, d});
		adj[s][t] = d;
		adj[t][s] = d;
	}
	vector<vector<ll> > dist(V, vector<ll>());
	for(int i = 0; i < V; i++){
		dist[i] = G.dijkstra(i);
	}
	int cnt = 0;
	for(int i = 0; i < V; i++){
		for(int j = i + 1; j < V; j++){
			if(adj[i][j] == INF) continue;
			if(adj[i][j] == dist[i][j]) cnt++;
		}
	}
	cout << E - cnt << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

ll solve(ll m,ll n){
        if(m%n==0) return n;
        return solve(n,m%n);
}

signed main(){
        llin(n);
        vpl4 a(n);
        FOR(i,0,n-1){
                cin >>a[i].se>>a[i].fi;
        }
        SORT(a);
        ll t=0;
        FOR(i,0,n-1){
                t+=a[i].se;
                if(t>a[i].fi){
                        sal("No")
                        return 0;
                }
        }
        sal("Yes")
}


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

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define RFOR(i,e,s) for(int (i)=(e)-1;(i)>=(int)(s);(i)--)
#define RREP(i,e) RFOR(i,e,0)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;
typedef priority_queue<int> PQI;
typedef priority_queue<PII> PQII;

const int Y = 1000;
int dsum[Y+1];

int main() {
  memset(dsum, 0, sizeof(dsum));
  FOR(i,1,Y+1) dsum[i] = dsum[i-1] + 200 - (i%3 ? 5 : 0);
  int n;
  scanf("%d ", &n);
  REP(i,n) {
    int y, m, d;
    scanf("%d%d%d ", &y, &m, &d);
    int res = dsum[y-1] + 20*(m-1) + d;
    if (y%3) res -= (m-1)/2;
    res = dsum[Y-1] + 1 - res;
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 3200
F = 2*10**5+5
mod = 998244353
fact = [1]*F
inv = [1]*F
for i in range(2,F):
    fact[i]=(fact[i-1]*i)%mod
inv[F-1]=pow(fact[F-1],mod-2,mod)
for i in range(F-2,1,-1):
    inv[i] = (inv[i+1]*(i+1))%mod

n,m,k=map(int,input().split())

def comb(n,k):
    ans=(fact[n]*inv[n-k])%mod
    return (ans*inv[k])%mod

ans=0

for i in range(k+1):
    tmpans=m*comb(n-1,i)
    tmpans=(tmpans*pow(m-1,n-i-1,mod))%mod
    ans+=tmpans
    ans%=mod
print(ans)

Measured memory_bytes: 79388
#include<bits/stdc++.h>
using namespace std;
long long t,s[200005];
int main()
{
	t=0;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		t+=x;
		s[i]=t;
	}
	long long ans=1e16;
	for(int i=0;i<n-1;i++)
	{
		long long x=s[i],y=t-s[i];
		ans=min(abs(x-y),ans);
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> vll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll A, B, C;
  cin >> A >> B >> C;

  ll ans;
  if(A + B >= C) ans = B + C;
  else ans = B + (A + B + 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
counter = 0
coutlist = []
value = False
for i in range(n):
    a,b = map(int, input().split())
    if i == 0:
        if a == b:
            counter+=1
            coutlist.append(counter)
            value = True
    else:
        if a == b and value == True:
            counter+=1
            value = True
            coutlist.append(counter)
        elif a == b and value == False:
            counter = 1
            value = True
            coutlist.append(counter)
        else:
            counter = 0
            value = False
            coutlist.append(counter)

if max(coutlist) >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 8992
package main

import (
	"fmt"
)

func judge(a string) bool {
	for i := range a {
		if a[i] == '#' {
			return true
		}
	}
	return false
}

func judgeO(a []string, j int) bool {
	for i := 0; i < len(a); i++ {
		if a[i][j] == '#' {
			return true
		}
	}
	j = j
	return false
}

func Tappend(matrixT []string, matrixO []string, j int) []string {
	for i := 0; i < len(matrixO); i++ {
		matrixT[i] += string(matrixO[i][j])
	}
	return matrixT
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	matrix := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&matrix[i])
	}
	matrixO := []string{}
	for i := 0; i < h; i++ {
		if judge(matrix[i]) == true {
			matrixO = append(matrixO, matrix[i])
		}
	}
	matrixT := make([]string, len(matrixO))
	for j := 0; j < w; j++ {
		if judgeO(matrixO, j) == true {
			matrixT = Tappend(matrixT, matrixO, j)
		}
	}
	for i := range matrixT {
		fmt.Println(matrixT[i])
	}
}


Measured memory_bytes: 1152
import java.util.Scanner;


public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = scan.next();
		int count = 0;

		for(int i = 0; i < n-1; i++) {
			String cur = s.substring(i, i+1);
			String next = s.substring(i+1, i+2);
			if(cur.equals(next)) {
				count++;
			}
		}
		int ans = s.length() - count;
		System.out.println(ans);
	}
}

Measured memory_bytes: 34352
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n; cin >>n;
  int rec=0,cnt=0;
  for(int i=0; i<2*n; i++){
    int x; cin >>x;
    if(i%2==0) rec=x;
    else if(x==rec) cnt++;
    else cnt=0;
    if(cnt==3){cout <<"Yes"; return;}
  }
  cout <<"No";
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  //int T; cin >>T; while(T--)
  solve();
return 0;}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s; cin >> s;
	if (s.size() >= 4 && s.substr(0, 4) == "YAKI") cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.ABC057
{
    class CheckPoints
    {
        struct Coord
        {
            int X, Y;
            public int Distance(Coord other)
            {
                return Abs(X - other.X) + Abs(Y - other.Y);
            }
            static int Abs(int a)
            {
                return (a > 0) ? a : -a;
            }
            public Coord(params int [] args)
            {
                X = args[0]; Y = args[1];
            }
        }
        public static void Main()
        {
            var nm = ReadLine().Trim().Split(' ').Select(i => int.Parse(i)).ToArray();
            var student = new Coord[nm[0]];
            var checkPoint = new Coord[nm[1]];
            for (var i = 0; i < student.Length; ++i)
                student[i] = new Coord(ReadLine().Trim().Split(' ').Select(s => int.Parse(s)).ToArray());
            for (var i = 0; i < checkPoint.Length; ++i)
                checkPoint[i] = new Coord(ReadLine().Trim().Split(' ').Select(s => int.Parse(s)).ToArray());
            var studentMinDistance = student.Select(s => checkPoint.Select(c => s.Distance(c)).Min()).ToArray();
            for (var i = 0; i < student.Length; ++i)
            {
                for (var j = 0; j < checkPoint.Length; ++j)
                {
                    if (studentMinDistance[i] == checkPoint[j].Distance(student[i]))
                    {
                        WriteLine(j + 1);
                        break;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>  // This will work only for g++ compiler. 
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forab(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define pb push_back
#define fi first
#define se second
#define __builtin_popcount(x) ones(x)
#define __builtin_popcountl(x) onesl(x)
#define __builtin_popcountll(x) onesll(x)// to be used with algorithms that processes a container Eg: find(all(c
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define InputOuput freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout);
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main(){
    //InputOuput;
    Fast;

    int n ; cin >> n;
     
    //vi dp(n,INT_MAX);
    vi h(n,0);
    for0(i,n) cin >> h[i];
    if(n<=1){
        cout << 0 <<'\n';
        return 0;
    }
    ll minus2 = 0, minus1 = 0;
    ll cost = 0;
    forab(i,1,n-1){
        ll diff1 = abs(h[i]-h[i-1]);
        ll  diff2 = (i>=2)? abs(h[i]- h[i-2 ]):INT_MAX;

        ll curr = min(minus2 + diff2 , minus1 + diff1);
        minus2 = minus1;
        minus1 = curr;
    } 
    cout << minus1 <<'\n';
    return 0;

}

Measured memory_bytes: 3652
from collections import deque


def resolve():
    h, w = map(int, input().split())
    maze = list(input() for _ in range(h))
    sy, sx = 0, 0
    gy, gx = h - 1, w - 1
    visited = [[-1 for _ in range(w)] for _ in range(h)]
    shortest = bfs(maze, visited, sy, sx, gy, gx)
    if shortest == -1:
        print(shortest)
    else:
        walls = sum([l.count("#") for l in maze])
        print(h * w - shortest - walls - 1)


def bfs(maze, visited, sy, sx, gy, gx):
    q = deque([[sy, sx]])
    visited[sy][sx] = 0
    while q:
        y, x = q.popleft()
        if y == gy and x == gx:
            return visited[gy][gx]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + j, x + k
            if new_y < 0 or new_x < 0 or new_y > gy or new_x > gx:
                continue
            if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                q.append([new_y, new_x])
    return -1


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc109/d.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int m[501][501];
int buf[501][501];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int h, w;
    cin >> h >> w;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> m[i][j];
            buf[i][j] = m[i][j];
        }
    }
    ll n = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(j == w){
                if(i == h) break;
                if(buf[i][j] % 2 == 1){
                    buf[i+1][j]++;
                    n++;
                }
                continue;
            }
            if(buf[i][j] % 2 == 1){
                buf[i][j+1]++;
                n++;
            }
        }
    }
    cout << n << "\n";

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(j == w){
                if(i == h) break;
                if(m[i][j] % 2 == 1){
                    cout << i << " " << j << " " << i + 1 << " " << j << "\n";
                    m[i+1][j]++;
                }
                continue;
            }
            if(m[i][j] % 2 == 1){
                cout << i << " " << j << " " << i << " " << j + 1 << "\n";
                m[i][j+1]++;
            }
        }
    }
    return 0;
}

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

using namespace std;

#define int long long

const int MAXN = 101;

int n;
int cx[MAXN], cy[MAXN], ch[MAXN];
void read() {
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> cx[i] >> cy[i] >> ch[i];
}

bool check(int x, int y, int h) {
    for (int i = 0; i < n; ++i) {
        if (max(0ll, h - abs(x - cx[i]) - abs(y - cy[i])) != ch[i]) {
            return 0;
        }
    }      
    return 1;
}

void solve() {
    for (int i = 0; i < n; ++i) {
        if (ch[i]) {
            swap(cx[0], cx[i]);
            swap(cy[0], cy[i]);
            swap(ch[0], ch[i]);
            break;
        }
    }

    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            int h = abs(i - cx[0]) + abs(j - cy[0]) + ch[0];
            if (h < 1) continue;
            if (check(i, j, h)) {
                cout << i << ' ' << j << ' ' << h << '\n';
                exit(0);
            }   
        }
    }   
}

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

    read();
    solve();    

    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, suma = 0;
    cin >> n >> k;
    while(n != 0) {
        n /= k;
        suma++;
    }
    cout << suma;
    return 0;
}


Measured memory_bytes: 256