akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long K, long long N, vector<long long> A) {
    ll c = 0;
    rep(i, N - 1) { c = max(c, A[i + 1] - A[i]); }
    c = max(c, K - A[N - 1] + A[0]);
    cout << K - c << endl;
}

int main() {
    long long N;
    long long K;
    scanf("%lld", &K);
    scanf("%lld", &N);
    vector<long long> A(N - 1 + 1);
    for (int i = 0; i <= N - 1; i++) {
        scanf("%lld", &A[i]);
    }
    solve(K, N, A);
    return 0;
}


Measured memory_bytes: 3328
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
d_al = dict()
for ai in a:
    for aij in ai:
        if aij in d_al:
            d_al[aij] += 1
        else:
            d_al[aij] = 1
od = 0
a2 = 0
for i in d_al.values():
    if i % 2 == 1:
        od += 1
    elif i % 4 == 2:
        a2 += 1
if h % 2 == 1 and w % 2 == 1:
    if od == 1 and a2 <= (h + w - 1) // 2:
        print('Yes')
    else:
        print('No')
elif h % 2 == 1:
    if od == 0 and a2 <= w // 2:
        print('Yes')
    else:
        print('No')
elif w % 2 == 1:
    if od == 0 and a2 <= h // 2:
        print('Yes')
    else:
        print('No')
else:
    if od == 0 and a2 == 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int c = a + b;
    if(c == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    int div = n / c;
    int counts = a * div;
    int rem = n % c;
    if(rem <= a)
        counts += rem;
    else
        counts += a;
    cout << counts << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b;
    while(cin >> a >> b, a){
        int cnt = 0;
        if(a < b) swap(a, b);
        while(b){
            cnt++;
            a %= b;
            swap(a, b);
        }
        cout << a << " " << cnt << "\n";
    }
    return 0;
}


Measured memory_bytes: 3084
import java.io.*;
import java.util.*;

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        long n = ipar();
        out.println(n * (n-1) / 2);

        out.flush();
        in.close();
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

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


Measured memory_bytes: 22740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    int a, b;
    cin >> a >> b;
    int max=a+b;
    if(max<a-b) max=a-b;
    if(max<a*b) max=a*b;
    out(max);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>

#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;


int main(void)
{
	int N, K; cin >> N >> K;
	int ans = (N + K - 3) / (K - 1);
	cout << ans << endl;


	return 0;
}

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

using namespace std;

struct UnionFind {
    vector<int> data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return (false);
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};

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

    UnionFind uf(n);
    vector<int> friends(n, 1);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
        friends[a]++, friends[b]++;
    }

    vector<vector<int>> block(n);
    for (int i = 0; i < k; i++) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        block[c].push_back(d), block[d].push_back(c);
    }

    for (int i = 0; i < n; i++) {
        if (i > 0)cout << " ";

        int ret = uf.size(i) - friends[i];
        for (auto x:block[i]) {
            if (uf.find(i) == uf.find(x))ret--;
        }
        cout << ret;
    }
    cout << endl;
    return 0;
}

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

using namespace std;

int N, K;

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

    if (K == 0) {
        cout << (long long)N * N << endl;
        return 0;
    }

    int b = K + 1;
    int w = 1;
    long long ans = 0;
    while (b <= N) {
        ans += N / b * w;
        ans += max(w - ((N / b * b + b - N) - 1), 0);
        b++;
        w++;
    }
    cout << ans << endl;
}

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

namespace agc028_a
{
	class Program
	{
		static void Main(string[] args)
		{
			long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
			long gcm = x.Min();
			while (!(x[0] % gcm == 0 && x[1] % gcm == 0)) gcm--;
			string s1 = Console.ReadLine(); string s2 = Console.ReadLine();
			string t1 = ""; string t2 = "";
			for (int i = 0; i < gcm; i++) t1 += s1[(int)(x[0] / gcm) * i];
			for (int i = 0; i < gcm; i++) t2 += s2[(int)(x[1] / gcm) * i];
			Console.WriteLine(t1 == t2 ? x[0] * x[1] / gcm : -1);
		}
	}
}

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

typedef pair<int,int> PAIR;
const int INF=100000000;
int rate_kind[8];

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

    int a;
    for (int i = 0; i < n; ++i){
        cin>>a;
        if(1<=a&&a<=399)rate_kind[0]=1;
        else if(400<=a&&a<=799)rate_kind[1]=1;
        else if(800<=a&&a<=1199)rate_kind[2]=1;
        else if(1200<=a&&a<=1599)rate_kind[3]=1;
        else if(1600<=a&&a<=1999)rate_kind[4]=1;
        else if(2000<=a&&a<=2399)rate_kind[5]=1;
        else if(2400<=a&&a<=2799)rate_kind[6]=1;
        else if(2800<=a&&a<=3199)rate_kind[7]=1;
        else if(3200<=a)rate_kind[8]++;
    }

    int sum=0;
    for (int i = 0; i < 8; ++i){
        sum+=rate_kind[i];
    }

    if(sum!=0)
        cout<<sum<<' '<<sum+rate_kind[8]<<endl;
    else
        cout<<1<<' '<<rate_kind[8]<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int v[n];
  int c[n];
  int sub[n];
  int max = 0;
  for(int i=0; i<n; i++) {
    cin >> v[i];
  }
  for(int i=0; i<n; i++) {
    cin >> c[i];
  }
  for(int i=0; i<n; i++) {
    sub[i] = v[i] - c[i];
  }
  for(int i=0; i<n; i++) {
    if(sub[i] >= 0) {
      max += sub[i];
    }
  }
  cout << max << endl;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

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

  int n; cin >> n;
  vector<P> v(n);
  for(int i=0;i<n;++i) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());

  vi mall(n+2), malr(n+2), mirl(n+2, INF), mirr(n+2, INF);
  for(int i=0;i<n;++i) {
    mall[i+1] = max(mall[i], v[i].first);
    mirl[i+1] = min(mirl[i], v[i].second);
  }

  for(int i=n-1;i>=0;--i) {
    malr[i+1] = max(malr[i+2], v[i].first);
    mirr[i+1] = min(mirr[i+2], v[i].second);
  }

  ll ans = 0;
  for(int i=1;i<=n-1;++i) {
    ll tmp1 = mirl[i] - mall[i] + 1;
    ll tmp2 = mirr[i+1] - malr[i+1] + 1;
    ans = max(ans, max(0ll, tmp1) + max(0ll, tmp2));
  }

  for(int i=2;i<=n-1;++i) {
    ll tmp1 = v[i-1].second - v[i-1].first + 1;
    ll tmp2 = min(mirl[i-1], mirr[i+1]) - max(mall[i-1] + 1, malr[i+1]) + 1;
    ans = max(ans, tmp1 + max(0ll, tmp2));
  }

  ll tmp1 = v[0].second - v[0].first + 1;
  ll tmp2 = mirr[2] - malr[2] + 1;
  ans = max(ans, tmp1 + max(0ll, tmp2));

  tmp1 = v[n-1].second - v[n-1].first + 1;
  tmp2 = mirl[n-1] - mall[n-1] + 1;
  ans = max(ans, tmp1 + max(0ll, tmp2));

  cout << ans << endl;

}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	else{
		int x=c-'0';
		while(gc>='0')x=x*10+c-'0';
		return x;
	}
}
#undef gc
int s(s64 n)
{
	int ans=0;
	while(n){ans+=n%10;n/=10;}
	return ans;
}
s64 P[20];
int k;
void dfs(s64 n,int i)
{
	if(!k)return ;
	if(i==-1)
	{
		--k;
		printf("%lld\n",n);
		return ;
	}
	rep(j,0,8)
	{
		s64 _n=n+(j+1)*P[i]-1;
		if(_n*(s(_n)+1)<=(_n+P[i])*s(_n))dfs(n+j*P[i],i-1);
	}
	dfs(n+9*P[i],i-1);
}
int main()
{
	cin >> k;
	P[0]=1;
	rep(i,1,16)P[i]=P[i-1]*10;
	for(int i=0;k;++i)
	{
		rep(j,1,9)dfs(j*P[i],i-1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

void rsorta_d32(void *base, const int count, const int size, int (*find)(const void*)){
	typedef int32_t rsort_t;
	char (*a)[size] = base;
	char (*b)[size] = (char(*)[size])malloc(count*size);
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(find(a[i])>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(find(a[i])>>(0<<3))&0xFF]; memcpy(b[to], a[i], size); }{char(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(find(a[i])>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(find(a[i])>>(1<<3))&0xFF]; memcpy(b[to], a[i], size); }{char(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(find(a[i])>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(find(a[i])>>(2<<3))&0xFF]; memcpy(b[to], a[i], size); }{char(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(find(a[i])>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(find(a[i])>>(3<<3))&0xFF]; memcpy(b[to], a[i], size); }{char(*t)[size]=a; a=b; b=t;}
	free(b);
}

int find(const void *a){
	return *(int*)a;
}

int n;
int a[100001];
int b[100001];
int c[100001];
int d[200001];

int inc(int i){
	i+=100000;
	while(i<=200000){
		d[i]++;
		i+=i&-i;
	}
}

int sum(int i){
	i+=100000;
	int s=0;
	while(i>0){
		s+=d[i];
		i-=i&-i;
	}
	return s;
}

long f(int x){
	for(int i=1; i<=n; i++){
		c[i]=c[i-1]+(a[i]<=x?1:-1);
	}
	memset(d, 0, sizeof(d));
	long ans=0;
	inc(c[0]);
	for(int i=1; i<=n; i++){
		ans+=sum(c[i]-1);
		inc(c[i]);
	}
	return ans;
}

int main(void){
	n=nextint();
	for(int i=1; i<=n; i++){
		a[i]=b[i]=nextint();
	}
	rsorta_d32(b+1, n, sizeof(int), find);
	int kl=1, kr=n;
	long m = (long)n*(n+1)/4+1;
	//printf("%d\n", m);
	while(kl<=kr){
		int km=(kl+kr)/2;
		//printf("%d %d %ld\n", km, b[km], f(b[km]));
		if(f(b[km])>=m) kr=km-1; else kl=km+1;
	}
	//printf("%d %d %ld\n", kl, b[kl], f(b[kl]));
	printf("%d\n", b[kl]);
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int ans[1000005];
int main(){
    int n;
    scanf("%d",&n);
    char s[1000005],t[1000005];
    scanf("%s %s",s,t);
    n=strlen(s);
    vector<pii> v;
    int now=n-1;
    int tot=0;
    int Max=0;
    int last=n;
    for(int i=n-1;i>=0;i--){
        if(now>i)now--;
        if(s[now]==t[i])continue;
      //  Max=max(Max,1); 
        while(s[now]!=t[i]){
            now--;
            if(now<0){
                printf("-1\n");
                return 0;
            }
        }
        if(i>=last){
            tot++;
        }
        else{
            tot=1;
        }
        last=now;
        //printf("%d %d %d\n",last,i,tot);
        Max=max(Max,tot);
    }
    if(Max<2)   
    printf("%d\n",Max);
    else{
        int now=n-1;
        int tot=0;
        int Max2=0;
        int last=n;
        deque<int> q;
        int offset=0;
        for(int i=n-1;i>=0;i--){
            if(now>i)now--;
            if(now==i&&t[i]==s[i]){
                while(!q.empty())q.pop_front();
                offset=0;
                continue;
            }
            if(i!=0&&t[i]==t[i-1])continue;
        //  Max=max(Max,1); 
            while(s[now]!=t[i]){
                now--;
            }
            if(q.empty()){
                q.pb(now);
                q.pb(now);
                q.pb(i);
            }
            else{
                //
                while(!q.empty()&&q.back()>=i+offset)q.pop_back();
                if(q.empty()){
                    q.pb(now);
                    q.pb(now);
                    q.pb(i);
                    offset=0;
                }
                else{    
                    if(q.front()!=now+offset){
                        q.front()=now+offset;
                    }
                    q.push_front(now+offset);
                    q.pb(i+offset);
                }
               
            }
            offset++;
          //  printf("%c %c %d %d %d\n",s[now],t[i],last,i,tot);
            Max2=max(Max2,(int)q.size());
        }
        printf("%d\n",min(Max,Max2-1));
    }
}

Measured memory_bytes: 6272
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		(new Solver()).Solve();
	}
}


public class Solver
{
	private int N;
	private int M;
	private int[] A;
	private int[] B;
	private int[] deg;
	private HashSet<Tuple<int, int>> used;
	private List<int>[] adj;
	private StringBuilder ans = new StringBuilder();
	
	public Solver()
	{
		N = GetInt();
		M = GetInt();
		A = new int[M];
		B = new int[M];
		deg = new int[N + 1];
		used = new HashSet<Tuple<int, int>>();
		adj = new List<int>[N + 1];
		for(int i = 1; i <= N; i++)
			adj[i] = new List<int>();
		
		for(int i = 0; i < M; i++)
		{
			A[i] = GetInt();
			B[i] = GetInt();
			adj[A[i]].Add(B[i]);
			adj[B[i]].Add(A[i]);
		}
	}

	public void Solve()
	{
		if(M % 2 == 1)
		{
			Console.WriteLine(-1);
			return;
		}

		List<int> order = bfs();
		for(int i = 0; i < N; i++)
		{
			int v = order[i];
			foreach(int u in adj[v])
			{				
				if(used.Contains(Tuple.Create(v, u)) || 
				   used.Contains(Tuple.Create(u, v)))
					continue;

				if(deg[v] % 2 == 1)
				{
					ans.AppendFormat($"{v} {u}\n");
					deg[v]++;
				}
				else
				{
					ans.AppendFormat($"{u} {v}\n");
					deg[u]++;
				}

				used.Add(Tuple.Create(v, u));
				used.Add(Tuple.Create(u, v));
			}
		}

		Console.Write(ans);
	}

	private List<int> bfs()
	{
		var order = new List<int>(N);
		
		var isInMST = new HashSet<Tuple<int, int>>();
		bool[] visited = new bool[N + 1];	
		var queue = new Queue<int>();		
		visited[1] = true;
		order.Add(1);
		queue.Enqueue(1);
		while(queue.Count > 0)
		{
			int v = queue.Dequeue();
			foreach(int u in adj[v])
			{
				if(used.Contains(Tuple.Create(v, u)) || 
				   used.Contains(Tuple.Create(u, v)) ||
				   isInMST.Contains(Tuple.Create(v, u)) || 
				   isInMST.Contains(Tuple.Create(u, v)))
					continue;

				if(visited[u])
				{
					ans.AppendFormat($"{v} {u}\n");
					used.Add(Tuple.Create(v, u));
					used.Add(Tuple.Create(u, v));
					deg[v]++;
				}
				else
				{
					visited[u] = true;
					order.Add(u);
					queue.Enqueue(u);
					isInMST.Add(Tuple.Create(v, u));
					isInMST.Add(Tuple.Create(u, v));
				}
			}
		}

		order.Reverse();
		return order;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 61312
n,k=gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
MOD = 10**9+7
lt = Array.new(n, 0) # それより小さい数の個数
rlt = Array.new(n, 0) # それより右にある小さい数の個数
n.times do |i|
  n.times do |j|
    lt[i] += 1 if a[j] < a[i]
    rlt[i] += 1 if j > i && a[j] < a[i]
  end
end
ans = 0
b = k*k - (1+k)*k/2
n.times do |i|
  ans += b*lt[i]
  ans += k*rlt[i]
  ans %= MOD
end
p ans
  


Measured memory_bytes: 1916
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  long n,a,b,sum = 0 , ksum = 0;
  C3(n,a,b);
  
  for(long i = 0 ; i < n ; i++ ){
    char c;
    cin >> c;
    if(c == 'a' && sum < a + b){
      Yes;
      sum++;
    }
    else if(c == 'b' && ksum < b && sum < a+b){
      Yes;
      sum++;
      ksum++;
    }
    else
      No;

  }
  ret 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  vector<int> list;

  for (int i = vec.front(); i <= vec.back(); i++) {
    int sum = 0;
    for (int data : vec) {
      sum += (data - i) * (data - i);
    }
    list.push_back(sum);
  }

  sort(list.begin(), list.end());
  cout << list.front() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n;
  cin>>n;
  int a[n+1];
  int b[n];

  REP(i,n+1){
    cin>>a[i];
  }
  REP(i,n){
    cin>>b[i];
  }

  ll count = 0;
  REP(i,n){
    if(a[i]>=b[i]){
      count += b[i];
      a[i] -= b[i];
    }else{
      count += a[i];
      b[i] -= a[i];
      a[i] = 0;
      if(a[i+1]>=b[i]){
        count += b[i];
        a[i+1] -= b[i];
      }else{
        count += a[i+1];
        b[i] -= a[i+1];
        a[i+1] = 0;
      }
    }
  }

  cout<<count<<endl;
 

  return 0;
}

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

using ll = long long;
#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, n, m) for(int (i)=(n); (i)<(m); ++i)
constexpr int INF = 1e9;
//constexpr ll INF = 1LL << 61;
//constexpr int mod = 1e9+7;
constexpr ll mod = 998244353;

ll dp[int(2*1e5+5)];
int main(){
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> LR(K);
  REP(i, K){
    int L, R;
    cin >> L >> R;
    LR[i] = {L, R};
  }
  dp[1] = 1;
  ll sum = 0;
  FOR(i, 2, N+1){
    REP(j, K){
      auto [L, R] = LR[j];
      if(L+1 <= i){
        sum += dp[i-L];
        sum %= mod;
      }
      if(R+1 < i){
        sum -= dp[i-R-1];
        sum %=mod;
        if(sum < 0){
          sum += mod;
        }
      }
    }
    dp[i] += sum;
    dp[i] %= mod;
  }
  cout << dp[N] << endl;
  return 0;
}


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


int main(){
    string SS, T, C="";
    vector<string> v;
    cin >> SS >> T;
    if(SS.size() < T.size()){
        cout <<  "UNRESTORABLE" << endl;
        return 0;
    }
    //cout << SS <<endl;
    //cout << T <<endl;
    rep(i, SS.size() - T.size() + 1){
        //cout << "i:"<<i<<endl;
        bool flag = true;
        C = SS;
        rep(j,T.size()){
            //cout << SS[i+j] <<" "<<T[j] <<endl;
            if(SS[i+j] == T[j] || SS[i+j] == '?'){
                
                C[i+j] = T[j];
                continue;
            }else{
                flag = false;
                break;
            }
        }
        if(flag){
            rep(j,C.size()){
                if(C[j] == '?'){
                    C[j] = 'a';
                }
            }
            v.push_back(C);
            //cout << "0" << endl;
        }
        
    }
    //cout <<"SS:"<<SS<<endl;
    if(v.size() > 0){
        sort(v.begin(), v.end());
        cout<< v[0] <<endl;
    }else{
        cout <<  "UNRESTORABLE" << endl;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main(){

    string S;
    cin >> S;

    string s = S.substr(0, (S.length()-1)/2);
    string ss = S.substr((S.length()+3)/2 - 1, S.length());

    //cout << s << " " << ss << endl;

    for(ll i = 0; i < (S.length()-1)/2; i++){
        if(S[i] != S[S.length() / 2 - 1 -i]){
            cout << "No" << endl;
            return 0;
        }
    }

    for(ll i = (S.length()+3)/2 - 1; i < S.length(); i++){
        if(S[i] != S[S.length() - 1 - i]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

}

Measured memory_bytes: 256
A,B = map(str, input().split())
ans = int(A + B)

def is_square(n):
    c = 1
    while True:
        if n / c == c:
            return True
        if n / c < c:
            break
        c += 1
    return False

print('Yes' if is_square(ans) else 'No')

Measured memory_bytes: 2940
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>

using namespace std;

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

#ifdef EBUG
#define debug(x) cout << "\033[31m" << #x << ": " << x << "\033[0m\n";
#else
#define debug(x)
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll k;
string s;

int main() {
  cin >> k;
  cin >> s;
  if (s.size() <= k) {
    cout << s << endl;
  } else {
    rep(i, k) {
      cout << s[i];
    }
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if (Abs(a-b) <= d && Abs(c-b) <= d) || Abs(c-a) <= d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
func Abs(a int) int {
	return int(math.Abs(float64(a)))
}


Measured memory_bytes: 512
while line = gets
	n, x = line.split( " " ).map { | val | val.to_i }
	break if 0 == n && 0 == x

	cnt = 0
	for i in ( 1 .. n-2 )
		for j in ( i+1 .. n-1 )
			if	x < ( i+j )
				break
			end
			for k in ( j+1 .. n )
				s = ( i + j + k )
				if x == s
					cnt += 1
					break
				end
			end
		end
	end
	
	puts( cnt )
end

Measured memory_bytes: 6104
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (void) {
    int n;
    int *x, *y;
    double sum1=0, sum2=0, sum3=0;
    double dis, max=0;

    scanf ("%d", &n);

    x = (int *) malloc (sizeof(int) * n);
    y = (int *) malloc (sizeof(int) * n);

    for (int i=0; i<n; i++) scanf ("%d", x+i);
    for (int i=0; i<n; i++) {
        scanf ("%d", y+i);
        dis = fabs (x[i]-y[i]);
        sum1 += dis;
        sum2 += pow (dis, 2);
        sum3 += pow (dis, 3);
        max = fmax (max, dis);
    }

    printf ("%lf\n%lf\n%lf\n%lf\n", sum1, sqrt(sum2), cbrt(sum3), max);
    
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9+7;
int main() {
	// your code goes here
	string s,t;
	cin>>s;
	cin>>t;
	int l1 =s.length(),l2=t.length();
	int ans = 99999999,curr=0;
	for(int i=0;i<l1-l2+1;i++){
		curr = 0;
		for(int j=0;j<l2;j++){
			if(s[i+j]!=t[j]){
				++curr;
			}
		}
		ans =min(curr,ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3580
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://beta.atcoder.jp/contests/abc099/tasks/abc099_b>
 問題文============================================================
 =================================================================
 解説=============================================================
 (b-a-1)*(b-a)/2-a
 ================================================================
 */
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int a,b; cin >> a >> b;
    cout <<  (b-a-1)*(b-a)/2-a << endl;
    return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep1 (i, n) {
    int x = i;
    int cnt = 0;
    while (x > 0) {
      cnt++;
      x /= 10;
    }
    if (cnt % 2 == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

struct Node{ int p, l, r;};
struct Node tree[MAX];
int n,depth[MAX];

int getDepth(int u){
  int d = 0;
  for(; tree[u].p!= -1 ;d++)
   u = tree[u].p;

  return d;
}

void print(int x){
  int i, count;
  printf("node %d: ", x);
  printf("parent = %d, ", tree[x].p);
  printf("depth = %d, ", depth[x]);

  if ( tree[x].p == -1 ) 
    printf("root, ");
  else if ( tree[x].l == -1 )
    printf("leaf, ");
  else
    printf("internal node, ");

  printf("[");
  for(i = 0, count = tree[x].l; count != -1; i++, count = tree[count].r){
    if (i!=0) 
        printf(", ");

    printf("%d", count);
  }
  printf("]\n");
}

main(){
  int i, j,k=0;
  int d, v, x, l;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) 
  tree[i].p = tree[i].l = tree[i].r = -1;

  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &x);
      if ( j == 0 ) 
        tree[v].l = x;
      else
        tree[l].r = x;

      l = x;
      tree[x].p = v;
    }
  }
  for ( i = 0; i < n; i++ ){
    depth[i] = getDepth(i);
    if ( depth[i]>k ) 
        k = depth[i];
  }

  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}


Measured memory_bytes: 3340
class SegmentTree:
  """Segmant Tree for query process.

  Args:
    a (List[int]): array.
    identity (int): identity element with f.
  """
  def __init__(self, a, identity=0):
    self.a = a
    self.n = len(a)
    self.identity = identity
    self.depth = (self.n - 1).bit_length()
    self.segment = (1 << self.depth) - 1
    self.tree = [identity] * (self.segment * 2 + 1)
    self.tree[self.segment : self.n + self.segment] = a
    for i in range(self.segment - 1, -1, -1):
      self.tree[i] = self.f(self.tree[2*i+1], self.tree[2*i+2])

  def update(self, i: int, x: int):
    i += self.segment
    self.tree[i] = x
    while i:
      i = (i - 1) // 2
      self.tree[i] = self.f(self.tree[2*i+1], self.tree[2*i+2])

  def query(self, l: int, r: int) -> int:
    """Query at [l, r]

    Args:
      l (int): left
      r (int): right

    Returns:
      int: result
    """
    if l > r:
      return self.identity
    l += self.segment
    r += self.segment
    res = self.identity
    while l <= r:
      if not l & 1:
        res = self.f(self.tree[l], res)
      if r & 1:
        res = self.f(res, self.tree[r])
      l = l // 2
      r = (r - 2) // 2
    return res

  def f(self, x: int, y: int) -> int:
    return x | y

n = int(input())
s = input()
q = int(input())
a = ord('a')
segment_tree = SegmentTree([1 << (ord(c) - a) for c in s])
for _ in range(q):
  query = input().split()
  if query[0] == '1':
    i = int(query[1]) - 1
    c = query[2]
    segment_tree.update(i, 1 << (ord(c) - a))
  else:
    l = int(query[1]) - 1
    r = int(query[2]) - 1
    bit = segment_tree.query(l, r)
    print(format(bit, 'b').count('1'))

Measured memory_bytes: 48184
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll solve(vector<ll> &L, vector<ll> &R, ll N) {
  vector<pll> l(N), r(N);
  REP(i, 0, N) l[i] = pll(L[i], i);
  REP(i, 0, N) r[i] = pll(R[i], i);

  sort(l.begin(), l.end(), greater<pll>());
  sort(r.begin(), r.end());

  vector<bool> used(N, false);
  ll lp = 0, rp = 0;
  ll pos = 0;
  ll ans = 0;

  REP(i, 0, N) {
    if(i % 2 == 0) {
      while(lp < N && used[l[lp].second]) lp++;
      ll npos;
      if(l[lp].first <= pos && pos <= r[lp].first) {
        npos = pos;
      } else {
        npos = l[lp].first;
      }
      ans += abs(npos - pos);
      pos = npos;
      used[l[lp].second] = true;
    } else {
      while(rp < N && used[r[rp].second]) rp++;
      ll npos;
      if(l[rp].first <= pos && pos <= r[rp].first) {
        npos = pos;
      } else {
        npos = r[rp].first;
      }
      ans += abs(npos - pos);
      pos = npos;
      used[r[rp].second] = true;
    }
    // cout << "  " << pos << endl;
  }
  // cout << endl;
  ans += abs(pos - 0);

  return ans;
}

int main(void) {
  ll N;
  cin >> N;
  vector<ll> L(N), R(N);
  REP(i, 0, N) cin >> L[i] >> R[i];

  ll ansr = solve(L, R, N);

  REP(i, 0, N) {
    ll l = -R[i];
    ll r = -L[i];
    L[i] = l;
    R[i] = r;
  }

  ll ansl = solve(L, R, N);

  // cerr << ansr << " " << ansl << endl;
  cout << max(ansr, ansl) << endl;
}


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

int main()
{
	int N, M, C;
	int B[20];
	int A[20][20];
	cin >> N >> M >> C;
	for (int i = 0; i < M; i++)
	{
		cin >> B[i];
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			cin >> A[i][j];
		}
	}

	int ans = 0;

	for (int i = 0; i < N; i++)
	{
		int temp = 0;
		for (int j = 0; j < M; j++)
		{
			temp += A[i][j] * B[j];
		}
		temp += C;
		if (temp > 0)	ans++;
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9+5;
 
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    vector<int> v(n);
 
    for(auto &i:v)        cin>>i;
 
    vector<int> dp(n);
 
    dp[n-1]=0;
    dp[n-2]=abs(v[n-1]-v[n-2]);
 
    for(int i=n-3 ; i>=0 ; i--)
    {
        int a = abs(v[i]-v[i+1]);
        int b = abs(v[i]-v[i+2]);
        dp[i] = min(a+dp[i+1] , b + dp[i+2]);
    }
    cout<<dp[0];
}

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

namespace AtCoder
{
    class Abc162C
    {
        static int[,] gcd;

        public static void Main()
        {
            var k = int.Parse(Console.ReadLine());

            gcd = new int[k + 1, k + 1];

            long sum = 0;
            for (int a = 1; a <= k; a++)
                for (int b = 1; b <= k; b++)
                    for (int c = 1; c <= k; c++)
                        sum += GetGcd(GetGcd(a, b), GetGcd(b, c));
            Console.WriteLine(sum);
        }

        static int GetGcd(int a, int b)
        {
            if (a > b)
            {
                var temp = a;
                a = b;
                b = temp;
            }
            if (gcd[a, b] != 0)
                return gcd[a, b];

            var r = b % a;
            if (r == 0)
                gcd[a, b] = a;
            else
                gcd[a, b] = GetGcd(r, a);
            return gcd[a, b];
        }
    }
}


Measured memory_bytes: 17768
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    cout << a * b - a - b + 1 << endl;

    return 0;
}


Measured memory_bytes: 888
import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase


"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""



def inpt():
    return [int(k) for k in input().split()]


def main():
    n=int(input())
    ar=inpt()
    mx=ar[0]
    ans=0
    for i in range(1,n):
        if(ar[i]<mx):
            ans+=mx-ar[i]
        mx=max(ar[i],mx)
    print(ans)

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


Measured memory_bytes: 35832
#include <iostream>

int main(){
    int a;
    int b;
    int c;
    int d;
    int e;
    int f;
  
    std::cin>>a>>b>>c>>d>>e>>f;
    if(a*1+b*5+c*10+d*50+e*100+f*500<1000){
    std::cout<<"0"<<std::endl;
    }else{
    std::cout<<"1"<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
 
#define hell                         1000000007
#define hell2                        998244353
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define all(v)                       v.begin(),v.end()
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'
 
const ll MAX=500005;
const ll SQN=330;
const ll LG=22;
const double PI=atan(1)*4;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    ll a,b,n;
    cin >> a >> b >> n;
    ll x=min(n,b-1);
    cout << (a*x)/b - a*(x/b) << endl;

}

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

struct Node{
  int id;
  int parent;
  int left;
  int right;
  int deg;
  int sibling;
  int depth;
  int height;
  string type;
};

class BinaryTree{
public:
  BinaryTree(int a){
    n = a;
    T = new Node[n];
    for(int i=0;i<n;i++) T[i].parent = -1;
  }
  ~BinaryTree(){delete [] T;}
  void setId(int x, int u){T[x].id = u;}
  void setLeft(int x, int u){T[x].left = u;}
  void setRight(int x, int u){T[x].right = u;}
  void plusDeg(int x){T[x].deg++;}
  int setHeight(int x);
  void setDepth(int x, int d);
  int getSibling(int x);
  void print(int x);

  int n;
  Node *T;
};

int BinaryTree::setHeight(int x){
  int h1 = 0, h2 = 0;
  if(T[x].left != -1) h1 = setHeight(T[x].left) + 1;
  if(T[x].right != -1) h2 = setHeight(T[x].right) + 1;
  return T[x].height = max(h1, h2);
}

void BinaryTree::setDepth(int x, int d){
  T[x].depth = d;
  if(T[x].left != -1) setDepth(T[x].left, d + 1);
  if(T[x].right != -1) setDepth(T[x].right, d + 1);
}

int BinaryTree::getSibling(int x){
  if(T[x].parent == -1) return -1;
  if(T[T[x].parent].left != -1 && T[T[x].parent].left != x)
    return T[x].sibling = T[T[x].parent].left;
  else if(T[T[x].parent].right != -1 && T[T[x].parent].right != x)
    return T[x].sibling = T[T[x].parent].right;
  return -1;
}

void BinaryTree::print(int x){
  cout << "node " << T[x].id << ": ";
  cout << "parent = " << T[x].parent << ", ";
  cout << "sibling = " << getSibling(x) << ", ";
  cout << "degree = " << T[x].deg << ", ";
  cout << "depth = " << T[x].depth << ", ";
  cout << "height = " << T[x].height << ", ";
  cout << T[x].type << endl;
}

int main(){
  int n;
  cin >> n;
  BinaryTree tree(n);
  int root;
  for(int i=0;i<n;i++){
    int id, l, r;
    cin >> id >> l >> r;
    tree.setId(id, id);
    tree.setLeft(id, l);
    tree.setRight(id, r);
    if(l != -1){
      tree.T[l].parent = id;
      tree.plusDeg(id);
    }
    if(r != -1){
      tree.T[r].parent = id;
      tree.plusDeg(id);
    }
  }

  for(int i=0;i<n;i++){
    if(tree.T[i].parent == -1){
      root = i;
      tree.T[i].type = "root";
    }
    else if(tree.T[i].deg == 0) tree.T[i].type = "leaf";
    else tree.T[i].type = "internal node";
  }
  tree.setDepth(root, 0);
  tree.setHeight(root);

  for(int i=0;i<n;i++){
    tree.print(i);
  }
  return 0;
}



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

namespace Tenka1
{
    class A
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            int[] cw = new int[N+1]; 
            int[] cb = new int[N+1];
            int counterW = 0, counterB = 0;

            for (int i = 0; i < N; i++)
            {
                if (S[i] == '#') counterB++;
                cb[i + 1] = counterB;
                if (S[N - i - 1] == '.') counterW++;
                cw[N - i - 1] = counterW;
            }

            int min = int.MaxValue;
            for(int i = 0; i < N+1; i++)
            {
                int m = cb[i] + cw[i];
                if (m < min) min = m;
            }


            Console.WriteLine(min);
        }
    }
}


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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

void code() {
    int n;
    cin>>n;
    int ans=0;
    vector<int> A(10005);

    for(int i=1; i<=100; i++) {
        for(int j=1; j<=100; j++){
            for(int k=1; k<=100; k++) {
                int t = i*i + j*j + k*k + i*j + j*k + k*i;
                if(t<=n)
                    A[t]++;
            }
        }
    }
    for(int i=1; i<=n; i++) {
        cout << A[i] << '\n';
    }

}

signed main() {
    std::ios_base::sync_with_stdio(false);
    int t=1;
    // cin>>t;
    for(int i=0; i<t; i++) {
        code();
    }
}


Measured memory_bytes: 3676
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
B = [[0]*w for _ in range(h)]
Bi = 0
Bj = 0
for i in range(n):
    cnt = a[i]
    while cnt>0:
        B[Bi][Bj] = str(i+1)
        cnt-=1
        if Bi%2==0:
            if Bj<w-1:
                Bj+=1
            else:
                if Bi<h-1:
                    Bi+=1
                else:
                    break
        else:
            if Bj>0:
                Bj-=1
            else:
                if Bi<h-1:
                    Bi+=1
                else:
                    break
[print(' '.join(B[i]),end='\n') for i in range(h)]

Measured memory_bytes: 3828