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

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    int A[n];
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    int B[h][w], nx = 0, ny = 0;
    bool f = true;
    for(int i = 0; i < n; i++){
        int j = 0;
        while(j < A[i]){
            B[nx][ny] = i + 1;
            if(f){
                if(ny + 1 >= w){
                    f = false;
                    nx++;
                }else ny++;
            }else{
                if(ny - 1 < 0){
                    f = true;
                    nx++;
                }else ny--;
            }
            j++;
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(j) cout << " " << B[i][j];
            else cout << B[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
def main():
    n=int(input())
    x=list(map(int,input().split()))
    ans = [0] * 100
    m=10**8
    for i in range(1,101):
        for j,aa in enumerate(x):
            ans[i-1] += (aa-i)**2
        m=min(m,ans[i-1])
    print(m)
if __name__=='__main__':
    main()


Measured memory_bytes: 3060
h,w,k = list(map(int,input().split()))
arr = [list(input()) for _ in range(h)]
ans = 0

import itertools
for conh in itertools.product([True,False], repeat = h):
    for conw in itertools.product([True,False], repeat = w):
        count = 0
        for i in range(h):
            for j in range(w):
                if conh[i] or conw[j]:
                    continue
                else:
                    if arr[i][j] == "#":
                        count += 1
        if count == k:
            ans += 1

print(ans)

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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

vector<vi> g(maxn);


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

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

	int n;
	cin >> n;
	double x[n+1],y[n+1];
	for(int i=1;i<=n;i++)
		cin >> x[i] >> y[i];
	vi v;
	for(int i=1;i<=n;i++)
	v.PB(i);
	double ans = 0;
	int cont = 0;
	do
	{
		cont++;
		for(int i=0;i<n-1;i++)
		{
			double X1 = x[v[i]] , X2 = x[v[i+1]];
			double Y1 = y[v[i]] , Y2 = y[v[i+1]];
			X1 -= X2;
			Y1 -= Y2;
			ans +=sqrt(X1*X1+Y1*Y1);
		}
	}while(next_permutation(all(v)));
	cout << setprecision(10) << fixed;
	cout << ans/cont;
	return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S == "SAT") {cout << 1 << endl;}
  else if (S == "FRI") {cout << 2 << endl;}
  else if (S == "THU") {cout << 3 << endl;}
  else if (S == "WED") {cout << 4 << endl;}
  else if (S == "TUE") {cout << 5 << endl;}
  else if (S == "MON") {cout << 6 << endl;}
  else {cout << 7 << endl;}
}

Measured memory_bytes: 3524
#include<stdio.h>
int main(){
  int high[100];
  int width[100];
  int i;
  int j;
  int count=0;
  int z;

  
  while(1){
  scanf("%d %d",&high[count],&width[count]);
  if(high[count] == 0 && width[count]==0) break;
  count++;
  }

  for(z=0;z<count;z++){
    for(i=0;i<high[z];i++){
      for(j=0;j<width[z];j++){
	if(i==0 || i==high[z]-1){
	printf("#");
	}
	else if(j==0 || j==width[z]-1){
	  printf("#");
	}
	else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2056
s = input()
n = len(s) - 1
ans = 0
for i in range(1 << n):
    tmp_l = []
    sep = 0
    for j in range(n):
        if (i >> j) & 1:
            tmp_l.append(int(s[sep:j + 1]))
            sep = j + 1
    tmp_l.append(int(s[sep:]))
    ans += sum(tmp_l)
print(ans)

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for(int i = 0; i < n; i++) cin >> p.at(i);
  
  sort(p.begin(), p.end());
  int ans = 0;
  for(int i = 0; i < k; i++) ans += p.at(i);
  
  cout << ans << endl;
}

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

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

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

mint comb(int n, int k) {
    mint x = 1;
    mint y = 1;
    rep(i,k) {
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main() 
{
    int x, y;
    cin >> x >> y;

    int a, b;
    a = 2*x -y;
    b = 2*y -x;
    if (a < 0 || b < 0) {
        cout << 0 << endl;
        return 0;
    }
    if (a%3 != 0 || b%3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    a /= 3; b /= 3;

    mint ans = comb(a+b, a);
    cout << ans << endl;
    
    return 0;
}


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

if Y == N * 10000:
    print " ".join(map(str, [N, 0, 0]))
elif Y > N * 10000:
    print " ".join(map(str, [-1, -1, -1]))
elif Y < N * 1000:
    print " ".join(map(str, [-1, -1, -1]))
elif Y == N * 1000:
    print " ".join(map(str, [0, 0, N]))


else:
    dif = N * 10000 - Y

    ext = dif % 9000
    if ext == 0:
        noguchi = dif / 9000
        print " ".join(map(str, [N-noguchi, 0, noguchi]))
    else:
        if ext == 1000:
            higuchi = 2
        elif ext == 2000:
            higuchi = 4
        elif ext == 3000:
            higuchi = 6
        elif ext == 4000:
            higuchi = 8
        elif ext == 5000:
            higuchi = 1
        elif ext == 6000:
            higuchi = 3
        elif ext == 7000:
            higuchi = 5
        elif ext == 8000:
            higuchi = 7

        dif = ((N - higuchi) * 10000 + higuchi * 5000)- Y
        if dif < 0:
            print " ".join(map(str, [-1, -1, -1]))
        else:
            noguchi = dif / 9000
            yukichi = N - (noguchi + higuchi)

            if not noguchi < 0 and not higuchi < 0 and not yukichi < 0:
                print " ".join(map(str, [yukichi, higuchi, noguchi]))
            else:
                print " ".join(map(str, [-1, -1, -1]))





Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >>s;
    int a=0,b=0,c=0;
    for(int i=0;i<3;i++){
        if(s[i]=='a')a++;

        else if(s[i]=='b')b++;

        else if(s[i]=='c')c++;
    }
    if(a==1&&b==1&&c==1){
        cout <<"Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int map[30][31];
int w,n;

void search(int s_x,int x,int y)
{
/*	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<w;j++)
		{
			cout << map[j][i] << " " ;
		}
		cout << endl;
	}
	
	getchar();
	system("cls");
*/	
	if(y==n)
	{
		map[x][n]=s_x+1;
		return ;
	}
	
	if(map[x][y]!=100)
		x=map[x][y];
	
	search(s_x,x,y+1);
}

int main()
{
	int a1,b1;
	int i,j;
	char a;
	
	cin >> w ;
	cin >> n ;
	
	for(i=0;i<=n;i++)
		for(j=0;j<w;j++)
			map[j][i]=100;
	
	for(i=0,j=0;i<n;i++,j++)
	{
		cin >> a1 >> a >> b1 ;
		map[a1-1][j]=b1-1;
		map[b1-1][j]=a1-1;
	}
	
/*	for(i=0;i<=n;i++)
	{
		for(j=0;j<w;j++)
		{
			cout << map[j][i] << " " ;
		}
		cout << endl;
	}
	
	getchar();
	system("cls");
*/	
	for(i=0;i<w;i++)
	{
		search(i,i,0);
	}
	
	for(i=0;i<w;i++)
	{
		cout << map[i][n] << endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
int main()
{
  char inp[4];
  scanf("%s",inp);
  int i,j;
  char tmp;
  for(i=0;i<2;i++)
  {
    for(j=i+1;j<3;j++)
      if(inp[i]>inp[j])
      {
        tmp=inp[j];
        inp[j]=inp[i];
        inp[i]=tmp;
      }
  }
  if(strcmp(inp,"abc")==0)
    printf("Yes");
  else
    printf("No");
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
int n, m, a;
int x[100000];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d", x + i);
	}
	std::sort(x, x + m);
	for (int i = 0; i < m - 1; i++) {
		x[i] = x[i + 1] - x[i];
	}
	std::sort(x, x + m - 1);
	for (int i = n; i < m; i++) {
		a += x[i - n];
	}
	printf("%d\n", a);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 300;
int n;
ll a, b, x;
void No(){ cout << -1 << endl; exit(0);}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  cin >> a >> b;
  FOR(_, 0, n-2){
    ll c;
    cin >> c;
    x ^= c;
  }
  ll s = a+b;
  ll ss = s, xx = x;
  V<bool> v(60);
  ll c = 0;
  FORR(i, 59, 0)if(x & bit(i)){
    x -= bit(i);
    s -= bit(i);
    v[i] = true;
  }
  FORR(i, 59, 0)if(bit(i)*2 <= s){
    if(v[i]) No();
    c += bit(i);
    s -= bit(i)*2;
  }
  if(c > a) No();
  FORR(i, 59, 0)if(v[i] && c+bit(i) <= a) c += bit(i);
  if(c == 0) No();
  if(c^(ss-c)^xx) No();
  cout << a-c << endl;
}

Measured memory_bytes: 3632
<?php
    $n;
    $s1;
    $s2;
    $u = 0;
    $a = 1;
    fscanf(STDIN, "%d", $n);
    fscanf(STDIN, "%s", $s2);
    fscanf(STDIN, "%s", $s1);
    
    for($i = 0; $i < $n; $i++){
        if($s1[$i] == $s2[$i]){
            if($u == 0) $a *= 3;
            if($u == 1) $a *= 2;
            $u = 1;
        }else{
            if($u == 0) $a *= 6;
            if($u == 1) $a *= 2;
            if($u == 2) $a *= 3;
            $u = 2;
            $i++;
        }
        $a %= 1000000007;
    }
    echo "$a\n";
?>


Measured memory_bytes: 3956
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A_i(N);
    int sum = 0;
    for(int i=0; i<N; i++){
        cin >> A_i[i];
        sum += A_i[i];
    }   
    int popular_count = 0;
    double judge_num = sum / (4.0*M);
    for(int i=0; i<N; i++){
        if(judge_num <= A_i[i]){
            popular_count += 1;
        }
    }
    if(popular_count >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
typedef long long ll;
using namespace std;

int main(){
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if(a1 + a2 + a3 >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}

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

void trace(int A[],int N){
    rep(i,N-1) cout << A[i] << " ";
    cout << A[N-1] << endl;
}



int BubbleSort(int A[],int N){
    bool flag = true;
    int cnt = 0;
    while(flag){
        flag = false;
        for (int i = N-1; i >0; --i)
        {
            if(A[i] < A[i-1]){
                swap(A[i],A[i-1]);
                flag = true;
                cnt++;
            }
        }
    }
    return cnt;
}

int main(){
    int N; cin >> N;
    int A[N]; rep(i,N) cin >> A[i];
    int ans = BubbleSort(A,N);
    trace(A,N);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	int K;
	cin >> s >> K;

	vector<string> ans;
	for (int alpha = 'a'; alpha <= 'z'; alpha++) {
		DMP(char(alpha));
		for (int i = 0; i < (int)s.size(); i++) {

			if (s[i] == alpha) {
				for (int substr = 1; substr <= K; substr++) {
					if (i + substr <= (int)s.size()) {
						ans.emplace_back(s.substr(i, substr));
					}
				}
			}

		}
		sort(ans.begin(), ans.end());
		ans.erase(unique(ans.begin(), ans.end()), ans.end());
		if ((int)ans.size() >= K) break;
	}

	sort(ans.begin(), ans.end());
	ans.erase(unique(ans.begin(), ans.end()), ans.end());
	cout << ans[K - 1] << "\n";

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

ll memo[51][2];

// d次元バーガーを食す
ll eat(ll d, ll x) {
  if (x <= 0) {
    return 0;
  }
  if (x >= memo[d][0]) {
    return memo[d][1];
  } else {
    x--;
    ll ans = 0;
    if (x >= memo[d - 1][0]) {
      ans += memo[d - 1][1];
      x -= memo[d - 1][0];
    } else {
      return ans + eat(d - 1, x);
    }
    // 真ん中のパティ
    if (x > 0) {
      x--;
      ans++;
    } else {
      return ans;
    }
    return ans + eat(d - 1, x);
  }
}

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

  ll n, x;
  cin >> n >> x;

  ll ans = 0;

  memo[0][0] = 1; // 全体の厚み
  memo[0][1] = 1; // パティの数

  REP(i, 51) {
    memo[i][0] = memo[i - 1][0] * 2 + 3;
    memo[i][1] = memo[i - 1][1] * 2 + 1;
  }

  cout << eat(n, x) << endl;

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))

if M <= N:
    print(0)
    exit()


X.sort()
diff = []
sum_dist = X[-1] - X[0]

for i, x in enumerate(X):
    diff.append(x - X[i - 1])


diff.sort(reverse=True)
print(sum_dist - sum(diff[:N - 1]))


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

int num[5];

int main(){
	cin >> num[1] >> num[2] >> num[3];

	swap(num[1],num[2]);
	swap(num[1],num[3]);

	cout << num[1] << " " << num[2] << " " << num[3] << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
int main() {
	ll h, w, i, ans = 1e+12, s1, s2,s3;
	cin >> h >> w;
	for (i = 1; i < h; i++) {
		s1 = i * w;
		if (w % 2 == 0 || (h - i) % 2 == 0) {
			s2 = (h - i)*w / 2;
			s3 = s2;
		}
		else {
			s2 = max(h - i, w) / 2 * min(h - i, w);
			s3 = s2 + min(h - i, w);
		}
		ans = min(ans, max(max(s1, s2), s3) - min(min(s1, s2), s3));
	}
	swap(h, w);
	for (i = 1; i < h; i++) {
		s1 = i * w;
		if (w % 2 == 0 || (h - i) % 2 == 0) {
			s2 = (h - i)*w / 2;
			s3 = s2;
		}
		else {
			s2 = max(h - i, w) / 2 * min(h - i, w);
			s3 = s2 + min(h - i, w);
		}
		ans = min(ans, max(max(s1, s2), s3) - min(min(s1, s2), s3));
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
// Code by Nguyen Huu Lam
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long long LL;

#define y0 Sword_Art_Online
#define y1 Your_lie_in_April
#define yn Darling_in_the_Franxx
#define tm Plastic_Memories
#define lr Charlotte
#define norm Weathering_with_you
#define left Violet_Evergarden
#define have Date_a_live
#define ends Your_name
#define prev Five_centimeters_per_second
#define hash Slient_voice

#define ordered_set tree<LL, null_type, less<LL>, rb_tree_tag, tree_order_statistics_node_update>
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

LL Rand(LL l, LL h){
    return uniform_int_distribution<LL>(l, h)(rng);
}

template <typename T> void read(T &t){
    t = 0; char ch = getchar(); int f = 1;
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    do { (t *= 10) += ch - '0'; ch = getchar(); } while (isdigit(ch)); t *= f;
}

const LL MaxN = 1 + 2e5;

LL n, a[MaxN], x, d[MaxN], k, kq;
unordered_map<LL, LL> cnt;

void InOut(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}

int main(){
    // InOut();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i = 1 ; i <= n ; ++i){
        cin >> x;
        x--;
        d[i] = d[i - 1] + x;
    }
    LL j = 0;
    cnt[0]++;
    for(int i = 1 ; i <= n ; ++i){
        LL temp = d[i] % k;
        if(i - j + 1 > k){
            cnt[d[j] % k]--;
            j++;
        }
        kq += cnt[temp];
        // cout << s.count(temp) << endl;
        cnt[temp]++;
    }
    cout << kq << endl;

    return 0;
}

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

int main(void) {
    int a,suma=0,sumb=0;
    for (int i=0;i<4;i++) {
        cin>>a;
        suma+=a;
    }
    for (int j=0;j<4;j++) {
        cin>>a;
        sumb+=a;
    }
    if (suma>sumb) {
        cout<<suma<<endl;
    } else if (suma<sumb) {
        cout<<sumb<<endl;
    } else if (suma==sumb) {
        cout<<suma<<endl;
    }
}


Measured memory_bytes: 3100
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

// i: index, n: size, a: start, b: end
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

// x: container(array, vector etc..)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5

#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main() {
  double n;
  cin >> n;

  if (ceil(n / 1.08) < ceil((n + 1) / 1.08)) {
    cout << ceil(n / 1.08) << endl;
    return 0;
  }

  cout << ":(" << endl;
  return 0;
}


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

using namespace std;

const int N = 200100;

int n, m, a[N];

int cal(int w, int d) {
	return (w + d - 1) / d;
}

int main() {

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

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	int at = -1;

	for (int i = 0; i < n; i++) {
		if (a[i] == 1) {
			at = i;
			break;
		}
	}

	int res = n;

	for (int j = 1; j <= m; j++) {
		int k = at + j - 1;
		int l = at - (m - j);
		if (l < 0 || k >= n) {
			continue;
		}
		int now = cal(l, m - 1) + cal(n - k - 1, m - 1);
		res = min(res, 1 + now);
	}

	printf("%d\n", res);
	
	return 0;

}

Measured memory_bytes: 4124
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
    cin>>n;
    int *arr=new int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int sum=0;
    int o=0;
    for(int i=1;i<n;i++)
    {  arr[i]+=o;
        o=max(o,-arr[i]+arr[i-1]);
     if(arr[i-1]>arr[i])
         sum+=arr[i-1]-arr[i];
    }
    cout<<sum<<endl;
}*/
/*
Written By mafailure
*/
//In the name of God
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long 
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  nds; 
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int power(int x, int y)
{ 
	if(y==0)return 1;
	int u=power(x,y/2);
	u=(u*u)%mod;
	if(y%2)u=(x*u)%mod;
	return u;
    
}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
	
	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
signed main()
{
	IOS
	
		int n;
		 cin>>n;
		 vi a(n);
		 fr(i,0,n) cin>>a[i];
		 int o=0;
		 int ok=a[0];
		 fr(i,1,n)
		 {
		 	
		 	o+=max(0LL,ok-a[i]);
		 	ok=max(ok,a[i]);
            // cout<<ok<<" ";
		 }
   // cout<<endl;
   
		 cout<<o<<endl;
	
	
}



Measured memory_bytes: 4764
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

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

  vector<int> points(N);
  int res = 999999999;

  int a = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    a += x;
    points.at(i) = x;
  }

  int p = a / N;
  for (int d = -2; d < 2; d++) {
    int r = 0;

    for (int i = 0; i < N; i++) {
      r += (points[i] - p + d) * (points[i] - p + d);
    }
    if (r < res) res = r;
  }

  cout << res << endl;
}

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

int main() {
  string o, s;
  cin >> o >> s;
  cout << "A" << s[0] << "C" << endl;
  return 0;
}

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

using ll = long long;
const int INF = 1e9+7;

void solve()
{
	char a;cin >> a;
	if(isupper(a))
		cout << "A\n";
	else
		cout << "a\n";
}

int main()
{
	int t=1;
	while(t--) solve();
}	


Measured memory_bytes: 3588
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
bool a=1;
cin>>s;
for (int i=0;i<(s.size()-3)/2;i++)
{
if(s[i]!=s[s.size()-1-i])
a = false;
}
for (int i=0;i<=(s.size()-3)/4;i++)
{
if(s[i]!=s[(s.size()-3)/2-i])
a = false;
}

if(a==false)cout <<"No";
else cout <<"Yes";
}

Measured memory_bytes: 256
let ask i =
  print_int i;
  print_newline();
  let s = read_line() in
  s
in

let rec search : int -> string -> int -> string -> unit = fun l ls r rs ->
  let m = (l+r)/2 in
  let ms = ask m in
  if ms <> "Vacant" then
    if (m-l+1) mod 2 = 0 then
      if ms = ls then
        search l ls m ms
      else
        search m ms r rs
    else
      if ms = ls then
        search m ms r rs
      else
        search l ls m ms
  else
    ()
in


let n = read_int() in
let ls = ask 0 in
if ls <> "Vacant" then
  let rs = ask (n-1) in
  if rs <> "Vacant" then
    search 0 ls (n-1) rs
  else ()
else ()
;;  
   


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

int main() {
	int n; cin >> n;
	vector<int>a(n), b(n), c(n);
	for (auto&& x : a)cin >> x;
	for (auto&& x : b)cin >> x;
	for (auto&& x : c)cin >> x;
	sort(a.begin(), a.end()); sort(b.begin(), b.end()); sort(c.begin(), c.end());

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		long long aNum = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		long long cNum = c.end() - upper_bound(c.begin(), c.end(), b[i]);
		ans += aNum * cNum;
	}
	cout << ans << endl;
		
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int count = 0;

/*1  insertionSort(A, n, g)
2      for i = g to n-1
3          v = A[i]
4          j = i - g
5          while j >= 0 && A[j] > v
6              A[j+g] = A[j]
7              j = j - g
8              cnt++
9          A[j+g] = v
10
11 shellSort(A, n)
12     cnt = 0
13     m = ?
14     G[] = {?, ?,..., ?}
15     for i = 0 to m-1
16         insertionSort(A, n, G[i])*/

void insertSort(int *A,int n,int g){
  int i,j;
  int key;
  for(i = g; i < n; i++){
    j = i;
    key = A[i];
    while(0 <= j - g){
      if(A[j-g] <= key) break;
      A[j] = A[j-g];
      j -= g;
      count++;
    }
   A[j] = key;
 }
}


int main(){
  int n;
  int i,j;
  int *A;
  int G[20];

  scanf("%d", &n);
  A = malloc(n * sizeof(int));
  for(i = 0; i < n; i++) scanf("%d", &A[i]);

  int m = 0;
  G[0] = 0;
  while(1){
    if(n < 3*G[m]+1) break;
    G[m+1] = 3*G[m] + 1;
    m++;
 }

 for(i = m; i > 0; i--) insertSort(A,n,G[i]);

  printf("%d\n", m);
  for(i = m; i >= 1; i--) printf("%d ", G[i]);
  printf("\n");
  printf("%d\n", count);

  for(i = 0; i < n; i++) printf("%d\n", A[i]);

  return 0;
}



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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {
	
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	REP(i, n - 2) {
		if (s[i] == 'A'&&s[i + 1] == 'B'&&s[i + 2] == 'C')ans++;
	}
	cout << ans << endl;


}


Measured memory_bytes: 256
// D,

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
  LL n, ans = 0;
  cin >> n;
  vector<LL> p, c, d;
  ans = 0;
  LL r = sqrt(n), x = n;
  for (LL i = 2; i <= r; ++i) {
    if ((x % i) == 0) {
      LL cnt = 0;
      while ((x % i) == 0) {
        x /= i;
        ++cnt;
      }
      p.push_back(i);
      c.push_back(cnt);
    }
  }
  if (x > 1 || p.empty()) {
    p.push_back(x);
    c.push_back(1);
  }
  d.resize(c.size());

  d[0] = 0;
  x = 1;
  int i;
  do {
    LL y = n / x;
    if (x < y - 1) {
      ans += y - 1;
    }
    for (i = 0; i < (int)d.size(); ++i) {
      d[i] += 1;
      if (d[i] <= c[i]) {
        x *= p[i];
        break;
      }
      d[i] = 0;
      for (int j = 0; j < c[i]; ++j) {
        x /= p[i];
      }
    }
  } while (i < (int)d.size());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
vector<ll>multiple;

void prime(int v){
  multiple[0]=-1;
  multiple[1]=-1;
  for(int i=2; i<=v; i++){
    if(multiple[i]!=0)continue;
    for(int j=i*2; j<=v; j+=i){
     multiple[j]=i;
    }
  }
  
  
  
  
  
}

int main(){
  ll n;
  cin >> n;
  multiple.resize(55556);
  prime(55555);
  for(int i=2; i<=55555; i++){
    if(n==0)break;
    if(multiple[i]==0 && i%5==1){
      cout << i << " ";
      n--;
    }
  }
  
}
  
  
  
  


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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

typedef long long ll;
typedef pair<int, int> P;

int main(){
  int a;
  
  scanf("%d", &a);
  a/=200;
  
  printf("%d",10-a);
  
  return 0;
}


Measured memory_bytes: 3812
/*
          Life before Death
          Strength before Weakness
          Journey before Destination
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define rep(i,a,n) for(ll i=a;i<n;i++)
    #define per(i,n,a) for (ll i=n;i>a;i--)
    #define te ll t; std::cin >> t; while(t--)
    #define SZ 100010
    //#define M_PI  3.141592653589793238462643383279502884L
    /*------Just DO IT--------------------------------------*/
    
    ll n,k,ma=1,cn;
  
    void primef() 
    { ll cnt,ans=1;
      rep(i,2,sqrt(cn)+2){
        if(n%i==0){
          cnt=0;
          while(n%i==0)  n/=i , cnt++;
          if(cnt>=k) ma*=pow(i,cnt/k);
        }
      }
      if(k==1) ma = cn;
    } 

    ll solve(){
      cin>>k>>n;
      cn = n;
      primef();
      cout<<ma<<endl;
    }
    
    int main() {
       fastio;
       solve();
    }

Measured memory_bytes: 384
char s[100][101];h;r[100],R,c[100],C,i,j;
main(w){scanf("%d%d",&h,&w);for(i=0;i<h;i++)scanf("%s",s[i]);
for(i=0;i<h;i++){int x=0;for(j=0;j<w;j++)if(s[i][j]=='#')x=1;if(x)r[R++]=i;}
for(j=0;j<w;j++){int x=0;for(i=0;i<h;i++)if(s[i][j]=='#')x=1;if(x)c[C++]=j;}
for(i=0;i<R;i++){for(j=0;j<C;j++)putchar(s[r[i]][c[j]]);puts("");}
}

Measured memory_bytes: 128
import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

class BIT:
    """ Binary Indexed Tree """

    def __init__(self, n):
        # 0-indexed
        n += 1
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

    def update(self, i, x):
        """ 値の更新：添字i, 値x """
        self.add(i, x - self.get(i))

    def print(self, N):
        for i in range(N):
            print(self.get(i), end=' ')
        print()

N, Q = MAP()
A = [a-1 for a in LIST()]

LR = []
for i in range(Q):
    l, r = MAP()
    l -= 1; r -= 1
    LR.append((l, r, i))

LR.sort(key=itemgetter(1))
prev = [-1] * N
bit = BIT(N)
j = 0
ans = [0] * Q
for l, r, i in LR:
    while j <= r:
        if prev[A[j]] != -1:
            bit.add(prev[A[j]], -1)
        prev[A[j]] = j
        bit.add(j, 1)
        j += 1
    ans[i] = bit.get(l, r+1)

for a in ans:
    print(a)


Measured memory_bytes: 178140
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}
/*
ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}*/
int main() {
	cin >> n;
	cin >> s;
	ll res = 0;
	rep(i, 10) {
		rep(j, 10) {
			rep(k, 10) {
				vector<ll> p(3);
				p[0] = i;
				p[1] = j;
				p[2] = k;
				ll cnt = 0;
				rep(ww, n) {
					if ((s[ww] - '0') == p[cnt]) {
						++cnt;
					}
					if (cnt == 3) {
						++res;
						break;
					}
				}
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 3644
import java.util.Scanner;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while(sc.hasNext()){
			int sum=sc.nextInt();
			int res=0;
			for(int a=0;a<10;a++)
				for(int b=0;b<10;b++)
					for(int c=0;c<10;c++)
						for(int d=0;d<10;d++)
							if(a+b+c+d==sum){
								res++;
							}
			ln(res);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
for i in range(n):
    if i == n-1:
        if  b[i] <= a[i]+a[i+1]:
            count += b[i]
        else:
            count += a[i]+a[i+1]
    else:
        if b[i] <= a[i]:
            count += b[i]
        else:
            count += a[i]
            if b[i]-a[i] > a[i+1]:
                count += a[i+1]
                a[i+1] = 0
            else:
                count += b[i]-a[i]
                a[i+1] -= b[i]-a[i]
print(count)

Measured memory_bytes: 82020
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){
    
    int n, t; cin >> n >> t;
    vector<pair<string, string> > a(n);
    vector<pair<string, string> > b(n);

    for(int i = 0; i < n; i++){
        string o, p, q, r; cin >> o >> p >> q >> r;
        a[i].first = o;
        a[i].second = p;
        b[i].first = q;
        b[i].second = r;
    }
    
    

    vector<pair<string, int> > ans;
    for(int i = 0; i < n - 1; i++){
        int g = stoi(a[i + 1].first.substr(0, 2)) * 60 + stoi(a[i + 1].first.substr(3, 2));
        int s = stoi(b[i].first.substr(0, 2)) * 60 + stoi(b[i].first.substr(3, 2));
        if(g - s >= t) ans.push_back({a[i + 1].second, g - s});
    }
        
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i].first << " " << ans[i].second << endl;
    }

    return 0;
}




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

int main()
{
    int N, D, X;
    cin >> N >> D >> X;

    int res = 0;
    int ai;
    for (int i = 0; i < N; i++)
    {
        cin >> ai;
        res += (D + ai - 1) / ai;
    }
    cout << res + X << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAXLEN 20000

typedef struct Pool {
	int position;
	int area;
} P;
char buf[ MAXLEN+2 ];
int stack[ MAXLEN+2 ];
P areas[ 10002 ];
int sindex, aindex;

int main( int argc, char *argv[] ) 
{
	int pool, sum = 0;
	int i, j;

	fgets( buf, MAXLEN, stdin );	
	sindex = aindex = 0;
	for( i=0; '\0'!=buf[i]; i++ ) {
		if( '\\' == buf[i] ) {
			stack[ sindex++ ] = i;
		} else if( 0 < sindex && '/' == buf[i] ) {
			j = stack[ --sindex ];
			pool = i - j;
			sum += pool;
			while( 0 < aindex ) {
				if( j < areas[ aindex-1 ].position ) {
					pool += areas[ --aindex ].area;
				} else {
					break;
				}
			}
			areas[ aindex ].position = j;
			areas[ aindex++ ].area = pool;
		}
	}
	printf( "%d\n", sum );
	printf( "%d", aindex );
    if( 0 < aindex ) printf( " " );
    for( i=0; i<aindex; i++ ) {
        printf( "%d", areas[ i ].area );
        if( i != aindex-1 ) printf( " " );
    }
    printf( "\n" );
    
    return 0;
}

Measured memory_bytes: 620
import java.util.Scanner;

public class Main {
  final static char WHITE = '.';
  final static char BLACK = '#';

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

    while (in.hasNext()) {
      int H = in.nextInt();
      int W = in.nextInt();
      char[][] a = new char[H][W];

      for (int i = 0; i < a.length; ++i) {
        a[i] = in.next().toCharArray();
      }

      boolean[] isRemovedH = new boolean[H];
      boolean[] isRemovedW = new boolean[W];
      
      for (int i = 0; i < a.length; ++i) {
        boolean isAllWhite = true;

         for (int j = 0; j < a[i].length; ++j) {
           if (a[i][j] == BLACK) {
             isAllWhite = false;
             break;
           }
         }

         isRemovedH[i] = isAllWhite;
      }

      for (int j = 0; j < a[0].length; ++j) {
        boolean isAllWhite = true;

         for (int i = 0; i < a.length; ++i){
           if (a[i][j] == BLACK) {
             isAllWhite = false;
             break;
           }
         }

         isRemovedW[j] = isAllWhite;
      }

      for (int i = 0; i < a.length; ++i) {
         if (isRemovedH[i] == false) {
           for (int j = 0; j < a[i].length; ++j) {
             if (isRemovedW[j] == false) {
               System.out.print(a[i][j]);
             }
           }
           System.out.println();
         }
      }
    }
  }
}

Measured memory_bytes: 28628
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e3 + 10;
const ll inf = 1e9 + 7;
int n , m , a[N][N];
ll times[N];

ll solve(vector<ll> A,vector<ll> B,int sig = 0) {
  if(A >= B) {
    int times = 0;
    while(true) {
      rep(i,1,sz(B)) {
        B[i] += B[i-1];
        B[i] = min(B[i] , inf);
        if(B[i] == inf)
          break;
      }
      times++;
      if(sig == 0) {
        if(A < B) return times;
        if(sz(B) == 2) return times + (A[1] - B[1] + B[0]) / B[0];
        if(B[2] == inf) return times + (A[1] - B[1] + B[0] - 1) / B[0];
      } else {
        if(A <= B) return times;
        if(sz(B) == 2 || B[2] == inf) return times + (A[1] - B[1] + B[0] - 1) / B[0];
      }
    }
  } else return -(solve(B , A , 1) - 1);
}

int main(){
  scanf("%d%d",&n,&m);
  rep(i,0,n) rep(j,0,m) scanf("%d",a[i]+j);
  bool error = false;
  rep(i,1,n) error |= a[i][0] < a[i-1][0];
  if(m == 1) rep(i,1,n) error |= a[i][0] <= a[i-1][0];
  if(error) return printf("-1\n") , 0;
  rep(i,1,n) {
    if(a[i][0] > a[i-1][0]) {
      times[i] = 0;
      continue;
    }
    vector<ll> A , B;
    rep(j,0,m) A.pb(a[i-1][j]) , B.pb(a[i][j]);
    ll del = solve(A,B);
    times[i] = max(0ll , times[i-1] + del);
  }
  ll ans = 0;
  rep(i,0,n) ans += times[i];
  printf("%lld\n",ans);
  return 0;
}


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

}

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

int main()
{
    int n;
    cin >> n;
    vector<char> s(n);
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> s.at(i);
        if (s.at(i) == 'Y')
        {
            count++;
        }
    }
    if (count == 0)
    {
        cout << "Three" << endl;
    }
    else
    {
        cout << "Four" << endl;
    }
}

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

using namespace std;

int main() 
{
	int n,i;
    cin >> n;
    vector<int> a(n);

    for (i = 0; i < n; i ++){
        cin >> a[i];
    }
    for (i = n-1; i >0 ; --i){
        cout << a[i] << " ";
    }
    cout << a[0] << endl;

    return 0;

}


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

const long long INF = 10000000000000000;
const int MAX_N = 100000;
int N;

std::vector<std::pair<int,int> > d[MAX_N+1];
long long K2N[MAX_N+1];

void dfs(int x, int y, long long distance){
   K2N[x] = distance;
   
   for(int i=0; i<d[x].size(); ++i){
      if(d[x][i].first==y) continue;
      dfs(d[x][i].first,x,distance+d[x][i].second);
   }
   return;
}

int main(){
   std::cin >> N;
   int a, b, c;
   for(int i=1; i<N; ++i){
      std::cin >> a >> b >> c;
      d[a].push_back(std::make_pair(b,c));
      d[b].push_back(std::make_pair(a,c));
   }
   int Q, K;
   std::cin >> Q >> K;
   int x[Q], y[Q];
   for(int i=0; i<Q; ++i){
      std::cin >> x[i] >> y[i];
   }

   dfs(K,-1,0);

   long long ans;
   for(int i=0; i<Q; ++i){
      ans = K2N[x[i]] + K2N[y[i]];
      std::cout << ans << std::endl;
   }

   return 0;
}


Measured memory_bytes: 15104