akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cctype>

using namespace std;

int main()
{
	int h, w;

	cin >> h >> w;

	if ((h % 3 == 0) || (w % 3 == 0))
	{
		cout << 0 << endl;
		return 0;
	}

	int ans = min(h, w);

	if (w >= 2)
	{
		if (w % 2)
		{
			for (int i = (h/4); i < (h / 3)+2; i++)
			{
				int a, b, c;
				a = w * i;
				b = (h - i) * (w / 2);
				c = (h - i) * (w / 2 + 1);
				int tmp = max(a, max(b, c)) - min(a, min(b, c));
				if (ans > tmp && tmp >= 0)
				{
					ans = tmp;
				}
			}
		}
		else
		{
			for (int i = (h/4); i < (h / 3)+2; i++)
			{
				int a, b, c;
				a = w *i;
				b = (h - i) * (w / 2);
				int tmp = max(a, b) - min(a, b);
				if (ans > tmp && tmp >= 0)
				{
					ans = tmp;
				}
			}

		}

	}

	if (h >= 2)
	{
		if (h % 2)
		{
			for (int i = (w/4); i < (w / 3)+2; i++)
			{
				int a, b, c;
				a = h *i;
				b = (w - i) * (h / 2);
				c = (w - i) * (h / 2 + 1);
				int tmp = max(a, max(b, c)) - min(a, min(b, c));
				if (ans > tmp && tmp >= 0)
				{
					ans = tmp;
				}
			}
		}
		else
		{
			for (int i = (w/4); i < (w / 3) +2; i++)
			{
				int a, b, c;
				a = h *i;
				b = (w - i) * (h / 2);
				int tmp = max(a, b) - min(a, b);
				if (ans > tmp && tmp >= 0)
				{
					ans = tmp;
				}
			}

		}

		cout << ans << endl;
		return 0;
	}

}

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

int main() {

	string s;
	cin >> s;

	int a = 0, b = 0;//a:0はじまり,b:1はじまり

	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			if (s.at(i) == '0') {
				b++;
			}
			else if (s.at(i) == '1') {
				a++;
			}
		}
		else {
			if (s.at(i) == '0') {
				a++;
			}
			else if (s.at(i) == '1') {
				b++;
			}
		
		}
	
	}


	if (a - b > 0) {
		cout << b << endl;
	}
	else {
		cout << a << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

int main(void){
    cin.tie(0);
	ios::sync_with_stdio(false);
    ll n,h;
    cin>>n;
    ll dp[3] = {0,0,0};
    ll hl[3] = {0,0,0};
    rep(i,n){
        dp[0] = dp[1];
        dp[1] = dp[2];
        dp[2] = inf;
        hl[0] = hl[1];
        hl[1] = hl[2];
        hl[2] = inf;
        cin>>hl[2];
        if(i==0) dp[2] = 0;
        if(i>1) dp[2] = min({dp[0]+abs(hl[0]-hl[2]),dp[1]+abs(hl[1]-hl[2])});
        else if(i>0) dp[2] = dp[1]+abs(hl[2]-hl[1]);
    }
    cout<<dp[2]<<endl;
}


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

#define ll long long
#define ld long double
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//    ll a,b;
//    cin >> a >> b;
//    if (a == b) cout << "Impossible" << endl;
//    else cout << "Possible" << endl;
    ll n,k;
    cin >> n >> k;
    ll a[n+1];
    for (ll i = 1; i <= n; i++)
        cin >> a[i];
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    ll answ = 0;
    for (ll i = 1; i <= k; i++)
        answ += a[i];
    cout << answ << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Monad (replicateM)
import Data.List (sort)

main :: IO ()
main = do
    n <- readLn
    s <- replicateM n readLn
    print $ solve s

solve :: [Int] -> Int
solve x
    | s `mod` 10 /= 0 = s
    | otherwise = t2
    where
        s  = sum x
        t1 = dropWhile (\x -> x `mod` 10 == 0) . sort $ x
        t2 = if null t1 then 0 else s - head t1

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

int main() {
    long long n, m;
    std::cin >> n >> m;
    std::vector<std::deque<long long>> g(n);
    for (int i = 0; i < m; i++) {
        long long a, b;
        std::cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    std::set<long long> s, res;
    s.insert(0);
    for (auto to : g[0]) s.insert(to);
    for (auto i : s) for (auto to : g[i]) res.insert(to);

    std::cout << (res.find(n - 1) != res.end() ? "POSSIBLE" : "IMPOSSIBLE") << std::endl;

    return 0;
}

Measured memory_bytes: 145664
package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)

	primes := listPrimes(n)

	primeCnts := make(map[int]int, 0)
	for m := 1; m <= n; m++ {
		ps := primeFactors(m, primes)
		for _, p := range ps {
			primeCnts[p] += 1
		}
	}

	// Awful...
	n2to3 := 0
	n4to := 0
	n4to13 := 0
	n14to := 0
	n2to23 := 0
	n24to := 0
	n74to := 0
	for _, cnt := range primeCnts {
		if 2 <= cnt && cnt < 4 {
			n2to3 += 1
		}
		if 4 <= cnt {
			n4to += 1
		}
		if 4 <= cnt && cnt < 14 {
			n4to13 += 1
		}
		if 14 <= cnt {
			n14to += 1
		}
		if 2 <= cnt && cnt < 24 {
			n2to23 += 1
		}
		if 24 <= cnt {
			n24to += 1
		}
		if 74 <= cnt {
			n74to += 1
		}
	}

	// 5 * 5 * 3 = 75
	n4_4_2 := combi(n4to, 2) * combi(n2to3+n4to-2, 1)
	// 15 * 5 = 75
	n14_4 := combi(n14to, 1) * combi(n4to13+n14to-1, 1)
	// 25 * 3 = 75
	n24_2 := combi(n24to, 1) * combi(n2to23+n24to-1, 1)

	total := n4_4_2 + n14_4 + n24_2 + n74to
	fmt.Println(total)
}

func listPrimes(limit int) []int {
	ns := make([]int, limit-1)
	for i := 2; i <= limit; i++ {
		ns[i-2] = i
	}

	divided := make([]bool, limit+1)

	ps := make([]int, 0)
	for _, n := range ns {
		if divided[n] {
			continue
		}
		ps = append(ps, n)
		for i := n; i < len(divided); i += n {
			divided[i] = true
		}
	}

	return ps
}

func primeFactors(n int, primes []int) []int {
	ps := make([]int, 0)
	idx := 0
	for n > 1 {
		p := primes[idx]
		if n%p == 0 {
			n /= p
			ps = append(ps, p)
		} else {
			idx += 1
		}
	}

	return ps
}

func factorial(n int) []int {
	fs := make([]int, n)
	for i := 0; i < n; i++ {
		fs[i] = n - i
	}
	return fs
}

func combi(a, b int) int {
	if a <= 0 || b <= 0 {
		return 0
	}

	denom := product(factorial(a)[0:b])
	numer := product(factorial(b))
	return denom / numer
}

func product(ns []int) int {
	v := 1
	for _, n := range ns {
		v *= n
	}
	return v
}


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

string reverse( string a );
string linking( string a, string b, int p );

int main()
{
    int n;
    string s, a, b;
    vector<string> v;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> s;

        int ss = s.size();
        for( int j = 1; j < ss; j++ )
        {
            a = "";
            b = "";
            for( int k = 0; k < j; k++ )
                a += s[k];
            for( int k = j; k < ss; k++ )
                b += s[k];
            for( int k = 0; k < 8; k++ )
            {
                string res = linking( a, b, k );
                vector<string>::iterator itr;
                for( itr = v.begin(); itr != v.end(); itr++ )
                    if( *itr == res )
                        break;
                if( itr == v.end() )
                    v.push_back( res );
            }
        }
        cout << v.size() << endl;
        v.clear();
    }
    return 0;
}

string reverse( string a )
{
    string res = "";
    for( int i = a.size() - 1; i >= 0; i-- )
        res += a[i];
    return res;
}

string linking( string a, string b, int p )
{
    switch( p )
    {
        case 0:
            return a + b;
            break;
        case 1:
            return reverse(a) + b;
            break;
        case 2:
            return a + reverse(b);
            break;
        case 3:
            return reverse(a) + reverse(b);
            break;
        case 4:
            return b + a;
            break;
        case 5:
            return reverse(b) + a;
            break;
        case 6:
            return b + reverse(a);
            break;
        case 7:
            return reverse(b) + reverse(a);
            break;
    }
}


Measured memory_bytes: 3104
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<string>
#include<map>
#include<list>
 
using namespace std;
 
using ll = long long int ;
 
 
int main(void){
	cin.tie(0);ios::sync_with_stdio(false);
 
    ll r;
    ll ans;
 
    cin >> r;

    ans = r*r;

    cout << ans << endl;
 
    return 0;
}

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

int main(void) {
  int i, j, num[4], min = 500;
  char s[400];
  scanf("%s", s);
  for(i = 0; i < 4; ++i) num[i] = 0;
  for(i = 0; i < strlen(s); ++i) {
    if(s[i] == 'K') ++num[0];
    else if(s[i] == 'U') ++num[1];
    else if(s[i] == 'P') ++num[2];
    else if(s[i] == 'C') ++num[3];
  }
  for(i = 0; i < 4; ++i) if(min > num[i]) min = num[i];
  printf("%d\n", min);
  return 0;
}


Measured memory_bytes: 2752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  prllf("%d",x);
#define pl(x)  prllf("%lld",x);
#define pf(x)  prllf("%.10lf",x);
#define ps(x)  prllf("%s",x);
#define en() prllf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define mod 100000007
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}
ll prime[1000000];bool visprime[10000000];
void sieve(){ll k=0;for(ll i=2;i*i<=1000000;i++){for(ll j=i*i;j<=1000000;j+=i){visprime[j]=true;}}for(ll i=2;i<=1000000;i++){if(visprime[i]==false) prime[k++]=i;}}


int main()
{
    int n;
    cin>>n;
    int arr[n];
    vector<pair<int,int>>p;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        p.pb({arr[i],i+1});
    }
    sort(p.begin(),p.end());

    for(auto u:p)
    {
        cout<<u.second<<" ";
    }
    cout<<endl;

}
























Measured memory_bytes: 2164
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#define MAX_N 100005

using namespace std;

int n;
vector<int> v;
vector<int> edge[MAX_N];

bool dfs1(int x,int p)
{
	v.push_back(x);
	if(x==n) return true;
	for(int i=0;i<edge[x].size();i++)
	{
		int t=edge[x][i];
		if(t!=p && dfs1(t,x)) return true;
	}
	v.pop_back();
	return false;
}

int dfs2(int x,int p)
{
	int ans=1;
	for(int i=0;i<edge[x].size();i++)
	{
		int t=edge[x][i];
		if(t!=p) ans+=dfs2(t,x);
	}
	return ans;
}

int main()
{
	scanf("%d",&n);
	int x,y;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	dfs1(1,0);
	int md=(v.size()-1)>>1;
	x=dfs2(v[md],v[md+1]);
	y=dfs2(v[md+1],v[md]);
	printf("%s\n",x>y ? "Fennec" : "Snuke");
}


Measured memory_bytes: 10872
#include <bits/stdc++.h>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>

#define fir first
#define sec second
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define repdown(i, j, k) for(int (i)=(j);(i)>=(j);(i)--)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using ll = long long;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using namespace std;

const int Mod = 1e9 + 7;
const int max_n = 3 * 1e5 + 1;
const int max_m = 83 * 1e5 + 1;
const ll INF = 10241024;
long double INFD = 100100100;

//_________template______________
inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

//_____________________array calc____________________________________//
/*
vvi mul(vvi &A, vvi &B){
  vvi C(A.size(), vi(B.size()))
  rep(i,A.size()){
    rep(j,B.size()){
      rep(k,B[0].size()){
        C[i][j] = (C[i][j] A[i][k] + B[k][j]) % Mod;
      }
    }
  }

  return C;
}

vvi pow(vvi A, ll n){
  vvi B(A.size(), vi(A.size()));
  rep(i=0;i<A.size();i++){
    B[i][i] = 1;
  }

  while (n >0){
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n = n >> 1;
  }
  return B;
}
*/
//_____________________Bynary Indexed Tree __________________________//
/*
const max_st = (1 << 15) - 1;
int bit[max_st];
int sum (int i){
  int s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, int x){
  while(i <= n){
    bit[i] += x;
    i += i & -i;
  }
}
*/
//_____________________　following sorce code_________________________//
int n;
struct edge{
  int id, to;
};

vector<vector<edge> > dist;
vi ans(max_n, 0);

void input(){
  IN(n);
  dist.resize(n);
  rep(i,n-1){
    int a,b;IN(a,b);--a;--b;
    dist[a].push_back((edge){i, b});
    dist[b].pb((edge){i, a});
  }
}

void dfs (int v, int c=-1, int u=-1){
  int loc = 1;
  vector<edge> a = dist[v];
  for(int i=0;i<a.size();i++){
    if(u == a[i].to)continue;
    if(loc == c)loc++;
    ans[a[i].id] = loc;
    dfs(a[i].to, loc, v);
    loc++;
  }
}

void solve(){
  input();
  dfs(0);
  int res = 0;
  rep(i,n-1)chmax(res, ans[i]);
  OUT(res);
  rep(i,n-1)OUT(ans[i]);
}

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





Measured memory_bytes: 11136
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef long long ll;

int n;

int isNotPrime[110];
int primes[110];
int nPrime;

int rs[110];

int main(void) {
  isNotPrime[0] = isNotPrime[1] = 1;
  REP(p, 101) {
    if(!isNotPrime[p]) {
      primes[nPrime++] = p;
      for(int j = p + p; j <= 100; j += p) {
        isNotPrime[j] = p;
      }
    }
  }
  cin >> n;
  for(int i = 1; i <= n; ++i) {
    int cur = i;
    REP(j, nPrime) {
      while(cur % primes[j] == 0) {
        cur /= primes[j];
        rs[j]++;
      }
    }
  }
  int res = 0;
  // 75
  REP(i, nPrime) {
    if(rs[i] >= 74) {
      ++res;
    }
  }
  // 25*3
  REP(i, nPrime) {
    REP(j, nPrime) {
      if(i == j) {
        continue;
      }
      if(rs[i] >= 24 && rs[j] >= 2) {
        ++res;
      }
    }
  }
  // 15*5
  REP(i, nPrime) {
    REP(j, nPrime) {
      if(i == j) {
        continue;
      }
      if(rs[i] >= 14 && rs[j] >= 4) {
        ++res;
      }
    }
  }
  // 5*5*3
  REP(i, nPrime) {
    REP(j, i) {
      REP(k, nPrime) {
        if(i == k || j == k) {
          continue;
        }
        if(rs[i] >= 4 && rs[j] >= 4 && rs[k] >= 2) {
          ++res;
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
struct P{
	int p[100010];
	void init()
	{
		for(int i=1;i<=n;i++)
			p[i]=i;
	}
};
P res;
P operator *(const P& a,const P& b)
{
	for(int i=1;i<=n;i++)
		res.p[i]=a.p[b.p[i]];
	return res;
}
P ans,t;
P fpow(const P& a,int b)
{
	ans.init();t=a;
	while(b)
	{
		if(b&1)ans=ans*t;
		t=t*t;
		b>>=1;
	}
	return ans;
}
P tmp;
P getinv(const P& a)
{
	for(int i=1;i<=n;i++)
		tmp.p[a.p[i]]=i;
	return tmp;
}
P A,Ainv,p,pinv,q,qinv,fans;
P a[7];
void input(P& a)
{
	for(int i=1;i<=n;i++)
		scanf("%d",&a.p[i]);
	return ;
}
int main()
{
	int k;
	scanf("%d %d",&n,&k);
	input(p);input(q);
	pinv=getinv(p);
	qinv=getinv(q);
	A=q*pinv*qinv*p;
	Ainv=getinv(A);
	a[1]=p;
	a[2]=q;
	for(int i=3;i<=6;i++)
		a[i]=a[i-1]*getinv(a[i-2]);
	fans=fpow(A,(k-1)/6)*a[(k-1)%6+1]*fpow(Ainv,(k-1)/6);
	for(int i=1;i<=n;i++)
		printf("%d ",fans.p[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 11776
/*
AOJ - ITP1_7_d
Date: 20181002
Author: Mikoron * ♡mikoiwate♡
 */

#define MAX 100

#include<stdio.h>

int main(void) {
        short i, j, k, n, m, l;
        long nm[MAX][MAX], ml[MAX][MAX], nl[MAX][MAX];

        scanf("%hd %hd %hd", &n, &m, &l);


        //initialize
        for(i = 0; i < MAX; i++) {
                for(j = 0; j < MAX; j++) {
                        nm[i][j] = ml[i][j] = nl[i][j] = 0;
                }
        }

        //input
        for(i = 0; i < n; i++) {
                for(j = 0; j < m; j++) {
                        scanf("%ld", &nm[i][j]);
                }
        }

        for(i = 0; i < m; i++) {
                for(j = 0; j < l; j++) {
                        scanf("%ld", &ml[i][j]);
                }
        }

        //calc & output
        for(i = 0; i < n; i++) {
                for(j = 0; j < l; j++) {
                        for(k = 0; k < m; k++) {
                                nl[i][j] += nm[i][k] * ml[k][j];
                        }
                        if(j != l-1) printf("%ld ", nl[i][j]);
                        else printf("%ld", nl[i][j]);
                }
                printf("\n");
        }
        return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        ll n;
        cin >> n;
        vl a(n + 1);
        rep(i, n + 1) cin >> a[i];
        vl b(n);
        rep(i, n) cin >> b[i];

        ll ans = 0;
        for (ll i = 0; i < n; ++i) {
            ll tm = min(b[i], a[i]);
            a[i] -= tm;
            b[i] -= tm;
            ans += tm;

            ll tmp = min(b[i], a[i + 1]);
            ans += tmp;
            b[i] -= tmp;
            a[i + 1] -= tmp;
        }
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a,b,c,d=0,n,m1,n2,m2,min=100000,k=0,ans=0;
    string s,s2;
    cin >> n;
    for(int i=1;n>=c;i++){
        d = c;
        c = i * i;
    }
    cout << d <<endl; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    ll n;
    cin>>n;
    cout<<((n&1)?n*2:n);
  	return 0;
}

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

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

using namespace std;

int main(){
	int n; scanf("%*d%*d%d",&n);
	vector<int> x(n),y(n);
	rep(i,n) scanf("%d%d",&x[i],&y[i]);

	map<int,set<int>> X,Y;
	rep(i,n){
		X[y[i]].emplace(x[i]);
		Y[x[i]].emplace(y[i]);
	}

	int cx=0,cy=0;
	for(auto p:X) cx=max<int>(cx,p.second.size());
	for(auto p:Y) cy=max<int>(cy,p.second.size());

	vector<int> Lx,Ly;
	for(auto p:X) if(p.second.size()==cx) Ly.emplace_back(p.first);
	for(auto p:Y) if(p.second.size()==cy) Lx.emplace_back(p.first);

	for(int x0:Lx) for(int y0:Ly) {
		if(X[y0].count(x0)==0 || Y[x0].count(y0)==0){
			printf("%d\n",cx+cy);
			return 0;
		}
	}
	printf("%d\n",cx+cy-1);

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back

void solve(){
    string a, b, c;
    cin >> a >> b >> c;
    cout << char(toupper(a[0])) << char(toupper(b[0])) << char(toupper(c[0]));
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3604
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_10_D

def dist(x,y,n)
    
    if n > 0 
        sum=0.0
        for i in 0..x.size-1
            sum += ((x[i]-y[i]).abs)**n
        end
        sum **= (1.0/n)
    else
        sum=0.0
        for i in 0..x.size-1
            a = ((x[i]-y[i]).abs)
            sum = a if sum<a
        end
        sum
    end
    
end

gets
x = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)

for i in 1..3 do
    p dist(x,y,i)
end
    p dist(x,y,-1)

Measured memory_bytes: 6192
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

std::map<pair<ll,ll>, ll> memo;
ll from_0[100010];
ll to_n[100010];



ll euclidean_gcd(ll a, ll b) {
  if(a < b) euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
    Fill(from_0,0);
    Fill(to_n,0);
    ll n;
    ll a[100010];
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if(i==0){
            from_0[i] = a[i];
            to_n[n-1-i] = a[n-1-i];
        }else{
            from_0[i] = euclidean_gcd(from_0[i-1],a[i]);
            to_n[n-1-i] = euclidean_gcd(to_n[n-i],a[n-i-1]);
        }
    }
    ll result = 0;
    for (int i = 0; i < n; i++) {
        ll tmp;
        if(i==0){
            tmp = to_n[i+1];
        }else if(i==n-1){
            tmp = from_0[i-1];
        }else{
            tmp = euclidean_gcd(from_0[i-1],to_n[i+1]);
        }
        // std::cout << tmp << std::endl;
        result = max(result,tmp);
    }
    
    std::cout << result << std::endl;
}

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

int main(){
    double x1, x2, y1, y2;
    cin >> x1 >> y1;
    cin >> x2 >> y2;

    cout << setprecision(10) << sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) << endl;


    return 0;
}


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

int32_t main()
{
 ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 int n; cin>>n; int ans;
 if(n>=400 && n<=599){ans=8;}
 if(n>=600 && n<=799){ans=7;}
 if(n>=800 && n<=999){ans=6;}
 if(n>=1000 && n<=1199){ans=5;}
 if(n>=1200&& n<=1399){ans=4;}
 if(n>=1400 && n<=1599){ans=3;}
 if(n>=1600 && n<=1799){ans=2;}
 if(n>=1800 && n<=1999){ans=1;}
 cout<<ans;
}

Measured memory_bytes: 3648
from itertools import groupby

S=input()
K=int(input())

l=[(k, list(v)) for k, v in groupby(S)]
if len(l) == 1:
    n = len(S)*K // 2
else:
    n=sum([len(v)//2 for k, v in l if len(v) > 1])*K
    if l[0][0]==l[-1][0] and len(l[0][1])%2 !=0 and len(l[-1][1])%2 !=0:
        n = n + K - 1
print(n)


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

//const int INF = INT_MAX;
//vector<vector<int>> adj;

int main() {

	int n;
	cin>>n;
	int a[n][3];
	for(int i=0; i<n; i++) {
		for(int j=0; j<3; j++)
			cin>>a[i][j];
	}

	int dp[n][3];
	dp[0][0] = a[0][0];
	dp[0][2] = a[0][2];
	dp[0][1] = a[0][1];

	for(int i=1; i<n; i++) {
		
			dp[i][0] = a[i][0] + max(dp[i-1][1],dp[i-1][2]);
			dp[i][1] = a[i][1] + max(dp[i-1][0],dp[i-1][2]);
			dp[i][2] = a[i][2] + max(dp[i-1][0],dp[i-1][1]);
		
	}

	int sum = 0;
	for(int i=0; i<3; i++) {
		if(sum < dp[n-1][i])
			sum = dp[n-1][i];
	}

	cout<<sum<<"\n";
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
using namespace std;
int a,b,k,x;
int main()
{
  cin>>k>>x;
  a=max(-1000000,x-k+1),b=min(1000000,x+k-1);
  cout<<a;
  for(;a<b;a++)
    cout<<" "<<a+1;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
LL a,b,x;
int main(){
	cin >> a >> b >> x;
	LL ans1 = a / x;
	LL ans2 = b / x;
	if(a%x==0) ans2++;
	printf("%lld\n",ans2-ans1);
	return 0;
	}

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

using namespace std;

long long solve(vector<int>& A){
    if(A[0]) return -1;
    long long res = 0;
    int pre = 0;
    for(auto& t : A){
        if(t >= pre + 2) return -1;
        res += (t == pre+1 ? 1 : t);
        pre = t;
    }
    return res;
}

int main(){
    int N;
    while(cin >> N){
        vector<int> A(N);
        for(auto& t : A) cin >> t;
        cout << solve(A) << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }



string ret[7] = {"null", "one pair", "two pair", "three card", "straight", "full house", "four card"};

int main() {
	vci t(5); char c;
	
	while (cin>>t[0]>>c>>t[1]>>c>>t[2]>>c>>t[3]>>c>>t[4]) {
		int ans = 0;
		
		vci v(13, 0);
		for_(i, 0, (int)t.sz) v[t[i]-1]++;
		
		int cnt = 0;
		
		// 0, 1, 2
		for_(i, 0, 13) if (v[i]==2) cnt++;
		ans = cnt;
		
		// 3
		cnt = 0;
		for_(i, 0, 13) if (v[i]==3) cnt++;
		if (cnt) ans = 3;
		
		// 4
		for_(i, 0, 10) {
			cnt = 0;
			for_(j, 0, 5) {
				if (v[(i+j)%13]==1) cnt++;
			}
			if (cnt==5) ans = 4;
		}
		
		// 5
		cnt = 0; int cnt2 = 0;
		for_(i, 0, 13) {
			if (v[i]==2) cnt++;
			if (v[i]==3) cnt2++;
		}
		if (cnt2==1 && cnt==1) ans = 5;
		
		cnt = 0;
		for_(i, 0, 13) if (v[i]==4) cnt++;
		if (cnt) ans = 6;
		
		cout << ret[ans] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
import heapq
k, t = map(int, input().split())
a = list(map(int, input().split()))
a = [-i for i in a]
heapq.heapify(a)
while len(a) > 1:
    m = heapq.heappop(a)
    while m < 0 and len(a) > 0:
        n = heapq.heappop(a)
        if n <= m:
            heapq.heappush(a, n-m)
            m = 0
        else:
            m -= n
    if m < 0:
        heapq.heappush(a, m)
res = heapq.heappop(a)

print(max(-res-1, 0))



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

int main() {
	int n, m;
	cin >> n >> m;
	int k, a,food[31];
	for (int i = 0; i < 31; i++) {
		food[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> a;
			food[a] += 1;
		}
	}
	int ans = 0;
	for (int i = 0; i < 31; i++) {
		if (food[i] == n) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int n,s,t,p,m;
string str[2];
string day[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
string ti[2]={"Day","Night"};
bool ok[2][7];
double pts[101];

double check(int n_day,int n_time,int n_stage){
	//printf("%d\n",n_stage);
	if(n_stage==m){
		double out=1.0;
		for(int i=0;i<m;i++){
			out*=pts[i];
		}
		return 1.0-out;
	}else{
		int rest=s;
		pts[n_stage]=1.0;
		bool flag=true;
		while(rest>0){
			//printf("%d %d %d %d\n",rest,n_time,n_day,rest);
			if(360<=n_time && n_time<1080){
				int tt=min(1080-n_time,rest);
				if(!ok[0][n_day])flag=false;
				n_time+=tt;
				rest-=tt;
			}else if(n_time<360){
				int tt=min(360-n_time,rest);
				if(!ok[1][n_day])flag=false;
				//printf("%d %d %d\n",tt,n_time,rest);
				n_time+=tt;
				rest-=tt;
				//printf("%d %d %d\n",tt,n_time,rest);
			}else{
				int tt=min(1440-n_time,rest);
				if(!ok[1][n_day])flag=false;
				n_time+=tt;
				rest-=tt;
			}
			if(n_time>=1440){
				n_time-=1440;
				n_day=(n_day+1)%7;
			}
		}
		if(360<=n_time && n_time<1080){
			if(!ok[0][n_day])flag=false;
		}else if(n_time<360){
			if(!ok[1][n_day])flag=false;
		}else{
			if(!ok[1][n_day])flag=false;
		}
		if(flag)pts[n_stage]*=pow((double)(p-1)/p,n);
		n_time+=t-s;
		if(n_time>=1440){
			n_time-=1440;
			n_day=(n_day+1)%7;
		}
		check(n_day,n_time,n_stage+1);
	}
}

int main(void){
	while(1){
		cin >> s >> n >> t >> str[0] >> str[1] >> p >> m;
		if(s+n+t+p+m==0)break;
		memset(ok,false,sizeof(ok));
		if(str[0]=="All"){
			if(str[1]=="All")memset(ok,true,sizeof(ok));
			if(str[1]==ti[0])memset(ok[0],true,sizeof(ok[0]));
			if(str[1]==ti[1])memset(ok[1],true,sizeof(ok[1]));
		}else{
			for(int i=0;i<7;i++){
				if(str[0]==day[i]){
					if(str[1]=="All")ok[0][i]=ok[1][i]=true;
					if(str[1]==ti[0])ok[0][i]=true;
					if(str[1]==ti[1])ok[1][i]=true;
				}
			}
		}
		double res=0.0;
		for(int i=0;i<7;i++){
			for(int j=0;j<1440;j++){
				//printf("%d\n",j);
				res=max(res,check(i,j,0));
			}
		}
		printf("%.10f\n",res);
	}
	return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
using namespace std;

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

signed main() {
    string s; cin >> s;
    string t = "abcdefghijklmnopqrstuvwxyz";
    vector<int> cnt(t.size(), 0);

    FOR(i, s.size()){
        int idx = t.find(s[i]);
        cnt[idx]++;
    }

    bool flag = true;
    FOR(i, cnt.size()) {
        if(cnt[i] % 2 == 1) flag = false;
    }

    cout << (flag ? "Yes" : "No") << endl;

}


Measured memory_bytes: 256
program ABC_091_B_TwoColorsCardGame
   implicit none
   integer N, M, i, j
   character(10), allocatable :: s(:), t(:)
   integer, allocatable :: counts(:)
   read(*, *) N
   allocate (s(1: N))
   allocate (counts(0: N))
   do i = 1, N
      read(*, *) s(i)
   end do
   read(*, *) M
   allocate (t(1: M))
   do i = 1, M
      read(*, *) t(i)
   end do
   counts(:) = 0
   do j = 1, N
       do i = 1, N
          if(s(j) == s(i)) then
	      counts(j) = counts(j) + 1
		  end if
	   end do
	   do i = 1, M
          if(s(j) == t(i)) then
	      counts(j) = counts(j) - 1
		  end if
	   end do
   end do
   write(*, *) maxval(counts)
end program ABC_091_B_TwoColorsCardGame 

Measured memory_bytes: 256
H,W = map(int,input().split())
Pic = [input() for i in range(H)]

ansPic = ["" for i in range(2*H)]

for i in range(H):
    ansPic[2*i] = Pic[i]
    ansPic[2*i+1] = Pic[i]
    
for i in ansPic:
    print(i)

Measured memory_bytes: 3060
from operator import mul
from functools import reduce

def combination(n, r):
    if not 0 <= r <= n: return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N = int(input())
S = input()

R = dict()
L = dict()


R["R"] = S.count("R")
L["R"] = 0
R["G"] = S.count("G")
L["G"] = 0
R["B"] = S.count("B")
L["B"] = 0

def num(n, x):
    res = 0
    for i in range(1,min(n,N-1-n) + 1):
        if S[n-i] != x and S[n+i] != x and S[n-i] != S[n+i]:
            res += 1
    return res

R[S[0]] -= 1
L[S[0]] += 1
res = 0
for i in range(1,N-1):
    x = S[i]
    R[x] -= 1
    three = sum( R[x]*L[x]for x in ["R","G","B"])
    res += three + ((N-1-i)-R[x])*L[x] + R[x]*(i-L[x]) + num(i,x)
    L[x] += 1

print(combination(N,3) - res)


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

int main(){
    
    int N,M;

    cin >> N >> M;

    vector<int> H(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    

    vector<set<int>> G(N);

    for (size_t i = 0; i < M; i++)
    {
        int A,B;
        cin >> A >> B;

        A--;B--;

        G[A].insert(B);
        G[B].insert(A);
    }

    vector<bool> result(N,true);

    
    for (size_t i = 0; i < N; i++)
    {
        for(auto temp:G[i]){
            if(H[i]>H[temp]){
                result[temp]=false;
            }else if(H[i]<H[temp]){
                result[i]=false;
            }else{
                result[temp]=false;
                result[i] = false;
            }
        }
    }
    

    cout << count(result.begin(),result.end(),true) << endl;

    return 0;
}

Measured memory_bytes: 17792
#include <stdio.h>

char s[999];
int main(){
	int n;
	scanf("%d",&n);
	if(n==0){
		puts("0");
		return 0;
	}
	int p=900;
	while(n){
		s[--p]='0'+(n&1);
		n=(n-(n&1))/-2;
	}
	puts(s+p);
}


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


def check(A):
    for a in A:
        if a % 2 == 1:
            continue
        if a % 3 == 0 or a % 5 == 0:
            continue
        return False
    return True


if check(A):
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 2940
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
    int A, B;
    cin >> A >> B;
    if(A > 8 || B > 8) {
        cout << ":(";
    } else {
        cout << "Yay!";
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close \
    std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c)         \
    (sort(c.begin(), c.end()), \
     c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define CASET    \
    int ___T;    \
    cin >> ___T; \
    for (int __CS = 1; __CS <= ___T; __CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
LL bin(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6 + 10;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9 + 7;
void add(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}
void dec(int &a, int b) {
    a -= b;
    if (a < 0) a += mod;
}
int main() {
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> ans(n + 10, 0);
    ans.eb(n);
    int p = abs(y - x);
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (i <= x) {
                if (j <= x) {
                    ans[j - i]++;
                } else if (j <= y) {
                    ans[min(y - j + 1 + x - i, j - i)]++;
                } else {
                    ans[x - i + j - y + 1]++;
                }
            } else if (x < i && i < y) {
                if (j <= y) {
                    ans[min(j - i, y - j + 1 + i - x)]++;
                } else
                    ans[min(j - i,i-x+1+j-y)]++;
            } else {
                ans[j - i]++;
            }
        }
    }
    for (int i = 1; i <= n - 1; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
s = input()

a = 0
for i in range(1000):
    i = '%03d' % i
    ss = s
    for c in i:
        p = ss.find(c)
        if p == -1:
            break
        ss = ss[p + 1:]
    else:
        a += 1

print(a)

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

int main() {
  string s,p,ss;
  cin >> s >> p;
  ss = s+s;
  for(int i = 0;i < s.size();i++){
    if(p == ss.substr(i,p.size())){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}



Measured memory_bytes: 3216
import math
x=int(input())
yn=0
count=x-1
for i in range(x,x+100):
    count+=1
    yn=0
    for j in range(2,int(math.sqrt(count))+1):
        if count%j==0:
            yn=1
            break
        else:
            continue
    if yn==0:
        ans=count
        break
print(ans)


Measured memory_bytes: 3060
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long h = sc.nextLong();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		int ans = 0;
		long dame = 0;
		Arrays.sort(a);
		Arrays.sort(b);
		for(int i = n-1; i >= 0 && dame < h; i--){
			if(b[i] > a[n-1]){
				ans++;
				dame+=b[i];
			}else{
				break;
			}
		}
		ans+=h-dame>0?(int)((h-dame)/a[n-1])+((h-dame)%a[n-1]==0?0:1):0;
		System.out.print(ans);
	}
}


Measured memory_bytes: 85296
#include<bits/stdc++.h>
using namespace std;
#define MN 300000
char s[MN+5];
int l[MN+5],r[MN+5]; 
int main()
{
	int n,i,ans=1e9;
	scanf("%d%s",&n,s+1);
	for(i=1;i<=n;++i)l[i]=l[i-1]+(s[i]=='W');
	for(i=n;i;--i)r[i]=r[i+1]+(s[i]=='E');
	for(i=1;i<=n;++i)ans=min(ans,l[i-1]+r[i+1]);
	printf("%d",ans); 
}

Measured memory_bytes: 2944
# input
N, K, Q = gets.split.map(&:to_i)
A = Q.times.map{gets.to_i}

# compute
C = Array.new(N, 0)
A.each do |i|
    C[i-1] += 1
end

# output
N.times do |i|
    puts (K - Q + C[i] > 0 ? "Yes" : "No")
end



Measured memory_bytes: 5756
//https://atcoder.jp/contests/abc166/tasks/abc166_e
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<static_cast<ll>(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main(){
#if LOCAL&01
  std::ifstream in("./test/sample-1.in");
  //std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  ll N; cin>>N;
  vector<ll> an(N+1);
  struct Info{
    ll a;
    ll ij;
    Info(ll ia,ll ii)
    : a(ia),ij(ii){}
  };
  unordered_map<ll,vector<Info>> itbl,jtbl;
  FOR(i,1,N+1){
    ll a; cin>>a;
    an.at(i)=a;
    auto aii=i+a;
    itbl[aii].push_back(Info(a,i));
    auto jaj=i-a;
    jtbl[jaj].push_back(Info(a,i));
  }

  ll ans=0;
  for(auto& aij:itbl){
    auto it = jtbl.find(aij.first);
    if (it != jtbl.end()){
      ans += (aij.second.size() * it->second.size());
    }
  }

  cout<<ans<<endl;

  return 0;
}


int main_() {
  ll N; cin>>N;
  vector<ll> an(N+1);
  FOR(i,1,N+1){
    cin>>an.at(i);
  }
  ll ans=0;
  FOR(i,1,N+1){
    FOR(j,i+1,N+1){
      ll v=abs(j-i);
      if(an[i]+an[j]==v){
        ++ans;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 37988
def euclid_devider(num_devided, num_devider):
    while num_devided % num_devider != 0:
        temp = num_devided % num_devider
        num_devided = num_devider
        num_devider = temp
    return num_devider

N = int(input())
A = list(map(int, input().split()))
ans = A[0]
for i in range(1,N):
    ans = euclid_devider(A[i], ans)
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string str;

    while(true)
    {
        getline(cin, str);
        if(str == "0"){ break; }


        int sum = 0;
        for(size_t i = 0; i < str.length(); i++)
        {
            sum += str[i] - '0';
        }
        cout << sum << endl;

    }

    return 0;
}

Measured memory_bytes: 3172
#include <stdio.h>

int main(void)
{
    int i, N;
    int A[200001];
    int max=0, sub_max=0, max_index;

    scanf("%d",&N);
    for(i=0; i<N; i++){
        scanf("%d",&A[i]);
    }

    for(i=0; i<N; i++){
        if(max < A[i]){
            max = A[i];
            max_index = i;
        } else if(sub_max <A[i]){
            sub_max = A[i];
        }
    }

    for(i=0; i<N; i++){
        if(max_index == i){
            printf("%d\n",sub_max);
        } else {
            printf("%d\n",max);
        }
    }

    return 0;
}

Measured memory_bytes: 2304
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	vector<ll> rain(n); fore(e, rain) cin >> e;
	ll amt = 0;
	forl(i, 0, n) {
		if(i%2) amt -= rain[i];
		else amt += rain[i];
	}
	rain.push_back(rain[0]);
	vector<ll> ans = {amt};
	forl(i, 0, n-1) {
		ans.push_back((rain[i]-(ans.back()/2))*2);
	}
	printe(ans);
}


Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
typedef pair<int,int> P;
typedef pair<int,P> PP; 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1e9+7;

signed main(){
  int n,l;
  cin>>n>>l;
  int sum=0;
  for(int i=0;i<n;i++){
    sum+=l+i;
  }
  int ans=sum,mi=MOD;
  for(int i=0;i<n;i++){
    if(abs(l+i)<mi){
	 mi=abs(l+i);
	 ans=sum-(l+i);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int a,b;
  string s;
  cin >> a >> b >> s;
  
  rep(i,a){
    if(s[i]=='-') {
      puts("No");
      return 0;
    }
  }
  
  if(s[a]!='-') {
    puts("No");
    return 0;
  }
  
    rep(i,b){
    if(s[a+i+1]=='-') {
    puts("No");
    return 0;
    }
  }
  
  cout << "Yes" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

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

const int INF = 1e9 + 7;

int ok[66];

void add(int x) {
	while(x) {
		int k = __lg(x);
		if(ok[k] == 0) {
			ok[k] = x;
			break;
		} else {
			x ^= ok[k];
		}
	}
}

bool can(int x) {
	for(int i = 63; i>= 0; i--) {
		if(x >> i & 1) {
			if(ok[i] == 0) return false;
			x ^= ok[i];
		}
	}
	return true;
}

void solve() {
	memset(ok, 0, sizeof ok);
	int n;
	cin >> n;
	vi a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	string s;
	cin >> s;
	for(int i = n - 1; i >= 0; i--) {
		if(s[i] == '0') {
			add(a[i]);
		} else {
			if(!can(a[i])) {
				cout << 1 << endl;
				return ;
			}
		}
	}
	cout << 0 << endl;
}

signed main()
{
	IO_OP;
	
	int t;
	cin >> t;
	while(t--) {
		solve();
	}	
	
}





Measured memory_bytes: 3612