akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL
#  define _GLIBCXX_DEBUG
#else
#  define cerr __get_ce
#endif
#include <bits/stdc++.h>
#define ff first
#define ss second
#define szof(x) ((int)x.size())

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
mt19937 tw(9450189);
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }


void solve() {
	int n;
	cin >> n;
	vector<int> inp;
	for (int i = 0; i < n; ++i) {
		int num;
		cin >> num;
		inp.push_back(num);
	}

	int l = 0, r = n + 1;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		// mid = 3;
		set<pii> have;
		have.insert({inp[0], 0});
		bool fl = true;
		for (int i = 1; i < n; ++i) {
			// int cnt = 0;
			// for (auto p : have) {
			// 	while (cnt < p.ff) {
			// 		cerr << p.ss;
			// 		++cnt;
			// 	}
			// }
			// cerr << endl;
			if (inp[i] > inp[i - 1]) {
				have.insert({inp[i], 0});
			} else {
				int last = -1;
				while (szof(have) && (--have.end())->ff >= inp[i]) {
					last = (--have.end())->ss;
					have.erase(--have.end());
				}
				have.insert({inp[i], last});
				while (szof(have) > 1 && (--have.end())->ss == mid - 1 && (----have.end())->ss == mid - 1) {
					have.erase(----have.end());
				}
				if ((--have.end())->ss < mid - 1) {
					auto p = *--have.end();
					have.erase(--have.end());
					if ((szof(have) && (--have.end())->ff < p.ff - 1) || (!szof(have) && p.ff > 1)) {
						have.insert({p.ff - 1, p.ss});
					}
					have.insert({p.ff, p.ss + 1});
				} else {
					if (szof(have) == 1) {
						fl = false;
						break;
					}
					auto p = *----have.end();
					have.erase(----have.end());
					if ((szof(have) > 1 && (----have.end())->ff < p.ff - 1) || (szof(have) == 1 && p.ff > 1)) {
						have.insert({p.ff - 1, p.ss});
					}
					have.insert({p.ff, p.ss + 1});
					// if (p.ss + 1 == mid - 1) {
					have.erase(--have.end());
					have.insert({inp[i], 0});
					// }
				}
			}
		}
		if (fl) {
			r = mid;
		} else {
			l = mid;
		}
		// break;
	}

	cout << r << "\n";
}


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	// cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}
	
#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}


Measured memory_bytes: 12532
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return

    prod = 1
    for a in A:
        prod *= a
        if prod >  1000000000000000000:
            print(-1)
            return

    print(prod)

main()

Measured memory_bytes: 21656
#include<iostream>
#include<vector>

struct UnionFindTree{
    private:
    std::vector<int> parent;
    
    public:
    UnionFindTree(int n) : parent(n){
        for(int i = 0; i < n; i++) parent[i] = i;
    }
    
    int find(int x){
        if(parent[x] == x) return x;
        return parent[x] = find(parent[x]);
    }
    
    void unite(int x, int y){
        parent[find(x)] = find(y);
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int n, q;
    std::cin >> n >> q;
    
    UnionFindTree tree(n);
    
    for(;q-->0;){
        int com, x, y;
        std::cin >> com >> x >> y;
        if(com) std::cout << tree.same(x, y) << std::endl;
        else tree.unite(x, y);
    }
    
    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	int n;
	int a[3][3];
	FOR(i,0,3){
		FOR(i1,0,3){in(a[i][i1]);}
	}
	in(n);
	map<int,int> map1;
	FOR(i,0,n){
		ini(x);
		map1[x] = 1;
	}
	if(map1[a[0][0]] and map1[a[0][1]] and map1[a[0][2]]){out("Yes");return 0;}
	if (map1[a[1][0]] and map1[a[1][1]] and map1[a[1][2]]) { out("Yes");return 0; }
	if (map1[a[2][0]] and map1[a[2][1]] and map1[a[2][2]]) { out("Yes");return 0; }
	if (map1[a[0][0]] and map1[a[1][0]] and map1[a[2][0]]) { out("Yes");return 0; }
	if (map1[a[0][1]] and map1[a[1][1]] and map1[a[2][1]]) { out("Yes");return 0; }
	if (map1[a[0][2]] and map1[a[1][2]] and map1[a[2][2]]) { out("Yes");return 0; }
	if (map1[a[0][0]] and map1[a[1][1]] and map1[a[2][2]]) { out("Yes");return 0; }
	if (map1[a[2][0]] and map1[a[1][1]] and map1[a[0][2]]) { out("Yes");return 0; }
	out("No");
	return 0;
}


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

const int N = 500005;
int n, pos[N], a[N], mex[N], q, x;

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> pos[0];
	for (int i = 1; i <= n; ++i) {
		std::cin >> a[i];
		pos[i] = std::min(pos[i - 1], std::abs(pos[i - 1] - a[i]));
	}
	mex[n + 1] = 1;
	for (int i = n; i; --i) {
		if (mex[i + 1] << 1 <= a[i])
			mex[i] = mex[i + 1];
		else
			mex[i] = mex[i + 1] + a[i];
	}
	std::cin >> q;
	while (q--) std::cin >> x, std::cout << (pos[x - 1] >= mex[x + 1] ? "YES" : "NO") << '\n';
	return 0;
}

Measured memory_bytes: 7808
n,m = gets.chomp.split(" ").map(&:to_i)
x = gets.chomp.split(" ").map(&:to_i).sort
if n >= m
  puts 0
  exit
end
dis = []
(m-1).times do |i|
  dis[i] = x[i+1] - x[i]
end
dis = dis.sort
puts dis[0..m-n-1].inject(:+)

Measured memory_bytes: 24036
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

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

using namespace std;
typedef long long ll;

int main() {

    ll N;
    cin >> N;
    ll A[N],B[N],C[N-1];
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    rep(i,N-1) cin >> C[i];
    ll out = 0;
    rep(i,N){
        out += B[A[i]-1];
        if(A[i] == A[i-1]+1) out += C[A[i]-2];
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int a,b,c,N,i;
    long long int sum = 0;

    scanf("%d",&N);
	for(i=1; i<=N; i++){
		if(i%3 == 0 || i%5 == 0){
			sum += 0;
		} else {
			sum += i;
		}
	}	

	printf("%lld",sum);
    return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> q;
    int a;
    REP(i, n) {
        cin >> a;
        if (q.empty()) {
            q.push_back(a);
        } else {
            auto x = lower_bound(ALL(q), a);
            if (x == q.begin()) {
                auto x = upper_bound(ALL(q), a);
                q.insert(x, a);
            } else {
                q.erase(x - 1);
                auto x = upper_bound(ALL(q), a);
                q.insert(x, a);
            }
        }
    }
    cout << q.size() << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

LL r[2][3];
LL dp[5000 * 5000 + 1];

LL f(LL n, int x, int y) {
	
	incII(i, 0, n) { dp[i] = -1; }
	dp[n] = 0;
	
	LL ans = 0;
	vector<int> p = { 0, 1, 2 };
	sort(ALL(p), [&](int i, int j) { return (r[x][j] * r[y][i] < r[x][i] * r[y][j]); });
	inc(i, 3) {
		decII(j, 0, n) {
			if(dp[j] == -1) { continue; }
			if(j >= r[x][p[i]]) { setmax(dp[j - r[x][p[i]]], dp[j] + r[y][p[i]]); }
		}
	}
	incII(j, 0, n) { setmax(ans, j + dp[j]); }
	
	return ans;
}

int main() {
	LL n;
	cin >> n;
	inc(i, 2) {
	inc(j, 3) {
		cin >> r[i][j];
	}
	}
	
	n = f(n, 0, 1);
	n = f(n, 1, 0);
	
	cout << n << endl;
	
	return 0;
}


Measured memory_bytes: 195584
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int r, d, x;
    cin >> r >> d >> x;
    for (int i = 1; i <= 10; i++){
        x = r*x - d;
        cout << x << '\n';
    }
}

int main(void){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=2e5+5;
int g(int x,int y){
    int c=0;
    while(x%y==0)c++,x/=y;
    return c;
}
int c[66][66];
void put(int x,int y){
    x+=30;
    y+=30;
    c[x][y]++;
}
int get(int x,int y){
    x+=30;
    y+=30;
    return c[x][y];
}
int32_t main(){
    int n;
    cin>>n;
    int ans=0,sam=0;
    forn(i,n){
        string s;
        cin>>s;
        int bi=0,sm=0,wp=0;
        forn(j,sz(s)){
            char c=s[j];
            if(c=='.'){
                wp=j;
                break;
            }else{
                bi*=10;
                bi+=c-'0';
            }
        }
        int g2,g5;
        if(wp){
            s=s.substr(wp+1);
            int le=sz(s);
            for(char c:s){
                sm*=10;
                sm+=c-'0';
            }
            int te=1;
            forn(j,le)te*=10;
            int x=bi*te+sm;
            g2=g(x,2);g5=g(x,5);
            g2-=le;            
            g5-=le;            
        }else{
            g2=g(bi,2);g5=g(bi,5);
        }
        if(g2>=0&&g5>=0)sam++;
        dbg(g2,g5);
        put(g2,g5);
    }
    for(int x1=-30;x1<=30;++x1){
        for(int y1=-30;y1<=30;++y1){
    for(int x2=-30;x2<=30;++x2){
        for(int y2=-30;y2<=30;++y2){
            if(x1+x2>=0&&y1+y2>=0)ans+=get(x1,y1)*get(x2,y2);

        }
    }
        }
    }
    dbg(ans,sam);
    ans-=sam;
    ans/=2;
    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	vector<ll> r(n + 1);
	rep(i, n) {
		cin >> a[i];
		if (r[i] < a[i]) r[i + 1] = a[i];
		else r[i + 1] = r[i];
	}
	ll ans = 100000000000000;
	for (int bit = 0; bit < (1 << n); bit++) {
		ll ansi = 0;
		int cnt = 0;
		vector<int> v;
		rep(i, n) {
			if (bit & (1 << i)) {
				cnt++;
				v.push_back(i);
			}
		}
		if (cnt == k) {
          ll maxbuil=0;//高くしたやつ
			rep(i, k) {
				ansi += max((ll)0, max(r[v[i]],maxbuil) - a[v[i]]+1);
                maxbuil=a[v[i]]+max((ll)0, max(r[v[i]],maxbuil) - a[v[i]]+1);
			}
			ans = min(ans, ansi);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
	    int K = s.nextInt();
	    String S = s.next();
	    int lenS = S.length();
	    if(lenS <= K) {System.out.println(S);}
	    else {
	    	System.out.println(S.substring(0,K)+"...");
	    	
	    }
		
	}

}


Measured memory_bytes: 38612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  char c;
  cin >> c;
  cout << (char)(c+1) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int N = cin.nextInt();
		for(int cases = 1;cases<=N;cases++){
			System.out.println("Case "+cases+":");
			int s = cin.nextInt();
			for(int i = 0;i<10;i++){
				s = s*s;
				String str = String.valueOf(s);
				for(int j = str.length();j< 8;j++){
					str = "0"+str;
				}
				str = str.substring(2,6);
				s = Integer.parseInt(str);
				System.out.println(s);
			}
		}
	}

}

Measured memory_bytes: 11000
N, K = map(int, input().split())

P = [p-1 for p in list(map(int, input().split()))]
C = list(map(int, input().split()))

INF = float('inf')

max_points = []
for i in range(N):
    max_point = -INF
    visit = [0] * N
    visit[i] = 1
    S = [0]
    pos = P[i]
    loop = 0  # P は順列なので、すでにvisitした点に戻ったとき、loopが位数となる
    while True:
        if visit[pos] == 0:
            visit[pos] = 1
            S.append(S[loop] + C[pos])
            pos = P[pos]
            loop += 1
        else:
            S.append(S[loop] + C[pos])
            pos = P[pos]
            loop += 1
            break

    loop_point = S[loop]
    # print(loop_point)
    # print(i, visit)
    if loop > K:
        max_point = max(S[1:K+1])
    else:
        if loop_point > 0:
            loop_num = K // loop
            max_point = max(max_point, loop_point * loop_num + max(S[:(K%loop)+1]))
            max_point = max(max_point, loop_point * (loop_num-1) + max(S[1:loop]))
        else:
            max_point = max(S[1:loop+1])

    max_points.append(max_point)

print(max(max_points))

Measured memory_bytes: 90844
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=100+10;
const int maxm=10000+10;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
const ll LINF=(1LL<<62);
const double PI=acos(-1.0);
#define mst(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<b;i++)
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define lowbit(x) x&(-x)
#define X first
#define Y second
int f[maxn];
int p[maxn][20];
int main(){
#ifdef local
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif
    //ios::sync_with_stdio(false); cin.tie(0);
    int n; scanf("%d",&n);
    for (int i=0;i<n;i++){
        int sta=0;
        for (int j=0;j<10;j++){
            int x; scanf("%d",&x);
            sta<<=1;
            sta|=x;
        }
        f[i]=sta;
    }
    for (int i=0;i<n;i++){
        for (int j=0;j<=10;j++){
            scanf("%d",&p[i][j]);
        }
    }
    int ans=-INF;
    for (int sta=1;sta<(1<<10);sta++){
        int res=0;
        for (int i=0;i<n;i++){
            int k=sta&f[i],cnt=0;
            for (int j=0;j<10;j++) {
                if (k&1) cnt++;
                k>>=1;
            }
            res+=p[i][cnt];
        }
        ans=max(ans,res);
    }
    printf("%d\n",ans);
    return 0;
}


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

namespace abcreftgh
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] s = new int[N];
            int sum = 0;
            for(int i = 0; i < N; i++)
            {
                s[i]=int.Parse(Console.ReadLine());
                sum += s[i];
            }
            if (sum % 10 == 0)
            {
                Array.Sort(s);
                for (int i = 0; i < N; i++)
                {
                    if (s[i] % 10 != 0)
                    {
                        sum -= s[i];
                        break;
                    }
                }
            }
            if (sum % 10 == 0)
            {
                sum = 0;
            }
            Console.WriteLine(sum);
            
            
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T>
using ordered_set =
       tree <T,null_type,less <T>,rb_tree_tag,tree_order_statistics_node_update> ;
///find_by_order()
///order_of_key()

template <class T,class U>
void maximize(T &x,U y){
    if(x < y)x=y;
}
template <class T,class U>
void minimize(T &x,U y){
    if(x > y)x=y;
}
template <class T>
T Abs(T x){
    return (x < (T)0 ? -x : x);
}
template <class T>
T safe_sqrt(T x){
    return sqrt(max(x,(T)0));
}
template <class T,class U,class V>
T addmod(T x,U k,V MOD){
    return ((x+k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T submod(T x,U k,V MOD){
    return ((x-k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T mul(T x,U y,V MOD){
    return ( (x % MOD) * (y % MOD) ) % MOD;
}

#define ll long long
#define pll pair <ll,ll>
#define pii pair <int,int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define emp emplace_back
#define MASK(i) ((1LL)<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)((c).size())
#define fn "test"    ///FILE_NAME_HERE

/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/

namespace task{

	const int N = 1e5 + 5;
	int n,k;
	int h[N],f[N];

    void solve(){
    	cin>>n>>k;
    	for(int i = 1;i <= n;++i){
    		cin>>h[i];
    		f[i] = 2e9;
    	}
    	f[1] = 0;
    	for(int i = 2;i <= n;++i){
    		for(int j = 1;j <= k and i - j > 0;++j){
    			minimize(f[i],f[i - j] + Abs(h[i] - h[i - j]));
    		}
    	}
    	cout<<f[n];
    }
}

int main(void){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    task::solve();
}


Measured memory_bytes: 1024
#include <stdio.h>
int main()
{
  int i, j, r, c, sum = 0;
  int sum1[110] = {};
  int data[110][110] = {};

  scanf("%d %d",&r, &c);
  for(i = 0; i < r; i++ ){
    for(j = 0; j < c; j++){
      scanf("%d", &data[i][j]);
    }
  }
  for(i = 0; i < r; i++){
    for(j = 0; j < c; j++){
      printf("%d ",data[i][j]);
      sum += data[i][j];
      sum1[j] += data[i][j];
    }
    printf("%d\n",sum);
    sum = 0;
  }
  for(i = 0; i < c; i++){
    printf("%d ",sum1[i]); 
    sum += sum1[i];
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 656
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var nab = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nab[0];
        var a = nab[1];
        var b = nab[2];
        if (n == 1)
        {
            if (a != b)
            {
                Console.WriteLine(0);
                return;
            }
            Console.WriteLine(1);
            return;
        }
        if (a <= b) Console.WriteLine((b - a) * (n - 2) + 1);
        else Console.WriteLine(0);
    }
}

Measured memory_bytes: 13396
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
string s;
int n;
vector<int> vk;
vector<long long> ans;

struct N {
  int pos;
  int size[100];
};

bool operator<(const N &l, const N &r) { return l.pos > r.pos; }

void solve(int q) {
  vector<int> dis(q), mis(q);
  int ds = 0, ms = 0;
  vector<N> dq, mq;
  vector<long long> esizes(q), msums(q);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < q; j++) {
      if (ds - dis[j] > 0) {
        if (dq[dis[j]].pos == i - vk[j]) {
          dis[j]++;
          esizes[j]++;
        }
      }
      if (ms - mis[j] > 0) {
        if (mq[mis[j]].pos == i - vk[j]) {
          msums[j] -= mq[mis[j]].size[j];
          mis[j]++;
        }
      }
    }
    if (s[i] == 'D') {
      N nn;
      nn.pos = i;
      dq.push_back(nn);
      ds++;
    } else if (s[i] == 'M') {
      N nn;
      nn.pos = i;
      for (int j = 0; j < q; j++) {
        nn.size[j] = esizes[j] + ds - dis[j];
        msums[j] += esizes[j] + ds - dis[j];
      }
      mq.push_back(nn);
      ms++;
    } else if (s[i] == 'C') {
      for (int j = 0; j < q; j++) {
        ans[j] += msums[j] - esizes[j] * (ms - mis[j]);
      }
    }
  }
}

int main() {
  cin >> n;
  cin >> s;
  int q;
  cin >> q;
  ans.resize(n);
  for (int i = 0; i < q; i++) {
    int k;
    cin >> k;
    vk.push_back(k);
  }
  solve(q);
  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int p,ans=0,ma=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>p;
		ans+=p;
		ma=max(ma,p);
	}
	cout<<ans-ma/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
int main(){
    string a,b;
    cin >> a >> b;
    a += b;
    int num = stoi(a);
    int i = 1;
    while(i*i <= num){
        if(i*i == num){
            cout << "Yes" << endl;
            return 0;
        }
        i++;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#AGC043-A
h,w = map(int,input().split())
grid = [input() for _ in range(h)]

dp = [[1000]*w for _ in range(h)]
dp[0][0] = 1 if grid[0][0] == "#" else 0
#進む前の相対位置
d = [(-1, 0), (0, -1)]

for i in range(h):
    for j in range(w):
        if i == 0 and j == 0:
            pass
        else:
            tmp = 1000
            for k in d:
                bx,by = j+k[0],i+k[1]
                if 0 <= bx <w and 0 <= by < h:
                    if grid[i][j] == '#' and grid[by][bx] == '.':
                        tmp = dp[by][bx] + 1
                    else:
                        tmp = dp[by][bx]
                dp[i][j] = min(dp[i][j],tmp)
                
print(dp[-1][-1])

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <queue>
#include <vector>

#define testin freopen("1.txt","r",stdin);
#define testout freopen("out.txt","w",stdout);

using namespace std;

int main(){
    int n,t,cnt;
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",&t);
        if(t!=i) cnt++;
    }
    if(cnt<=2) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
//けんちょんさん写経
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
long long n;
void func(long long cur, int use, long long &counter){
    if(cur > n) return;
    if(use == 0b111) ++counter;

    func(cur * 10 + 7,use | 0b001, counter);
    func(cur * 10 + 5,use | 0b010, counter);
    func(cur * 10 + 3,use | 0b100, counter);
}
int main(){
    cin >> n;
    long long res=0;
    func(0,0,res);
    cout << res << endl;
}


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

template<int Modulus>
struct modint {
	using value_type = int;

	static constexpr int mod = Modulus;
	static_assert(mod > 1, "Modulus must be greater than 1");

private :
	value_type x;

	template<class T>
	static constexpr value_type normalize (T value) noexcept {
		if (value < 0) {
			value = (-value) % mod;
			return (value ? value : mod - value);
		}
		return (value % mod);
	}

public :
	explicit constexpr modint () noexcept : x(0) { }

	template<class T>
	constexpr modint (T value) noexcept : x(normalize(value)) { }

	constexpr modint operator+ () const noexcept {
		return modint(*this);
	}

	constexpr modint operator- () noexcept {
		if (x != 0) x = mod - x;
		return modint(*this);
	}

	constexpr modint &operator+= (const modint &p) noexcept {
		if ((x += p.x) >= mod) x -= mod;
		return (*this);
	}

	constexpr modint &operator-= (const modint &p) noexcept {
		if ((x += mod - p.x) >= mod) x -= mod;
		return (*this);
	}

	constexpr modint &operator*= (const modint &p) noexcept {
		x = (int)(1LL * x * p.x % mod);
		return (*this);
	}

	constexpr modint &operator/= (const modint &p) noexcept {
		return ((*this) *= p.inverse());
	}

	constexpr modint operator+ (const modint &p) const noexcept {
		return (modint(*this) += p);
	}

	constexpr modint operator- (const modint &p) const noexcept {
		return (modint(*this) -= p);
	}

	constexpr modint operator* (const modint &p) const noexcept {
		return (modint(*this) *= p);
	}

	constexpr modint operator/ (const modint &p) const noexcept {
		return (modint(*this) /= p);
	}

	constexpr bool operator== (const modint &p) const noexcept {
		return (x == p.x);
	}

	constexpr bool operator!= (const modint &p) const noexcept {
		return (x != p.x);
	}

	constexpr modint pow (long long exp) const noexcept {
		modint value(1), buff(x);
		while (exp) {
			if (exp & 1) value *= buff;
			buff *= buff;
			exp >>= 1;
		}
		return value;
	}

	constexpr modint inverse () const noexcept {
		return pow(mod - 2);
	}

	friend std::ostream &operator<< (std::ostream &os, const modint &p) {
		return (os << p.x);
	}

	friend std::istream &operator>> (std::istream &is, modint &p) {
		long long v;
		is >> v;
		p = modint(v);
		return (is);
	}

};

#include <iostream>
#include <functional>

constexpr int MAX = 2010;
constexpr int MOD = 1'000'000'007;

int main() {
	int s;
	std::cin >> s;
	std::vector<modint<MOD>> memo(MAX, -1);
	
	std::function<modint<MOD>(int)> dp = [&] (int n) {
		if (n < 3) return memo[n] = 0;
		if (n < 6) return memo[n] = 1;
		if (memo[n] != -1) return memo[n];
		return memo[n] = dp(n - 1) + dp(n - 3);
	};
	
	std::cout << dp(s) << '\n';
	
	return 0;
}

Measured memory_bytes: 3548
using System.Linq;
using System;

public class Team
{
    public int tid { get; set; }
    public int ac { get; set; }
    public int score { get; set; }
}

public class Hello
{
    public const int INF = 999999999;
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var M = int.Parse(line[0]);
            var T = int.Parse(line[1]);
            var P = int.Parse(line[2]);
            var R = int.Parse(line[3]);
            if (M == 0 && T == 0 && P == 0 && R == 0) break;
            var wa = new int[T, 10];
            var teams = new Team[T];
            for (int i = 0; i < T; i++)
                teams[i] = new Team { tid = i + 1, ac = 0,  score = INF };
            for (int i = 0; i < R; i++)
            {
                line = Console.ReadLine().Trim().Split(' ');
                var m = int.Parse(line[0]);
                var t = int.Parse(line[1]) - 1;
                var p = int.Parse(line[2]) - 1;
                var j = int.Parse(line[3]);
                if (j == 0)
                {
                    teams[t].ac++;
                    teams[t].score += m + wa[t,p] * 20;
                }
                else wa[t,p]++;
            }
            print(teams);
        }
    }
    public static void print(Team[] t)
    {
        var a = t.OrderByDescending(x => x.ac).ThenBy(x => x.score).ThenByDescending(x => x.tid).ToArray();
        var pre1 = a[0].ac;
        var pre2 = a[0].score;
        Console.Write(a[0].tid);
        for (int i = 1; i < t.Length; i++)
        {
            Console.Write(a[i].ac == pre1 && a[i].score == pre2 ? '=' : ',');
            Console.Write(a[i].tid);
            pre1 = a[i].ac; pre2 = a[i].score;
        }
        Console.WriteLine();
    }
}


Measured memory_bytes: 10252
N = int(input())
S = input()

nE = 0
n = 0
minn = 0
for a in range(1, N):
	wE = (1 if S[a] == 'E' else 0)
	n = n + (1 if S[a-1] == 'W' else 0) - wE
	minn = min(minn, n)
	nE = nE + wE
print(minn + nE)

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	pii x[n + 1];

	rep(i, 1, n)
	{
		cin >> x[i].ff;
		x[i].ss = i;
	}
	sort(x + 1, x + n + 1);
	// zip(i, 1, n + 1)
	// {
	// 	cout << x[i].ff << " " << x[i].ss << en;
	// }
	int pos = n / 2;
	int y = x[pos + 1].ff;
	int z = x[pos].ff;
	//cout << y << " " << z << en;
	int b[n + 1];
	rep(i, 1, n)
	{
		if (i <= pos)
		{
			//cout << x[i].ss << en;
			b[x[i].ss] = y;
		}
		else
		{
			//cout << x[i].ss << en;
			b[x[i].ss] = z;
		}
	}
	rep(i, 1, n)
	{
		cout << b[i] << en;
	}


	return 0;
}



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

using namespace std;

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

  int bigger, smaller;
  if (n > m) {
    bigger = n;
    smaller = m;
  } else {
      bigger = m;
      smaller = n;
  }

  int ans = 0;
  for (int i = 0; i < bigger; i++) {
    ans += smaller * pow(10, i);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

		String line = inData.nextLine();
		String regex = "[a-z]";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(line);

		if (m.find()) {
			System.out.println("a");
		} else {
			System.out.println("A");
		}

		inData.close();
	}
}


Measured memory_bytes: 26856
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double rad = (H*30 + M*0.5 - M*6)*M_PI/180.0;
    double ans = sqrt(A*A + B*B -2.0*A*B*cos(rad));
    printf("%10.10f\n", ans);

    return 0;
}

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

int main() {
    string S;
    cin >> S;
    map<char, int> mp;
    for(int i = 0; i < S.size(); i++) mp[S[i]]++;
    int ans = 0;
    for(char a = 'a'; a <= 'z'; a++) {
        ans += (mp[a] % 2);
    }
    cout << (ans) / 2 << endl;
    return 0;
}


Measured memory_bytes: 3220
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, L):
    """Test Case
    >>> print_ans(5, 2)
    18
    >>> print_ans(3, -1)
    0
    >>> print_ans(30, -50)
    -1044
    """
    ar = np.arange(N)
    ar = ar + L
    minimum = np.argmin(np.abs(ar))
    print(np.sum(ar) - ar[minimum])



if __name__ == '__main__':
    N, L = map(int, input().rstrip().split())
    print_ans(N, L)




Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
int main()
{
    ll a,b,c,i,j,k;
    cin>>a>>b;
    c=(a*500);
    if(c>=b)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


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

int main() {
  int N, R, P, C;
  while (cin >> N && cin >> R && N > 0 && R > 0) {
    int n[N];
    for (int i = 0; i < N; i++) n[i] = N-i;

    while (R > 0) {
      cin >> P; 
      cin >> C;
      rotate(n, n+P-1, n+P+C-1);
      R--;
    }
        cout << n[0] << endl;
  }
  
}

Measured memory_bytes: 3032
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.joining;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final int[] a = new int[n];
        final int[] result = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        int tmp = a[0];
        for (int i = 1; i < n; ++i) {
            tmp = a[i] - tmp;
        }
        result[0] = tmp;

        for (int i = 0; i < n - 1; i++) {
            result[i + 1] = (a[i] - result[i] / 2) * 2;
        }

        System.out.println(String.join(" ", Arrays.stream(result).mapToObj(Integer::toString).collect(Collectors.toList())));
    }
}


Measured memory_bytes: 67932
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int N;
int x[8],y[8];

double dist(int p1,int p2){
    double dx=x[p1]-x[p2];
    double dy=y[p1]-y[p2];
    return sqrt(dx*dx+dy*dy);
}

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i];
    }

    double sum;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            sum+=dist(i,j)*2/N;
        }
    }

    cout<<setprecision(16)<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

int N, K;
vector<vector<int>> adj;
vector<int> a, b;
map<pair<int, int>, int> color;

void input(){
    cin >> N;
    adj.resize(N);
    a.resize(N-1);
    b.resize(N-1);
    rep(i, N-1){
        cin >> a[i] >> b[i];
        --a[i]; --b[i];
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
    }
    rep(i, N) chmax(K, (int)adj[i].size());
}

void rec(int from, int now){
    int c = 1;
    for(auto to : adj[now]) if(from != to){
        if(from!=-1 && c == color[make_pair(min(from, now), max(from, now))]) ++c;
        color[make_pair(min(now, to), max(now, to))] = c;
        ++c;
    }
    for(auto to : adj[now]) if(from != to) rec(now, to);
}

void solve(){
    rec(-1, 0);
    
    cout << K << endl;
    rep(i, N-1){
        int l = a[i], r = b[i];
        cout << color[make_pair(min(l, r), max(l, r))] << endl;
    }
}

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

    input();
    solve();

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int h, w;
	char s;
	cin >> h >> w;
	REP(i, 0, w+2) cout << "#";
	cout << endl;
	REP(i, 0, h){
		cout <<  "#";
		REP(j, 0, w){
			cin >> s;
			cout << s;
		}
		cout << "#" << endl;
	}
	REP(i, 0, w+2) cout << "#";
}


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

int main(void){
	int a,b,c,d;
	int n;
	int count;

	while(cin>>n){
		count=0;
		if(n>36){
			cout << "0" << endl;
			continue;
		}
		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				for(c=0;c<10;c++){
					for(d=0;d<10;d++){
						if(a+b+c+d==n) count++;
					}
				}
			}
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1164
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}

ll n;
ll m;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> n;
    cin >> m;
    solve();
}

// 2 ≤ n, m ≤ 100

// ll n, ll m
// K 市にある街区の個数を出力せよ。
void solve(){
    cout<<(n-1)*(m-1)<<endl;
}


Measured memory_bytes: 3636
// https://atcoder.jp/contests/agc017/tasks/agc017_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

// 二乗法によるべき乗
int ipow(int base, int exp) {
    int result = 1;
    while (exp) {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        base *= base;
    }

    return result;
}

vector<vector<long long>> comb(int n, int r) {
    vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));
    for (int i = 0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int j = 1; j < v.size(); j++) {
        for (int k = 1; k < j; k++) {
            v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
        }
    }
    return v;
}

void solve() {
    int N, P;
    cin >> N >> P;
    int odd = 0, even = 0;
    REP(i, N) {
        int t;
        cin >> t;
        if (t % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }
    int sum1 = ipow(2, even);
    int sum2 = 0;
    auto com = comb(odd, odd);
    if (P == 0) {
        // 偶数は任意、奇数は偶数個
        for (int i = 0; i <= odd; i += 2) {
            sum2 += com[odd][i];
        }
    } else {
        // 偶数は任意、奇数は奇数個
        for (int i = 1; i <= odd; i += 2) {
            sum2 += com[odd][i];
        }
    }
    cout << sum1 * sum2 << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3652
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] a = new int[10];
        for (int i = 0; i < 10; i++)
            a[i] = int.Parse(Console.ReadLine());
        Array.Sort(a);
        Array.Reverse(a);
        Console.WriteLine("{0}\n{1}\n{2}", a[0], a[1], a[2]);
    }
}

Measured memory_bytes: 9280
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2005000
#define MOD 1000000007
#define N 305
#define M 1000005
#define LOG 18
#define KOK 4000000
using namespace std;


int n,m;
int fr[N],f[N],a[N][N];
vector<ii> v[N];

bool ok(int val) {

	memset(fr,0,sizeof(fr));
	memset(f,0,sizeof(f));

	for(int i=1;i<=m;i++) v[i].clear();

	for(int i=1;i<=n;i++) fr[a[i][1]]++,v[a[i][1]].pb({i,1});

	int tot=m;

	while(tot && *max_element(fr+1,fr+1+m)>val) {

		int pos=max_element(fr+1,fr+1+m)-fr;

		f[pos]=1;

		tot--;

		bool flag=1;

		for(ii now:v[pos]) {

			int tut=now.nd;

			while(f[a[now.st][tut]]) ++tut;

			if(tut>m) {flag=0;break ;}

			v[a[now.st][tut]].pb({now.st,tut});

			fr[a[now.st][tut]]++;

		}

		v[pos].clear();

		fr[pos]=0;

		if(!flag) return 0;

	}

	return tot;

}

int main() {

//	freopen("input.txt","r",stdin);	

	scanf("%d %d",&n,&m);

	for(int i=1;i<=n;i++) {

		for(int j=1;j<=m;j++) {

			scanf("%d",&a[i][j]);

		}

	}

	int bas=1,son=n;

	while(bas<=son) {

		if(ok(orta)) son=orta-1;
		else bas=orta+1;

	}

	printf("%d",bas);

}



Measured memory_bytes: 1792