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

int main()
{
	int n, d;
	while (cin >> n >> d, n){
		vector<int> s(n, 0);
		vector<deque<int>> q(n);
		for (int i = 0; i < n; i++){
			int m;
			cin >> m;
			for (int j = 0; j < m; j++){
				int c;
				cin >> c;
				q[i].push_back(c);
				s[i] += c;
			}
		}
		while (true){
			bool update = false;
			for (int i = 0; i < n; i++){
				while (!q[i].empty()){
					int t = s[i];
					s[i] -= q[i].back();
					int maxi = *max_element(begin(s), end(s));
					if (maxi - s[i] <= d){
						q[i].pop_back();
						update = true;
					}
					else {
						s[i] = t;
						break;
					}
				}
			}
			if (!update) break;
		}
		bool res = true;
		for (int i = 0; i < n; i++){
			if (!q[i].empty()) res = false;
		}
		cout << (res ? "Yes" : "No") << endl;
	}
}

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

N = int(input())
A = list(map(int, input().split()))
S = [0]
for a in A:
    S += [S[-1] + a]

ans = float("inf")
l = 0
r = 2
for i in range(1, N - 1):
    while S[l] < S[i] - S[l + 1]:
        l += 1
    while S[r] - S[i] < S[N] - S[r + 1]:
        r += 1

    a = S[l]
    b = S[i] - S[l]
    c = S[r] - S[i]
    d = S[N] - S[r]

    ans = min(ans, max(a, b, c, d) - min(a, b, c, d))
print(ans)

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

int main()
{
    char S[1001];
    int n;

    scanf("%s\n",&S);

    n=strlen(S);
    
    if(S[n-1]=='s'){
        printf("%ses\n",S);
    }
    else{
        printf("%ss\n",S);
    }

    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000

int main() {
	
	long long N,K;
	cin>>N>>K;
	cout<<min(N%K,K-(N%K))<<endl;
	
    return 0;
}


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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);

	int m;
	for(m=1;m*(m-1)/2<n;m++);
	if(m*(m-1)/2!=n) return puts("No"),0;

	vector<vector<int>> A(m,vector<int>(m));
	int e=0;
	rep(u,m) for(int v=u+1;v<m;v++) {
		A[u][v]=A[v][u]=e;
		e++;
	}

	printf("Yes\n%d\n",m);
	rep(u,m){
		printf("%d",m-1);
		rep(v,m) if(v!=u) printf(" %d",A[u][v]+1);
		puts("");
	}

	return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
vl modinv;
void fillModInv(ll n, ll mod){
  modinv = vl(n+1);
  modinv[1] = 1;
  FOR(i,2,n+1){
    modinv[i] = modinv[mod%i] * (mod - mod/i) % mod;
  }
}
/*}}}*/
int main() {
  string s;
  cin >> s;

  ll n = s.length();
  //cout << s << endl;
  vector<vl> md(2,vl(2019,0));
  ll ans = 0;
  FOR(i,1,n+1){
    char c = s[i-1];
    ll num = (ll)(c-'0');
    REP(j,2019){
      md[i&1][(j*10+num)%2019] += md[(i-1)&1][j];
    }
    REP(j,2019){
      md[(i-1)&1][j] = 0;
    }
    md[i&1][num] += 1;
    ans += md[i&1][0];
  }
  
  //cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
    int l,r;
    cin>>l>>r;
    if(r - l >= 2018 || l%2019 > r%2019){
        cout<<0<<endl;
        return 0;
    }
    int ans = 2019;
    l = l % 2019;
    r = r % 2019;
    for(int i = l; i < r;i++){
        for(int j = l + 1;j < r+1;j++){
            if(i * j % 2019 < ans){
                ans = i * j % 2019;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
defmodule Main do
  def main do
      s =
      IO.read(:line)
      |> String.trim
      subs = String.slice(s, 2..-2)
      s = String.to_charlist(s)
      subs = String.to_charlist(subs)
      ans = "AC"
      ans = if List.first(s) != ?A do
      	"WA"
      else
        "AC"
      end
      sz = s |> length
      ans = if ans == "AC" do
        if s |> Enum.filter(fn(x) -> x >= ?a and x <= ?z end) |> length != sz - 2 do
          "WA"
          else
          "AC"
        end
        else
        "WA"
      end
      ans = if ans == "AC" do
        if Enum.count(subs, fn x -> x == ?C end) != 1 do
          "WA"
          else
          "AC"
        end
        else
        "WA"
       end
      IO.puts(ans)
      
  end
end


Measured memory_bytes: 31216
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long long int monster(long long int x) 
{
	long long int hoge = 2;
	for (int i = 0; i < x; i++) 
	{
		if (x < hoge) 
		{
			return hoge - 1;
		}
		else 
		{
			hoge *= 2;
		}
	}
}

int main()
{
	long long int H;
	cin >> H;
	
	cout << monster(H) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <unordered_map>
#include <assert.h>
using namespace std;

#define ran(i, a, b) for ((i) = (a); (i) < (b); (i)++)
#define rep(i, a) ran ((i), 0, (a))
#define rep1(i, a) ran ((i), 1, (a)+1)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
#define _0 first
#define _1 second
#define _pb(x) push_back(x)
#define _mp(x, y) make_pair(x, y)
#if defined(SHIROKO1_LOCAL) && !defined(NDEBUG)
#define DEBUG(...) fprintf(stderr, "[DEBUG] " __VA_ARGS__)
#else
#define DEBUG(...) ((void)0)
#endif

int main()
{
	int N;
	static int p[100100];
	int i;
	cin >> N;
	rep (i, N)
		cin >> p[i];
	int ans = 0;
	int l = 0;
	rep (i, N) {
		if (p[i] == i+1) {
			if (!l) {
				ans++;
				l = 1;
			} else l = 0;
		} else
			l = 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
N = int(input())
ans = [0]*(N+1)
for x in range(1, 500):
    for y in range(1, 500):
        for z in range(1, 500):
            tmp = x**2+y**2+z**2+x*y+y*z+z*x
            if N >= tmp:
                ans[tmp] += 1
for a in ans[1:]:
    print(a)


Measured memory_bytes: 69384
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define RREP(i, n) for(int i=0; i>(int)(n); i--)
#define ALL(v) v.begin(), v.end()
#define INF 1e9
typedef long long ll;
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(a>b){a=b; return 1;}return 0;}

using namespace std;

int h[100001], dp[100001];

int main(void){
	int N;
	cin >> N;
	REP(i, N){
		cin >> h[i];
	}
	REP(i, N){
		dp[i] = INF;
	}
	dp[0] = 0;

	REP(i, N){
		chmin(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
		chmin(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
	}
	
	cout << dp[N-1] << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 100001
#define INF   1000000000
#define p     1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

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

    double a, b, x;
    cin >> a >> b >> x;

    double ans;
    if(a*a*b/2.0 < x) {
      ans = atan(2*b/a - 2*x/(a*a*a)) * (180.0/M_PI);
    }
    else if (a*a*b/2.0 == x) {
      ans = atan(b/a) * (180.0/M_PI);
    }
    else {
      ans = 90.0 - atan(2*x/(a*b*b)) * (180.0/M_PI);
    }
    
    printf("%.12lf\n", ans);    
    
    return 0;
}
    




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

int n,m,q,ans=-1e9-7;
int now[100005];

struct node
{
	int a,b,c,d;
}que[100005];

signed main()
{
	cin>>n>>m>>q;
	for (int i=1;i<=q;i++)  cin>>que[i].a>>que[i].b>>que[i].c>>que[i].d;
	for (int i=1;i<=n;i++)  now[i]=1;
	
	while (now[0]==0)
	{
		int sumv=0;
		for (int i=1;i<=q;i++)
		{
			if (now[que[i].b]-now[que[i].a]==que[i].c)  sumv+=que[i].d;
		}
		ans=max(ans,sumv);
		
		for (int i=n;i>=0;i--)
		{
			if (now[i]<m)
			{
				 now[i]++;
				 for (int j=i+1;j<=n;j++)  now[j]=now[j-1];
				 break;
			}
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3636
n = int(input())
_, *B = [int(x) for x in input().split()]

T = 0
for b in B:
    T |= 1 << b

s = []

for i in range(1 << n):
    if (i & T) == T:
        s.append(f'{i}:')
        for j in range(n):
            if i & 1 << j:
                s.append(f' {j}')
        s.append('\n')

print(''.join(s), end='')



Measured memory_bytes: 188820
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){

    string s;cin>>s;
    map<char,int> m;
    for(auto i:s) m[i]++;
    if(m.size()>=2) cout<<"Yes";
else cout<<"No";


    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
#define MOD 1000000007

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

  for (auto i = 0; i * k <= b; i++)
  {
    if (i * k >= a)
    {
      cout << "OK" << endl;
      return 0;
    }
  }

  cout << "NG" << endl;

  return 0;
}


Measured memory_bytes: 3632
open System
open System.Collections.Generic

let ReadOne T = stdin.ReadLine()|> T
let ReadSplit T = stdin.ReadLine().Split()|>Array.map T
[<EntryPoint>]
let main argv =
    Set[for i in [0..2] do yield stdin.Read()]
    |>fun c -> if Set.count c=3 then "Yes" else "No"
    |>stdout.WriteLine
    0


Measured memory_bytes: 14304
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    inf = float("inf")
    sc = [-inf] * N
    sc[0] = 0
    ans = 0
    for i in range(2 * N):
        for ai, bi, ci in zip(a, b, c):
            ai -= 1
            bi -= 1
            sc[bi] = max(sc[bi], sc[ai] + ci)
        if i == N - 1:
            ans = sc[N - 1]
    if ans < sc[N - 1]:
        print("inf")
        return
    print(sc[N - 1])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, a, b, c)


if __name__ == '__main__':
    main()


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


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

    int ans = 0;
    int n = 2;

    while(n--){
        if(a>=b){
            ans += a;
            --a;
        }else{
            ans += b;
            --b;
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

int arr[305][305];
ll dp[305][305][305];
int gauss(int n){
  int z=0;
  REP(i,n){
    int fl=z;
    while(arr[fl][i]==0&&fl<n) fl++;
    if(fl==n) continue;
    REP(j,n) swap(arr[fl][j],arr[z][j]);  
    REPP(j,z+1,n) if(arr[j][i]){
      REP(k,n) arr[j][k]^=arr[z][k];
    }
    z++;
  }

  return z;
}
ll pw[305*305];
int main(){
  int n; scanf("%d",&n);  
  REP(i,n) REP(j,n) scanf("%d",&arr[i][j]);
  REP(i,n) REP(j,n) if(i<j) swap(arr[i][j],arr[j][i]);
  int p=gauss(n);
  dp[0][0][p]=1;
  pw[0]=1;
  REPP(i,1,n*n+5) pw[i]=pw[i-1]*2%mod;
  ll ans=0;
  REP(i,n) REP(j,n+1) REP(k,n+1) if(dp[i][j][k]&&j<=k){
    if(k<n){
      dp[i+1][j+1][k+1]=(dp[i+1][j+1][k+1]+dp[i][j][k]*(pw[(n-k)]+mod-1)%mod*pw[k]%mod)%mod;
    }
    dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k]*(pw[j])%mod)%mod;
    if(j<k){
      dp[i+1][j+1][k]=(dp[i+1][j+1][k]+dp[i][j][k]*pw[j]%mod*(pw[(k-j)]+mod-1)%mod)%mod;
    }


  }
  REP(j,n+1) ans+=dp[n][j][j]*pw[n*(n-j)]%mod;//,printf("%d %lld\n",j,dp[n][j][j]);
  printf("%lld\n",ans%mod); 
  return 0;
}

Measured memory_bytes: 110464
#include <stdio.h>

int main(void) {
  int N, o, t, s;
  scanf("%d", &N);
  for (int i=0;i<4; i++){
    o = N%10;
    t = N/10%10;
    s = N/100%10;
  }
  if (o == 7 || t == 7 || s == 7)
    printf("Yes");
  else
    printf("No");
  return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;

int main() {
	int n;
	scanf("%d", &n);
	n--;
	int t = 0, a, b;
	;
	scanf("%d%d%d", &t, &a, &b);
	if ((abs(a - 0) + abs(b - 0) > t)
			|| (((abs(a - 0) + abs(b - 0)) & 1) && !(t & 1))
			|| (!((abs(a - 0) + abs(b - 0)) & 1) && (t & 1)))
		return printf("No\n"), 0;

	while (n--) {
		int desa, desb, nexttime;
		scanf("%d%d%d", &nexttime, &desa, &desb);
		if ((((abs(desa - a) + abs(desb - b)) & 1) && !((nexttime - t) & 1))
				|| (abs(desa - a) + abs(desb - b) > nexttime - t)
				|| (!((abs(desa - a) + abs(desb - b)) & 1)
						&& ((nexttime - t) & 1)))
			return printf("No\n"), 0;
		a = desa;
		b = desb;
		t = nexttime;
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 3760
a, b, c, x, y = gets.chomp.split(' ').map{|i| i.to_i}
z = 0
if a + b > 2 * c
        d = (x < y) ? x : y
        x -= d
        y -= d
        z += 2 * d
end
if a > 2 * c
        d = x
        x -= d
        z += 2 * d
end
if b > 2 * c
        d = y
        y -= d
        z += 2 * d
end
sum = a * x + b * y + c * z
#puts "#{a} #{b} #{c} #{x} #{y} #{z}"
puts sum

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
using namespace std;
typedef pair<ll, ll> pint;
 
 
void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }
 
}
 
int main() {
 
    string S;
    cin >> S;
    rep(i, S.size()){
        if (S[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
 
    cout << "No" << endl;
 
 
 
}

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

int main(){
  typedef struct{
    char name[20];
    int time;
    //task before;
    //task next;
  } Task;
  Task task[300000]; 
  //task que[100000];
  int n,q,c,z=0;


  scanf("%d%d",&n,&q);
  for(c=0;c<n;c++){
    scanf("%s %d",task[c].name,&task[c].time);
  }
  /*
  for(c=0;c<n;c++){
    printf("%s %d\n",task[c].name,task[c].time);
  }
  */
  c=0;
  while(1){
    if(task[c].time > q){
      task[c].time -= q;
      z += q;
    }else if(task[c].time <= q){
      z += task[c].time;
      task[c].time = 0;
    }
    
    if(task[c].time > 0){
      task[n] = task[c];
      n++;
    }
    else if(task[c].time <= 0){
      printf("%s %d\n",task[c].name,z);
    }
    
    if(c==n-1)break;
    c++;
  }
  return 0;
}



Measured memory_bytes: 6300
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    string s;
    cin>>n>>q;
    cin>>s;
    int a[q],b[q];
    for(int i=0;i<q;i++){
        cin>>a[i]>>b[i];
    }
    int maki[n];
    maki[0]=0;
    for(int i=1;i<n;i++){
        if(s[i]=='C'&&s[i-1]=='A'){
            maki[i]=1;
        }
        else{
            maki[i]=0;
        }
        maki[i]+=maki[i-1];
    }
    for(int i=0;i<q;i++){
        cout<<maki[b[i]-1]-maki[a[i]-1]<<endl;
    }
    
    return 0;
}





Measured memory_bytes: 2256
fun main(args:Array<String>?): Unit {
    val d = readLine()!!.trim().toCharArray()
    val byChar = ('A' .. 'Z').map{c -> d.map{if (it == c) 1 else 0}.toIntArray()}
    for (line in byChar) {
        for (i in line.indices.drop(1)) line[i] += line[i - 1]
        for (i in line.lastIndex - 8 downTo 0) line[i + 8] -= line[i]
    }
    val aizu = "AIZUNYAN"
    for (i in d.indices){
        if (byChar['A'.toIndex()][i] == 2 && byChar['I'.toIndex()][i] == 1 && byChar['D'.toIndex()][i] == 1 && byChar['U'.toIndex()][i] == 1 && byChar['N'.toIndex()][i] == 2 && byChar['Y'.toIndex()][i] == 1) {
            for (j in aizu.indices){
                d[i - aizu.length + j + 1] = aizu[j]
            }
        }
    }
    println(d.joinToString(""))
}
fun Char.toIndex(): Int = this - 'A'


Measured memory_bytes: 35092
#define s(X,Y,Z) (t=X,X=Y,Y=t,f(Z?&X:&Y),a&7)
f(int*a){*a=(*a&7)<<4|*a>>4;}m,a,b,c,t,r;main(n){while(scanf("%d",&n),n){for(r=1,a=97,b=82,c=67;n--;scanf(" %c%*s",&t),m=t-76,r+=m%6==0?s(c,b,m):1<m&&m<8?s(b,a,m^7):s(c,a,m>0));printf("%d\n",r);}}

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

int main()
{   
  int a,b,k;
  cin>>a>>b>>k;
  int minm=min(a,b);
  vector<int>v;
  for(int i=1; i<=minm; i++)
  {
    if(a%i==0 && b%i==0)
      v.push_back(i);
  }
  cout<<v[v.size()-k];
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N_MAX = 1000000;
int a[N_MAX];

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

  int min_ele = N_MAX;
  int min_ix = -1;
  
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n){
    if(a[i] < min_ele){
      min_ele = a[i];
      min_ix = i;
    }
  }
  
  int rightlen = n - min_ix - 1; // include min element
  int right_time = rightlen/(k-1) + (rightlen%(k-1) != 0);
  // if(rightlen == k) right_time = 1;
  int hamide =  k - rightlen%(k-1) - 1;
  if(rightlen%(k-1)==0) hamide = 0;
  int leftlen = max(0, min_ix - hamide);
  int left_time = leftlen/(k-1) + (leftlen%(k-1) != 0);
  /*
  cout << "rightlen: " << rightlen << endl;
  cout << "leftlen: " << leftlen << endl;
  cout << "right_time: " << right_time << endl;
  cout << "left_time: " << left_time << endl;
  */
  cout << right_time + left_time << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
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;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}

int main(){
    ll n; cin >> n;
    vector<tuple<ll,ll,ll>> v(n);
    rep(i,n){
        ll a,b,c; cin >> a >> b;
        c = b+a;
        v[i] = tie(c,a,b);
    }
    sort(rall(v));
    ll ta = 0, ao = 0;
    for(ll i=0; i<n; i+=2){
        ll a,b;
        tie(ignore,a,b) = v[i];
        ta += a;
        if(i==n-1) break;
        tie(ignore,a,b) = v[i+1];
        ao += b;
    }
    cout << ta-ao << endl;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int m = K/2;
  int a = 0;
  for(int i = 0; i < N; i++){
    int x_i;
    cin >> x_i;
    if(x_i <= m){
      a += 2*x_i;
    }
    else{
      a += 2*(K-x_i);
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N, X, T;
    cin >> N >> X >> T;
    ll ans = ((N+(X-1))/X) * T;
    cout << ans;
}

Measured memory_bytes: 3632
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  val NIL = -1

  case class Node(var parent:Int = NIL,var left:Int = NIL,var right:Int = NIL,var height:Int = NIL, var depth:Int = NIL) { }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = (0 until n).map(_=>new Node).toArray

    for(i<-0 until n) {
      val s = readLine.split(" ").map(_.toInt)
      tree(s(0)).left = s(1)
      tree(s(0)).right = s(2)
      if(s(1) != NIL) tree(s(1)).parent = s(0)
      if(s(2) != NIL) tree(s(2)).parent = s(0)
    }

    def setDepth(id:Int,d:Int):Unit = {
      if(id!=NIL) {
        tree(id).depth = d
        setDepth(tree(id).left,d+1)
        setDepth(tree(id).right,d+1)
      }
    }

    def setHeight(id:Int):Int = {
      val hr:Int = if(tree(id).right != NIL) setHeight(tree(id).right) + 1 else 0
      val hl:Int = if(tree(id).left != NIL) setHeight(tree(id).left) + 1 else 0
      val x = if(hl>hr) hl else hr
      tree(id).height = x
      x
    }

    def getSibling(id:Int):Int = {
      if(tree(id).parent == NIL) NIL
      else {
        val parentNode = tree(tree(id).parent)
        if(parentNode.left != id && parentNode.left != NIL) parentNode.left
        else if(parentNode.right != id && parentNode.right != NIL) parentNode.right
        else NIL
      }
    }

    val root = tree.indexWhere(_.parent == NIL)
    setDepth(root, 0)
    setHeight(root)

    for(i<-0 until n) {
      print("node " + i + ": ")
      print("parent = " + tree(i).parent + ", ")
      print("sibling = " + getSibling(i) + ", ")
      val (l,r) = (if(tree(i).left != NIL) 1 else 0, if(tree(i).right != NIL) 1 else 0)
      print("degree = " + (l+r) + ", ")
      print("depth = " + tree(i).depth + ", ")
      print("height = " + tree(i).height+ ", ")
      if(tree(i).parent == NIL) println("root")
      else if(tree(i).left == NIL && tree(i).right == NIL) println("leaf")
      else println("internal node")
    }
  }
}

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

typedef long long ll;

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N+10);
    ll sum = 0;
    for(int i=0; i<=N; i++){
        cin>>A[i];
        sum += A[i];
    }

    ll cur = 1;
    ll ans = 1;

    for(int i=0; i<=N; i++){
        cur -= A[i];
        if(cur < 0){
            ans = -1;
            break;
        }

        sum -= A[i];
        cur = min(sum,cur*2);
        ans += cur;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4044
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		Integer[] b = new Integer[n];
		Integer[] c = new Integer[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			b[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
		}
		Arrays.sort(a);
		Arrays.sort(c);
		long ans = 0, aa, cc;
		for (int i = 0; i < n; i++) {
			aa = ~Arrays.binarySearch(a, b[i], (x, y) -> x.compareTo(y) >= 0 ? 1 : -1);
			cc = n - ~Arrays.binarySearch(c, b[i], (x, y) -> x.compareTo(y) > 0 ? 1 : -1);
			ans += aa * cc;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 103184
#include<iostream>

int main (){
    std::cin.tie(0); 
	std::ios::sync_with_stdio(false);
    std::string S,T;std::cin >> S >> T;
    int ans=1001,tmpCount=0;
    for (int i=0;i<=S.length() - T.length() ; ++i) {
        tmpCount=0;
        for(int j=0;j<T.length();++j){
            if(S[i+j] != T[j]) tmpCount++;
        }
        ans = std::min(tmpCount,ans);
    }

    std::cout << ans;
    return 0 ;
}



Measured memory_bytes: 3672
temp = gets.chomp.split(" ")
a = temp[0].to_i
b = temp[1].to_i
c = temp[2].to_i
tread_count = temp[3].to_i

if tread_count % 2 == 0 
    ans = a - b 
else
    ans = b - a
end


if ans.abs > (10**18)
    puts "Unfair"
    exit
end

puts ans


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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    cout << "ABC" << N << endl;

    return 0;
}


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

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

  int min = *min_element(num.begin(), num.end());
  int max = *max_element(num.begin(), num.end());

  cout << max - min << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n; cin >> n;
    vector<string> a(n);
    rep (i, n) {
        cin >> a[i];
        sort(begin(a[i]), end(a[i]));
    }
    sort(begin(a), end(a));
    vector<int> b;
    int cnt = 1;
    for (int i = 0; i < a.size(); ++i) {
        if (i == a.size()-1) {
            if (cnt != 0) b.push_back(cnt);
            else b.push_back(1);
        } else {
            if (a[i] == a[i + 1]) {
                cnt++;
            } else {
                b.push_back(cnt);
                cnt = 1;
            }
        }
    }
    ll ans = 0;
    for (ll x : b) ans += x*(x-1LL)/2LL;
    cout << ans << endl;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
const ll p = 1000000007;
const int NMAX = 320000;
bool prime[NMAX];

ll fac[NMAX],finv[NMAX],inv[NMAX];
void combinit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	
	FORq(i,2,NMAX-1){
		fac[i] = fac[i-1] * i % p;
		inv[i] = p - inv[p%i] * (p / i) % p;
		finv[i] = finv[i-1] * inv[i] % p;
	}
}
long long comb(int n,int r){
	if (n<r) return 0;
	if (n < 0 || r < 0) return 0;
	return fac[n] * (finv[r] * finv[n-r] % p) % p;
}


vector<pair<ll,ll> > prime_fac(ll n){
	vector<pair<ll,ll> >ret;
	for(ll p = 2; p * p <= n; ++p){
		if (n % p != 0) continue;
		int divc = 0;
		while(n % p == 0){
			++divc;
			n /= p;
		}
		ret.PB(MP(p,divc));
	}
	if (n != 1) ret.PB(MP(n,1));

	return ret;
}

int main(){
	ll N,M;
	cin >> N >> M;
	vector<pair<ll, ll> > prime = prime_fac(M);

	ll ans = 1;
	combinit();

	REP(i,prime.size()){
		ll x = prime[i].snd;
		ans = (ans * (comb(x + N - 1,x) % p))%p;
	}

	PRINTLLD(ans);
	
}

Measured memory_bytes: 7808
#include <algorithm>
#include <iostream>
#define N 310
#define INF (1e9)
using namespace std;
int n,p[N][N],ans,c,b,ma,d[N][N];

int main(){
  cin>>n;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++) cin>>p[i][j];
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++) d[i][j]=p[i][j];
  for(int i=1;i<=n;i++)
    for(int j=2;j<=n;j++) d[i][j]=d[i][j-1]+p[i][j];
  for(int i=2;i<=n;i++)
    for(int j=1;j<=n;j++) d[i][j]=d[i-1][j]+d[i][j];
  ans=p[1][1];
  for(int k=1;k<=n;k++){
    for(int l=k;l<=n;l++){
      b=c=1;
      while(c!=n){
	ma=-INF;
	for(int i=c+1;i<=n;i++){
	  int sum=d[i][l]-d[b-1][l]-d[i][k-1]+d[b-1][k-1],sum2=0;
	  if(i-b>=2&&l-k>=2) sum2=d[i-1][l-1]-d[b][l-1]-d[i-1][k]+d[b][k];
	  if(ma<sum-sum2) ma=sum-sum2,c=i;
	}
	ans=max(ans,ma);
	for(int i=b;i<=c;i++){
	  int sum=d[c][l]-d[i-1][l]-d[c][k-1]+d[i-1][k-1],sum2=0;
	  if(c-i>=2&&l-k>=2) sum2=d[c-1][l-1]-d[i][l-1]-d[c-1][k]+d[i][k];
	  ans=max(ans,sum-sum2);
	}
	b=c;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
const int N=100001;
int n,l,a[N],last=-1;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	FOR(i,0,N)a[i]=0;
	cin>>n>>l;
	FOR(i,1,n+1){
		cin>>a[i];
		if(a[i]+a[i-1]>=l)last=i-1;
	}
	if(last==-1){
		cout<<"Impossible"<<endl;
	}else{
		cout<<"Possible"<<endl;
		for(int i=1;i<last;i++){
			cout<<i<<endl;
		}
		for(int i=n-1;i>last;i--){
			cout<<i<<endl;
		}
		cout<<last<<endl;
	}

	return 0;
}

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





int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int count = 0;
    for (int r = 0; r <= 3000; r++)
    {
        for (int g = 0; g <= 3000; g++)
        {
            int v = N - R * r - G * g;
            if ( v >= 0 and v % B == 0) count++;
        }
        
    }
    cout << count << endl;
    
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        List<Integer> list = new ArrayList<Integer>();
        Set<Integer> set = new HashSet<Integer>();
        
        int num;
        for(int i=0;i<N;i++){
            num = sc.nextInt();
            list.add(num);
            set.add(num);
        }
        int a = list.size();
        int b = set.size();
        
        if(a==b){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 75052
def solve():
    X = int(input())

    ans = 0
    if X <= 3:
        ans = 1
    else:
        for b in range(2,100):
            if b ** 2 > X:
                break
            p = 2
            while pow(b,p) <= X:
                p += 1
            else:
                ans = max(ans, pow(b,p-1))
    
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 38384
n = int(input())

string_n = str(n)

third_digit = string_n[0]

next_third_digit = int(third_digit) + 1

if int(third_digit * 3) - n >= 0:
    print(int(third_digit * 3))
else:
    print(int(str(next_third_digit) * 3))
    

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

#define MAX 2000001
#define VMAX 10000

int main()
{
    unsigned short A[MAX], B[MAX];

    int C[VMAX + 1];
    int n, i, j;
    scanf("%d", &n);

    for(i = 0; i <= VMAX; i++) C[i] = 0;
    for(i = 0; i < n; i++){
        scanf("%hu", &A[i + 1]);
        C[A[i + 1]]++;
    }

    for(i = 1; i <= VMAX; i++){
        C[i] = C[i] + C[i - 1];
    }
    for(j = n; j > 0; j--){
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }
    for(i = 1; i <= n; i++){
        if(i > 1) printf(" ");
        printf("%d", B[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 8888
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    string s,t;cin>>s>>t;
    cout<<t<<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    int N;
    cin >>N;
    long long A[N];
    long long ans;
    FOR(i,N){
        cin >>A[i];
        if(i==0){
            ans=A[i];
        }else{
            ans=gcd(A[i],ans);
        }
    }
    cout <<ans<<endl;
    return 0;
}




Measured memory_bytes: 1024
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int
main(void)
{
        int N;
        int minus = 0;
        uint64_t sum = 0;
        int min = INT_MAX;

        scanf("%d\n", &N);
        for (int i = 0; i < N; i++) {
                int a;
                scanf("%d%*c", &a);
                if (a < 0)
                        minus++;
                sum += abs(a);
                if (abs(a) < min)
                        min = abs(a);
        }

        if (minus % 2)
                sum -= min * 2;

        printf("%lu", sum);
}



Measured memory_bytes: 256
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    H, W, K = MI()
    cake = [[s for s in input()] for h in range(H)]

    cursor = 0
    skip_rows = False
    for h in range(H):
        if '#' in cake[h]:
            cursor += 1
            first_flag = True
            for w in range(W):
                if cake[h][w] == '.':
                    cake[h][w] = cursor
                else:
                    if first_flag:
                        cake[h][w] = cursor
                        first_flag = False
                    else:
                        cursor += 1
                        cake[h][w] = cursor
            last_row = h
        else:
            skip_rows = True

    if skip_rows:
        if last_row < H - 1:
            for h in range(last_row + 1, H):
                cake[h] = cake[last_row]
        for h in range(H - 2, -1, -1):
            if '.' in cake[h]:
                cake[h] = cake[h + 1]

    for row in cake:
        row = [str(e) for e in row]
        print(' '.join(row))
        
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 8168
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int n, u, k, v;
  cin >> n;
  vector<vi> adj(n, vi(n, 0));
  REP(i, n) {
    cin >> u >> k;
    REP(j, k) {
      cin >> v;
      adj[u - 1][v - 1] = 1;
    }
  }
  REP(i, n) print(adj[i]);
}


Measured memory_bytes: 3116
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
ans = 0
for i in range(105, n+1, 2):
  cnt = 1
  for k in range(3, int(i**0.5)+1, 2):
    if i % k == 0:
      cnt += 1
  if cnt == 4:
    ans += 1
print(ans)












Measured memory_bytes: 27020
#include <iostream>
#include<math.h>
using namespace std;

int main(){ 
    int n;  
    int cath=100000;

    cin>>n; 

    for(int i=1;i<=n;i++){
        cath*=1.05;
        if(cath%1000!=0)cath+=1000-cath%1000;
    }
    cout<<cath<<endl;

    return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

    public static void main(String[] args) {

        String num;
        char ch;
        boolean b = false;

        Scanner sc = new Scanner(System.in);
        num = sc.nextLine();
        ch = num.charAt(0);

        for(int i=1;i<4;i++){
            if(ch==num.charAt(i)){
                b = true;
                break;
            }
            ch = num.charAt(i);
        }

        if(b){
            System.out.println("Bad");
        }else{
            System.out.println("Good");
        }


    }
}

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

struct TCoordinate
{
	double X;
	double Y;
};

struct TPolarCoordinate
{
	int Distance;
	int Degree;
};

TCoordinate Move(TPolarCoordinate PolarCoordinate, TCoordinate CurrentCoordinate)
{
	CurrentCoordinate.Y += PolarCoordinate.Distance * cos(PolarCoordinate.Degree * M_PI / 180);
	CurrentCoordinate.X += PolarCoordinate.Distance * sin(PolarCoordinate.Degree * M_PI / 180);
	return CurrentCoordinate;
}

int main()
{
	TCoordinate CurrentCoordinate = {0, 0};
	int BeforeInputDegree = 0;
	while(true){
		TPolarCoordinate Input;
		char Dummy;
		cin >> Input.Distance >> Dummy >> Input.Degree;
		if(Input.Distance == 0 && Input.Degree == 0) break;
		CurrentCoordinate = Move({Input.Distance, BeforeInputDegree}, CurrentCoordinate);
		BeforeInputDegree += Input.Degree;
	}
	double GaussX, FractionalX, GaussY, FractionalY;
	FractionalX = modf(CurrentCoordinate.X, &GaussX);
	FractionalY = modf(CurrentCoordinate.Y, &GaussY);
	cout << fixed << setprecision(0) << GaussX << endl << GaussY << endl;
	return 0;
}

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

int H, W;
int L[2010][2010], R[2010][2010], U[2010][2010], D[2010][2010];
vector<string> S;

int main() {
    scanf("%d %d", &H, &W);
    S.resize(H);
    rep(i,H) cin >> S[i];

    rep(i,H)rep(j,W){
        if (S[i][j] == '#') L[i][j] = 0;
        else if (j == 0) L[i][j] = 1;
        else L[i][j] = L[i][j-1] + 1;

        if (S[i][j] == '#') U[i][j] = 0;
        else if (i == 0) U[i][j] = 1;
        else U[i][j] = U[i-1][j] + 1;

        int tempi = H - i - 1;
        int tempj = W - j - 1;

        if (S[tempi][tempj] == '#') R[tempi][tempj] = 0;
        else if (tempj == W-1) R[tempi][tempj] = 1;
        else R[tempi][tempj] = R[tempi][tempj + 1] + 1;

        if (S[tempi][tempj] == '#') D[tempi][tempj] = 0;
        else if (tempi == H-1) D[tempi][tempj] = 1;
        else D[tempi][tempj] = D[tempi + 1][tempj] + 1;
    }

    int maxsum = 0;
    rep(i,H)rep(j,W) maxsum = max(maxsum, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
    cout << maxsum << endl;
    return 0;
}

Measured memory_bytes: 67456
import java.util.Scanner;

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

        int N = sc.nextInt();
        int D = sc.nextInt();
        int[][] X = new int[N][D];
        for (int i=0; i<N; i++) {
            for (int j=0; j<D; j++) {
                X[i][j] = sc.nextInt();
            }
        }

        System.out.println(solve(N, D, X));
    }

    private static int solve(int N, int D, int[][] X) {
        int count = 0;

        for (int i=0; i<N; i++) {
            for (int j=i+1; j<N; j++) {
                double dist = 0;
                for (int k=0; k<D; k++) {
                    dist += Math.pow(X[i][k] - X[j][k], 2);
                }
                dist = Math.sqrt(dist);

                if (Math.abs(dist - (int)dist) == 0) count++;
            }
        }

        return count;
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
int main(void)
{
int i, sum;
char x[1100];

while(1){
sum = 0;
i = 0;

scanf("%s",&x);

if(x[0] == '0')
break;

while(1){

if(x[i] == '\0')
break;

sum += x[i] - '0';

i++;
}

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

return 0;
}

Measured memory_bytes: 536
#include <iostream>

using namespace std;

int main()
{
    string S;
    cin >> S;
    int a, b, c;
    a = b = c = 0;

    for (int i = 0; i < 3; i++){
        if (S.at(i) == 'a'){
            a++;
        }
        if (S.at(i) == 'b'){
            b++;
        }
        if (S.at(i) == 'c'){
            c++;
        }
    }
    if ((a == 1) && (b == 1) && (c == 1)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
//杀害兔子太好了，没有了。
#include<cstdio>
#include<iostream>
#include<algorithm>
#define MN 2005
int n,k,q,a[MN],num[MN],cnt,ans=1047483648;
bool check(int l,int r)
{
	int now=0;
	for(int i=1,j;i<=n;i++)
	{
		if(a[i]>=l)
		{
			int tot=0;
			for(j=i;j<=n&&a[j]>=l;j++) if(a[j]<=r) tot++;
			now+=std::min(std::max(j-i-k+1,0),tot);
			i=j;
		}
	}
	return now>=q;
}
int main()
{
	scanf("%d%d%d",&n,&k,&q);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),num[i]=a[i];
	std::sort(num+1,num+n+1);
	cnt=std::unique(num+1,num+1+n)-num-1;
	for(int i=1;i<=cnt;i++)
	{
		int l=0,r=cnt-i;
		while(l<=r)
		{
			int mid=l+r+1>>1;
			if(check(num[i],num[i+mid])) {ans=std::min(ans,num[i+mid]-num[i]);r=mid-1;}
			else l=mid+1;
		}
	}
	printf("%d\n",ans);
}

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

const int N = 100 * 1000 + 5;


bool dp1[N], dp0[N], mark[N];
vector <int> adj[N];

void dfs(int v) {
	mark[v] = true;
	bool b = false;
	int c = 0, cl = 0;
	for (auto u : adj[v]) {
		if (!mark[u]) {
			dfs(u);
			cl++;
			if (dp0[u]) {
				c++;
			}
			if (dp1[u]) {
				b = true;
			}
		}
	}
	if (c == cl) {
		dp1[v] = true;
	}
	if (c + 1 == cl && b) {
		dp0[v] = true;
	}

}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1);
	if (dp0[1]) {
		cout << "Second";
	}
	else {
		cout << "First";
	}
	return 0;
}

Measured memory_bytes: 9428
#include <stdio.h>

long min(long a,long b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int N;
  scanf("%d",&N);

  long sum,a[N];
  long ans = 0;
  long sample = 0;

  for(int i = 0;i < N;i++) scanf("%ld",&a[i]);

  sum = 0;
  for(int i = 0;i < N;i++){
    sum += a[i];
    if(i%2 == 0){
      if(sum <= 0){
        ans += 1-sum;
        sum = 1;
      }
    }else{
      if(sum >= 0){
        ans += 1+sum;
        sum = -1;
      }
    }
  }

  sum = 0;
  for(int i = 0;i < N;i++){
    sum += a[i];
    if(i%2 != 0){
      if(sum <= 0){
        sample += 1-sum;
        sum = 1;
      }
    }else{
      if(sum >= 0){
        sample += 1+sum;
        sum = -1;
      }
    }
  }

  printf("%ld\n",min(ans,sample));

  return 0;
}

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

int main(void){
    int n,h[100011],count=0,max=0;
    cin>>n;
    for(int i=0;i<n;i++){
        h[i]=0;
    }

    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=0;i<n-1;i++){
        if(h[i]>=h[i+1]){count+=1;}
        else{count = 0;}
        max = (max<count)? count:max;
    }

    cout<<max<<endl;
}

Measured memory_bytes: 640