akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ABC046B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            long n = input[0];
            long k = input[1];

            long result = k;
            result *= Pow(k - 1, n - 1);
            Console.WriteLine(result);
        }

        static long Pow(long n, long k)
        {
            long result = 1;

            for(long i = 0; i < k; i++)
            {
                result *= n;
            }

            return result;
        }
    }
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
 


int main() {
	int N; cin >> N;
	int amin = 1e9;
	int ans = -2e9;
	for (int i = 0; i < N;++i){
		int a; cin >> a;
		if (i) {

			ans = max(ans, a - amin);
		}
		amin = min(amin, a);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3096
/***
*	author  :_shamim
*	created : 05.05.2020
*
***/

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <list>
#include <set>
#include <queue>
#include <iterator>
#include <bitset>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll             long long
#define _              ios_base::sync_with_stdio(0);cin.tie(0);
#define loop           for(i=0;i<n;i++)
#define pb             push_back
#define tc()           int t;cin>>t;while(t--)          

using namespace std;

ll i,j,temp;

int main()
{_
	
	int N,pos,neg;
	cin>>N;

	if(N%2==0){
		cout<<(double)1/(double)2<<endl;
	}
	else{
		pos = N/2;
		neg = N - pos;
		cout<<(double)neg/(double)N<<endl;
	}
	return 0;
}

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

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

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


struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};







int main(int argc, const char * argv[]) {
    ll X,Y;
    cin >> X >> Y;
    if((X+Y)%3 != 0){
        cout << 0 << endl;
        return 0;
    }
    ll cnt = (X+Y)/3;
    ll A = X - cnt;
    ll B = Y - cnt;
    
    if(A<0 || B<0){
        cout << 0 << endl;
        return 0;
    }
    combination c(A+B);
    mint ans = c(A+B,A);
    
    cout << ans.x << endl;
    
    
   return 0;
}



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

int main () {
  int n, x;
  int m[110];
  cin >> n >> x;
  for (int i = 0; i < n; i++) cin >> m[i];

  int min_m = 2000;
  for (int i = 0; i < n; i++) {
    x -= m[i];
    min_m = min(min_m, m[i]);
  }
  int count = n;
  count += x / min_m;
  cout << count << endl;
}


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

using namespace std;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int cost[n] = {0};
  for (int i = 0; i < m; i++) {
    int index;
    cin >> index;
    cost[index] = 1;
  }

  int result1 = 0;
  for (int i = x; i > 0; i--) {
    result1 += cost[i];
  }
  int result2 = 0;
  for (int i = x; i < n; i++) {
    result2 += cost[i];
  }

  cout << min(result1, result2) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> tree(n, vector<int>(n, 0));
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        tree[r - l][l]++;
    }
    for (int j = 0; j < n - 1; j++) {
        tree[1][j] += tree[0][j] + tree[0][j + 1];
    }
    for (int i = 2; i < n; i++) {
        for (int j = 0; j < n - i; j++) {
            tree[i][j] += tree[i - 1][j] + tree[i - 1][j + 1] - tree[i - 2][j + 1];
        }
    }
    for (int i = 0; i < q; i++) {
        int p, q;
        cin >> p >> q;
        p--, q--;
        cout << tree[q - p][p] << endl;
    }
}


Measured memory_bytes: 1920
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <time.h>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)
#define COUNTER int i= 0,j = 0,k = 0,l = 0,m = 0, n= 0;
#define RETURN cout << endl;
/*vector<vector<int>>ArrayName = vector<vector<int>>(sizeofx, vector<int>(sizeofy, 0));*/
using namespace std;

int main ()
{
    int candy;
    COUNTER
    while(cin >>candy )
    {
        while(true)
        {
            if(candy <= 39)
                break;
            candy = candy -39;
        
        }
        cout << "3C";printf("%.2d\n",candy);
        
    }
}

Measured memory_bytes: 1164
import java.util.*;

class DSU {
	private int n;
	private int[] parentOrSize;

	public DSU(int n) {
		this.n = n;
		this.parentOrSize = new int[n];
		Arrays.fill(parentOrSize, -1);
	}

	int merge(int a, int b) {
		if (!(0 <= a && a < n))
			throw new IndexOutOfBoundsException("a=" + a);
		if (!(0 <= b && b < n))
			throw new IndexOutOfBoundsException("b=" + b);

		int x = leader(a);
		int y = leader(b);
		if (x == y) return x;
		if (-parentOrSize[x] < -parentOrSize[y]) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		parentOrSize[x] += parentOrSize[y];
		parentOrSize[y] = x;
		return x;
	}

	boolean same(int a, int b) {
		if (!(0 <= a && a < n))
			throw new IndexOutOfBoundsException("a=" + a);
		if (!(0 <= b && b < n))
			throw new IndexOutOfBoundsException("b=" + b);
		return leader(a) == leader(b);
	}

	int leader(int a) {
		if (parentOrSize[a] < 0) {
			return a;
		} else {
			parentOrSize[a] = leader(parentOrSize[a]);
			return parentOrSize[a];
		}
	}

	int size(int a) {
		if (!(0 <= a && a < n))
			throw new IndexOutOfBoundsException("" + a);
		return -parentOrSize[leader(a)];
	}

	ArrayList<ArrayList<Integer>> groups() {
		int[] leaderBuf = new int[n];
		int[] groupSize = new int[n];
		for (int i = 0; i < n; i++) {
			leaderBuf[i] = leader(i);
			groupSize[leaderBuf[i]]++;
		}
		ArrayList<ArrayList<Integer>> result = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			result.add(new ArrayList<>(groupSize[i]));
		}
		for (int i = 0; i < n; i++) {
			result.get(leaderBuf[i]).add(i);
		}
		result.removeIf(ArrayList::isEmpty);
		return result;
	}
}

public class Main {
    static final long BIG = 1_000_000_000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        DSU G = new DSU(N);
        for(int q=0; q<Q; q++){
            int t = sc.nextInt();
            int u = sc.nextInt();
            int v = sc.nextInt();
            if(t==0) G.merge(u,v);
            else System.out.println(G.same(u, v) ? 1 : 0);
        }
    }
}

Measured memory_bytes: 59972
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, h[20], ans, ta;

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> h[i];
		if (ta <= h[i]) {
			ans++;
			ta = h[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int h, w;
	cin >> h >> w;
	char c[100][100] = { '.' };
	for(int i = 0;i<h;i++){
		for (int j = 0; j < w; j++) {
			cin >> c[i][j];
		}
	}
	int ans[100][100] = { -1 };
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (c[i][j] == 'c') {
				ans[i][j] = 0;
			}
			else if (c[i][j] == '.') {
				ans[i][j] = -1;
				for (int k = j; k >= 0; k--) {
					if (c[i][k] == 'c') {
						ans[i][j] = j-k;
						break;
					}
				}
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (j == w - 1) {
				cout << ans[i][j] << endl;
			}
			else {
				cout << ans[i][j] << " ";
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
bool a[26];
int main()
{
	string s;
	cin>>s;
	int i;
	for(int i=0;i<26;i++)a[i] = false;
	for (i = 0; i < s.length(); i++)
	{
		a[s[i] - 'a'] = true;
	}
	for(i=0;i<26;i++)
	{
		if(a[i] == false)
			break;
	}
	if(i < 26)
		cout<<s << char(i+'a')<<endl;
	else
		{
			string t = s;
			bool val = next_permutation(s.begin(),s.end());			
				if(val == false)
					cout<<-1;
				else {
					for(i=0;i<s.length();i++)
					{
						if(s[i]!=t[i])
						{
							cout<<s[i];
							break;
						}
						cout<<s[i];
					}
				}

		}
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
friends_table = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    friends_table[a-1] += [b-1]
    friends_table[b-1] += [a-1]

group_list = [i for i in range(N)]
friends_candidate = [[] for i in range(N)]

for i in range(N):
    # すでにDFS済み
    if i != group_list[i]:
        continue
    next_stack = [i]
    friend = [i]
    while next_stack:
        u = next_stack.pop(-1)
        for v in friends_table[u]:
            # 訪問済み
            if i == group_list[v]:
                continue
            friend += [v]
            group_list[v] = i
            next_stack += [v]
    for f in friend:
        friends_candidate[f] = friend

blocks_table = [[] for i in range(N)]
for _ in range(K):
    a, b = map(int, input().split())
    if group_list[a-1] == group_list[b-1]:
        blocks_table[a-1] += [b-1]
        blocks_table[b-1] += [a-1]

for i in range(N):
    print(len(friends_candidate[i]) - len(friends_table[i]) - len(blocks_table[i])-1)

Measured memory_bytes: 87856
<?php
list($n, $x) = explode(" ", trim(fgets(STDIN)));
$aArray = explode(" ", trim(fgets(STDIN)));

sort($aArray);

if(array_sum($aArray) < $x){
    echo $n - 1;
}elseif(array_sum($aArray) == $x){
    echo $n;
}else{
    $count = 0;
    foreach($aArray as $a){
        $x-=$a;
        if($x >= 0){
            $count++;
        }
    }
    echo $count;
}


Measured memory_bytes: 4728
import copy

h,w,k=[int(aaa) for aaa in input().split()]

c=[]
ans=0

for _ in range(h):
    c.append(list(input()))

for i in range(2**h):
    for j in range(2**w):
        d=copy.deepcopy(c)
        i2='000000'+format(i,'b')
        j2='000000'+format(j,'b')
        #対応する場所の色を変える
        #おケツから数える
        for k2 in range(1,h+1):
            if i2[-k2]=='1':
                for i3 in range(w):
                    d[k2-1][i3]='@'
        for l in range(1,w+1):
            if j2[-l]=='1':
                for j3 in range(h):
                    d[j3][l-1]='@'

        #数を数える
        cnt=0
        for d2 in d:
            cnt+=d2.count('#')
        #一致してたらプラ1
        if cnt==k:
            ans+=1
print(ans)


Measured memory_bytes: 9288
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    int n,i,min=100000,sum1=0,sum2=0;
    scanf("%d",&n);
    int w[n];
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
        sum2+=w[i];
    }
    for(i=0;i<n;i++){
        sum1+=w[i];
        sum2-=w[i];
        if(abs(sum1-sum2)<min){
            min = abs(sum1-sum2);
        }
    }
    printf("%d",min);
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	string s;
	cin >> s;
	vector<char> v;
	for (char c : s)v.push_back(c);
	sort(v.begin(), v.end());

	bool res = true;
	if (v[0] != v[1])res = false;
	if (v[2] != v[3])res = false;
	if (v[1] == v[2])res = false;
	cout << (res ? "Yes" : "No") << endl;
	return 0;
}


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

typedef long long ll;

int main(){
    ll N,K;
    cin>>N>>K;
    ll ans = 0;

    for(ll b=1; b<=N; b++){
        ans += N/b * max(b-K,0ll); 
        if(N%b){
            ans += max(N%b - K + 1,0ll); 
        }
    }

    if(K == 0) ans = N*N;

    cout<<ans<<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<int>> x(n), y(n);
  REP(i, n) {
    cin >> a[i];
    x[i].resize(a[i]);
    y[i].resize(a[i]);
    REP(j, a[i]) {
      cin >> x[i][j] >> y[i][j];
      --x[i][j];
    }
  }
  int ans = 0;
  REP(bits, 1 << n) {
    bool ok = true;
    REP(i, n) {
      if (!((bits >> i) & 1)) continue;
      REP(j, a[i]) {
        if (((bits >> x[i][j]) & 1) != y[i][j]) ok = false;
      }
    }
    if (ok) ans = max(ans, __builtin_popcount(bits));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    vector<P> v[N];
    for(int i=0; i<N-1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        v[a].push_back(P(b, c));
        v[b].push_back(P(a, c));
    }

    int Q, K;
    cin >> Q >> K;
    K--;
    int x[Q], y[Q];
    for(int i=0; i<Q; i++){
        cin >> x[i] >> y[i];
        x[i]--;y[i]--;
    }

    queue<pair<int, ll>> q;
    ll d[N];
    fill(d, d+N, -1);
    q.push(make_pair(K, (ll)0));
    while(!q.empty()){
        int now = q.front().first;
        d[now] = q.front().second;
        q.pop();
        for(auto next : v[now]){
            int p = next.first;
            ll cost = next.second;
            if(d[p] != -1) continue;
            q.push(make_pair(p, d[now]+cost));
        }
    }

    for(int i=0; i<Q; i++){
        ll ans = d[x[i]] + d[y[i]];
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 10740
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<double> x(n);
    vector<string> u(n);
    double ans=0;

    for(int i=0;i<n;i++){
        cin>>x[i]>>u[i];
        if(u[i]=="JPY") ans+= x[i];
        else if(u[i] =="BTC") ans += x[i]*380000.0;
    }

    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;

bool hantei(string a, string b){
    REP(i, a.size()){
        if (a[i] != b[i]) return false;
    }
    return true;
}

int main(){
    string str, test;
    cin >> str >> test;
    bool fin = false;
    REP(i, str.size()){
        if(hantei(str, test)){
            cout << "Yes\n";
            fin = true;
            break;
        }
        string cop = str;
        str[0] = str[str.size() - 1];
        REP(j, str.size() - 1) {
            str[j + 1] = cop[j];
        }
    }

    if (!fin) cout << "No\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read() {
	int x; scanf("%d", &x); return x;	
}
const int maxn = 2e5 + 10;
const int INF = 1e9;
int a[maxn], c[maxn], d[maxn];
int main() {
	#ifdef LOCAL
		freopen("1.in", "r", stdin);
	#endif
	int n = read();
	cout << (n % 1000 == 0 ? 0 : 1000 - (n % 1000)) << endl;
	return 0;		
}

Measured memory_bytes: 3756
#include<iostream>
#include<string>
using namespace std;
int main(){
	
	string A,B,C;
	cin>>A>>B>>C;
	if(A[A.size()-1]==B[0] && B[B.size()-1]==C[0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
X = list(map(int, input().split()))
num = float("inf")
for i in range(N - K + 1):
    p = X[i]
    q = X[i + K - 1]
    if q < 0:
        num = min(num, abs(p))
    elif p < 0:
        num = min(num, abs(p) + 2 * abs(q))
        num = min(num, abs(p) * 2 + abs(q))
    else:
        num = min(num, q)

print(num)




Measured memory_bytes: 14224
def count_digit(num):
  cnt = 0
  while num > 0:
    num = num//10
    cnt += 1
  return cnt

def F(A, B):
  return max(count_digit(A), count_digit(B))

N = int(input())
mn = 10
for i in range(1, int(N**(1/2)) + 1):
  if N % i == 0:
    if mn > F(i, N//i):
       mn = F(i, N//i)
print(mn)

Measured memory_bytes: 3060
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    int K = scanner.nextInt();
    final int M = 1_000_000_007;

    int[] fib = new int[] {1, 1, 2, 3, 5, 8, 13, 21, 34};
    long[][] d = new long[H + 1][W + 1];
    d[0][1] = 1;
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        d[i][j] =    d[i - 1][j]     * fib[j - 1] * fib[W - j] % M;
        if(j > 1) {
          d[i][j] += d[i - 1][j - 1] * fib[j - 2] * fib[W - j] % M;
          d[i][j] %= M;
        }
        if(j < W) {
          d[i][j] += d[i - 1][j + 1] * fib[j - 1] * fib[W - j - 1] % M;
          d[i][j] %= M;
        }
      }
    }
    System.out.println(d[H][K]);
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int N=s.size();
  int a = N-1;
  int z = 1;
  for(int i=0; i<N; i++){
    if(i < a && s[i] == 'A'){
      a = i;
    }
    if(i > z && s[i] == 'Z'){
      z = i;
    }
  }
  cout << z - a + 1 << endl;
}


Measured memory_bytes: 640
#define ll long long int
#include <bits/stdc++.h>
//#include <fstream>
using namespace std;
 
#define         ff               first
#define         ss               second
#define         mp               make_pair
#define         pb               push_back
#define         pf               push_front
#define         vi               vector<ll>
#define         pii              pair<ll,ll>
#define         qi               queue<ll>
#define         mem(a,b)         memset(a,b,sizeof(a))
#define         print(a)         cout<<a<<'\n'
#define         sorted(arr)      sort(arr.begin(),arr.end())
#define         gcd(a,b)         gcd((a),(b))
#define         lcm(a,b)         ((a)*(b))/gcd((a),(b))
#define         all(v)           v.begin(),v.end()
#define         read(a)          scanf("%d", &a)
#define         f(a,n)           for(ll i=a;i<n;i++)
#define         in2(n,m,arr)     for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define         debug(a)         cerr<<a<<" ";
#define         debug1(a)        cerr<<a<<'\n'
 
/*typedef tree<int, null_type, less<int>, rb_tree_tag , tree_order_statistics_node_update> Set;*/
 
 
const unsigned ll mod = 1e9 + 7 ;
const ll inf = (ll)1e15 + 42;
const ll N = (ll)1e6 + 2;

ll power ( ll x , unsigned ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod ;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res % mod ;
}
 
//struct node{
//    ll x , y , z;
//};
//map<pair<ll, ll>,ll> c;
//vector<set<ll>> tree;
//vector<ll> ar ;
//set<ll> s;
//ll get(ll x)
//{
//    if(x == ar[x])
//        return x;
//    return ar[x] = get(ar[x]);
//}
//void merge(ll a ,ll b)
//{
//    a = get(a);
//    b = get(b);
//    if(a == b)
//    {
//        return ;
//    }
//    ar[b] = ar[a];
//    //ans[a] += ans[b];
//    //return true;
// }
//
//ll sev[275];
//vector<ll> pri;
//void seive()
//{
//    for(ll i = 2 ; i < 275 ; i ++)
//    {
//        if(!sev[i])
//        {
//            for(ll j = i ; j < 275 ; j += i)
//            {
//                if(!sev[j])
//                    sev[j] = i;
//            }
//        }
//        if(sev[i] == i)
//            pri.pb(i);
//    }
//}

void solve()
{
    ll n ;
    cin >> n;
    ll arr[n + 1] , dp[n + 1];
    for(ll i = 1 ; i <= n ; i ++)
        cin >> arr[i];
    arr[0] = arr[1];
    mem(dp , 0);
    for(ll i = 2 ; i <= n ;i ++)
        dp[i] = min(abs(dp[i - 1] + abs(arr[i - 1] - arr[i])) , abs(dp[i - 2] + abs(arr[i - 2] - arr[i]))) ; //cout << dp[i] << ' ';
    cout << dp[n] << '\n';
}
/*
 5 810688740
 7 948963500
 */

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t ;
    t = 1;
    //cin >> t;
    //seive();
    while(t --)
    {
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
    
}
 


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int H = ni();
        int W = ni();
        boolean[][] B = new boolean[H][W];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                int x = ni();
                B[i][j] = (x == 0);
            }
        }

        int max = 0;

        int[][] dp = new int[H][W];
        for (int i = 0; i < H; i++) {
            if (B[i][0]) {
                dp[i][0] = 1;
                max = 1;
            }
        }
        for (int i = 0; i < W; i++) {
            if (B[0][i]) {
                dp[0][i] = 1;
                max = 1;
            }

        }

        for (int i = 1; i < H; i++) {
            for (int j = 1; j < W; j++) {
                if (!B[i][j]) continue;

                int x = Math.min(dp[i - 1][j], dp[i][j - 1]);
                if (B[i - x][j - x]) {
                    max = Math.max(max, x + 1);
                    dp[i][j] = x + 1;
                } else {
                    dp[i][j] = x;
                }
            }
        }

        out.println(max * max);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 87608
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define P pair<int,int>
#define rep(i,n) for(int i = 1; i <= (n); i++)
#define asort(x) sort(x.begin(),x.end())
 
int main() {
    ll n, m, a, b, cnt=0;
    cin>>n>>m;
    vector<ll> h(n+1), c(n+1);
    rep(i,n) cin>>h[i];
    rep(i,m) {
        cin>>a>>b;
        if(h[a] > h[b]){            
            c[b]++;
        } else if(h[b] > h[a]){
            c[a]++;
        } else {
            c[a]++;
            c[b]++;
        }
    }
    rep(i,n) {
        if(c[i] == 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main(void){
    char moji[1001], tmp[1001], order[8];
    int q, a, b;
    scanf("%s", moji);
    scanf("%d", &q);
    for(int i=0; i<q; i++){
        scanf("%s %d %d", order, &a, &b);
        if(!strcmp(order, "print")){
            for(int j=a; j<=b; j++) printf("%c", moji[j]);
            printf("\n");
        }else if(!strcmp(order, "reverse")){
            for(int j=0; j<=b-a; j++) tmp[b-j] = moji[a+j];
            for(int j=a; j<=b; j++) moji[j] = tmp[j];
        }else if(!strcmp(order, "replace")){
            scanf("%s", tmp);
            for(int j=a; j<=b; j++) moji[j] = tmp[j-a];
        }
    }
    return 0;
}


Measured memory_bytes: 2112
n = int(input())
a = list(map(int,input().split()))
a.sort()
flag = n-2
for i in range(n-1):
  if 2*a[i] > a[n-1]:
    if a[i]-a[n-1]/2 > a[n-1]/2 - a[i-1]:
      flag = i-1
    else:
      flag = i
    break

print(a[n-1],a[flag])

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, a;
  unordered_map<string, int> mp;
  cin >> n;

  rep(i, n) {
    cin >> a;
    if (a % 4 == 0)
      mp["four"]++;
    else if (a % 2 == 0)
      mp["two"]++;
    else
      mp["other"]++;
  }

  if (mp["other"] == 0) {
    cout << "Yes" << endl;
    return 0;
  }

  if (mp["two"] % 2 == 1) mp["other"]++;
  cout << ((mp["four"] >= mp["other"] - 1) ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>
#include <assert.h>


using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;

int digitsum(int x) {
	int sum = 0;
	while (x != 0) {
		sum += (x % 10);
		x /= 10;
	}
	return sum;
}

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

	int res = INF;
	for (int i = 1; i < N; i++)
	{
		res = min(res, digitsum(i) + digitsum(N - i));
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<set>
 
#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
#define P pair<int,int>
#define F first
#define S second
 
using namespace std;

int main(){
  vi pack(3);
  Srep(3) cin >> pack[i];
  Vsort(pack);
  cout << (pack[2] == pack[1] + pack[0] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3604
import sys
s=int(input())
S=list(map(int,input().split()))
t=int(input())
T=list(map(int,input().split()))
S=list(set(S))
ans=0
S.sort()
def bs(n,key,S):
  left=0
  right=n
  while left<right:
    mid=int((left+right)/2)
    if S[mid]==key:
      return 1
    elif key<S[mid]:
      right=mid
    else:
      left=mid+1
  return 0

for i in range(len(T)):
  if bs(len(S),T[i],S):
    ans+=1
print(ans)


Measured memory_bytes: 16716
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

sum_bin = [0 for _ in range(41)]  # sum_bin[i]: i-1ビット目に1がいくつあるか

for a in A:
    for j in range(len(format(a, 'b'))):
        if a >> j & 1:
            sum_bin[j] += 1
# print(sum_bin)


def f(x):
    c = 0
    for i in range(40, -1, -1):
        if x >> i & 1:
            c += (N-sum_bin[i])*2**i
        else:
            c += sum_bin[i]*2**i
    return c


# Kを考慮しないXの貪欲解
g_X = 0
for i in range(40, -1, -1):
    if sum_bin[i] < N-sum_bin[i]:
        g_X += 2**i
# print('g_X', bin(g_X)[2:])


ans = f(0)

l = len(bin(K))-2
# print('l', l)
for i in range(l):  # 下の桁から見ていく
    if K >> i & 1:
        c = ''
        if K >> i+1 != 0:
            c = format(K >> i+1, 'b')
        c += '0'+bin(g_X)[43-i:]
        # print(c, i)
        ans = max(ans, f(int(c, 2)))
ans = max(ans, f(K))
print(ans)


Measured memory_bytes: 14620
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a,b,c = inpm()

cnt = 0
if a == b:
    cnt+=1
if b == c:
    cnt+=1
if c == a:
    cnt+=1

ans = 'No'
if cnt == 1:
    ans = 'Yes'

print(ans)

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

int main(){
    int n,m; cin >> n >> m;
    vector<vector<ll> > id(n+1);
    vector<ll> p(m),y(m);
    for(int i = 0; i < m; i++){
        cin >> p[i] >> y[i];
        id[p[i]].push_back(y[i]);
    }
    for(int i = 0; i < n ;i++){
        sort(id[i+1].begin(),id[i+1].end());
    }
    for(int i = 0; i < m ;i++){
        printf("%012lld\n",ll(p[i])*1000000+int(lower_bound(id[p[i]].begin(),id[p[i]].end(),y[i])-id[p[i]].begin()+1));
    }
    return 0;
}

Measured memory_bytes: 8576
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var inputs = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            var n = inputs[0];
            var p = inputs[1];
            var time=0;
            var queue = new Queue<Process>(n);
            while (queue.IsFull() == false)
            {
                var temp=Console.ReadLine().Split();
                var process = new Process();
                process.Name = temp[0];
                process.Time = int.Parse(temp[1]);
                queue.Enqueue(process);
            }

            while (queue.IsEmpty() == false)
            {
                var process = queue.Dequeue();
                if (process.Time > p)
                {
                    time += p;
                    process.Time = process.Time - p;
                    queue.Enqueue(process);
                }
                else
                {
                    time += process.Time;
                    Console.WriteLine("{0} {1}", process.Name, time);
                }
            }

            Console.Read();
        }
    }
    class Process
    {
        public string Name { get; set; }
        public int Time { get; set; }
    }
    class Queue<T>
    {
        private T[] array;
        private int top = 0;
        private int back = 0;
        private bool isFull = false;

        public Queue(int capacity)
        {
            array = new T[capacity];
        }
        public void Enqueue(T item)
        {
            array[top++] = item;
            if (top == array.Length)
            {
                top = 0;
            }
            if (top == back)
            {
                isFull = true;
            }
        }
        public T Dequeue()
        {
            isFull = false;
            var temp = array[back++];
            if (back == array.Length) back = 0;
            return temp;
        }
        public bool IsEmpty()
        {
            if (isFull == true) return false;
            return top == back;
        }
        public bool IsFull()
        {
            return isFull;
        }
        
    }

}

Measured memory_bytes: 12952
using System;

class Atcoder91
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);

        int[] tasks = { a, b, c };
        Array.Sort(tasks);

        Console.WriteLine((tasks[2] - tasks[1]) + (tasks[1] - tasks[0]));
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll x;
	scanf("%lld",&x);
	ll mon=100;
	ll cnt=0;
	while(mon<x)
	{
		mon=mon*1.01;
		cnt++;
		if(mon>=x) 
		{
			cout<<cnt;
			return 0;
		}
	}
	return 0;
 } 

Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main()
{
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if(s == "abc"){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main() {
  int h, w;
  while (cin >> h >> w, h | w) {
    string a(w, '#');
    string b = '#' + string(w - 2, '.') + '#';
    cout << a << endl;
    for (int i = 0; i < h - 2; i++) {
      cout << b << endl;
    }
    cout << a << endl << endl;
  }
}

Measured memory_bytes: 3152
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int N;

std::vector<std::string> a;

void dfs(std::string s, char c)
{
  if (s.size() == N) {
    a.push_back(s);

    return;
  }

  for (char x = 'a'; x <= c + 1; x ++) {
    s.push_back(x);

    dfs(s, std::max(x, c));

    s.pop_back();
  }
}

int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::cin >> N;

  dfs("", 'a' - 1);

  std::sort(ALL(a));

  for (const auto& s : a)
    std::cout << s << std::endl;

  return 0;
}


Measured memory_bytes: 9332
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    bool f = false;
    for (int i = 1; i <= 3; i++)
    {
        if ( (a * b * i ) % 2 == 1 ) f = true;
    }

    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    ll x;
    cin >> x;
    ll cnt = (x / 11) * 2;
    x = x % 11;
    if (x > 6) {
        cnt += 2;
    } else if (x > 0) {
        cnt += 1;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():
   
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())

    ans = 0

    for i in range(1, N+1):
        if i <= K:
            ans += X

        else:
            ans += Y

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define nl '\n'
#define vec vector<ll>
#define pr pair<ll,ll>
#define vecp vector< pr >
#define pq priority_queue<ll>
#define pqp priority_queue<pr>
#define ff first
#define ss second
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fa(x,v) for(auto x:v)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define PI 3.14159265
 const ll MOD=1000000007;
 ll powerm(ll a, ll b, ll MOD) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
ll power(ll a, ll b) {

  ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}
ll binarySearch(ll a[],ll low,ll high,ll key){
    while(low<=high)
    {
        ll mid=low+((high-low)/2);
        if(a[mid]<key)
        {
            low=mid+1;
        }
        else if(a[mid]>key)
        {
            high=mid-1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
ll gcd(ll a, ll b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
vec sieve;
void Sieve(int N) {
    const ll maxn = N+1;
    sieve.resize(maxn);
    f(i,0,maxn) sieve[i] = i;
    sieve[1] = -1;
    sieve[0] = -1;
    f(i, 2, maxn) if (i == sieve[i]) for (ll j = 2 * i ; j < maxn ; j += i) if (sieve[j] == j) sieve[j] = i;
}
ll dp[101][100001];
ll recur(ll n,ll w,ll*a,ll*wt)
{
	if(dp[n][w]!=-1)
	return dp[n][w];
	if(n==0 || w==0)
	{
	dp[n][w]=0;
	return dp[n][w];
}
	if(wt[n]<=w)
	dp[n][w]=max((a[n]+recur(n-1,w-wt[n],a,wt)),recur(n-1,w,a,wt));
	else
	dp[n][w]=recur(n-1,w,a,wt);
	return dp[n][w];
}
int main()
{
	fast
	ll n,w;
	cin>>n>>w;
	ll a[n+1],wt[n+1];
	f(i,1,n+1)
	cin>>wt[i]>>a[i];
	f(i,0,n+1)
	f(j,0,w+1)
	dp[i][j]=-1;
	ll ans=recur(n,w,a,wt);
	cout<<ans<<nl;
	return 0;
}



Measured memory_bytes: 82496
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

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

  int x, y;
  cin >> x >> y;
  int ans = 0;
  ans += max(0, (4 - x));
  ans += max(0, (4 - y));
  if (x == 1 && y == 1)
    ans += 4;
  ans *= 100000;
  cout << ans << endl;
}


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



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n,m,h,w;
    cin>>n>>m>>h>>w;
    int ans[n][m]={};
    int a[n+1]={},b[m+1]={};
    a[1] = 1111111;
    b[1] = 1111111;
    for(int i=1;i<n;i++){
        a[i+1] = a[i]+1;
        if(i+1 >= h) a[i+1] = a[i+1-h]-1;
    }
    for(int i=1;i<m;i++){
        b[i+1] = b[i]+1;
        if(i+1>=w) b[i+1] = b[i+1-w]-1;
    }
    int sum = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ans[i][j] = a[i+1] - a[i];
            sum += ans[i][j];
        }
    }
    if(sum>0 && n%h){
        cout << "Yes\n";
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cout << ans[i][j] << " ";
            }
            cout << "\n";
        }
        return 0;
    }
    sum = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ans[i][j] = b[j+1] - b[j];
            sum += ans[i][j];
        }
    }
    if(sum > 0 && m%w){
        cout << "Yes\n";
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cout << ans[i][j] << " ";
            }
            cout << "\n";
        }
        return 0;
    }
    cout << "No\n";
    
}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
        return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
        return a / gcd(a, b) * b;
}

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

llint n, x;
llint len[51];
llint p[51];

llint dfs(int m, llint x);

int main()
{
        ci >> n >> x;

        len[0] = p[0] = 1;
        for(int i = 1; i <= n; i++) {
                p[i] = 1 + p[i - 1] * 2;
                len[i] = 3 + len[i - 1] * 2;
        }


        co << dfs(n, x) << en;

        return 0;
}

llint dfs(int m, llint x)
{
        if(m == 0) return 1;

        llint rec = 0;
        llint mid = len[m] / 2 + 1;

        if(1 < x && x < mid) {
                rec += dfs(m - 1, x - 1);
        } else if(x == mid) {
                rec += 1 + p[m - 1];
        } else if(mid < x){
                rec += 1 + p[m - 1] + dfs(m - 1, x - mid);
        }

        return rec;
}

Measured memory_bytes: 256
//abc165_e.cpp
//Mon May 25 21:36:24 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

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

	int low = 1;
	int high = n;
	// int check = 0;
	// if (n%2==0){
		// check = n/2;
	// }
	for (int i=0;i<m;i++){
		if (n%2==1){
			cout << low << " " << high << endl;
		}else {
			// int x = 0;
			if (n/2==high-low || n/2-1==high-low){
				high--;
			}
			cout << low << " " << high << endl;
		}
		low++;
		high--;
	}

//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3576
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a = scan.nextInt();
    int b = scan.nextInt();
    int[] h = new int[n];
    long s = 0;
    for (int i = 0; i < n; i++) {
      h[i] = scan.nextInt();
      s += (h[i] - 1) / a + 1;
    }
    long left = -1;
    long right = s;
    while (right - left > 1) {
      long mid = (left + right) / 2;
      if (possible(a, b, h, mid)) {
        right = mid;
      } else {
        left = mid;
      }
    }
    System.out.println(right);
  }
  
  private static boolean possible(int A, int B, int[] h_array, long p_max) {
    long p = 0;
    for (int h : h_array) {
      if (h <= p_max * B) {
        continue;
      }
      long pi = (h - p_max * B - 1) / (A - B) + 1;
      p += pi;
      if (p > p_max){
        return false;
      }
    }
    return true;
  }
}

Measured memory_bytes: 51124
n,m = map(int,input().split())
arr = list(map(int,input().split()))
l = len(arr)

while m != 0 :
    arr.sort(reverse=True)
    j = arr[0] // 2
    for i in range(l):
            if arr[i] > j:
                if m != 0:
                    m -= 1
                else:
                    break
                arr[i] //= 2
            else:
                break
    if arr[0] == 0:
        break
            

print(sum(arr))        


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

int n, a;

int main() {
	cin >> n;
	map<int, int>num;
	for (int i = 0; i < n; i++) {
		cin >> a;
		num[a % 4]++;
	}
	string ans = "No";
	if (num[2] >= 2) {
		int check = n - num[2] - num[0];
		if (check <= num[0])ans = "Yes";
	}
	else if (n - num[0] - 1 <= num[0])ans = "Yes";
	cout << ans << endl;
}

Measured memory_bytes: 256
/* https://atcoder.jp/contests/dp/tasks/dp_c */

#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    cin>>n;
    int inp[n][3];
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<3;j++)
        {
            cin>>inp[i][j];
        }
    }
    
    /* 0 --> Swim
       1 --> Catching Bugs
       2 --> Homework*/
       
       int dp[n+1][3];
       dp[0][0]=0; dp[0][1]=0; dp[0][2]=0;
       
       for (int i=1;i<n+1;i++)
       {
           dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + inp[i-1][0];
           
           dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + inp[i-1][1];
           
           dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + inp[i-1][2];
       }
       
       cout<<max( {dp[n][0], dp[n][1], dp[n][2]} );
    return 0;
}
/*

       for (int i=0;i<n+1;i++)
       {
           for (int j=0;j<3;j++)
           {
               cout<<dp[i][j]<<" ";
           }
           cout<<endl;
       }
*/

Measured memory_bytes: 2560