akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;

int main(void) {
	int N, M;
	scanf("%d %d", &N, &M);
	int A[100];
	int total = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		total += A[i];
	}
	int pop = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] >= total / (4. * M)) {
			pop++;
		}
	}

	if (pop >= M) {
		cout << "Yes" << endl;

	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int a[111][111];
int cnt[111][111];
int n,m;

int if_swap(int i, int x, int y){
    int p = a[i][x]/m, q = a[i][y]/m;
    if(p==q)return 0;
    int diff = 0;
    diff += -cnt[x][p];
    diff += cnt[x][q];
    diff += -cnt[y][q];
    diff += cnt[y][p];
    return diff+2;
}

int do_swap(int i, int x, int y){
    int p = a[i][x]/m, q = a[i][y]/m;
    if(p==q)return 0;
    --cnt[x][p];++cnt[x][q];
    --cnt[y][q];++cnt[y][p];
    swap(a[i][x], a[i][y]);
    return 0;
}
struct Xor128{
    unsigned x,y,z,w;

    Xor128(unsigned w_=88675123):x(123456789),y(362436069),z(521288629),w(w_){};

    inline unsigned xor128(){
        unsigned t;
        t = x^(x<<11);
        x = y;
        y = z;
        z = w;
        return w = (w^(w>>19))^(t^(t>>8));
    }

    int nextInt(int x,int y){
        if(x>y)swap(x,y);
        return xor128()%(y-x)+x;
    }

    double nextDouble(double a,double b){
        return (double)(xor128()&0xffff)/0xffff*(b-a)+a;
    }

};

void make_test(int n, int m){
    vector<int> x(n*m);
    iota(x.begin(),x.end(),1);
    random_shuffle(x.begin(), x.end());
    cout<<n<<" "<<m<<endl;
    rep(i,n*m)cout<<x[i]<<" ";
    cout<<endl;
    exit(0);
}
int main(){
    cin>>n>>m;
    //make_test(n,m);
    rep(i,n)rep(j,m)cin>>a[i][j];
    rep(i,n)rep(j,m)--a[i][j];
    rep(i,m)rep(j,n)cnt[i][j]=-1;
    rep(i,n)rep(j,m)cnt[j][a[i][j]/m]++;
    int score = 0;
    rep(i,m)rep(j,n)score += cnt[i][j]*cnt[i][j];
    score/=2;
    auto rnd = Xor128();
    while(score){
        int i = rnd.nextInt(0, n), x = rnd.nextInt(0, m), y = rnd.nextInt(0, m);
        if(x==y)continue;
        int ret = if_swap(i,x,y);
        if(ret<=0)score += ret, do_swap(i,x,y);
        if(score==0)break;
    }
    rep(i,n){
        rep(j,m)cout<<a[i][j]+1<<" ";
        cout<<endl;
    }
    vector<int> b[m];
    rep(i,n)rep(j,m)b[j].push_back(a[i][j]);
    rep(i,m)sort(b[i].begin(),b[i].end());
    rep(i,n){
        rep(j,m)cout<<b[j][i]+1<<" ";
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
int	n,m,a,b,s,sa,sb;
bool flag; 
char ans[1010][1010];
int read()
{
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
void solve(int x,int y)
{
	if(n&1)
		for(int i=1;i<m&&x;i+=2,x--)
			ans[n][i]='<',ans[n][i+1]='>';
	if(m&1)
		for(int i=1;i<n&&y;i+=2,y--)
			ans[i][m]='^',ans[i+1][m]='v';
	for(int i=1;i<n;i+=2)
		for(int j=1;j<m;j+=2)
		{
			if(x)
				for(int d=0;d<2&&x;d++,x--)
					ans[i+d][j]='<',ans[i+d][j+1]='>';
			else
				for(int d=0;d<2&&y;d++,y--)
					ans[i][j+d]='^',ans[i+1][j+d]='v';
		}
}
int main()
{
	n=read();m=read();a=read();b=read();
	s=n*m/2;sa=n*(m/2);sb=m*(n/2);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			ans[i][j]='.';
	if(a+b>s||a>sa||b>sb) flag=0;
	else if(a+b<s) flag=1,solve(a,b);
	else if((n&1)&&(m&1))
	{
		flag=1;
		if((sa-a)&1)
		{
			solve(a-1,b+1);
			ans[n-2][m-2]='^';ans[n-2][m-1]='<';ans[n-2][m]='>';
			ans[n-1][m-2]='v';ans[n-1][m-1]='.';ans[n-1][m]='^';
			ans[n][m-2]='<';ans[n][m-1]='>';ans[n][m]='v';
		}
		else solve(a,b);
	}
	else
		if((sa-a)&1) flag=0;
		else flag=1,solve(a,b);
	if(flag) 
	{	
		puts("YES");
		for(int i=1;i<=n;i++,puts(""))
			for(int j=1;j<=m;j++)
				putchar(ans[i][j]);
	}
	else puts("NO");
    return 0;
}



Measured memory_bytes: 2176
<?php
 
list($H,$W,$N) = explode(" ",trim(fgets(STDIN)));
 
$ans = array(1 => 0,
             2 => 0,
             3 => 0,
             4 => 0,
             5 => 0,
             6 => 0,
             7 => 0,
             8 => 0,
             9 => 0
             );
 
$count = ($H - 2) * ($W - 2);
 
if($N > 0){
    for($i = 1;$i <= $N;$i++){
        list($a,$b) = explode(" ",trim(fgets(STDIN)));
        for($j = -1;$j <= 1;$j++){
            if($a + $j > 1 && $a + $j < $H){
                for($k = -1;$k <= 1;$k++){
                    if($b + $k > 1 && $b + $k < $W){
                        if(isset($map[$a + $j][$b + $k])){
                            $map[$a + $j][$b + $k] ++;
                        }else{
                            $map[$a + $j][$b + $k] = 1;
                        }
                    }
                }
            }
        }
    }
    
    foreach($map as $val){
        foreach($val as $val2){
            $ans[$val2] ++;
            $count --;
        }
    }
}
 
echo $count . PHP_EOL;
echo implode(PHP_EOL,$ans);
 
?>

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, D;
    cin >> N >> D;
    cout << ((N-1)/(2*D+1))+1 << endl;
    return 0;
}

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

int main(){
    int D;
    cin>>D;
    if(D==25){
        cout<<"Christmas"<<endl;
    }
    else if(D==24){
        cout<<"Christmas Eve"<<endl;
    }
    else if(D==23){
        cout<<"Christmas Eve Eve"<<endl;
    }
    else{
        cout<<"Christmas Eve Eve Eve"<<endl;
    }
}


Measured memory_bytes: 256
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print()
ans = 0
for i in range(N - 2):
    S = [P[i], P[i + 1], P[i + 2]]
    SS = sorted(S)
    if S[1] == SS[1]:
        ans += 1
print(ans)


Measured memory_bytes: 12484
n = gets.to_i

cities = n.times.map{gets.split}
cities_sorted = cities.sort do |a, b|
  (a[0] <=> b[0]).nonzero? || (b[1].to_i <=> a[1].to_i)
end

cities_sorted.each do |c|
  puts cities.find_index(c)+1
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio	
	int n,d;
	cin >> n >> d;
	int suma = (2*d)+1;
	int ans = 0;
	int ama = 0;
	if(n%suma != 0){
		ama+=1;
	}else{
		ama = 0;
	}
	ans = (n/suma)+ama;
	cout << ans << endl;
	return 0;
}








Measured memory_bytes: 3652
function main()
  
  N = parse(Int, readline())
  X = map(x -> parse(Int, x), split(readline()))
  
  X_sort = sort(X)
  
  ans = Dict()
  
  for i in 1:N
    mid = div(N, 2)
    if i <= mid
      mid = div(N, 2) + 1
    end
    ans[X_sort[i]] = X_sort[mid]
  end
  
  for i in X
    println(ans[i])
  end
  
end

main()

Measured memory_bytes: 166272
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

import decimal
a,b,c = map(int, input().split())
val = (c-a-b)**2 - 4*a*b
if c-a-b<0:
    print("No")
else:
    if val>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 77220
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 100000;
const ll LINF = 1LL<<61;

int main()
{
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;

    auto calc = [&](char c)
    {
        if(c == 'r') return p;
        if(c == 's') return r;
        if(c == 'p') return s;
    };

    auto dp = make_vec(n, 2, 0); //0:k日前に負ける 1:勝つ
    for(int i = 0; i < k; i++)
    {
        dp[i][0] = 0;
        dp[i][1] = calc(t[i]);
        for(int j = i; j < n - k; j += k)
        {
            int nj = j + k;
            chmax(dp[nj][0], dp[j][0]);
            chmax(dp[nj][0], dp[j][1]);
            chmax(dp[nj][1], dp[j][0] + calc(t[nj]));
            if(t[nj] == t[j]) continue;
            chmax(dp[nj][1], dp[j][1] + calc(t[nj]));
        }
    }
    int ans = 0;
    for(int i = n - k; i < n; i++)
    {
        ans += max(dp[i][0], dp[i][1]);
    }
    // cout << dp << endl;
    cout << ans << endl;

    return 0;
}

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

int n;

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

	int ans = 0;
	cin >> n;

	int cur = 1;
	while (cur <= n) {
		ans += min(cur * 9, n - cur + 1);
		cur *= 100;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n;
bool ok;
int main(){
	scanf("%d",&n);
	while(n>0){
		if(n%10==9){
			ok=1;
			printf("Yes");
			break;
		}
		n/=10;
	}
	if(ok==0) printf("No");
	return 0;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(a);
        int ans = 0;
        for (int i = n - 1; i >= n - k; i--) {
            ans += a[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <iostream>

using namespace std;

int main() {
	int H, W;

	while (cin >> H >> W && (H != 0 || W != 0)) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if(i == 0 || j == 0 || i == (H-1) || j == (W-1))
    				cout << "#";
    			else
    			    cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}



Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int T, D, L;

int main(void)
{
	while(1){
		cin >> T >> D >> L;
		if(T == 0 && D == 0 && L == 0) break;
		
		int rem = 0, h, ans = 0;
		for(int i = 1; i <= T; i++){
			cin >> h;
			if(i == T) continue;
			if(h >= L) rem = D;
			if(rem > 0) ans++;
			rem--;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
int a,b,i,k;
scanf("%d %d %d",&a,&b,&k);
for(i=a>b?b:a;i>0;i--){
	if(b%i==0 && a%i==0){
		k-=1;
		if(k==0){
			printf("%d",i);
			break;
		}
	}
}
}

Measured memory_bytes: 128
using System;

namespace pro
{



    class MainClass
    {
        public static void Main()
        {
            string str0 = Console.ReadLine();
            string str1 = Console.ReadLine();
            int count = 0;
            for (int i = 0; i < 3; i++)
            {
                if (str0[i] == str1[i])
                {
                    count++;
                }
            }
            Console.WriteLine(count);


        }
    }


}

Measured memory_bytes: 13140
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const double Pi=acos(-1.0);
int n,l,t[5005];
int main()
{
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)scanf("%d",&t[i]);
	double x=0,y=0;
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++)
	{
		x+=cos(Pi*(0.0+t[j]+t[i])/l)*(n-(j-i+1))+cos(Pi*(0.0+t[j]+t[i]+l)/l)*(j-i-1);
		y+=sin(Pi*(0.0+t[j]+t[i])/l)*(n-(j-i+1))+sin(Pi*(0.0+t[j]+t[i]+l)/l)*(j-i-1);
	}
	x/=n*(n-1.0)*(n-2)/6;
	y/=n*(n-1.0)*(n-2)/6;
	printf("%.12lf %.12lf\n",x,y);
	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

set<int> XU[200001], XD[200001], YL[200001], YR[200001];

set<int> PU[400001], PD[400001], PL[400001], PR[400001];
set<int> MU[400001], MD[400001], ML[400001], MR[400001];

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


	int N;
	cin >> N;


	rep(i, N) {
		int X, Y;
		char C;
		cin >> X >> Y >> C;

		if (C == 'U') {
			XU[X].insert(Y);
			PU[X + Y].insert(Y);
			MU[X - Y + 200000].insert(Y);
		}
		if (C == 'D') {
			XD[X].insert(Y);
			PD[X + Y].insert(Y);
			MD[X - Y + 200000].insert(Y);
		}
		if (C == 'R') {
			YR[Y].insert(X);
			PR[X + Y].insert(X);
			MR[X - Y + 200000].insert(X);
		}
		if (C == 'L') {
			YL[Y].insert(X);
			PL[X + Y].insert(X);
			ML[X - Y + 200000].insert(X);
		}
	}

	int kotae = 2e9;
	rep(i, 200001) {
		auto U = XU[i].begin(), D = XD[i].begin();
		while (U != XU[i].end()) {
			while (D != XD[i].end() && *U > *D) {
				D++;
			}
			if (D != XD[i].end()) chmin(kotae, (*D - *U) * 5);
			U++;
		}
	}
	rep(i, 200001) {
		auto U = YR[i].begin(), D = YL[i].begin();
		while (U != YR[i].end()) {
			while (D != YL[i].end() && *U > * D) {
				D++;
			}
			if (D != YL[i].end()) chmin(kotae, (*D - *U) * 5);
			U++;
		}
	}

	rep(i, 400001) {
		if (PR[i].size() && PU[i].size()) {
			auto A = PR[i].begin(), B = --PU[i].end();
			while (A != PR[i].end()) {
				while (B != PU[i].begin() && *A + *(B) > i) {
					B--;
				}
				if (*A + *B < i) chmin(kotae, 10 * (i - (*A + *B)));
				A++;
			}
		}
	}
	rep(i, 400001) {
		if (PD[i].size() && PL[i].size()) {
			auto A = --PD[i].end(), B = PL[i].begin();
			while (A != PD[i].begin()) {
				while (B != PL[i].end() && *A + *(B) < i) {
					B++;
				}
				if (B != PL[i].end()) chmin(kotae, 10 * ((*A + *B) - i));
				A--;
			}
			while (B != PL[i].end() && *A + *(B) < i) {
				B++;
			}
			if (B != PL[i].end()) chmin(kotae, 10 * ((*A + *B) - i));
		}
	}
	rep(i, 400001) {
		if (MR[i].size() && MD[i].size()) {
			auto A = MR[i].begin(), B = MD[i].begin();
			while (A != MR[i].end()) {
				while (B != MD[i].end() && *A - *B > i - 200000) {
					B++;
				}
				if (B != MD[i].end()) chmin(kotae, 10 * (i + *B - *A - 200000));
				A++;
			}
		}
	}
	rep(i, 400001) {
		if (MU[i].size() && ML[i].size()) {
			auto A = MU[i].begin(), B = ML[i].begin();
			while (A != MU[i].end()) {
				while (B != ML[i].end() && *B - *A < i - 200000) {
					B++;
				}
				if (B != ML[i].end()) chmin(kotae, 10 * (*B - *A - i + 200000));
				A++;
			}
		}
	}

	if (kotae > 1e9) co("SAFE");
	else co(kotae);


	Would you please return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, long long K, std::vector<long long> A){
    LL max_bit = 0;
    LL ans1 = 0;
    LL ans2 = 0;
    bool skip_flag = true;
    RREP(i, 41){
        LL cnt = 0;
        REP(j, A.size()){
            cnt += ((A[j] & (1LL << (LL)i)) == 0);
        }
        LL zero = (1LL << (LL) i) * (A.size() - cnt);
        LL one = (1LL << (LL) i) * cnt;

        if((K & (1LL << (LL)i)) == 0) {
            if(ans1 != 0) ans1 = max(ans1 + zero, ans1 + one);
            ans2 = ans2 + zero;
        } else {
            if(ans1 == 0) { ans1 = zero; }
            else { ans1 = max(max(ans1 + zero, ans1 + one), ans2 + zero); }
            ans2 = ans2 + one;
        }
    }

    cout << max(ans1, ans2) << endl;
}

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


Measured memory_bytes: 1024
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

color = [[-1]*W for _ in range(H)]
p, q = 0, 0
move_down_flg = 1

for i in range(N):
    for _ in range(a[i]):
        color[p][q] = i + 1
        if move_down_flg == 1 and p < H-1:
            p += 1
        elif move_down_flg == 1 and p == H-1:
            move_down_flg = 0
            q += 1
        elif move_down_flg == 0 and p > 0:
            p -= 1
        else:
            move_down_flg = 1
            q += 1

for x in color:
    print(*x)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t>vec(N);
    for (int64_t i=0; i<N; i++) {
        cin >> vec.at(i);
    }


    map<int64_t, int64_t>d;
    for (int64_t i=0; i<N; i++) {
        int64_t num = vec[i];
        if(d.count(num) > 0) {
            d[num] = d[num] + 1;
        } else {
            d[num] = 1;
        }
    }

    int64_t number_count = 0;
    int64_t count = 0;
    int64_t num = 0;
    bool is_first = true;
    bool is_can = true;
    for (auto c : d) {
        if (is_first) {
            num = c.first;
            count += 1;
            number_count = c.second;
            is_first = false;
        } else {
            num = num^c.first;
            count += 1;
            if (number_count != c.second) {
                is_can = false;
                break;
            }
        }
    }

    if (d[0] > 0 && count <= 2) {
        int64_t zero_count = 0;
        int64_t other_count = 0;
        for (auto c: d) {
            if (c.first == 0) {
                zero_count = c.second;
            } else {
                other_count = c.second;
            }
        }

        if (other_count == 0 || zero_count*2==other_count) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else if (is_can && num == 0 && count == 3) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////

signed main() {
  int n;
  cin>>n;
  int a,b;
  cin>>a>>b;
  int ans=modpow(2,n)-1;
  int c1=1,c2=1;
  for(int i=n;i>=n-a+1;i--){
    c1=c1*i%MOD;
  }
  rep(i,a){
    c1=c1*gyaku(i+1)%MOD;
  }
  for(int i=n;i>=n-b+1;i--){
    c2=c2*i%MOD;
  }
  rep(i,b){
    c2=c2*gyaku(i+1)%MOD;
  }
  ans=(ans-c1-c2)%MOD;
  while(ans<0)ans+=MOD;
  cout<<ans<<endl;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  int cnt = 0;
  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    if (a!=i){
      cnt++;
    }
  }
  if (cnt==2 || cnt==0){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

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

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a) for (int i = (a); i > 0; --i)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    UnionFind(int size) : par(size), rank(size) {
        REP(i, size) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
    bool same(int x, int y) { return find(x) == find(y); }
};

struct edge {
    int u, v, cost;
};

bool comp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }

int N, E;
edge es[2 * 100005];

int kruskal() {
    sort(es, es + E, comp);
    UnionFind uf(N);
    int res = 0;
    REP(i, E) {
        edge& e = es[i];
        if (!uf.same(e.u, e.v)) {
            uf.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

struct Point {
    int x, y, id;
};

bool compx(Point& p1, Point& p2) { return p1.x < p2.x; }
bool compy(Point& p1, Point& p2) { return p1.y < p2.y; }

signed main() {
    cin >> N;

    vector<Point> ps(N);
    REP(i, N) {
        Point p;
        cin >> p.x >> p.y;
        p.id = i;
        ps[i] = p;
    }

    sort(ps.begin(), ps.end(), compx);
    FOR(i, 1, N) {
        es[E].u = ps[i - 1].id;
        es[E].v = ps[i].id;
        es[E].cost = ps[i].x - ps[i - 1].x;
        E++;
    }
    sort(ps.begin(), ps.end(), compy);
    FOR(i, 1, N) {
        es[E].u = ps[i - 1].id;
        es[E].v = ps[i].id;
        es[E].cost = ps[i].y - ps[i - 1].y;
        E++;
    }

    cout << kruskal() << endl;

    return 0;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	ULL GCD(ULL a, ULL b) { return (b == 0) ? a : GCD(b, a % b); }

	const ULL M = 1000000007;
	static const ULL Sz = 200000;
	ULL pow2[Sz + 1];
	ULL C[Sz];
	
	void Solve() {
		/*
		UL n, m; cin >> n >> m;
		ULL A[100000]; rep(i, n) cin >> A[i];
		ULL d = 1;
		while (A[0] % (d * 2) == 0) d *= 2;
		rep(i, n) {
			if (A[i] % d != 0) { cout << 0 << endl; return; }
			A[i] /= d;
			if (A[i] % 2 == 0) { cout << 0 << endl; return; }
		}
		ULL lcm = 1;
		rep(i, n) {
			lcm = lcm * A[i] / GCD(lcm, A[i]);
			if (lcm > m) { cout << 0 << endl; return; }
		}
		cout << (m + lcm) / (lcm * 2) << endl;
		*/
		UL N; cin >> N;
		pow2[0] = 1;
		rep(i, N) {
			pow2[i + 1] = pow2[i] * 2 % M;
		}
		rep(i, N) cin >> C[i];
		sort(C, C + N);
		ULL ans = 0;
		rep(i, N) {
			ULL j = N - i;
			ULL ad = ((j - 1) * 500000004 + 1) % M;
			ad = ad * pow2[j - 1] % M;
			ad = ad * C[i] % M;
			ad = ad * pow2[i] % M;
			ans = (ans + ad) % M;
		}
		ans = ans * pow2[N] % M;
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 3328
import math
a,b,h,m=map(int,input().split())
new_h=h+m/60
k=new_h/12*360*math.pi/180
s=m/60*360*math.pi/180
L=[a*math.cos(k),a*math.sin(k)]
l=[b*math.cos(s),b*math.sin(s)]
x1=L[0]
y1=L[1]
x2=l[0]
y2=l[1]
long=math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(long)

Measured memory_bytes: 9428
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let a = scan.readn::<i64>(3);
    println!("{}", if a.iter().sum::<i64>() >= 22 {"bust"} else {"win"});
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4476
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
void putans(ll x,ll y,string s){
  cout<<x<<" "<<y<<" "<<s<<endl;
}
int main() {
  cout << fixed << setprecision(30);
  ll n,p;
  cin>>n>>p;
  vec a(n);
  bool kisuu=false;
  loop(i,n){
    cin>>a[i];
    if(a[i]%2==1)kisuu=true;
  }
  if(kisuu)putout((ll)pow(2,n-1));
  else{
    if(p)putout(0);
    else putout((ll)pow(2,n));
  }
}

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

int main() {
    int N, M;  cin >> N >> M;
    vector<vector<int>> G(N, vector<int>());
    for (int i = 0; i < M; ++i) {
        int a, b;  cin >> a >> b;  --a;  --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> ans(N);
    using P = pair<int, int>;
    queue<P> q;
    q.push(P(0, -1));
    while (!q.empty()) {
        P p = q.front();  q.pop();
        for (int nv : G[p.first]) {
            if (ans[nv] == 0 && nv != 0) {
                q.push(P(nv, p.first));
                ans[nv] = p.first + 1;
            }
        }
    }
    // DUMP(ans);

    for (int i = 1; i < N; ++i) {
        if (ans[i] == 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; ++i) cout << ans[i] << endl;
}


Measured memory_bytes: 10552
n,m=(int(x) for x in input().split())
a=[]
for i in range(n):
  aa=list(map(int,input().split()))
  a.append(aa)
b=[]
for i in range(m):
  bb=int(input())
  b.append(bb)
c=[]
for i in range(n):
  ci=0
  for j in range(m):
    cie=a[i][j]*b[j]
    ci+=cie
  c.append(ci)
for i in range(len(c)):
  print(c[i])


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


int main(){
    ll n,k;cin>>n>>k;
    string s;cin>>s;
    ll now=n;
    vector<ll> an;
    while(1){
        for(ll i=k;i>0;i--){
            if(s[max(now-i,0LL)]=='0'){
                now=now-i;
                if(now<0)an.push_back(now+i);
                else an.push_back(i);
                break;
            }
            
            if(i==1){
                cout<<-1<<endl;
                return 0;
            }
        }
        if(now<=0)break;
    }
    for(ll i=an.size()-1;i>=0;i--){
        cout<<an[i];
        if(i!=0)cout<<" ";
    }
}

    









Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int n; cin >> n;
    vi a(n);
    REP(i, n) cin >> a[i];
    int maxans = -1, ans;
    REP(i, n){
        REP(j, n){
            if (i == j) continue;
            ans = abs(a[i] - a[j]);
            maxans = max(maxans, ans);
        }
    }
    cout << maxans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

                    
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    int A_1, A_2, A_3;
    cin >> A_1 >> A_2 >> A_3;
    if ((A_1+A_2+A_3) >= 22) cout << "bust" << endl;
    else cout << "win" << endl; 
}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        long n = obj.nextLong(),a = obj.nextLong(),b = obj.nextLong(),k = n%(a+b);
        System.out.println(((n/(a+b))*a+((k>=a)?a:k)));
    }
}


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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int sum = 0;
    int a[105010];
    a[0] = 0;
    a[N + 1] = 0;
    rep(i, N) cin >> a[i + 1];
    rep(i, N + 1) {
        sum += abs(a[i + 1] - a[i]);
    }
    rep(i, N) {
        cout << sum - abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i]) << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
from itertools import accumulate
import bisect

N = int(input())
A = list(map(int,input().split()))
acmA = list(accumulate(A))
idx = bisect.bisect(acmA, acmA[-1]/2)
print(min(abs(acmA[idx-1]-(acmA[-1]-acmA[idx-1])),abs(acmA[idx]-(acmA[-1]-acmA[idx]))))

Measured memory_bytes: 25768
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<map>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int n;
int x;
int arr[100100];
int main()
{
	read(n);
	int ans=0;
	for(int i=0;i<n;i++)
	{
		read(x);
		for(int j=0;j<3;j++)
		{
			arr[x+j]++;
			ans=max(ans,arr[x+j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
int main(){
  char N,M;
  cin>>N>>M;
  string str1,str2;
  for(ll i=0;i<(int)(N-'0');i++){
    str1+=M;
  }
  for(ll i=0;i<(int)(M-'0');i++){
    str2+=N;
  }
  vector<string> vec(2);
  vec.at(0)=str1;
  vec.at(1)=str2;
  sort(vec.begin(),vec.end());
  cout<<vec.at(0)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int N=0;
  char S[4];
  int i;
  scanf("%s",S);
  for(i=0;i<5;i++){
    if(S[i]=='+'){
      N=N+1;
    }
    else if(S[i]=='-'){
      N=N-1;
    }
  }
  printf("%d",N);
  return 0;
}

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

int main() {
    int N, a;
    cin >> N;
    bool exist_odd = false;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (a % 2 != 0) exist_odd = true;
    }
    if (exist_odd) cout << "first" << endl;
    else cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    int d; cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d)rep(j, 26) cin >> s[i][j];
    vector<vector<int>> last(d, vector<int>(26));
    rep(i, d)rep(j, 26) last[i][j] = 0;
    vector<int> ans(d + 1, 0);
    int max_score;
    int max_con;
    int score, sum;
    rep(i, d){
        max_score = 0;
        rep(j, 26){
            sum = 0;
            rep(k, 26){
                if(k != j) sum += c[k] * ((i + 1) - last[i][k]);
            }
            score = s[i][j] - sum;
            if(max_score < score){
                max_score = score;
                max_con = j;
            }
        }
        last[i][max_con] = i + 1;
        ans[i] = max_con + 1;
    }
    rep(i, d) cout << ans[i] << endl;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;

int main(){
  int N;
  cin >> N;
  // 入力を入れるvector
  vector<int> P(N);
  rep(i, N){
    cin >> P[i];
  }
  // 昇順の数列を入れるvector
  vector<int> Q(N);
  rep(i, N){
    Q[i] = i+1;
  }
  // PとRの要素が同じかどうかを判断するboolを入れるvector
  vector<bool> R(N);
  rep(i, N){
    if (P[i]!=Q[i]) R[i]=true;
    else R[i]=false;
  }
  // 異なっている箇所が2箇所以下であればOK
  int sums=0;
  rep(i, N){
    sums += R[i];
  }
  if (sums<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

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

  for (int i=0; i<a; i++) {
    if ((b*i+c)%a == 0) {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,l,arr[300];

int main(){
	scanf("%d%d",&n,&l);
	int t1,mins=1e5;
	int fus=1;
	for(int i=1;i<=n;i++){
		arr[i]=l+i-1; 
//		cout<<arr[i]<<endl;
		if(arr[i]<mins&&arr[i]>=0){
			mins=arr[i];
			fus=0;
		}
	}
	int maxs=0;
	if(fus) {
		sort(arr+1,arr+n+1);
	}
	for(int i=1;i<=n;i++){
		if(!fus){
			if(arr[i]!=mins){
				maxs+=arr[i];
			}	
		}else{
			if(arr[i]!=arr[n])
				maxs+=arr[i]; 
		}
	}
	cout<<maxs<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100010;
const int INF=2147483647;
int a[N];
int main()
{
    int n,k,m;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]==1)
            m=i;
    }
    int ans=0;
    if(m<=k){
        ans=(n-k)/(k-1)+((n-k)%(k-1)!=0)+1;
    }
    else if(m>=n-k){
        ans=(n-k)/(k-1)+((n-k)%(k-1)!=0)+1;
    }
    else{
        ans=(m-1)/(k-1)+((m-1)%(k-1)!=0);
        m=ans*(k-1)+1;
        ans+=(n-m)/(k-1)+((n-m)%(k-1)!=0);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;
const ll limit =1e18;
int main(){
    int n;
    cin >> n;
    ll ans=1;
    bool flg = false;
    rep(i,n){
        ll a;
        cin >> a;
        if(a==0){
            cout << 0 << endl;
            return 0;
        }else if(flg || a>(limit/ans)){
            flg=true;
            continue;
        }
        ans*=a;
    }
    if(flg) cout<<-1<<endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
package main

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

func solution(n, t int, ts []int) uint64 {
        var sum uint64 = 0
        for i := 1; i < n; i++ {
                d := ts[i] - ts[i-1]
                if d >= t {
                        sum += uint64(t)
                } else {
                        sum += uint64(d)
                }
        }
        return sum + uint64(t)
}

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

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

using namespace std;

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

void solve() {
  ll a, b, c;
  cin >> a >> b >> c;
  cout << min(b+c, a+2*b+1) << endl;
}

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


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

using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    bool possible = false;
    for (int a = 1; a < 10; ++a) {
        for (int b = 1; b < 10; ++b) {
            if (a*b == n) {
                possible = true;
            }
        }
    }
    if (possible) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string S, T, U;
	int A, B;
	cin >> S >> T >> A >> B >> U;
	if(U[0] == S[0])
		cout << A -1 << " " << B;
	else
		cout << A << " " << B - 1;
	return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> a(h);
  vector<int> row(h), col(w);

  for (int i = 0; i < h; i++) cin >> a[i];

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        row[i] = 1;
        col[j] = 1;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    if (row[i] == 1) {
      for (int j = 0; j < w; j++) {
        if (col[j] == 1) cout << a[i][j];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
//#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
#define INF (long long)102000000000000
#define NAX (int)1e2+2
typedef long long ll;
typedef unsigned long long ull;
//#define NAX (int)1e5+2
class solution{
public:
	void solve(){
		int n;
		cin>>n;
		vector<int> a(n),b(n),test(n);
		for(int i=0;i<n;i++){
			test[i] = i+1;
		}
		for(int i =0;i<n;i++){
			cin>>a[i];
		}
		for(int i =0;i<n;i++){
			cin>>b[i];
		}
		int count_a,count_b;
		int count = 1;
		do{
			if(test == a){
				count_a = count;	
			}
			if(test == b){
				count_b = count;
			}
			count++;
		}while(next_permutation(test.begin(),test.end()));
		cout<<abs(count_a-count_b);
	}
};
	  
int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();

 return 0;
}


Measured memory_bytes: 256
import itertools

N = int(input())
L = list(map(int,input().split()))

# N = 2000
# L = list(range(N))

# # 重複を消す
# L = list(set(L))
# N = len(L)

# Lを小さい順にソート
L = sorted(L)

# j=0〜max(L)について，L[i]<jを満たす最大のi: X[j] = i
X = []
for j in range(L[-1]+1):
    flag = False
    for i in range(N-1,-1,-1):
        if L[i] < j:
            X.append(i)
            flag = True
            break
    # 見つからなければ
    if not flag: X.append(None)

# j=0〜max(L)について，L[i]>jを満たす最小のi: Y[j] = i
Y = []
for j in range(L[-1]+1):
    flag = False
    for i in range(N):
        if L[i] > j:
            Y.append(i)
            flag = True
            break
    # 見つからなければ
    if not flag: Y.append(None)

#print(L)

ind1 = 0
ind2 = N-1
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]

        # print(b-a,a+b,Y[b-a],X[a+b])

        # cのindexの範囲 = Y[b-a]〜X[a+b]
        cmin = Y[b-a]
        if a+b <= L[-1]:
            cmax = X[a+b]
        else:
            cmax = N - 1

        # cminはjより大きい
        if cmin is not None and cmin <= j:
            cmin = j + 1

        #print(b-a,a+b,cmin,cmax)

        # if a == 2 and b == 3:
        #     print(b-a,a+b,cmin,cmax)
        #     exit()
        
            
        # どちらかがNoneなら0
        if cmin is not None and cmax is not None and cmin <= cmax:
            ans += cmax - cmin + 1

print(ans)

Measured memory_bytes: 3188
#include <cstdio>
#include<cstring>
#include <algorithm>
int n,d,a;

struct M{
	long long x,h;
	bool operator< (const M&a)const{
		return x<a.x;
	}
}m[200010];

long long c[200010];
void add(int x,long long d)
{
	while(x<=n)
	{
		c[x]+=d;
		x+=x&-x;
	}
}
long long que(int x)
{
	long long ans=0;
	while(x)
	{
		ans+=c[x];
		x-=x&-x;
	}
	return ans;
}

int main()
{
	// freopen("test.in","r",stdin);
	scanf("%d%d%d",&n,&d,&a);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&m[i].x,&m[i].h);
	std::sort(m+1,m+1+n);
	for(int i=1;i<=n;i++)
	{
		add(i,m[i].h);
		add(i+1,-m[i].h);
	}
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		if(que(i)<=0) continue;
		int ll=i,rr=n,mid=ll+rr>>1;
		while(ll+1<rr)
		{
			if(m[i].x+d>=m[mid].x-d) ll=mid;
			else rr=mid-1;
			mid=ll+rr>>1;
		}
		if(m[i].x+d+d>=m[rr].x) mid=rr;
		long long cnt=(que(i)+a-1)/a;
		add(i,-cnt*(long long)a);
		add(mid+1,cnt*(long long)a);
		ans+=cnt;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864