akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
#dp1 #Frog1

n = int(input())
h = list(map(int,input().split()))

dp = [0]*n
dp[1] = abs(h[0]-h[1])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]))
print(dp[n-1])


Measured memory_bytes: 52208
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    q=int(input())
    h.append(q)
left=0
right=max(h)+1
def en(t):
    cnt=0
    for i in range(n):
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)!=0:
            cnt+=((h[i]-b*t)//((a-b))+1)
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)==0:
            cnt+=((h[i]-b*t)//(a-b))
    if cnt<=t:
        return  True
    return  False
while left+1<right:
    tmp=(left+right)//2
    if en(tmp):
        right=tmp
    else:
        left=tmp
print(right)


Measured memory_bytes: 55736
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,ans;
  cin>>a>>b>>c>>d;
  for(int i=0;i<100000000000;i++){
    c-=b;
    if(c<=0){
      ans=1;
      break;
    }
    a-=d;
    if(a<=0){
      ans=0;
      break;
    }
  }
  if(ans==1) cout<<"Yes"<<endl;
  if(ans==0) cout<<"No"<<endl;
}

Measured memory_bytes: 3632
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 9000000000000;
const ll mod = 2e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

int bd[2010][2010];

signed main() {
	set<char> se;
	REP (i,3) {
		char x;
		cin >> x;
		se.insert(x);
	}
	if (se.size() == 3) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string str; cin >> str;
	int sum = 0;
	for(int i=0; i<str.size(); i++)
	{
		sum += str[i] - '0';
		if(sum >= 9) sum -= 9;
	}
	if(sum == 0) cout << "Yes";
	else	     cout << "No";
}

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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e11;

using namespace std;

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

    int N, K;
    string S;
    cin >> N >> K >> S;
    
    cout << S.substr(0, K-1) << (char)(S[K-1] - 'A' + 'a') << S.substr(K) << endl;

    return 0;
}


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

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
signed main()
{
    rootdada;

    int k;
    cin >> k;
    string s;
    cin >> s;
    int l = s.length();
    if (k >= l)
        cout << s << endl;
    else
    {
        rep(i, 0, l)
        {
            if (i < k)
                cout << s[i];
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=1e5+5;
const int INF=1e9;
int n;
vector <int>edge[MAX];
int num1,num2;
int dis1[MAX],dis2[MAX];
int x,y;
void dfs1(int x)
{
    for(int i=0;i<edge[x].size();i++)
    {
        int to=edge[x][i];
        if(dis1[to]>dis1[x]+1)
        {
            dis1[to]=dis1[x]+1;
            dfs1(to);
        }
    }
}
void dfs2(int x)
{
    for(int i=0;i<edge[x].size();i++)
    {
        int to=edge[x][i];
        if(dis2[to]>dis2[x]+1)
        {
            dis2[to]=dis2[x]+1;
            dfs2(to);
        }
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&x,&y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    fill(dis1,dis1+MAX-1,INF);
    fill(dis2,dis2+MAX-2,INF);
    dis1[1]=0;dis2[n]=0;
    dfs1(1);
    dfs2(n);
    for(int i=1;i<=n;i++)
    {
        if(dis1[i]<=dis2[i])
            num1++;
        else
            num2++;
    }
    if(num1>num2)
        printf("Fennec\n");
    else
        printf("Snuke\n");
    return 0;
}


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

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

    vector<pair<pair<string, int>, int>> vec_p(N);
    pair<pair<string, int>, int> p;

    for (int i = 0; i < N; i++) {
        string s;
        int score;

        cin >> s >> score;
        p = make_pair(make_pair(s, -score), i + 1);

        vec_p.at(i) = p;
    }

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

    for (int i = 0; i < N; i++) {
        int ans;
        ans = vec_p.at(i).second;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3616
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

a,b,c,k = readInts()

if k%2==1:
	ans = b-a
else:
	ans = a-b

if ans>10**18:
	print("Unfair")
else:
	print(ans)

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

int dist[2001][2001];

signed main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    X--; Y--;
    REP(i, N - 1) FOR(j, i + 1, N) dist[i][j] = j - i;
    dist[X][Y] = 1;
    REP(i, N - 1){
        FOR(j, i + 1, N){
            dist[i][j] = min(dist[i][j], abs(i - X) + abs(j - Y) + 1);
        }
    }
    /*
    REP(i, N){
        REP(j, N) cerr << dist[i][j] << " ";
        cerr << endl;
    }
    */
    unordered_map<int, int> mp;
    REP(i, N - 1) FOR(j, i + 1, N) mp[dist[i][j]]++;
    FOR(i, 1, N){
        PRINT(mp[i]);
    }
    return 0;
}

Measured memory_bytes: 15360
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main()
{
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int d = x;
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] <= d) {
			d -= a[i];
			ans++;
		}
		else {
			break;
		}
	}
	if (a[n - 1] == d) ans++;
	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 <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

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

    int h, w;
    cin >> h >> w;
    vector<vector<bool>> s(h, vector<bool>(w, false));
    rep(i, h) rep(j, w){
        char c;
        cin >> c;
        if(c == '.'){
            s[i][j] = true;
        }
    }

    vector<vector<bool>> t(h - 1, vector<bool>(w - 1, false));
    rep(i, h - 1) rep(j, w - 1){
        t[i][j] = s[i][j] ^ s[i+1][j] ^ s[i][j+1] ^ s[i+1][j+1];
    }

    vector<vector<int>> hist(h - 1, vector<int>(w - 1));
    rep(i, w - 1){
        int cnt = 0;
        rep(j, h - 1){
            if(t[j][i]){
                cnt = 0;
                continue;
            }
            hist[j][i] = ++cnt;
        }
    }

    int ans = max(h, w);
    rep(i, h - 1){
        stack<P> st;
        st.emplace(hist[i][0], 0);
        for(int j = 1; j < w - 1; j++){
            if(st.top().first == hist[i][j]){
                continue;
            }
            if(st.top().first < hist[i][j]){
                st.emplace(hist[i][j], j);
                continue;
            }
            int idx;
            while(not st.empty() && hist[i][j] <= st.top().first){
                P p = st.top();
                st.pop();
                idx = p.second;

                ans = max(ans, (j - idx + 1) * (p.first + 1));
            }
            st.emplace(hist[i][j], idx);
        }
        int idx;
        while(not st.empty()){
            P p = st.top();
            st.pop();
            idx = p.second;

            ans = max(ans, (w - idx) * (p.first + 1));
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 32768
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int n,k,r,s,p;

int pts(char c){
   if(c == 'p') return s;
   if(c == 'r') return p;
   return r;
}

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   string t;
   cin >> n >> k >> r >> s >> p >> t;
   vector<int> a(n),b(n);
   int ans = 0;
   f(i,0,n){
      if(i < k){
         a[i] = pts(t[i]);
         b[i] = 0;
      }else{
         b[i] = a[i-k];
         a[i] = pts(t[i]);
         if(t[i] == t[i-k]){
            a[i] += b[i-k];
         }else{
            a[i] += a[i-k];
         }
         a[i] = max(a[i],b[i]);
      }
      if(i>=n-k) ans += max(a[i],b[i]);
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 2000
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N, K;
    cin >> N >> K;
    if(K % 2){
        ll ct = N / K;
        print(ct * ct * ct);
        return 0;
    }
    ll od = N / K;
    K /= 2;
    ll ev = N / K - od;

    print(ev * ev * ev + od * od * od);

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

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

        int n = in.nextInt();
        int[] arr = in.nextIntArray(n);
        int prev = arr[0];
        int sum = prev;
        for (int i=1; i<n; i++) {
            if (arr[i] > prev) {
                sum += arr[i] - prev;
            }
            prev = arr[i];
        }
        out.println(sum);
        out.close();


        //INT OVERFLOW -> USE LONG
        //ARR OUT OF BOUNDS
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public double[] nextDoubleArray(int n) {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextDouble();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        public char[] nextCharArray(int n) {
            char[] arr = nextLine().trim().replaceAll("\\s", "").toCharArray();
            return arr;
        }

        public String[] nextStringArray(int n) {
            String[] arr = new String[n];
            for (int i = 0; i < n; i++) {
                arr[i] = next();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 22228
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcount((unsigned int)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

ll N, K;
const ll size = 1e5+100;
vl G[size];

const ll mod = 1e9+7;

ll dfs(ll now, ll par){
    ll res = 1;
    ll cnt = K-1;
    if(par >= 0) cnt--;
    
    for(ll to : G[now]){
        if(to == par) continue;
        ll tmp = cnt*dfs(to, now)%mod;
        cnt--;
        res = res*tmp%mod;
    }
    return res%mod;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    rep(i, N-1){
        ll a, b; cin >> a >> b; a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    ll ans = K * dfs(0, -1) % mod;
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 11648
N = int(input())
A = list(map(int,input().split()))

A = sorted(A)
B = A[::]
n = A[-1]
temp = n // 2
min_ = 10 ** 9 + 7
for i in range(N - 1):
    A[i] -= temp
    A[i] = abs(A[i])
min_ = min(A)
for i in range(N - 1):
    if A[i] == min_:
        ans = B[i]
print(n, ans)

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

int main(){
   
  int S,F;
  cin >> S >> F;
  
  if(S>F)
    cout << "safe" << endl;
  else
    cout << "unsafe" << endl;

}




Measured memory_bytes: 3624
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = sorted(readInts())
    pre_ = (V[0] + V[1])/2
    if n == 2:
        print(pre_)
        exit()
    else:
        for i in range(2,n):
            pre_ = (pre_ + V[i])/2
    print(pre_)
if __name__ == '__main__':
  main()


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

int main() {
	ll a, b, x;
	cin>>a>>b>>x;
	ll p = b/x;
	ll q = a/x;
	ll r = p-q;
	if(a%x==0) r++;
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
x = []
flag = True
for i in reversed(range(n)):
    if i == 0:
        if not flag:
            x.append(a[i])
        break
    flag2 = flag
    if flag:
        if a[i - 1] < a[i]:
            x.append(a[i])
            flag2 = not flag2
    else:
        if a[i - 1] > a[i]:
            x.append(a[i])
            flag2 = not flag2
    flag = flag2
x = x[::-1]
m = len(x)
if m % 2 == 1:
    x = x[1:]
# print("x =", x)
cur_money = 1000
cur_stock = 0
for i in range(m):
    if i % 2 == 0:
        cur_stock += cur_money // x[i]
        cur_money %= x[i]
    else:
        cur_money += x[i] * cur_stock
        cur_stock = 0
print(cur_money)

Measured memory_bytes: 61484
#include "bits/stdc++.h"
    #define LF '\n'
    #define ALL(x) x.begin(), x.end()
    #define iostreamBooster() do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
    using namespace std;
    typedef int64_t i64;
    typedef pair<int,int> pii;
    template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
    template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
    constexpr int INF = 0x3f3f3f3f;
    constexpr i64 LINF = 0x3f3f3f3f'3f3f3f3fLL;
    i64 a[1000100];
    i64 f(i64 n) {
    if (n & 1) {
    return 3*n + 1;
    } else {
    return n/2;
    }
    }
    signed main()
    {
    set<i64> U;
    int ans = 0;
    cin >> a[1];
    U.insert(a[1]);
    for (int i = 2; i <= 1000005; ++i) {
    a[i] = f(a[i-1]);
    if (U.count(a[i])) {
    ans = i;
    break;
    } else {
    U.insert(a[i]);
    }
    }
    cout << ans << endl;
    return 0;
    }


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

using namespace std;

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

    vector<pair<int, int> > P(M);
    for (int i = 0; i < M; ++i) {
        cin >> P[i].first >> P[i].second;
    }

    for (int i = 0; i < 1000; ++i) {
        if (to_string(i).length() != N) continue;

        int tmp = i;
        vector<int> d(1, tmp % 10);
        while (tmp) {
            d.emplace_back(tmp % 10);
            tmp /= 10;
        }
        reverse(d.begin(), d.end());

        bool ok = true;
        for (auto x:P) {
            if (d[x.first - 1] != x.second) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}



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();
    int[] t = new int[n];
    int[] a = new int[n];
    int[] k1 = new int[n];
    int[] k2 = new int[n];
    for(int i = 0; i < n; i++) {
      t[i] = sc.nextInt();
      if(i == 0) {
        k1[0] = 1;
      } else {
        if(t[i] > t[i - 1]) k1[i] = 1;
      }
    }
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }
    k2[n - 1] = 1;
    for(int i = n - 1; i >= 1; i--) {
      if(a[i - 1] > a[i]) k2[i - 1] = 1;
    }
    long ans = 1;
    long mod = (long)Math.pow(10, 9) + 7;
    for(int i = 0; i < n; i++) {
      if(k1[i] == 1) {
        if(k2[i] == 1) {
          if(t[i] != a[i]) ans = 0;
        } else {
          if(t[i] > a[i]) ans = 0;
        }
      } else {
        if(k2[i] == 1) {
          if(t[i] < a[i]) ans = 0;
        } else {
          ans = (ans * (long)Math.min(t[i], a[i])) % mod;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 89804
import java.util.Scanner;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n;
		n=sc.nextInt();
		String words[] = new String[n];
		for(int i=0;i<n;i++)
			words[i]=sc.next();
		int flag=0;
		/*String aa ="aaj";
		System.out.println(words[1].matches(aa));*/
		for(int i=0;i<n-1;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(words[i].matches(words[j]))
				{
					flag=1;
					break;
				}
			}
		}
		if(flag==0)
		{
			for(int i=1;i<n;i++)
			{
				if((words[i-1].charAt(words[i-1].length()-1))==(words[i].charAt(0)))
				{
					
				}
				else
				{
					flag=1;
					break;
				}
			}
		}
		if(flag==0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 32512
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ
N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

next_q = [(0, 0)]
while len(next_q)>0:
    nw, nc = next_q.pop()
    color[nw] = nc
    for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2))
for i in color:
    print(i)

Measured memory_bytes: 39464
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main(){
    cout<<fixed<<setprecision(10);
    int A,B;
    cin>>A>>B;
    if(9<A||9<B){
        cout<<-1;
        return 0;
    }
    cout<<A*B;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        String[] input1;
        String[] input2;
		try (Scanner sc = new Scanner(System. in)) {
		input1 = sc.nextLine().split(" ");
        input2 = sc.nextLine().split(" ");
        }
      
      int N = Integer.parseInt(input1[0]);
      int X = Integer.parseInt(input1[1]);
      int sum=0;
      int ans=1;
      
      for (int i=0;i<N;i++) {
          sum += Integer.parseInt(input2[i]);
          if (X >= sum) {
            ans+=1;
          }
      }
      System.out.println(ans);
	}
}


Measured memory_bytes: 23764
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    static ArrayList<Integer> stones[];
    static long W;
    static long N;
    static long F;
    public static void main(String[] args)  {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        W = scanner.nextInt();
        stones = new ArrayList[4];
        for (int i = 0;i < 4;++i){
            stones[i] = new ArrayList<>();
        }
        for (int i = 0;i < N;++i){
            int w = scanner.nextInt();
            int v = scanner.nextInt();
            if(i == 0){
                F = w;
            }
            stones[(int)(w - F)].add(v);
        }
        for (int i = 0;i < 4;++i){
            stones[i].sort((a,b) -> b - a);
        }
        System.out.println(search());
    }

    public static long search(){
        long r = 0;
        for (long i1 = -1;i1 < stones[0].size();++i1){
            for (long i2 = -1;i2 < stones[1].size();++i2) {
                for (long i3 = -1; i3 < stones[2].size(); ++i3) {
                    for (long i4 = -1; i4 < stones[3].size(); ++i4) {
                        if((i1 + 1) * F + (i2 + 1) * (F + 1) + (i3 + 1) * (F + 2) + (i4 + 1) * (F + 3) > W)continue;
                        long t = 0;
                        if(i1 >= 0)for (int i = 0; i <= i1; ++i) {
                            t += stones[0].get(i);
                        }
                        if(i2 >= 0)for (int i = 0; i <= i2; ++i) {
                            t += stones[1].get(i);
                        }
                        if(i3 >= 0)for (int i = 0; i <= i3; ++i) {
                            t += stones[2].get(i);
                        }
                        if(i4 >= 0)for (int i = 0; i <= i4; ++i) {
                            t += stones[3].get(i);
                        }
                        if(r < t)r = t;
                    }
                }
            }
        }
        return r;
    }

}




Measured memory_bytes: 28116
def main():
    inf=float("inf")
    n=int(input())
    alst=[list(map(int,input().split())) for _ in range(n)]
 
    for i in range(n):
        alst[i][i]=inf
 
    sm=0
    token=0
 
    for i in range(n):
        for j in range(i+1,n):
            for k in range(n):
                if alst[i][k]+alst[k][j]>alst[i][j]:
                    continue
                elif alst[i][k]+alst[k][j]==alst[i][j]:
                    break
                else:
                    token=1
                    break
            else :
                sm+=alst[i][j]
    
    if token : sm=-1
 
    print(sm)
 
main()

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

int main(){
    int r,d,a0;
    cin >> r >> d >> a0;
    ll a[11];
    a[0] = a0;
    for(int i = 0; i < 10; ++i){
        cout << a[i]*r - d << endl;
        a[i+1] = a[i]*r - d;
    }
    return 0;
}

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

int main() {
    int d; cin >> d;
    vector<int> c(26);
    for (int i=0; i<26; ++i) cin >> c[i];
    vector<vector<int> > s(d, vector<int>(26));
    for (int i=0; i<d; ++i) {
        for (int j=0; j<26; ++j) {
            cin >> s[i][j];
        }
    }
    vector<int> t(d);
    for (int i=0; i<d; ++i) cin >> t[i];
    long long now = 0;
    vector<int> last(26, -1);
    for (int i=0; i<d; ++i) {
        now += s[i][t[i] - 1];
        last[t[i] - 1] = i;
        for (int j=0; j<26; ++j) {
            now -= c[j] * (i - last[j]);
        }
        cout << now << endl;
    }
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
#define inf 0x3f3f3f3f
#define ll long long
const int mod=1e9+7;
ll jie(ll x)
{
	ll res=1;
	for(ll i=1;i<=x;i++)
	{
		res=res*i%mod;
	}
	return res;
}
int main() 
{
	ll a,b;
	cin>>a>>b;
	if(abs(a-b)>1)
	{
		cout<<0<<endl;
	}
	else 
	{
		if(a>b)
			swap(a,b);
		if(a==b)
		{
			cout<<jie(a)*jie(b)%mod*2%mod<<endl;
		}
		else if(a+1==b)
		{
			cout<<jie(a)*jie(b)%mod<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(N):
    if A[i]%2==0:
        if not (A[i]%3==0 or A[i]%5==0):
            ans+=1
if ans==0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
//https://atcoder.jp/contests/abc148/tasks/abc148_e
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N=100; cin>>N;
    if(N%2!=0){
        cout<<0<<endl;
        return 0;
    }
#if 0
    ll tmp=0;
    auto count = [](ll iv){
        ll v=iv;
        ll cnt=0;
        while(v%5==0){
            ++cnt;
            v/=5;
        }
        dump(iv,cnt);
        return cnt;
    };
    for(ll i=2;i<=N;i+=2){
        if (i%5==0)tmp+=count(i);
    }
    dump(tmp);
#endif
    ll ans=0;
    ll div5=10;
    while(true){
        ll ad=(N/div5);
        if(ad<=0)break;
        ans += ad;
        div5 *= 5;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int partition(int arr[],int low,int high){

    int mid;

    if(low<high){
        mid=(low+high)/2;
        partition(arr,low,mid);
        partition(arr,mid+1,high);
        mergeSort(arr,low,mid,high);
    }
    return 0;
}

int mergeSort(int arr[],int low,int mid,int high){

    int i,m,k,l,temp[10];

    l=low;
    i=low;
    m=mid+1;

    while((l<=mid)&&(m<=high)){

         if(arr[l]<=arr[m]){
             temp[i]=arr[l];
             l++;
         }
         else{
             temp[i]=arr[m];
             m++;
         }
         i++;
    }

    if(l>mid){
         for(k=m;k<=high;k++){
             temp[i]=arr[k];
             i++;
         }
    }
    else{
         for(k=l;k<=mid;k++){
             temp[i]=arr[k];
             i++;
         }
    }

    for(k=low;k<=high;k++){
         arr[k]=temp[k];
    }
    return 0;
}

int main(){
    int i,str[10];
    for(i=0;i<10;i++) scanf("%d",&str[i]);
    partition(str,0,9);
    for(i=9;i>6;i--) printf("%d\n",str[i]);
    return 0;
}

Measured memory_bytes: 600
import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	
	String INPUT = "";
	
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
		PrintWriter out = new PrintWriter(System.out);
		
		solve(sc, out);
		out.flush();
	}
	
	void solve(Scanner sc, PrintWriter out) {
		int H, W;
		
		for (;;) {
			H = sc.nextInt();
			W = sc.nextInt();
			if (H == 0 && W == 0) break;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 34808
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int len = String.valueOf(n).length();
		int c = 0;

		for(int i = 1; i <= len; i += 2) {
			if(i < len) {
				c += (int)Math.pow(10, i - 1) * 9;
			} else {
				if(i == 1) c += n;
				else c += n - (int)Math.pow(10, i - 1) + 1;
			}
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 35592
#include <bits/stdc++.h>
#define pc(x) putchar_unlocked(x);
typedef int64_t int64;
using namespace std;

inline void fastscan(int &num) {
    bool neg = false;
    int c;
    num = 0;
    c = getchar();
    if (c == '-') {
        neg = true;
        c = getchar();
    }
    for (; (c > 47 && c < 58); c = getchar()) num = num * 10 + c - 48;
    if (neg) num *= -1;
}

inline void fastout(int n) {
    int N = n, rev, count = 0;
    rev = N;
    if (N == 0) { pc('0'); pc('\n'); return ;}
    while ((rev % 10) == 0) { count++; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;}
    while (count--) pc('0');
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; fastscan(N);
    int v[N];
    for (int i = 0; i < N; ++i) fastscan(v[i]);
    int sum = 0;
 
    for (int i = 1; i < N; ++i) sum += abs(v[i - 1] - v[i]);
    sum = sum + abs(0 - v[0]) + abs(v[N - 1] - 0);
    int diff[N];
    diff[0] = abs(0 - v[0]) + abs(v[0] - v[1]) - abs(0 - v[1]);
    for (int i = 1; i < N - 1; ++i){
        diff[i] = abs(v[i - 1] - v[i]) + abs(v[i] - v[i + 1]) - abs(v[i - 1] - v[i + 1]);
    }
    diff[N - 1] = abs(v[N - 2] - v[N - 1]) + abs(v[N - 1] - 0) - abs(v[N - 2] - 0);

    for (int i = 0; i < N; ++i){
        fastout(sum - diff[i]); pc('\n');
    }
    return 0;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }


void solve() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(all(A));
  int sum = 0;
  int k = 0;
  for(int i = N - 1; i >= 0; i--) {
    if (k & 1) sum -= A[i]; else sum += A[i];
    k++;
  }
  cout << sum << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

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

typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<int>v(n);
    for (int i = 0; i < n; ++i){
        cin >> v.at(i);
    }
    int min_num = 1000000007;
    for (int i = 1; i <= 100; ++i){
        int tmp = 0;
        for (int j = 0; j < n; ++j){

            tmp += (v.at(j)-i)*(v.at(j)-i);

        }

        min_num = min(min_num, tmp);
    }
    cout << min_num << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <assert.h>
#include <sstream>
#include <type_traits>
#define SET(x,y) x |= (1 << y)
#define CLEAR(x,y) x &= ~(1<< y)
#define READ(x,y) ((0u == (x & (1<<y)))?0u:1u)
#define TOGGLE(x,y) (x ^= (1<<y))
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define si(n) scanf("%d",&n)
#define sf(n) scanf("%f",&n)
#define sl(n) scanf("%lld",&n)
#define slu(n) scanf("%llu",&n)
#define sd(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
#define pnl printf("\n")
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pF first
#define pS second
#define CL(a,b) memset(a,b,sizeof(a))
#define sqr(x) ((x)*(x))
#define intLIMIT numeric_limits<int>
#define longLIMIT numeric_limits<long long>
#define GCD(a,b) __gcd((a),(b))
#define dbl(x) (double)(x)
#define vi vector <int>
#define vii vector < pair <int, int> >
#define vll vector <long long>
#define allof(x) (x).begin(), (x).end()
#define fastCin cin.sync_with_stdio(0);cin.tie(0)
#define scanUnsigned(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#define printArr(a,l) cout<<#a<<": ";for(int i=0;i<(l);i++){cout<<a[i]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(int i=0;i<(r);i++){for(int j=0;j<(c);j++){cout<<a[i][j]<<" ";}cout<<endl;}
char _;
using namespace std;
void PRINT (int x, int y) { for (int i = y-1; i >= 0; i--) { cout << READ(x,i); } cout << endl; }

vector<string>vec_splitter(string s){s+=',';vector<string>res;while(!s.empty()){res.push_back(s.substr(0,s.find(',')));s=s.substr(s.find(',')+1);}
return res;}
void debug_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM){cerr<<endl;}
template<typename Head,typename...Tail>void debug_out(vector<string>args,int idx,int LINE_NUM,Head H,Tail...T){if(idx>0)cerr<<", ";else cerr<<"Line("<<LINE_NUM<<") ";stringstream ss;ss<<H;cerr<<args[idx]<<" = "<<ss.str();debug_out(args,idx+1,LINE_NUM,T...);}
#ifdef LOCAL_DBG
#define dbg(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define dbg(...) 42
#endif

int main () {
	fastCin;
	ll mod = 1e9+7;
	ll n;
	cin >> n;
	ll ans = 1; // total
	if (n < 2) {
		cout << 0 << "\n";
	} else {
		ll ans2 = 1; //neither 9 or 0
		ll ans3 = 1; //not both 9 and 0
		for (int x =0 ; x < n; x++) {
			ans *= (ll)10;
			ans %= mod;
			ans2 *= (ll)8;
			ans2 %= mod;
			// if (x != 0) {
				ans3 *= (ll)9;
				ans3 %= mod;
			// }
		}
		// ans3 *= n;
		ans3 -= ans2;
		ans3 += mod;
		ans3 %= mod;

		ans3 *= 2;
		ans3 %= mod;
		dbg (ans2, ans3);
		cout << (ans - ans2 - ans3 + 3*mod) % mod << "\n";
		// ll tmp = 1;
		// for (int x = 0; x < n-2; x++) {
		// 	tmp *= (ll)10;
		// 	tmp %= mod;
		// }
		// tmp *= (ll)n;
		// tmp %= mod;
		// tmp *= (ll)(n-1);
		// tmp %= mod;
		// dbg (tmp);
	}
	return 0;
}

Measured memory_bytes: 3200
#include<iostream>

using namespace std;

int main(){
	int r, D, x2000; cin >> r >> D >> x2000;

	int xi = x2000;
	for(int i = 0; i < 10; ++i){
		cout << r*xi - D << endl;
		xi = r*xi - D;
	}

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
    int h,n,cnt=0;
    scanf("%d%d",&h,&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        cnt+=a[i];
    }
    if(cnt>=h)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
}



Measured memory_bytes: 512
#include <string>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>
#include <queue>
#include <iomanip>

#include <string.h>

typedef unsigned long long u64; 
typedef unsigned int uint;

using namespace std;

#define MIN(a, b) a < b ? a : b

int main()
{
	int n;
	list<int> answer;

	cin >> n;
	bool isRight = false;

	for(int i = 0; i < n; i++)
	{
		int m;
		cin >> m;
		if(isRight)
		{
			answer.push_back(m);
		}
		else
		{
			answer.push_front(m);
		}
		isRight = !isRight;
	}

	if( isRight)
	{
		for(auto it = answer.begin(); it != answer.end(); it++)
		{
			cout << *it << " ";
		}
	}
	else
	{
		for(auto it = answer.rbegin(); it != answer.rend(); it++)
		{
			cout << *it << " ";
		}
	}
	
	cout << endl;
}

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

#define FOR(type, i, a, b) for (type i = (a); i < (b); ++i)
#define RFOR(type, i, a, b) for (type i = (b)-1;i >= (a); --i)
#define REP(type, i, n) for (type i = 0; i < (n); ++i)
#define RREP(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)

constexpr auto PI = 2 * acos(0.0);
constexpr auto INF = 0x33433433;

using ll = long long;
using llu = unsigned long long;

llu solve(llu a, llu b) {
  if (b % a == 0) return a * ((b / a) * 2 - 1);
  return a * ((b / a) * 2) + solve(b % a, a);
}

int main(void) {
  llu N, X; scanf("%llu %llu", &N, &X);

  if (X < N-X) printf("%llu\n", X + N-X + solve(X, N-X));
  else printf("%llu\n", X + N-X + solve(N-X, X));

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bisect(l,r,f,discrete=True,left=True):
    """
    l,r: l<r int if discrete else float
    f: function defined on [l,...,r] to {False,True}
    if discrete: f defined on Z; else: R
    if left: f satisfies that there uniquely exists d such that iff i<=d then f(i)
    else: iff i>=d then f(i) is True
    return d such as those above
    """
    assert r>l
    if discrete: assert isinstance(l,int) and isinstance(r,int)
    eps=1 if discrete else 10**-12
    if (not left)^f(r): return r if left else r+1
    elif left^f(l): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if (not left)^f(h): l=h
        else: r=h
    return h if not discrete else l if left else r

class RollingHash(object):
    """
    construct: O(N)
    get_hash: O(1)
    LCP: O(logN)
    """
    def __init__(self,S,m1=10**9+9,b1=1007,m2=10**9+7,b2=1009):
        """
        S: string
        m1>m2: prime sufficiently large
        b1,b2: base 0<bi<mi
        """
        assert m1>m2 and 0<b1<m1 and 0<b2<m2
        n=len(S)
        self.__n=n
        self.__m1=m1
        self.__m2=m2
        self.__H1,self.__H2=[0]*(n+1),[0]*(n+1)
        self.__P1,self.__P2=[1]*(n+1),[1]*(n+1)
        for i,s in enumerate(S):
            self.__H1[i+1]=(self.__H1[i]*b1+ord(s))%m1
            self.__H2[i+1]=(self.__H2[i]*b2+ord(s))%m2
            self.__P1[i+1]=self.__P1[i]*b1%m1
            self.__P2[i+1]=self.__P2[i]*b2%m2

    @property
    def len(self):
        return self.__n

    def hash(self,l,r=None):
        """
        l,r: int (0<=l<=r<=n)
        return (hash1,hash2) of S[l:r]
        """
        if r is None: r=self.len
        assert 0<=l<=r<=self.len
        return ((self.__H1[r]-self.__P1[r-l]*self.__H1[l]%self.__m1)%self.__m1,(self.__H2[r]-self.__P2[r-l]*self.__H2[l]%self.__m2)%self.__m2)

    def LCP(self,l1,r1=None,rh2=None,l2=0,r2=None):
        if r1 is None: r1=self.len
        if rh2 is None: rh2=self
        if r2 is None: r2=rh2.len
        assert 0<=l1<=r1<=self.len and 0<=l2<=r2<=rh2.len
        L=0
        R=min(r1-l1,r2-l2)
        if self.hash(l1,l1+R)==rh2.hash(l2,l2+R): return R
        while(R-L>1):
            H=(L+R)//2
            if self.hash(l1,l1+H)==rh2.hash(l2,l2+H): L=H
            else: R=H
        return L

def resolve():
    n=int(input())
    S=input()
    # d=0ではtrue,d=nではfalseなので、そこでbisectする
    rh=RollingHash(S)
    def judge(d):
        # initialize
        J={rh.hash(i,i+d):-1 for i in range(n-d+1)}
        for i in range(n-d+1):
            h=rh.hash(i,i+d)
            if J[h]!=-1:
                if i-J[h]>=d: return True
            else: J[h]=i
        return False
    print(bisect(0,n,judge))
resolve()

Measured memory_bytes: 43760