akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;

int main() {
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(j < A && i < B || j >= A && i >= B)
                cout << '0';
            else
                cout << '1';
        }
        cout << endl;
    }
    return 0;
}


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

int main(){
  int N,M,C,buf;
  cin >> N >> M >> C;

  vector<int> vec(M);
  for(int j=0; j<M; j++){
    cin >> vec.at(j);
  }

  int cnt= 0;
  vector<int> point(M);
  for(int i=0; i<N; i++){
    int score= C;
    for(int j=0; j<M; j++){
      cin >> buf;
      score+= vec.at(j)* buf;
    }
    
    if(score > 0) cnt++;
  }

  cout << cnt << endl; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    int ans=0;
    for(int i=1; i<=n; i++){
        int d=0;
        int x=i;
        while(x){
            x/=10; d++;
        }
        if(d&1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//
// Segment Tree
template< typename DATA, DATA FAIL >
class SegmentTree {
private:
	int size__;
	Vec< DATA > data;
	
	inline int left_t(int k) { return (k << 1) + 1; }
	inline int right_t(int k) { return (k << 1) + 2; }
	inline int center(int l, int r) { return (l + r) >> 1; }
	
	DATA calc(DATA d1, DATA d2) { return max(d1, d2); }
	
	DATA query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return FAIL;
		if (a <= l && r <= b) return data[k];
		return calc(query(a, b, left_t(k), l, center(l, r)),
					query(a, b, right_t(k), center(l, r), r));
	}
	
public:
	SegmentTree(int n, DATA ini) {
		for (size__ = 1; size__ < n; size__ <<= 1);
		data.assign(2 * size__ - 1, ini);
	}
	
	void update(int k, DATA a) {
		k += size__ - 1;
		data[k] = a;
		
		while (k > 0) {
			k = (k - 1) >> 1;
			data[k] = calc(data[left_t(k)], data[right_t(k)]);
		}
	}
	
	DATA query(int a, int b) { return query(a, b, 0, 0, size__); }
	
	int size() { return size__; }
};

int main() {
	int N;
	cin >> N;
	
	Vec< int > A(N);
	for_(i,0,N) cin >> A[i];
	
	SegmentTree< int, -1 > seg(N+1, (int)0);
	for_(i,0,N) seg.update(i, A[i]);
	
	int ans = 0;
	Vec< bool > vis(N, false);
	for_(i,0,N) {
		if (!vis[i]) {
			int cur = i;
			++ans;
			while (1) {
				vis[cur] = true;
				//cerr << A[cur] << " ";
				int lb = cur, ub = N;
				while (ub - lb > 1) {
					int med = (lb + ub) / 2;
					if (seg.query(cur, med+1) > A[cur]) ub = med;
					else lb = med;
				}
				if (ub == N) break;
				seg.update(ub, -1);
				cur = ub;
			}
			//cerr << endl << endl;
		}
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<vector<bool>> adjacent(n, vector<bool>(n,false));

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v;
			cin >> v;
			adjacent[u-1][v - 1] = true;
		}
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << adjacent[i][j] << (j == n-1 ? "\n" : " ");
		}
	}

}

Measured memory_bytes: 3080
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
// C - March
int N;
ll march[5];
char pattern[5] = {'M', 'A', 'R', 'C', 'H'};
ll ans = 0;
 
int main(){
    cin >> N;
    rep(i, 0, N){
        string S;
        cin >> S;
        rep(i, 0, 5){
            if(S[0] == pattern[i]){
                ++march[i];
                break;
            }
        }
    }
 
    rep(a, 0, 5){
        rep(b, a+1, 5){
            rep(c, b+1, 5){
                ans += march[a] * march[b] * march[c];
            }
        }
    }
    cout << ans << endl;
    return 0;
}
 
 

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int n, m, x;
	int a[100];
	int j = 0, h = 0; //j→xよりも左側の料金所の数　h→xよりも右側の料金所の数

	cin >> n >> m >> x;

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

	for (int i = 0; i < m; i++) {
		if (a[i] < x) {
			j++;
		}
		else {
			h++;
		}
	}

	if (j < h) {
		cout << j << endl;
	}
	else {
		cout << h << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            int max=0;
            int m=0;
            for (int i = 0; i < n; i++) {
                int a=sc.nextInt();
                int b=sc.nextInt()+sc.nextInt();
                if(max<b) {
                    max=b;
                    m=a;
                }
            }
            System.out.println(m+" "+max);
        }
    }
}


Measured memory_bytes: 161676
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

LL Mint::md = 1000000007;

int n;
int *f;
int main() {
	cin >> n;
	f = new int[n];
	for (int i = 0; i < n; ++i) {
		f[i] = 0;
	}
	int a;
	for (int i = 0; i < n - 1; ++i) {
		scanf("%d", &a);
		f[a - 1] += 1;
	}
	for (int i = 0; i < n; ++i) {
		printf("%d\n", f[i]);
	}
	return 0;
}

Measured memory_bytes: 4616
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define pb         push_back
#define mp         make_pair
#define ll         long long
#define PI         acos(-1.0)
#define ALL(A)     ((A).begin(), (A).end())
#define vsort(v)   sort(v.begin(),v.end())
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    int N, K;
    cin >> N >> K;
    int pasta[N+1];
    FOR(i, 0, N+1) pasta[i] = 0;
    FOR(i, 1, K+1){
        int hi, pas;
        cin >> hi >> pas;
        pasta[hi] = pas;
    }
    ll int dp[N+1][4][4];
    FOR(i, 0, N+1){
        FOR(j, 0, 4){
            FOR(k, 0, 4){
                dp[i][j][k] = 0;
            }
        }
    }
    FOR(i, 1, 4){
        if(pasta[1]==0){
            dp[1][i][0] = 1;
        }
        else{
            if(i==pasta[1]) dp[1][i][0] = 1;
        }
    }

    FOR(i, 1, N+1){
        FOR(j, 0, 4){
            FOR(k, 0, 4){
                if(dp[i][j][k]==0) continue;
                FOR(m, 1, 4){
                    if(j==k && m==k) continue;
                    if(pasta[i+1]==0){
                        dp[i+1][m][j] = dp[i+1][m][j] + dp[i][j][k];
                        dp[i+1][m][j] %= 10000;
                    }
                    else{
                        if(pasta[i+1]==m){
                            dp[i+1][m][j] = dp[i+1][m][j] + dp[i][j][k];
                            dp[i+1][m][j] %= 10000;
                        }
                        //else dp[i+1][m][j] = 0;
                    }
                }

            }
        }
    }
    ll int ans = 0;
    FOR(i, 1, 4){
        FOR(j, 1, 4){
            ans += dp[N][i][j];
            ans = ans % 10000;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3116
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

if A+B+C+D == 7: print("{0}+{1}+{2}+{3}=7".format(A,B,C,D))
elif A-B+C+D == 7: print("{0}-{1}+{2}+{3}=7".format(A,B,C,D))
elif A-B-C+D == 7: print("{0}-{1}-{2}+{3}=7".format(A,B,C,D))
elif A-B-C-D == 7: print("{0}-{1}-{2}-{3}=7".format(A,B,C,D))
elif A+B-C+D == 7: print("{0}+{1}-{2}+{3}=7".format(A,B,C,D))
elif A+B+C-D == 7: print("{0}+{1}+{2}-{3}=7".format(A,B,C,D))
elif A+B-C-D == 7: print("{0}+{1}-{2}-{3}=7".format(A,B,C,D))
elif A-B+C-D == 7: print("{0}-{1}+{2}-{3}=7".format(A,B,C,D))

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

int main(){
	int r, d, x;
	int res[11];
	cin >> r >> d >> x;
	res[0] = x;
	
	for(int i = 1; i < 11; i++){
		res[i] = r * res[i-1] - d;
		cout << res[i] << endl;
	}
	
	return 0;
}

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

int main(void)
{
        int i,j,m;
        char s[110],t[110],c[110];

        scanf("%s%s",s,t);

        m=strlen(s);
        strcpy(c,s);
        for(i=0;i<m;i++){
                if(strcmp(c,t)==0){
                        printf("Yes\n");
                        return 0;
                }
                c[0]=s[m-1];
                for(j=1;j<m;j++){
                        c[j]=s[j-1];
                }
                strcpy(s,c);
        }
        printf("No\n");
        return 0;
}


Measured memory_bytes: 1644
#include<iostream>
#include<algorithm>

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


int main(){
    
    int n;
    int a[100];
    cin >> n;
    rep(i,n) cin >> a[i];

    sort(a,a + n, greater<int>());

    int alice = 0, bob = 0;

    rep(i,n){
        if(i%2 != 0) bob += a[i];
        else alice += a[i];
    }
 
    cout << alice - bob << endl;
    

    return 0;
};



Measured memory_bytes: 256
#include <cstdio>
int main() {
	int n,m,map[1000],dice[1000];
	while(scanf("%d %d",&n,&m),n) {
		for(int i=0;i<n;i++) {
			scanf("%d",&map[i]);
		}
		for(int i=0;i<m;i++) {
			scanf("%d",&dice[i]);
		}
		int res,now=0;
		for(int i=0;i<m;i++) {
			now=now+dice[i];
			if(now>=n-1){res=i+1;break;}
			now+=map[now];
			if(now>=n-1){res=i+1;break;}
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 998244353;

ll modpow(ll base, int p) {
    ll mul = base;
    ll ret = 1;
    while (p) {
        if (p&1) {
            ret *= mul;
            ret %= MOD;
        }
        mul *= mul;
        mul %= MOD;
        p >>= 1;
    }
    return ret;
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    unordered_set<string> keta2,keta2n, keta3;
    rep(i, n) {
        string c{s[i]};
        keta2n.clear();
        for (auto &st : keta2) {
            string ss = st + c;
            if (ss.size() == 3) keta3.emplace(ss);
            else keta2n.emplace(ss);
            keta2n.emplace(st);
        }
        keta2n.emplace(c);
        swap(keta2, keta2n);
    }    
    /*
    for (auto& st : keta2) {
        cout << st << ","; 
    }
    cout << endl;
    for (auto& st : keta3) {
        cout << st << ","; 
    }
    cout << endl;
    */
    cout << keta3.size() << endl;
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a + b) / 2 << endl;
}

Measured memory_bytes: 3072
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#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 all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

unsigned GetDigit(unsigned num) {
	unsigned digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

signed main(void) {
	int n;
	cin >> n;
	int a;
	for(int i = sqrt(n);i>0;i--){
		if (n%i == 0) {
			a = i;
			break;
		}
	}
	int b = n / a;
	print(max(GetDigit(a), GetDigit(b)));
}

Measured memory_bytes: 3632
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int64_t A,B,C,D;
int64_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> A >> B >> C >> D;
	D = std::min({A * 8, B * 4, C * 2, D});
	C = std::min({ A * 4, B * 2, C});
	B = std::min({ A * 2, B});
	in >> N;

	out << ((N / 2)*D) + ((N % 2)*C) << endl;


	return 0;
}
#endif


Measured memory_bytes: 256
N = int(input())
if N == 1:
    print(1)
elif N == 2:
    print(5)
elif N == 3:
    print(11)
else:
    ans = N*(N+1)-1
    for i in range(2,N//2+1):
        t = N//i
        ans += i*(t*(t+1)//2-1)
    print(ans)

Measured memory_bytes: 9012
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll d;
  std::cin>>d;

  constexpr ll TYPE=26;
  std::array<ll,TYPE> c;
  rep(i,0,TYPE)std::cin>>c[i];

  std::vector<std::array<ll,TYPE>> s(d);
  rep(i,0,d){
    rep(j,0,TYPE)std::cin>>s[i][j];
  }

  ll ans=0;

  std::vector<ll> contest(d);

  std::array<std::set<ll>,TYPE> sched;
  rep(i,0,TYPE)sched[i].emplace(-1);
  std::array<ll,TYPE> last;
  last.fill(-1);

  rep(i,0,d){
    ll t;
    std::cin>>t;
    t--;
    contest[i]=t;
    ans+=s[i][t];
    last[t]=i;
    sched[t].emplace(i);
    rep(j,0,TYPE)ans-=c[j]*(i-last[j]);
  }

  rep(i,0,TYPE)sched[i].emplace(d);

  ll m;
  std::cin>>m;

  while(m--){
    ll day,q;
    std::cin>>day>>q;
    day--;q--;
    ll prev=contest[day];
    ans-=s[day][prev];
    ans+=s[day][q];

    ll val=day-*(--sched[prev].lower_bound(day));
    ll len=*sched[prev].upper_bound(day) - day;
    ans-=c[prev]*val*len;
    sched[prev].erase(day);


    sched[q].insert(day);
    val=day-*(--sched[q].lower_bound(day));
    len=*sched[q].upper_bound(day) - day;
    ans+=c[q]*val*len;

    contest[day]=q;

    std::cout<<ans<<"\n";
  }

  return 0;
}

Measured memory_bytes: 3752
program main
    implicit none
    integer i,flag
    integer length
    character s*10

    flag = 0

    read(*,*) s
    
    length = len_trim(s)

    do i = 1,length
        if (mod(i,2) == 1) then
            if (s(i:i) == "h") then
                flag = 0
            else 
                flag = 1
            end if
        else if (mod(i,2) == 0) then
            if (s(i:i) == "i") then
                flag = 0
            else 
                flag = 1
            end if
        end if

        if (flag == 1) then
            exit
        end if

    end do

    if (mod(length,2) == 1) then
        flag = 1
    end if
    
    if(flag == 0) then
        write(*,*) "Yes"
    else 
        write(*,*) "No"
    end if

end program

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

int main(){
    long long N, M;
    cin >> N >> M;
    if (N == 1 && M == 1) {
        cout << 1 << endl;
    } else if (N == 1) {
        cout << M - 2 << endl;
    } else if (M == 1) {
        cout << N - 2 << endl;
    } else {
        cout << (N - 2) * (M - 2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;

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

  ll ans=0;
  for(ll i=k+1; i<=n; i++){
    ans += (n/i)*(i-k);
    if(n%i) ans += max(n%i-k+1LL*((k==0)?0:1), 1LL*0);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
struct ii
{
	long long x,y,id;
}num[100005];
long long n,m,i,j,ans,fa[100005];
struct bian
{
	long long x,y,z;
}bi[200005];
bool cmp(ii x,ii y){return x.x<y.x;}
bool cmp2(ii x,ii y){return x.y<y.y;}
bool cmp3(ii x,ii y){return x.id<y.id;}
bool cmp4(bian x,bian y){return x.z<y.z;}
int find(int x){if (x==fa[x]) return x;return fa[x]=find(fa[x]);}
long long dis(long long x,long long y)
{
	return min(abs(num[x].x-num[y].x),abs(num[x].y-num[y].y));
}
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>num[i].x>>num[i].y;
		num[i].id=i;
	}
	sort(num+1,num+n+1,cmp);
	for (i=1;i<n;i++)
	{
		bi[i]=(bian){num[i].id,num[i+1].id,0};
	}
	sort(num+1,num+n+1,cmp2);
	for (i=1;i<n;i++)
	{
		bi[i+n-1]=(bian){num[i].id,num[i+1].id,0};
	}
	sort(num+1,num+n+1,cmp3);
	for (i=1;i<=2*n-2;i++)
	{
		bi[i].z=dis(bi[i].x,bi[i].y);
	}
	sort(bi+1,bi+n+n-1,cmp4);
	for (i=1;i<=n;i++) fa[i]=i;
	for (i=1;i<=n+n-2;i++)
	{
		if (find(bi[i].x)!=find(bi[i].y))
		{
			fa[find(bi[i].x)]=find(bi[i].y);
			ans+=bi[i].z;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8064
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

void Main() {
  int n, m; cin >> n >> m;
  if(n < m) swap(n, m);
  for(int i = 0; i < n; i++) {
    cout << m;
  }
  cout << "\n";
}

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

int n,m;
int maxL,minR;
int main (){
	std::cin >> n >> m;
	maxL=0,minR=INT_MAX;
	for (int L,R;m--;){
		std::cin >> L >> R;
		maxL=std::max(maxL,L);
		minR=std::min(minR,R);
	}
	if (maxL<=minR)
		std::cout << minR-maxL+1 << '\n';
	else 
		std::cout << 0 << '\n';
	return 0;
}



Measured memory_bytes: 256
export LC_ALL=C;read w h n;((--w));((--h));eval tee '>(awk -vw=$w -vh=$h -vk='{0..7}\ \''NR%8==k{t=w<++$1?w:$1;u=$2<3?2:$2-1;v=h<++$2\
?h:$2;for(i=$1<4?2:$1-2;i<=t;i++)for(j=u;j<=v;j++)print i,j|"dd>>"k;w}'\'\)|dd>__;sort ?|uniq -c|sort|uniq -cw7|awk -vw=$w -vh=$h '{a\
[$2]=$1;t=t"-"$1}END{a[0]=--w"*"--h""t;for(i=0;i<=9;i++)printf"$((%s)) ",a[i]?a[i]:0|"eval echo `dd`"}'|tr \  \\n

Measured memory_bytes: 123360
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string str;
    ll w;
    cin >> str;
    cin >> w;
    
    vector<string> ans ;
    
    string dump = "";
    rep(i, str.size()){
        dump+=str[i];
        if(dump.size() == w){
            ans.pb(dump);
            dump= "";
        }
    }
    if(dump.size()!=0) ans.pb(dump);

    rep(i, ans.size()){
        cout << ans[i][0] ;
    }
    cout << endl;
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi 1
#define LL long long
#define ULL unsigned long long
#define LD long double

using namespace std;

int main()
{
  LL Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;

  LL one = 0;
  one = min(Q*2, H);
  one = min(one*2, S);
  LL two = 0;
  two = min(one*2, D);

  cout << N/2 * two + (N%2) * one << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long int x[n];
    vector<long long int> v1,v2;
    for(int i = 0;i < n;i++)
    {
        long long int t;
        cin >> t;
        v1.push_back(t);
    }
    v2 = v1;
    sort(v2.begin(),v2.end());
    long double mid = (v2.at(n / 2 - 1) + v2.at(n / 2)) / 2.0;
    for(int i = 0;i < n;i++)
    {
        if(v1.at(i) < mid)
        {
            cout << v2.at(n / 2) << "\n";
        }
        else
        {
            cout << v2.at(n / 2 - 1) << "\n";
        }
        
    }

    return 0;
}

Measured memory_bytes: 5488
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		scan.useDelimiter("[^-0-9.]+");
		
		int n = scan.nextInt();

		for(int i=0;i<n;i++){
			long x1 = (long)Math.round(scan.nextDouble()*100000);
			long y1 = (long)Math.round(scan.nextDouble()*100000);
			long x2 = (long)Math.round(scan.nextDouble()*100000);
			long y2 = (long)Math.round(scan.nextDouble()*100000);
			long x3 = (long)Math.round(scan.nextDouble()*100000);
			long y3 = (long)Math.round(scan.nextDouble()*100000);
			long x4 = (long)Math.round(scan.nextDouble()*100000);
			long y4 = (long)Math.round(scan.nextDouble()*100000);
			
			if((x2-x1)*(y4-y3)-(x4-x3)*(y2-y1)==0){
				System.out.println("YES");
			}else
			{
				System.out.println("NO");
			}
		}
		
		scan.close();
	}
}

Measured memory_bytes: 29736
#include <iostream>
#include <algorithm>//sort
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>//pair
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
  int H, A, ans = 0;
  cin >> H >> A;
  rep(i, 100000){
    H -= A;
    ans++;
    if(H <= 0){
      cout << ans << endl;
      return 0;
    }
  }
}


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
	//cin >> tt;
	while (tt--)
	{
		int n; cin >> n;
		int k; cin >> k;
		int sum = 0;
		for (int i = 0; i < k; i++)
		{
			int temp; cin >> temp;
			sum += temp;
		}
		cout << max(n - sum, -1LL);
	}
    return 0;
}


Measured memory_bytes: 3652
import bisect
N = input()
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())
A.sort()
B.sort()
C.sort()

BC_type_num = []
pre = 0
for b in reversed(B):
    upper_bound = bisect.bisect_right(C, b)
    BC_type_num.append(pre + N - upper_bound)
    pre += N - upper_bound
BC_type_num.reverse()

res = 0
for a in A:
    upper_bound = bisect.bisect_right(B, a)
    if upper_bound < N:
        res += BC_type_num[upper_bound]

print res

Measured memory_bytes: 17720
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll ans=1,n;
  cin >> n;
  for(int i=1; i<=n; i++) {
    ans*=i;
    ans%=MOD;
  }
  cout << ans << endl;
}

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

using namespace std;

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

const int MOD = 998244353;

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    ll n;
    cin >> n;
    ll sum = 0LL;
    vector<ll> cou(100001, 0);
    for (int i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        ++cou[a];
        sum += a;
    }
    
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        ll b, c;
        cin >> b >> c;
        cou[c] += cou[b];
        sum += (c - b) * cou[b];
        cou[b] = 0;
        cout << sum << "\n";
    }
    
    return 0;
}


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

int main(){
    char S[6];
    rep(i, 6) cin >> S[i];

    if ( (S[2] == S[3]) && (S[4] == S[5]) ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n;
  while( n = getInt() ){
    int ans = 0;
    for(int a = 0; ; a++){
      int aa = a * a;
      if(aa + aa + aa + aa > n) break;
      for(int b = a; ; b++){
        int bb = b * b;
        if(aa + bb + bb + bb > n) break;
        for(int c = b; ; c++){
          int cc = c * c;
          if(aa + bb + cc + cc > n) break;
          int dd = n - aa - bb - cc;
          double d = sqrt(dd);
          int    di = (int)(d + 1e-10);
          if(abs(d-di) < 1e-10){
            ans++;
          }
        }
      }
    }
    print(ans);
  }
  return 0;
}

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

int main(int argc, char* argv[]){
	char str[4]={0};

	scanf("%s", str);
	if(strcmp(str, "ABC")==0){
		printf("ARC\n");
	}
	else{
		printf("ABC\n");
	}
	return 0;
}

Measured memory_bytes: 1596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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 REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[9] = { 0, 0,0,1,1,1,-1,-1,-1 };
int dyy[9] = { 0, 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool arr[100000100];
vector<ll>sosuu;
void Eratosthenes() {
	ll N = 10000010;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (ll i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (ll j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (ll i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu.pb(i);
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}

ll stoL(string s) {
	ll n = s.length();
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += pow2(10, n - i - 1)*(ll)(s[i] - '0');
	}
	return ans;
}


int imos[2020][2020];
map<int,int>compX, compY;
string A[1010];
signed main() {
	int A, B, C;
	cin >> A >> B >> C;
	print(A*B/2);
}


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

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;




int32_t main()
{




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

  double ans =(double) a*b;

  cout << (int)(ans);

    return 0;
}


Measured memory_bytes: 3744
N,M = map(int,input().split())

G = [[] for i in range(N)]

for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

for i in range(N) :
    if len(G[i]) % 2 != 0 :
        ans = "NO"
        break
else :
    ans = "YES"

print(ans)


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

namespace Atc_0027
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int N = int.Parse(str);

            double odd = 0;

            for (int i = 1; i <= N; i++)
            {
                if (i % 2 == 1)
                {
                    odd++;
                }
            }

            double ret = (double)odd / (double)N;

            Console.WriteLine(ret);

        }
    }
}


Measured memory_bytes: 27552
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll h,w,n;cin>>h>>w>>n;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
    vector< pair<ll,ll> > arr;
    for(ll i=0;i<h;i++){
        if(i%2==0){
            for(ll j=0;j<w;j++)arr.push_back({i,j});
        }
        else{
            for(ll j=w-1;j>=0;j--)arr.push_back({i,j});
        }
    }

    ll ans[h][w];
    ll p=0;
    for(ll i=0;i<arr.size();i++){
       // cout<<arr[i].first<<" "<<arr[i].second<<endl;
        while(a[p]==0)p++;
        a[p]--;
        ans[arr[i].first][arr[i].second]=p+1;
    }

    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++)cout<<ans[i][j]<<" ";
        cout<<"\n";
    }
}





Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const ll mod=1e9+7;
ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+=b)>=mod)a-=mod;
  return a;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}


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

  int n,m;

  cin >> n >> m;
  vector<vector<vector<int>>> dp(m+1, vector<vector<int>>(n+1, vector<int>(n+1)));
  //  int dp[m+1][n+1][n+1];//日にち、最初の町含む連結成分、孤立点
  //  cout << "" << endl;
  rep(i,m+1) rep(j,n+1) rep(l,n+1){
    dp[i][j][l]=0;
  }
  dp[0][1][n-1]=1;
  rep(i,m){
    rep(j,n+1){
      rep(l,n+1){
	if(j+l>n)continue;
	dp[i+1][j][l] =ad(mu(dp[i][j][l],(n-j-l)),dp[i+1][j][l]);
	if(l>=1) dp[i+1][j][l-1] = ad(mu(dp[i][j][l],l), dp[i+1][j][l-1]);
	dp[i+1][n-l][l] =ad(mu(dp[i][j][l],j),dp[i+1][n-l][l]);
	//	cout << "day conect alone " << i << " " << j <<  " " << l << " " <<dp[i][j][l] << endl;
      }
    }
    //    cout << "day "<< i << endl;
  }
  cout << dp[m][n][0] << endl;
  

  
  //  cout << endl << endl;
  //  cout << static_cast<double>(clock()) / CLOCKS_PER_SEC << "s"<<endl;
  return 0;
    

}


Measured memory_bytes: 110336
$dx = [0,1,0,-1]
$dy = [1,0,-1,0]
$bc = 0
$wc = 0
def bfs(f, sy, sx, h, w, visited, bc, wc)
    f[sy][sx] = "*"
    wf = false
    bf = false
    count = 1
    q = [[sy,sx]]
    visited.push([sy,sx])
    col = f[sy][sx].downcase
    while q.size > 0
        sy, sx = q.shift
        for i in 0..3
            cy = sy + $dy[i]
            cx = sx + $dx[i]
            if cy.between?(0,h-1) && cx.between?(0,w-1) && !visited.include?([cy,cx])
                if  f[cy][cx] == "W"
                    wf = true
                elsif
                    f[cy][cx] == "B"
                    bf = true
                elsif
                    count += 1
                    q.push([cy,cx])
                    visited.push([cy,cx])
                    f[cy][cx] = "*"
                end
            end
        end
    end
    bc += count if bf && !wf
    wc += count if !bf && wf
    return [f,visited,bc,wc]
end
def pp(f)
    f.each do |r|
        puts r
    end
    puts
end
loop do
    w, h = gets.split.map(&:to_i)
    break if w == 0 && h == 0
    f = h.times.map{gets.strip}
    visited = []
    bc = wc = 0
    h.times do |i|
        w.times do |j|
            next if f[i][j] == "W" || f[i][j] == "B" || visited.include?([i,j])
            f, visited, bc, wc = bfs(f,i,j,h,w,visited,bc,wc)
        end
    end
    puts "#{bc} #{wc}"
end

Measured memory_bytes: 6164
n, m = map(int, input().split())
q = [tuple(map(int, input().split())) for _ in range(m)]

for i in range(1000):
    i = str(i)
    if len(i) != n:
        continue
    flag = True
    for s, c in q:
        if len(i) < s:
            flag = False
            break
        if i[s-1] != str(c):
            flag = False
            break
    if flag:
        print(i)
        exit()
print(-1)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    int n; cin >> n;
    vector<int> a(n+1);
    vector<pii> b[n+1];
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        for(int j = 0; j < a[i]; ++j) {
            int x, y;
            cin >> x >> y;
            b[i].emplace_back(x, y);
        }
    } 
    int ans = 0;
    for(int i = 1; i < (1 << n); ++i) {
        int cnt = 0;
        bool flag = true;
        for(int j = 0; j < n && flag; ++j) {
            if((i >> j) & 1) {
                cnt++;
                for(int k = 0; k < a[j+1] && flag; ++k) {
                    if(((i >> (b[j+1][k].first-1) & 1 )!= b[j+1][k].second)) flag = false;
                }
            }
        }
        if(flag) ans = max(ans, cnt);
    }
    cout << ans;
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> H){
  int maxN = 0;
  REP(x, N) {
    if (maxN > H.at(x)) {
      cout << NO << endl;
      return;
    }
    maxN = max(maxN, H.at(x)-1);
  }
  cout << YES << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> H(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&H[i]);
  }
  solve(N, std::move(H));
}


Measured memory_bytes: 1024
package main

import (
        "bufio"
        "fmt"
        "os"
)

func solution(n int, a []int) int {
        const MOD = 1e9 + 7
        out := 0
        cur := make([]int, n+1)
        cur[0] = a[0]
        for i := 0; i < n; i++ {
                cur[i+1] = a[i] + cur[i]
        }
        for i := 0; i < n; i++ {
                sum := (cur[n] - cur[i+1]) % MOD
                out += a[i] * sum
                out %= MOD
        }
        return out
}

func main() {
        r := bufio.NewReader(os.Stdin)
        var n int
        fmt.Fscan(r, &n)
        a := make([]int, n)
        for i := range a {
                fmt.Fscan(r, &a[i])
        }
        fmt.Println(solution(n, a))
}

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

int main()
{

long long int a,b;
  long long int ans;
  cin>>a>>b;
  long long int lar = max(a, b); 
    long long int small = min(a, b); 
    for (long long int i = lar; ; i += lar) { 
        if (i % small == 0) 
        {ans=i;break;} }
 cout<<ans;
      return 0;
}

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

int main() {
    int H, W;

    while(-1) {
    cin >> H >> W;

    if(H ==0&& W==0) break;

    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W; j++) {
            cout << '#';
        }
        cout << endl;
    }
    cout << endl;
    }

}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int N; cin >> N;
  ll MIN=10e9+1;
  int count=1;
  ll sum=0;
  for(int i=0;i<N;i++){
    ll a; cin >> a;
    sum+=abs(a);
    if(a<0){
      count*=-1;
    }
    MIN=min(MIN,abs(a));
  }
  if(count==-1){
    sum-=2*MIN;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256