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


using namespace std ;
const int maxn = 2*100000+10 ;

typedef long long ll ;

ll d[maxn] ;
int n ;

int main(void){
	scanf("%d",&n) ;
	for(int i=1; i<=n; i++) scanf("%lld",&d[i]) ;
	if(n%2==0) {
		for(int i=n; i>=2; i-=2) printf("%lld ",d[i]) ;
		for(int i=1; i<n; i+=2) printf("%lld ",d[i]) ;
		printf("\n") ;
	} else {
		for(int i=n; i>=1; i-=2) printf("%lld ",d[i]) ;
		for(int i=2; i<=n; i+=2) printf("%lld ",d[i]) ;
		printf("\n") ;
	}

	return 0 ;
}



Measured memory_bytes: 3712
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static List<long> primefactorize(long n)
        {
            var primes = new List<long>();
            for (var i = 2; i * i <= n; ++i)
            {
                if (n % i == 0)
                {
                    while (n % i == 0)
                    {
                        primes.Add(i);
                        n /= i;
                    }
                }
            }
            if (n != 1) primes.Add(n);
            return primes;
        }
        static long eulersPhi(long n)
        {
            foreach (var p in primefactorize(n).Distinct())
                n -= n / p;
            return n;
        }
        static void Main(string[] args)
        {
            var n = Sarray()[0];
            var ps = primefactorize(n).Distinct();
            var ans = n;
            foreach (var p in ps)
                ans = ans - ans / p;
            WriteLine(ans);
        }
    }
}


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

const int INF = 1001001001;
vector<int> to[100005];

int main() {
  int n, m;
  cin >> n >> m;
 rep(i,m) {
   int a, b;
   cin >> a >> b;
   --a; --b;
   to[a].push_back(b);
   to[b].push_back(a);
 }
  
  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
  
  cout << "Yes" << endl; 
  rep(i,n) {
    if(i == 0) continue;
    int ans = pre[i];
    ++ans;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 10616
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b,c,d,e,f,g=0;
  cin>>a>>b>>c;
  while(a!=b||b!=c){
    d=a;
    e=b;
    f=c;
    a=max(d,max(e,f));
    b=min(d,min(e,f));
    c=d+f+e-a-b;
    if(a==c)b+=2;
    else a--;
    g++;
  }
  cout<<g;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  string S; cin >> S;
  if(S=="ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,m,f[10005][4][2];
char ch[10005];
int dfs(int x,int y,int c){
    if(y>m)return 0;
    if(x>n)return y==m;
    if(f[x][y][c]!=-1)return f[x][y][c];
    int ok=c==1?ch[x]-'0':9;
    int sum=0;
    for(int i=0;i<=ok;i++)sum+=dfs(x+1,y+(i!=0),c&&i==ok);
    return f[x][y][c]=sum;
}
int main(){
    memset(f,-1,sizeof(f));
	scanf("%s",ch+1);
    in(m);
    n=strlen(ch+1);
    cout<<dfs(1,0,1)<<endl;
	return 0;
}
//法大师傅士大夫·1


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int x = c-a;
	int y = d-b;
	cout << c-y << ' ' << d+x << ' ' << a-y << ' ' << b+x; 
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,mn[200],a=0;
	cin>>n;
	for(int i=0;i<n*2;i++)
	{
		cin>>mn[i];
	}
	sort(mn,mn+n*2);
	int ans=0;
	for(int i=0;i<n*2;i++)
	{
		ans+=mn[i];
		i++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

N, C  = map(int, input().split())
x_cw = []   # 時計
x_acw = []  # 反時計
v_cw = []     # 寿司
for i in range(N):
    x,v = map(int, input().split())
    x_cw.append(x)
    v_cw.append(v)
v_acw = v_cw[::-1]
x_acw = [C - x for x in x_cw[::-1]]
x_cw = [0] + x_cw
x_acw = [0] + x_acw
# print(x_cw)
# print(x_acw)
v_cw1 = [v_cw[i]-(x_cw[i+1]-x_cw[i]) for i in range(N)]        # 時計回り折り返さない
v_cw2 = [v_cw[i]-2*(x_cw[i+1]-x_cw[i]) for i in range(N)]     # 時計回り折返しが入るとき
v_acw1 = [v_acw[i]-(x_acw[i+1]-x_acw[i]) for i in range(N)]        # 反時計折り返さない
v_acw2 = [v_acw[i]-2*(x_acw[i+1]-x_acw[i]) for i in range(N)]     # 反時計折返しがはいるとき

acc_cw1 = list(accumulate(v_cw1))
acc_acw1 = list(accumulate(v_acw1))
acc_cw2 = list(accumulate(v_cw2))
acc_acw2 = list(accumulate(v_acw2))

acc_acw1 = acc_acw1[::-1]
acc_cw1 = acc_cw1[::-1]


max_cw2 = []
m = 0
# 右スタート、左バックパターン
for c in acc_cw2:
    m = max(c,m)
    max_cw2.append(m)
ans_cw = acc_acw1[0] #初期値
for i in range(1,N):
    ans_cw = max(ans_cw, max_cw2[i-1]+acc_acw1[i])

# 左スタート、右バックパターン
m = 0
max_acw2 = []
for c in acc_acw2:
    m = max(c, m)
    max_acw2.append(m)
ans_acw = acc_cw1[0] # 初期値 
for i in range(1,N):
    ans_acw = max(ans_acw, max_acw2[i-1]+acc_cw1[i])
ans = max(ans_acw,ans_cw)
print(max(0,ans))


Measured memory_bytes: 52344
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&a!=c)
        cout<<"Yes";
    else if(a==c&&a!=b)
    cout<<"Yes";
    else if(b==c&&b!=a)
        cout<<"Yes";
    else
        cout<<"No";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
class mint{
    public:
        long long x;
 
    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a; 
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    ll t=INF;
    for(int i=0;i<5;i++){
        ll a;cin >> a;
        chmin(t,a);
    }
    cout << 4+(n+t-1)/t << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

double color[20][3];
double dist[20][20];

int bitcount(int arg)
{
    int ret = 0;
    while(arg > 0)
	{
        if(arg & 1) 
		{
			ret++;
		}
        arg >>= 1;
    }
    return(ret);
}

void solve()
{
	int n,m;
	cin >> n >> m;
	memset(color, 0, sizeof(color));
    memset(dist, 0, sizeof(dist));
    for(int i = 0; i < n; ++i)
	{
        cin >> color[i][0] >> color[i][1] >> color[i][2];
    }
    for(int i = 0; i < n; ++i)
	{
        for(int j = i; j < n; ++j)
		{
            dist[i][j] = (color[i][0] - color[j][0]) * (color[i][0] - color[j][0]) + 
				         (color[i][1] - color[j][1]) * (color[i][1] - color[j][1]) +
						 (color[i][2] - color[j][2]) * (color[i][2] - color[j][2]);
            dist[j][i] = dist[i][j];
        }
    }
    double max_sum = -1;
    for(int i = 0; i < (1 << n); ++i)
	{
        if(bitcount(i) == m)
		{
            double sum = 0;
            for(int j = 0; j < n; ++j)
			{
                if((i & (1 << j)))
				{
                    for(int k = j + 1; k < n; ++k)
					{
                        if((i & (1 << k)))
						{
                            sum += dist[j][k];
                        }
                    }
                }
            }
            max_sum = max(max_sum, sum);
        }
    }
    printf("%.17f\n", max_sum);
}
int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1252
#include <stdio.h>

int main()
{
  int n, i, j;
  int ans;
  char era[1000000];

  while(scanf("%d", &n) != EOF){

    for(i=0; i<=n; i++)
      era[i] = 1;

    ans=0;

    for(i=2; i<=n; i++){
      if(era[i] == 1){
        ans++;
        for(j=i; j<=n; j+=i) era[j]=0;
      }
    }

    printf("%d\n", ans);
  }

  return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n,l; cin >> n >> l;
    vl a(n);
    rep(i,n)a[i]=i+l;
    ll idx,mi = INF;
    rep(i,n){
        if(mi > abs(a[i])){
            mi = abs(a[i]);
            idx = i;
        }
    }
    cout << accumulate(all(a),0LL) - a[idx] << endl;
}


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

ll solve(ll h){
  if (h == 1){
    return 1;
  }
  return 1 + solve(h/2) * 2;
}

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

  ll count = solve(H);
  cout << count << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> ball(N + 1, 1);
    vector<int> check(N + 1, false);
    check[1] = true;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        if (check[x]) {
            check[y] = true;
        }
        if (ball[x] == 1) {
            check[x] = false;
        }
        ball[x] -= 1;
        ball[y] += 1;
    }
    int ans = 0;
    for (int i = 0; i < check.size(); i++) if (check[i]) ++ans;
    cout << ans << endl;
}

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

int main(){
    long long N;cin>>N;
    long long res=0;
    if(N%2==0){
        N/=10;
        res+=N;
        while(N>=5){
        N/=5;
        res+=N;
    }
    }
    cout<<res<<endl;

}

Measured memory_bytes: 256
import itertools

N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]

ans = float("inf")
for x in list(itertools.product([0,1], repeat=N)):
    tmp = 0
    tmp_A = [0] * M
    for i in range(N):
        if x[i] == 1:
            tmp += CA[i][0]
            for j in range(M):
                tmp_A[j] += CA[i][1+j]
    if min(tmp_A) >= X:
        ans = min(ans, tmp)

print(ans if ans < float("inf") else -1)

Measured memory_bytes: 9656
object Main extends App {
  import java.{ util => ju }
  import scala.annotation._
  import scala.collection._
  import scala.collection.{ mutable => mu }
  import scala.collection.JavaConverters._
  import scala.math._
  import scala.io.StdIn.readLine

  val sc = new ju.Scanner(System.in)

  val n = sc.nextInt()
  var nums = Array.fill(n)(sc.nextInt())

  var swapCount = 0
  for (i <- 0 until n) {
    for (j <- n - 1 until i by -1) {
      if (nums(j) < nums(j - 1)) {
        val bigger = nums(j)
        nums(j) = nums(j - 1)
        nums(j - 1) = bigger
        swapCount += 1
      }
    }
  }

  printArray(nums)
  println(swapCount)

  def printArray(nums: Array[Int]) {
    for (i <- 0 until nums.length - 1) print(nums(i) + " ")
    println(nums.last)
  }
}

Measured memory_bytes: 45292
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin >> n >> m;
    ll h[n];
    rep(i,n) cin >> h[i];
    bool ary[n];
    rep(i,n) ary[i] = true;
    rep(i,m)
    {
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        
        if (h[a]>h[b])
        {
            ary[b] = false;
        }
        else if (h[a]<h[b])
        {
            ary[a] = false;
        }
        else
        {
            ary[a] = false;
            ary[b] = false;
        }
        
    }
    int ans = 0;
    rep(i,n)
    {
        if (ary[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 4532
#include <iostream>

std::string N;

int main() {
    std::cin >> N;
    if ( (N[0]==N[1] && N[1]==N[2]) || (N[1]==N[2] && N[2]==N[3]) ) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using li = long int;
#define pb push_back


li N, tmp;
vector<int> name;


int main(){
    cin >> N;
    while(N > 0){
      	N -= 1;
        tmp = N % 26;
        name.pb(tmp);
        N -= tmp;
        N /= 26;
    }

    reverse(name.begin(), name.end());
    for(int i = 0; i < name.size(); i++) cout << (char)('a'+name[i]);
  	cout << endl;
    return 0;

}


Measured memory_bytes: 3636
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var min = int.MaxValue;

            for (var j = -100; j <= 100; j++)
            {
                var total = 0;
                for (var i = 0; i < n; i++)
                {
                    total += Math.Min((int) Math.Pow(Math.Abs(a[i] - j), 2), min);
                }
                min = Math.Min(total, min);
            }

            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 13396
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int sum = 0, last = 0;
        int[] a = new int[n + 2];
        for (int i = 1; i <= n; i++)
            sum += Math.abs(last - (last = a[i] = scanner.nextInt()));
        sum += Math.abs(last);
        for (int i = 1; i <= n; i++)
            System.out.println(sum - ((a[i - 1] >= a[i] && a[i] >= a[i + 1]) || (a[i - 1] <= a[i] && a[i] <= a[i + 1]) ? 0 : Math.abs(a[i - 1] > a[i] ? Math.min(a[i - 1], a[i + 1]) - a[i] : Math.max(a[i - 1], a[i + 1]) - a[i]) * 2));
    }
}

Measured memory_bytes: 63512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <atcoder/dsu>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q;
    cin, n, q;
    atcoder::dsu uf(n);
    REP(i, 0, q) {
        int t, a, b;
        cin, t, a, b;
        if (t == 0) {
            uf.merge(a, b);
        } else {
            print(uf.same(a, b));
        }
    }
    return 0;
}


Measured memory_bytes: 3872
h, w = map(int, input().split())
lst = [input() for _ in range(h)]
nlst = [[0] * (w + 2) for _ in range(h + 2)]
for i in range(h):
    for j in range(w):
        if lst[i][j] == '#':
            nlst[i][j] += 1
            nlst[i][j + 1] += 1
            nlst[i][j + 2] += 1
            nlst[i + 1][j] += 1
            nlst[i + 1][j + 2] += 1
            nlst[i + 2][j] += 1
            nlst[i + 2][j + 1] += 1
            nlst[i + 2][j + 2] += 1

output = [''] * h
for i in range(h):
    for j in range(w):
        if lst[i][j] == '.':
            output[i] += str(nlst[i + 1][j + 1])
        else:
            output[i] += '#'
print(*output, sep='\n')

Measured memory_bytes: 3064
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
h,w,k=MI()
lis=[[0]*w for i in range(h)]
for i in range(h):
    s=SI()
    for j in range(w):
        if s[j]=="#":
            lis[i][j]=1
#print(lis)
ans=0
for x in product([0,1],repeat=h+w):
    count=0
    for i in range(h):
        for j in range(w):
            if x[i]==0 and x[h+j]==0 and lis[i][j]==1:
                count+=1
    if count==k:
        ans+=1
print(ans)
    

Measured memory_bytes: 68572
import java.util.Scanner;
class Main {
     
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Dice dice = new Dice(scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt());
        int a = scan.nextInt();
        for(int i = 0; i < a; i++) {
            int T = scan.nextInt();
            int S = scan.nextInt();
            Dice copy = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
             
            int ans = solv(T,S,copy,0); 
            System.out.println(ans);
        }
    }
    public static int solv(int a, int b, Dice dice,int count) {
        if(dice.Top == a && dice.S == b) return dice.E;
        if(count == 4) return -1;
        int ans = -1;
        Dice tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnN();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnS();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnE();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnW();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
        return ans;
    }
     
     
     
}
 
class Dice {
    int Top; //1
    int Bottom; //6
    int N; //   5
    int S; //   2
    int W; //左 4
    int E; //右 3
    Dice(int a, int b, int c, int d, int e, int f) {
        Top = a;
        S = b;
        E = c;
        W = d;
        N = e;
        Bottom = f;
    }
    public void TurnN() {
        int tmp = Top;
        Top = S;
        S = Bottom;
        Bottom = N;
        N = tmp;
    }
    public void TurnW() {
        int tmp = Top;
        Top = E;
        E = Bottom;
        Bottom = W;
        W = tmp;
    }
    public void TurnE() {
        int tmp = Top;
        Top = W;
        W = Bottom;
        Bottom = E;
        E = tmp;
    }
    public void TurnS() {
        int tmp = Top;
        Top = N;
        N = Bottom;
        Bottom = S;
        S = tmp;
    }
     
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<vector<int>> diff;
vector<vector<int>> dp;

int dfs(int l, int r) {
  if (dp[l][r]!=-1) return dp[l][r];
  if (l==0||r==0) return dp[l][r] = 0;
  return dp[l][r] = min(dfs(l-1,r), dfs(l,r-1)) + diff[l][r];
}

int main() {
  int H, W; cin >> H >> W;
  string block[H]; rep(i,H) cin >> block[i]; 

  diff.resize(H+1,vector<int>(H+1));
  dp.resize(H+1,vector<int>(H+1));

  int result = 0;
  rep(i,W-1) {
    char l[H]; rep(j,H) l[j] = block[j][i];
    char r[H]; rep(j,H) r[j] = block[j][i+1];
    for (int ln=H; ln>=0; ln--) {
      // diff計算
      if (ln==H) {
        rep(rn,H+1) {
          int tmp = 0;
          rep(h,rn) tmp += l[(ln-1)-h]==r[(rn-1)-h];
          diff[ln][rn] = tmp;
        }
      }
      else {
        for (int rn=H; rn>=0; rn--) {
          if (ln==0||rn==0) diff[ln][rn] = 0;
          else if (rn==H) {
            int tmp = 0;
            rep(h,ln) tmp += l[(ln-1)-h]==r[(rn-1)-h];
            diff[ln][rn] = tmp;
          }
          else diff[ln][rn] = diff[ln+1][rn+1] - (l[ln]==r[rn]);
        }
      }
    }
    // rep(i,H+1) { rep(j,H+1) cout << diff[i][j] << " "; cout << endl; } cout << endl;
    // dp計算
    rep(tmp,H+1) fill(dp[tmp].begin(), dp[tmp].end(), -1);
    result += dfs(H,H);
    // rep(i,H+1) { rep(j,H+1) cout << dp[i][j] << " "; cout << endl; } cout << endl;
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  while(1){
    cin >> n;
    if(n==0) return 0;
    long long a[n],sum=0,ans=0;
    for(int i=0;i<n;i++){
      cin >> a[i];
      sum+=a[i];
    }
    sum/=n;
    for(int i=0;i<n;i++){
      if(a[i]<=sum) ans++;
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3176
#include <cstdio>
#include <cstring>
using namespace std;

int n;
int ans;
char s[105];

void init() {
	scanf("%s", s+1);
	n = strlen(s+1);
	return ;
}

void solve() {
	for(register int i = 1; i <= n/2; i++) {
		if(s[i] != s[n-i+1]) ans++;
	}
	printf("%d", ans);
	return ;
}

int main() {
	init();
	solve();
	return 0;
}

Measured memory_bytes: 128
//
//  AtCoder0901
//

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, h, prev = 0, cnt=0, max=0;
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> h;
        if(prev >= h){
            cnt++;
        }else{
            if(max < cnt) max = cnt;
            cnt = 0;
        }
        prev = h;
    }
    if(max < cnt) max = cnt;
    cout << max;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n;
    cin >> n;
    cout << n*n*n<< endl;
}

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

int main(){
    int n,x;
    int tot;
    
    while(1){
        tot =0;
        cin >> n >> x;
        if(n==0 && x==0) break;
        for(int i=1; i<=n; i++)
            for(int j=i+1; j<=n; j++)
                for(int k=j+1; k<=n; k++)
                    if(x == (i+j+k)) 
                        tot++;
        cout << tot << endl;
    };
    
}


Measured memory_bytes: 3076
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)
P p[100000];
ll N;
ll x,y;
P py[100000];
P px[100000];
bool musta1[100000];
bool mustb1[100000];
bool musta2[100000];
bool mustb2[100000];

bool ok(ll W){
	memset(musta1,0,sizeof(musta1));
	memset(musta2,0,sizeof(musta2));
	memset(mustb1,0,sizeof(mustb1));
	memset(mustb2,0,sizeof(mustb2));
	// about Y
	rep(i,N){
		if(py[i].fr-py[0].fr>W){
			if(py[N-1].fr-py[i].fr>W) return 0;
			mustb1[py[i].sc]=1;
		}
		else if(py[N-1].fr-py[i].fr>W) musta1[py[i].sc]=1;
	}
	// about X
	rep(i,N){
		if(px[i].fr-px[0].fr>W){
			if(px[N-1].fr-px[i].fr>W) return 0;
			mustb2[px[i].sc]=1;
		}
		else if(px[N-1].fr-px[i].fr>W) musta2[px[i].sc]=1;
	}
	rep(i,N){//a1=a2 b1=b2
		if((musta1[i]&&mustb2[i])||(mustb1[i]&&musta2[i])) break;
		if(i==N-1) return 1;
	}
	rep(i,N){
		if((musta1[i]&&musta2[i])||(mustb1[i]&&mustb2[i])) break;
		if(i==N-1) return 1;
	}
	return 0;
}
int main()
{
	cin>>N;
	rep(i,N){
		cin>>x>>y;
		p[i].fr=-x+y;
		p[i].sc=x+y;
		py[i].fr=p[i].fr;
		px[i].fr=p[i].sc;
		py[i].sc=px[i].sc=i;
	}
	sort(py,py+N);
	sort(px,px+N);
	ll lb=0;
	ll ub=1e+6;
	while(ub-lb>1){
		ll mid=(ub+lb)/2;
		if(ok(mid)) ub=mid;
		else lb=mid;
	}
	cout<<ub<<endl;
}

Measured memory_bytes: 8156
fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    val p = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    var cnt = 0
    for (i in 0 until n - 2) {
        if (p[i + 1] > p[i] && p[i + 1] < p[i + 2]) cnt++
        if (p[i + 1] < p[i] && p[i + 1] > p[i + 2]) cnt++
    }
    println(cnt)
}

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

int main(){
    char b;
    cin >> b;
    vector<char> c(128);
    c.at('A')='T';
    c.at('T')='A';
    c.at('G')='C';
    c.at('C')='G';
    cout << c.at((int)b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    string p;
    cin >> s >> p;
    s = s + s;
    int ans = 0;
    for(int i = 0;i < s.size() - p.size() + 1;i++) {
        int flag = 1;
        for(int j=0;j < p.size();j++) {
            if(s[i+j]!=p[j]) {
                flag = 0;
                break;
            }
        }
        if(flag){
            ans =1;
            break;
        }
        
    }
    cout <<(ans?"Yes":"No")<<endl;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
 
#define rep(i, n) for (ll i=0;i<(n); i++)
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; }
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
//using ll=long long;
typedef long long ll;
typedef pair<ll, ll> pi;

ll h,w;
ll ans;
//vector<char> masu;




int main(){
  string s;
  cin >>s;

  vector<string> S;

  S.push_back("AKIHABARA");
  S.push_back("AKIHABRA");
  S.push_back("AKIHBARA");
  S.push_back("AKIHBRA");

  S.push_back("AKIHABAR");
  S.push_back("AKIHABR");
  S.push_back("AKIHBAR");
  S.push_back("AKIHBR");

  S.push_back("KIHABARA");
  S.push_back("KIHABRA");
  S.push_back("KIHBARA");
  S.push_back("KIHBRA");

  S.push_back("KIHABAR");
  S.push_back("KIHABR");
  S.push_back("KIHBAR");
  S.push_back("KIHBR");

  string a = "NO";
  rep(i, 16){
    
    if(S[i]==s) a = "YES";
  }
  
    
  cout << a <<endl;

  
  
}


Measured memory_bytes: 256
a, b, c, d, e, f = map(int,input().split( ))
mx = 0
ans = [0,0]
for i in range(f//(a*100)+1):
    sup_b = f-i*a*100
    
    for j in range(sup_b//(b*100)+1):
        wat = i*a*100 + j*b*100
        
        if wat > f or not wat:
            continue
        sup_sug = min(e*(wat/100), f - wat)

        
        for k in range(int(sup_sug//c)+1):
            l = (sup_sug - k*c)//d
            
            if (k*c + l*d)/wat > e/100:
                continue
                
            if mx < (k*c + l*d)/wat:
                mx = (k*c + l*d)/wat
                ans = [(k*c + l*d) + wat, k*c + l*d]
if int(ans[0])==0 and int(ans[1])==0:
    print(100*a,0)
else:
    print(int(ans[0]),int(ans[1]))


Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int a[310][310];
int b[310][310];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, N) rep(j, N) cin >> a[i][j];
    rep(i, N) rep(j, N) b[i][j] = a[i][j];
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                b[i][j] = min(b[i][j], b[i][k] + b[k][j]);
            }
        }
    }
    int ans = 0;
    rep(i, N) {
        rep(j, N) {
            if (a[i][j] != b[i][j]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    rep(i, N) {
        rep(j, N) { 
            bool exist = false;
            rep(k, N) {
                if (i == k || j == k) continue;
                if (a[i][k] + a[k][j] == a[i][j]) {  
                    exist = true;
                }
            }
            if (!exist) ans += a[i][j];
        }
    }

    cout << ans/2 << endl;

    return 0;
}


Measured memory_bytes: 1664
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.reverse()
c = []
for i in range(1,n):
    a[i] += a[i-1]
    b[i] += b[i-1]
b.reverse()
c = [a[i]+b[i] for i in range(n)]
print(max(c))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//



     signed main(){
  int d;
  clock_t st=clock();
  cin>>d;
    clock_t ed=clock();

  int c[26];
  for(int i=0;i<26;i++)cin>>c[i];
  int t[d],s[d][26],x[26]={};
    vector<int>v[26];
    for(int i=0;i<26;i++)v[i].push_back(-1);

  for(int i=0;i<d;i++)for(int j=0;j<26;j++)cin>>s[i][j];
   // cerr<<'i';
  for(int i=0;i<d;i++){
      for(int j=0;j<26;j++)x[j]+=c[j];
      int k=0;
      for(int j=1;j<26;j++)if(x[k]+s[i][k]<x[j]+s[i][j])k=j;
      t[i]=k;
      x[k]=0;
      v[k].push_back(i);
  }
  for(int i=0;i<26;i++)v[i].push_back(d);
//for(int i=0;i<d;i++)cout<<t[i]+1<<endl;
  // cerr<<double(clock()-st)/CLOCKS_PER_SEC<<endl;
//while(false){
while(double(clock()-st)/CLOCKS_PER_SEC<1.95){
  if(rand()%5){
    int p=rand()%d;
    auto q=find(v[t[p]].begin(),v[t[p]].end(),p);
    q++;
  // int m=(p+(*q))/2;
   int m=p+rand()%((*q)-p);
//cerr<<m<<' '<<p<<endl;
   if(m==p)continue;
   auto r1=find(v[t[m]].begin(),v[t[m]].end(),m);
   auto r0=r1-1,r2=r1+1;
   if((m-p)*((*q)-m)*c[t[p]]+s[m][t[p]]>(m-(*r0))*((*r2)-m)*c[t[m]]+s[m][t[m]]){
 
    v[t[p]].insert(q,m);
    v[t[m]].erase(r1);
    t[m]=t[p];
   }
  }else{
    int u=1;
    if(rand()%2)u++;
    u%=26;
    int p=rand()%(d-u);
    if(t[p]==t[p+u]||p+u==d){continue;}
    auto q1=find(v[t[p]].begin(),v[t[p]].end(),p);
    auto q0=q1-1,q2=q1+1;
      auto r1=find(v[t[p+u]].begin(),v[t[p+u]].end(),p+u);
    auto r0=r1-1,r2=r1+1;
    if((p-(*q0))*((*q2)-p)*c[t[p]]+s[p][t[p]]+(p+u-(*r0))*((*r2)-p-u)*c[t[p+u]]+s[p+u][t[p+u]]-((p+u-(*q0))*((*q2)-p-u)*c[t[p]]+s[p+u][t[p]]+(p-(*r0))*((*r2)-p)*c[t[p+u]]+s[p][t[p+u]])<rand()%signed(100*(1.97-double(clock()-st)/CLOCKS_PER_SEC))){
      (*q1)=p+u;
      (*r1)=p;
      swap(t[p],t[p+u]);
    }
   
  }




}
     for(int i=0;i<d;i++)cout<<t[i]+1<<endl;


     }


 


 






    





      

        


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
typedef long long ll;
const int N=20000005;
int n,k,x,t,a,b;
string s;
vector<int>v;
int main(){

	cin >> x;
	int ans = x/500*1000;
	ans+=floor((x%500)/5)*5;
	cout << ans<<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 m=sc.nextInt();int a=sc.nextInt();
  int count=0;
  for(int i=0;i<=n;i++){
  	String po=i+"";
    String[]popo=po.split("",0);
    int p=0;
    for(int j=0;j<popo.length;j++)p+=Integer.parseInt(popo[j]);
    if(m<=p&&p<=a)count+=i;
  }
  System.out.println(count);
}
}


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

int main(){
    string ans = "No";
    string n;
    cin >> n;
    
    long long sum = 0;
    for (int i = 0; i < n.size(); i++) {
        sum += n[i] - 48;
    }
    
    if (sum % 9 == 0) ans = "Yes";
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <numeric>
#include <string>
using namespace std;
typedef long long int ll;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[4];
    for(int i=0;i<4;i++){
        cin >> a[i];
    }
    sort(a,a+4);
    cout << min(abs(a[0]+a[3]-a[2]-a[1]),abs(a[0]+a[2]-a[1]-a[3])) << endl;
}



Measured memory_bytes: 3216
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	int w;
	cin >> w;
	cout << w * 32 << endl;
}


Measured memory_bytes: 3088
cnt = input()
numlist = list(map(int, input().split())) 
flg = True
num = 0

while True:

    for x in range(len(numlist)):
    
        if numlist[x] % 2 != 0:
            flg = False
            break

        numlist[x] = (numlist[x] / 2)
    
    if flg == False:
        break

    num  += 1

print(num)

    

Measured memory_bytes: 2940
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, k; cin >> n >> k;
	vector<int> a(n); rep(i, n)cin >> a[i];
	ll res = 1e18;
	rep(i, 1 << n)
	{
		int cnt = 1;
		ll cost = 0;
		int now = a[0];
		for (int j = 1; j < n; ++j)
		{
			if (i&(1 << j))
			{
				++cnt;
				cost += max(0, now + 1 - a[j]);
				now = max(a[j], now + 1);
			}
			else now = max(now, a[j]);
		}
		if (cnt >= k)chmin(res, cost);
	}
	cout << res << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];

  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  int dp[n+10];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
  }
  cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include<cstdio>
#include<vector>

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

using namespace std;

struct edge{ int v,d,id; };

int n;
vector<edge> G[10];

bool lex(int *a,int *b){
	for(int i=0;;i++){
		if(a[i]==-1 || b[i]==-1) break;
		if(a[i]!=b[i]) return a[i]<b[i];
	}
	return false;
}

int ans,ans_path[21];
void dfs(int u,int S,int d,int n_path,int *path){
	rep(i,G[u].size()){
		edge e=G[u][i];
		if(!(S&1<<e.id)){
			path[n_path]=e.v;
			path[n_path+1]=-1;
			dfs(e.v,S|1<<e.id,d+e.d,n_path+1,path);
		}
	}

	if(ans<d || ans==d && lex(path,ans_path)){
		ans=d;
		rep(i,n_path+1) ans_path[i]=path[i];
	}
}

int main(){
	for(int m;scanf("%d%d",&n,&m),n;){
		rep(u,n) G[u].clear();
		rep(i,m){
			int u,v,d; scanf("%d%d%d",&u,&v,&d); u--; v--;
			G[u].push_back((edge){v,d,i});
			G[v].push_back((edge){u,d,i});
		}

		ans=-1;
		ans_path[0]=77;
		ans_path[1]=-1;
		int path[21];
		rep(u,n){
			path[0]=u;
			dfs(u,0,0,1,path);
		}

		printf("%d\n",ans);
		for(int i=0;~ans_path[i];i++) printf("%s%d",i?" ":"",ans_path[i]+1);
		puts("");
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> a(N);
    int S = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        S += a[i];
    }
    cout << S - N << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
bool ok (char c, int i) {
  switch (i) {
    case 0: if (c == 'U') return true; break;
    case 1: if (c == 'R') return true; break;
    case 2: if (c == 'D') return true; break;
    case 3: if (c == 'L') return true; break;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, n, sx, sy;
  string s, t;
  cin >> h >> w >> n >> sx >> sy >> s >> t;
  sx--, sy--;
  rep(i, 4) {
    int x = sx, y = sy;
    rep(j, n) {
      if (ok(s[j], i))
        x += dx[i], y += dy[i];
      if (x < 0 || x >= h || y < 0 || y >= w) {
        cout << "NO" << endl;
        return 0;
      }
      int k = (i+2)%4;
      if (ok(t[j], k) && x+dx[k] >= 0 && x+dx[k] < h && y+dy[k] >= 0 && y+dy[k] < w) {
        x += dx[k], y += dy[k];
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 920
from collections import Counter
def get_prime_factors(x):
    out = []
    if x < 1:
        return out
    while not x%2:
        out.append(2)
        x //= 2
    i = 3
    while i*i <= x:
        if not x%i:
            out.append(i)
            x //= i
        else:
            i += 2
    if x != 1:
        out.append(x)
    return out
    
    
def main():
    n = int(input())
    primes = Counter(get_prime_factors(n))
    ans = 0
    for k, v in primes.items():
        num = 1
        while v >= num:
            v -= num
            num += 1
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){

    int N,K;
    cin>>N>>K;
    vint L(N);
    rep(i,N)cin>>L[i];
    sort(all(L));reverse(all(L));
    cout<<accumulate(L.begin(),L.begin()+K,0ll)<<endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
h=list(map(int,input().split()))
h.append(0)
ans=0
flag = False
for hei in range(1,101):
  for i in range(N+1):
    if h[i] >= hei and i!=N:
      flag = True
    else:
      if flag:
        ans+=1
        flag = False
print(ans)


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

int64_t GetDigit(int64_t num)
{
    return log10(num) + 1;
}

int main()
{
    int64_t N, sqrtN;
    cin >> N;
    sqrtN = sqrt((double)N);
    int64_t fab = GetDigit(N);
    for (int64_t A = 1; A <= sqrtN; A++)
    {
        int64_t B;
        if (N % A != 0)
        {
            continue;
        }
        else
        {
            B = N / A;
            fab = min(fab, max(GetDigit(A), GetDigit(B)));
        }
    }
    cout << fab << endl;
}

Measured memory_bytes: 512
/*

*/
#include <bits/stdc++.h>

using namespace std;

#define ll           long long int
#define mp           make_pair
#define pb           push_back
#define fi           first
#define si           second
#define fastIO       ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F(a,n)       for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n)      for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n)       for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n)      for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m)    for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m)   for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m)   for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m)  for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
const int nax = 1e7;
const int mod = 1e9+7;



int main(){
fastIO
	int n, *a, ans=0;;
	cin>>n;
	a = new int[n];
	F(a, n);
	for(int i=0; i<n; i++){
		if(i%2==0 && a[i]%2==1){
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3608
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

AN=[]
for _ in range(N):
    AN.append(list(input()))
    
#print(AN)

AM=[]
for _ in range(M):
    AM.append(list(input()))

#print(AM)
for i in range(N-M+1):
    for j in range(N-M+1):
        #print(i,j)
        flag=True
        for k in range(M):
            if AN[i+k][j:j+M]!=AM[k]:
                #print(AN[i+k][j:j+M],AM[k])
                flag=False
        if flag:
            print("Yes")
            exit()
        
print("No")

Measured memory_bytes: 3064