akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

        int[] c = new int[n];
        int[][] a = new int[n][m];
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        boolean isAchievable = false;
        int minRefBooksPrice = -1;

        // ex:100(=4)
        int numPattern =  (int) Math.pow(2, n);
        // ex:1000(=8) due to set 1 prefix
        int flagnum =  numPattern * 2;

        // ex:1000(=8) to 1011(=11)
        for (int i = flagnum; i < flagnum+numPattern; i++) {
            String flag = Integer.toBinaryString(i);

            int [] curRikaido = new int[m];
            int curPrice = 0;
            //フラグに従い積み上げ
            for (int j = 0; j < n; j++) {
                if (flag.charAt(j+2)=='1') {
                    for (int j2 = 0; j2 < curRikaido.length; j2++) {
                        curRikaido[j2] += a[j][j2];
                    }
                    curPrice += c[j];
                }
            }
            //判定
            boolean isCurAchi = true;
            for (int j2 = 0; j2 < curRikaido.length; j2++) {
                if(curRikaido[j2]<x) {
                    isCurAchi = false;
                }
            }
            //値段更新
            if (isCurAchi) {
                if (minRefBooksPrice == -1) {
                    minRefBooksPrice =curPrice;
                }else if(minRefBooksPrice >curPrice) {
                    minRefBooksPrice =curPrice;
                }
            }
        }

        // 出力
        System.out.println(minRefBooksPrice);
    }
}

Measured memory_bytes: 38644
n=int(input())#11:02
facts=[]
lies=[]
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

for i in range(n):
    fact=0
    lie=0
    q=int(input())
    for j in range(q):
        x,y=map(int,input().split())
        if y==0:
            lie+=1<<(x-1)
        else:
            fact+=1<<(x-1)
    lies.append(lie)
    facts.append(fact)

ans=0
for i in range(1<<n):
    flag=True
    for j in range(n):
        if i&(1<<j):
            fact=facts[j]
            lie=lies[j]
            if (fact != (fact&i)) or (lie!=(lie&~i)):
                flag=False
                break
    if flag:
        ans=max(ans,popcnt(i))
print(ans)
"""
3
3
1 1
2 1
3 1
1
1 1
1
1 1

"""

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    cout << N * N * N << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    ll ans=0;
    int n = s.length();
    for(int i=0;i < 1 << n-1;i++){
        ll sum=0;
        ll a = s[0] - '0';
        REP(j,n-1){
            if(i & (1<<j)){
                sum += a;
                a = 0;
            }
            a = a * 10 + s[j+1] - '0';
        }
        sum += a;
        ans += sum;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
const int MAX = 510000;

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){
    return n * finv[k] % MOD;
}

signed main(){
  int N,A,B; cin>>N>>A>>B;
  bitset<60> X(N);
  int sum=1;
  vi P(61,2);
  REP(i,1,60) P[i]=P[i-1]*P[i-1]%MOD;
  rep(i,0,60){
    if(X.test(i)){
      sum*=P[i];
      sum%=MOD;
    }
  }
  sum--;
  COMinit();
  int ans=0;
    int Sum=1;
    rep(i,0,A){
      Sum*=N-i;
      Sum%=MOD;
    }
    ans+=COM(Sum,A);
    Sum=1;
    rep(i,0,B){
      Sum*=N-i;
      Sum%=MOD;
    }
    ans+=COM(Sum,B);
  ans%=MOD;
  cout<<(sum+MOD-ans)%MOD<<endl;
  }



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

int main(){
  int n, x;
  cin >> n;
  map<ll, int> mp;
  ll rui = 0;
  ll ans = 0;
  for(int i=0; i<n; ++i){
    cin >> x;
    rui += x;
    ans += mp[rui];
    ++mp[rui];
  }
  ans += mp[0];
  cout << ans << endl;
}

Measured memory_bytes: 12800
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "Yes" : "No")
using namespace std;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n = 0, a[10000], count = 0;
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		while (a[i] % 2 == 0) {
			count++;
			a[i] /= 2;
		}
	}
	cout << count;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007
#define EPS 1e-9

int N;
double L;
double S[90000],T[90000];
double U[90000];

bool ok(double x){
  double crt=L;
  repl(i,1,N+1){
    crt=min(L,crt+(S[i]-T[i-1])*x);
    crt=min(L,crt+(T[i]-S[i])*(x-U[i]));
    if(crt<EPS)return false;
  }
  crt=min(L,crt+(86400-T[N])*x);

  double crt2=crt;
  repl(i,1,N+1){
    crt2=min(L,crt2+(S[i]-T[i-1])*x);
    crt2=min(L,crt2+(T[i]-S[i])*(x-U[i]));
    if(crt2<EPS)return false;
  }
  crt2=min(L,crt2+(86400-T[N])*x);
  
  return abs(crt2-crt)<EPS;
}

int main(){
  while(1){
    scanf("%d%lf",&N,&L);
    if(N==0)break;
    double ub=0;
    S[0]=T[0]=U[0]=0;
    repl(i,1,N+1){
      scanf("%lf%lf%lf",&S[i],&T[i],&U[i]);
      maxch(ub,U[i]);
    }
    double lb=0;
    rep(hoge,100){
      double mid=(lb+ub)/2;
      if(ok(mid))ub=mid;
      else lb=mid;
    }
    printf("%.10f\n", ub);
  }
  return 0;
}



Measured memory_bytes: 5180
N = int(input())
A = list(map(int, input().split()))
X = 1
if 0 in A:
  print(0)
else:
  flg = True
  for i in range(N):
    X *= A[i]
    if X > int(1e18):
      flg = False
      break
  if flg:
    print(X)
  else:
    print(-1)


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

int main() {
	int N, K;
	vector<int> A;

	cin >> K >> N;
	int max=0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A.push_back(a);

		if (i != 0) {
			if (max < A[i] - A[i - 1]) {
				max = A[i] - A[i - 1];
			}
		}

	}
	if (max < (K - A[N - 1]) + A[0]) {
		max = (K - A[N - 1]) + A[0];
	}
	cout << K - max;
	return 0;




}

Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using SS = stringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + ( p ), ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

template < typename T > inline bool chmin( T &a, const T &b ){ if ( b < a ) { a = b; return true; } return false; }
template < typename T > inline bool chmax( T &a, const T &b ){ if ( a < b ) { a = b; return true; } return false; }

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const char *MSG[] = { "Impossible", "Possible" };

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

	int N;
	cin >> N;
	VI A( N );
	cin >> A;
	sort( ALL( A ), greater< int >() );

	const int diam = A[0];
	if ( A[0] != A[1] )
	{
		cout << *MSG << endl;
		return 0;
	}

	VI ds( N );
	for ( int i = 0; i <= diam - i; ++i )
	{
		ds[ diam - i ] += 1 + ( i != diam - i );
	}

	FOR( a, A )
	{
		if ( ds[a] )
		{
			--ds[a];
			continue;
		}

		if ( !ds[ a - 1 ] )
		{
			cout << *MSG << endl;
			return 0;
		}
	}

	cout << MSG[ all_of( ALL( ds ), bind( equal_to< int >(), 0, _1 ) ) ] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int d;
    int n;
    scanf("%d %d", &d, &n);
    int a = 1;
    for(int f=0; f<d; f++) {
        a = a * 100;
    }
    if(n == 100) {
        printf("%d\n", 101 * a);
    }
    else{
        printf("%d\n", n*a);
    }
}

Measured memory_bytes: 128
// #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#include <bits/stdc++.h>
//~ #include <atcoder/all>
using namespace std;
using ll = long long;
//~ using P = pair<int, int>;

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 A = (1<<2) | (1<<3) | (1<<5) | (1<<7);
//~ for (int bit=A; ; bit=(bit-1)&A){
//~ if (!bit) break;
//~ }
int next_combination(int sub)
{
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
//~ int n=5;
//~ int k=3; // nCkの組み合わせ、ただしk=0には対応してない
//~ int bit=(1<<k)-1; // 1000 -> 0111
//~ for(; bit < (1<<n); bit=nex_combination(bit){
//~ }
bool isPrime(int a)
{
    if (a == 2)
        return true;
    if (a <= 1 || a % 2 == 0)
        return false;

    for (int i = 3; i * i <= a; i += 2)
    {
        if (a % i == 0)
            return false;
    }
    return true;
}
//~ vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
vector<int> aaa;
// index が条件を満たすかどうか
bool isOK(int index, int key)
{
    if (aaa[index] >= key)
        return true;
    else
        return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key)
{
    int ng = -1;              //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)aaa.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//~ int v[100100];
//~ int INF = 1 << 30;
//~ vector<vector<int>> dp(310, vector<int>(310));
//~ ll dp[110][100100];
//~ vector<int> dp(100100, 0));

//~ int seen[110];
//~ int ans[110][2];
//~ ll MOD = 1e9 + 7;
vector<vector<int>> a(3, vector<int>(3, 0));
vector<vector<bool>> b(3, vector<bool>(3, false));

bool bingoCheck(void)
{
    rep(i, 3)
    {
        if ((b[i][0] == true && b[i][1] == true && b[i][2] == true) ||
            (b[0][i] == true && b[1][i] == true && b[2][i] == true))
            return true;
    }
    if ((b[0][0] == true && b[1][1] == true && b[2][2] == true) ||
        (b[2][0] == true && b[1][1] == true && b[0][2] == true))
        return true;

    return false;
}

int main()
{
    rep(i, 3) rep(j, 3) cin >> a[i][j];

    int n;
    cin >> n;

    rep(i, n)
    {
        int c;
        cin >> c;

        rep(j, 3)
        {
            rep(k, 3)
            {
                if (a[j][k] == c)
                {
                    b[j][k] = true;
                }
            }
        }
    }

    if (bingoCheck())
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long prime(long long n){
    long long i;
    if(i==3||i==2)
        return 1;
    for(i=2;i*i<=n;i++){
        if(n%i==0)
            return 0;
    }
    return 1;
}
int main()
{
    long long a,b,i,tt=0,tnt=0,d;
    scanf("%lld%lld",&a,&b);
    long long c=__gcd(a,b);
    if(c==1){
        printf("1\n");
        return 0;
    }
    if(prime(c)==1)
        tt++;
    else{
            tt=0;
    for(i=2;i<=c;i++){
        if(c%i==0){
            //printf("1\n");
            tt++;
            d=c/i;
            c=d;
            while(c%i==0){
                d=c/i;
                c=d;}
                //printf("%lld\n",c);
            long long y=prime(c);
           if((y==1)&&c>1){
            tt++;
            //printf("haha %lld\n",tt);
            tnt=1;
           }

        }
        if(tnt==1)
        break;
    //printf("%lld\n",tot);

    }
    }
    tt++;

    printf("%lld\n",tt);

}


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

int main(){
	int team, ac, q, team_ac[100], rank, eq[99], d, i, team_max = 0, j, ju;
	while(scanf("%d,%d", &team, &ac) != 0){
		if(team == ac && team == 0) break;
		team_ac[team - 1] = ac;
		if(team_max < team) team_max = team;
	}
	while(scanf("%d", &team) != EOF){
		rank = 1;
		d = 0;
		for(i = 0; i < team_max; i++){
			if(team_ac[team - 1] < team_ac[i]){
				ju = 0;
				for(j = 0; j < d; j++){
					if(eq[j] == team_ac[i]){
						ju = 1;
						break;
					}
				}
				if(ju == 0){
					eq[d] = team_ac[i];
					rank++;
					d++;
				}
			}
		}
		printf("%d\n", rank);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <iomanip>  
#include <cmath>
#include <algorithm> 
#include <vector> 

using namespace std; 

int k, a, b;

int main(){
    cin >> k >> a >> b;
    for (int i = a; i <= b; ++i) {
        if (i % k == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
}
/* 3.57 */

Measured memory_bytes: 3636
n = int(input())
h = [i for i in map(int, input().split())]

DP = [0, abs(h[0]-h[1])]

for i in range(n-2):
    DP += [min(abs(h[i+2]-h[i])+DP[i], abs(h[i+2]-h[i+1])+DP[i+1])]

print(DP[-1])

Measured memory_bytes: 13980
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

template <class T, class U>
ll euclid_gcd(T a, U b){
    if(a < b)return euclid_gcd(b,a);
    ll r;
    while((r = a%b)){
        a = b;
        b = r;
    }
    return b;
}

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
int main(){
    ll n,X; cin >> n >> X;
    vector<ll> x(n+1), dif(n);
    rep(i,n) cin >> x[i];
    x[n] = X;
    sort(all(x));
    ll ret = numeric_limits<ll>::max() / 4;
    rep(i,n)dif[i] = x[i+1] - x[i];
    rep(i,n-1){
        ll temp = euclid_gcd(dif[i], dif[i+1]);
        chmin(ret, temp);
    }
    cout << (n == 1 ? dif[0] : ret) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,A[1000010],cnt[1000010],ans[1000010];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	for(int i=n;i>=1;i--){
		int res=0;
		for(int j=i;j<=n;j+=i){
			res+=cnt[j];
		}
		res%=2;
		cnt[i]=res^A[i];
	}
	for(int i=1;i<=n;i++){
		if(cnt[i]==1)ans[++ans[0]]=i;
	}
	cout<<ans[0]<<endl;
	for(int i=1;i<=ans[0];i++)printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 9728
#include<stdio.h>

int main()
{
  int N, A[100];
  int result;
  int i, j, k;

  //Read N and Sets
  scanf("%d", &N);
  for(i=0; i<N; i++)scanf("%d", &A[i]);

  //Begin Bubble Sort
  result=0;
  for(i=0; i<N; i++)
    {
      for(j=N-1; j>=i+1; j--)
	{
	  //if A[j]<A[j+1], change;
	  if(A[j]<A[j-1])
	    {
	      k=A[j];
	      A[j]=A[j-1];
	      A[j-1]=k;
	      result++;
	    }
	}
    }

  //print
  for(i=0; i<N; i++)
    {
      if(i!=N-1)printf("%d ", A[i]);
      else printf("%d", A[i]);;
    }
  printf("\n%d\n", result);



  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
  	cin>>a[i];
  }
  int cnt=0;
  for(int i=0;i<n;i++)
  {
  	// int cnt=0;
  	if(a[i]%2==0)
  	{
  		cnt++;
  	}
  }
  int cnt2=0;
  for(int i=0;i<n;i++)
  {
  	//int cnt2=0;
  	if(a[i]%2==0 && ((a[i]%3==0) ||(a[i]%5==0)))
  	{
  		cnt2++;
  	}
  }
  if(cnt==cnt2)
  {
  	cout<<"APPROVED"<<endl;
  }
  else
  {
  	cout<<"DENIED"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int dp[21][2100000];
int done;
int n;
int a[21][21];
int d[21];
int solve(int rowmask,int i)
{
      if(rowmask==done&&i==n)
      return 1;
      if(dp[i][rowmask]!=-1)
      return dp[i][rowmask];
      int safe = d[i]&(~rowmask);
      int ans = 0;
      while(safe)
      {
          int p = safe&(-safe);
          safe = safe-p;
          ans = (ans%mod+solve(rowmask|p,i+1)%mod)%mod;
      }
      return dp[i][rowmask] = ans;    
}
int main() {
    cin>>n;
    done = (1<<n)-1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=0;i<n;i++)
    {
        int tem=1;
        int ans= 0;
        for(int j=n-1;j>=0;j--)
        {
           ans+=tem*a[i][j];
           tem*=2;
        }
        d[i] = ans;
    }
    memset(dp,-1,sizeof dp);
    cout<<solve(0,0);
}


Measured memory_bytes: 175880
fun main(args: Array<String>) {

    val list: List<Int> = readLine()!!.split(" ").map{ it.toInt() }

    var h = list.get(2) - list.get(0)
    var m = list.get(3) - list.get(1)

    val ans = h * 60 + m - list.get(4)

    print(ans)
}

Measured memory_bytes: 36504
n = int(input())
l, r = 0, 10 ** 4
while r - l > 1:
    m = (l + r) // 2
    if m * (m - 1) // 2 <= n:
        l = m
    else:
        r = m
if l * (l - 1) // 2 != n:
    print('No')
else:
    print('Yes')
    print(l)
    a = [[] for _ in range(l)]
    t = 1
    for i in range(l):
        for j in range(i + 1, l):
            a[i].append(t)
            a[j].append(t)
            t += 1
    for x in a:
        print(len(x), end=' ')
        print(' '.join(map(str, x)))


Measured memory_bytes: 9076
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<algorithm>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for (auto it = A.begin(); it != A.end(); ++it)cin >> *it;

    //for (auto it = A.begin(); it != A.end(); ++it)cout << *it << endl;
    
    int sum = accumulate(A.begin(), A.end(), 0);
    int res = 0;

    for (auto it = A.begin(); it != A.end(); ++it) {
        if (4 * M * (*it) >= sum)res++;
    }
    if (res >= M)cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n,i,j,k,l,m,a=1,flag=0;
	int ans[451][450]={0};
	scanf("%d",&n);
	for(i=1;i<=450;i++)
	{
		if(2*n==(i*(i+1)))
		{
			flag=1;
			break;
		}
	
	}
	if(flag==0)printf("No");
	else
	{
		printf("Yes\n");
		printf("%d\n",(i+1));
		
		for(j=0;j<i;j++)
		{
			for(k=j;k<i;k++)
			{
				ans[j][k]=a+(k-j);
				ans[k+1][j]=a+(k-j);
			}
			a+=(i-j);
		}
		for(l=0;l<(i+1);l++)
		{
			printf("%d ",i);
			for(m=0;m<i;m++)
			{
				printf("%d ",ans[l][m]);
			}
			printf("\n");
		}
	}
}


Measured memory_bytes: 2048
import Data.List
import Control.Applicative

data Tri = NotT | SharpT | RightT | DullT

typeOfTri :: [Int] -> Tri
typeOfTri [a, b, c]
  | c > a+b = NotT
  | x == LT = SharpT
  | x == EQ = RightT
  | x == GT = DullT
  where x = compare (b*b+a*a) (c*c)

loop :: Int -> Int -> Int -> Int -> IO ()
loop a b c d = do
  tri <- sort . fmap read . words <$> getLine :: IO [Int]
  case typeOfTri tri of
    NotT   -> putStrLn . unwords $ show <$> [a, b, c, d] 
    SharpT -> loop (a+1) b c (d+1)
    RightT -> loop (a+1) (b+1) c d
    DullT  -> loop (a+1) b (c+1) d

main :: IO ()
main = loop 0 0 0 0
  


Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using pii = pair<int,int>; 
using db = double; 
using vi = vector<int>; 
#define fir first
#define sec second
#define pb push_back
#define lowbit(x) ((x)&(-(x))) 

const int maxn = 200006;

int n, k; 
int a[maxn]; 

int main() {
	cin>>n>>k; 
	int m = 0, g; 
	for (int i = 1; i <= n; ++i) {
		scanf( "%d", &a[i] ); 
		if (i == 1) g = a[1]; 
		g = __gcd(g, a[i]); 
		m = max(m, a[i]); 
	}
	if (k <= m && k % g == 0) puts( "POSSIBLE" ); 
	else puts( "IMPOSSIBLE" ); 
}


Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
R = [0]*(N+1)
ans = 0
for i in range(N):
    if B[i] + R[i] < A[i]:
        ans += B[i]+R[i]
    else:
        if R[i] < A[i]:
            R[i+1] = B[i]+R[i]-A[i]
        else:
            R[i+1] = B[i]
        ans += A[i]
if R[N] < A[N]:
    ans += R[N]
else:
    ans += A[N]
print(ans)

Measured memory_bytes: 19004
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        d: usize,
        c: [usize; 26],
        s: [[usize; 26]; d],

    }

    let mut answer = vec![0; d];

    for i in 0..d {
      println!("{}", answer[i]+1)
    }
}


Measured memory_bytes: 2316
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  ios::sync_with_stdio(false);
  int N, Q; cin >> N >> Q;
  set<int> S;
  REP(i, N) {
    int c; cin >> c;
    S.insert(c);
  }
  while(Q--) {
    int q; cin >> q;
    int ans = 0;
    for(int j = q; j <= 300000; j += q) {
      auto it = S.lower_bound(j);
      if(it != S.begin()) {
        --it;
        ans = max(ans, (*it) % q);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 15264
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

int an[105];
int maxn,a,b,c;

void check()
{
	for(int i = 0; i <= 100; i++){
		maxn = max(maxn,an[i]);
	}
}

int main()
{
	cin >> a >> b >> c;
	an[a]++;
	an[b]++;
	an[c]++;
	check();
	cout << 3-maxn+1 << endl;
}

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

using namespace std;

#ifdef Lin1043
    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
    #define massert(...) assert(...)
#else
    #define DEBUG(...)
    #define massert(...)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

struct iopener
{
    iopener()
    {
#ifdef Lin1043
        freopen("./in" , "r" , stdin);
#endif
    }
} iop;

typedef long long LL;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}

const int N = 100000 + 5;

int n , A[N] , B[N];

int main()
{
    read(n);
    rep(i , 1 , n)
        B[i] = read(A[i]);
    sort(B + 1 , B + 1 + n);
    LL Ans = 0;
    rep(i , 1 , n)
    {
        int p = lower_bound(B + 1 , B + 1 + n , A[i]) - B;
        Ans += abs(p - i) % 2 == 1 ? 1 : 0;
    }
    cout << Ans / 2 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;


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

    int A,B;
    cin >> A >> B;
    if(A%2 == 0 || B%2 == 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

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

int main()
{
    int H,W,flag,f=1;
    char S[60][60];
    scanf("%d %d",&H,&W);
    getchar();
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            scanf("%c",&S[i][j]);
        }
        getchar();
    }
    for(int i=0;i<=H+1;i++){
        S[i][0]='.';
        S[i][W+1]='.';
    }
    for(int i=0;i<=W+1;i++){
        S[0][i]='.';
        S[H+1][i]='.';
    }
    for(int i=1;i<=H;i++){
        for(int j=1;j<W;j++){
            if(S[i][j]=='#'){
                flag=0;
                if(S[i-1][j]=='#'||S[i+1][j]=='#'||S[i][j-1]=='#'||S[i][j+1]=='#')
                    flag=1;
                if(flag==0)
                    break;
            }
        }
        if(flag==0){
            f=0;
            cout<<"No";
            break;
        }
    }
    if(f==1)
        cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

using P = pair<int, int>;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int h, w, k;
    int x1, x2, y1, y2;
    cin >> h >> w >> k;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;
    x2--;
    y1--;
    y2--;
    // print(x1, y1, x2, y2);
    vector<string> g(h);
    for(int i = 0; i < h; i++) {
        cin >> g[i];
        // cerr << g[i] << endl;
    }
    static queue<P> que;
    static vector<vector<int>> d(h, vector<int>(w, INF));
    d[x1][y1] = 0;
    que.emplace(P(x1, y1));
    while(que.size()) {
        auto now = que.front();
        que.pop();
        assert(0 <= now.first && now.first < h);
        assert(0 <= now.second && now.second < w);
        for(int i = 0; i < 4; i++) {
            for(int j = 1; j <= k; j++) {
                int ni = now.first + dy[i] * j;
                int nj = now.second + dx[i] * j;
                if(ni < 0 || ni >= h || nj < 0 || nj >= w) {
                    break;
                }
                assert(0 <= ni && ni < h);
                assert(0 <= nj && nj < w);
                if(g[ni][nj] == '@') {
                    break;
                }
                if(d[ni][nj] <= d[now.first][now.second]) {
                    break;
                }
                if(d[ni][nj] > d[now.first][now.second] + 1) {
                    d[ni][nj] = d[now.first][now.second] + 1;
                    que.push(P(ni, nj));
                }
            }
        }
    }
    print(d[x2][y2] >= INF ? -1 : d[x2][y2]);
}

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

using namespace std;

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

const int inf = 1e9+10;

int dp[3010];

signed main()
{
    int N, T, S; cin >> N >> T >> S;

    vector<int> A(N), B(N);

    rep(i, N) {
        cin >> A[i] >> B[i];
    }

    rep(i, N) {
        for (int j = T - B[i]; j >= 0; --j) {
            if (j < S && S < j + B[i]) continue;
            dp[j + B[i]] = max(dp[j + B[i]], dp[j] + A[i]);
        }
    }

    int ans = 0;

    rep(i, T+1) ans = max(ans, dp[i]);

    cout << ans << endl;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main(int argc, char const* argv[]) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k = 2;
	cin >> n;
	vector<int> arr(n);
	vector<int> dp(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int in_size = min(n - 1, k);
	for (int i = 0; i <= in_size; i++) {
		dp[i] = abs(arr[i] - arr[0]);
	}
	for (int i = k + 1; i < n; i++) {
		int ans = INT_MAX;
		for (int j = 1; j <= k; j++) {
			ans = min(ans, dp[i - j] + abs(arr[i] - arr[i - j]));
		}
		dp[i] = ans;
	}
	cout << dp[n - 1] << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; string s; cin >> n >> s;
    int ans = 0;
    // 1からn-1までの切断方法を全探索
    for (int i = 1; i < n; i++)
    {
        // aからzが出現するかどうか調べる
        int cnt = 0;
        for (char c = 'a'; c <= 'z'; c++)
        {
            bool left = false, right = false;
            for (int j = 0; j < i; j++)
            {
                if (s[j] == c) left = true;
            }
            for (int j = i; j < n; j++)
            {
                if (s[j] == c) right = true;
            }
            if (left && right)
            {
                cnt++;
            }
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std ;
int main()
{
  int num ;
  cin >> num ;
  
  double red[num] , blue[num] , undersum , pom;
  
  for(int i=0; i<num; i++){
    cin >> red[i] ;
  }
  
  for(int j=0; j<num; j++){
    blue[j] = 1/red[j] ;
  }
  
  for (int k=0; k<num; k++){
    undersum += blue[k] ;
  }
  
  pom = 1/undersum ;
  
  cout << pom <<endl ;
  
  return 0 ;
}
  
  

Measured memory_bytes: 256
N, K, Q = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

ans = 1e9
as.sort.uniq.each do |v|
  ws =
    as
    .chunk(&:nil?)
    .reject { |b, _r| b }
    .flat_map do |_b, r|
      r.size >= K ? r.sort[0..(r.size - K)] : []
    end
    .sort
  break if ws.size < Q
  ans = [ans, ws[Q - 1] - ws[0]].min
  as = as.map { |a| a == v ? nil : a }
end

puts ans


Measured memory_bytes: 12152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
#define INF 1e9
using namespace std;
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
template<typename T> void cmax(T &a, T b) { a = max(a, b); }

signed main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  sort(all(d));
  if (d[n / 2 - 1] == d[n / 2])
    cout << 0 << endl;
  else {
    cout << d[n / 2] - d[n / 2 - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    string s; cin>>s;
    int n=s.size(),tmp=0,ans=9*n;
    rep(i,n) tmp+=s[i]-'0';
    rep(i,n){
        if(s[i]!='9'){
            if(i==n-1) ans--;
            else ans=ans-9+(s[i]-'1');
            break;
        }
    }
    ans=max(ans,tmp);
    if(n==1) ans=s[0]-'0';
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int w[n];
    int v[n];
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    long long int dp[n+1][m+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0||j==0){
                dp[i][j] = 0;
            }
            else{
                dp[i][j] = ((j-w[i-1]>=0)?max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]):dp[i-1][j]);
            }
//            cout<<dp[i][j]<<" ";
        }
//        cout<<endl;
    }
    cout<<dp[n][m];
    return 0;
}


Measured memory_bytes: 79104
#include <stdio.h>
#include <math.h>

int main(){
	double ax, bx, ay, by;
	scanf("%lf %lf %lf %lf", &ax, &ay, &bx, &by);
	printf("%.8f\n", sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay)));
	return 0;
}

Measured memory_bytes: 656
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }



template<class Abel> struct WeightedUnionFind {
	vector<ll> par;
	vector<ll> rank;
	vector<Abel> diff_weight;

	WeightedUnionFind(ll n = 1, Abel SUM_UNITY = 0) {
		init(n, SUM_UNITY);
	}

	void init(ll n = 1, Abel SUM_UNITY = 0) {
		par.resize(n); rank.resize(n); diff_weight.resize(n);
		for (ll i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
	}

	ll root(ll x) {
		if (par[x] == x) {
			return x;
		}
		else {
			ll r = root(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}

	Abel weight(ll x) {
		root(x);
		return diff_weight[x];
	}

	ll find(ll x) { // x のグループ番号を得る. (O(α(n)))
		return root(x);
	}

	bool unite(ll x, ll y, Abel w) { // weight(y) = weight(x) + w となるように x と y をマージする.
		w += weight(x); w -= weight(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y), w = -w;
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}

	Abel diff(ll x, ll y) { // x と y とが同じグループにいるとき、weight(y) - weight(x) を返す.
		return weight(y) - weight(x);
	}
};


int main() {
	
	ll N, M;
	cin >> N >> M;

	WeightedUnionFind<ll> uf(N);
	rep(i, M) {
		ll l, r, d;
		cin >> l >> r >> d;
		--l, --r;
		if (uf.find(l) == uf.find(r)) {
			ll diff = uf.diff(l, r);
			if (diff != d) {
				cout << "No" << endl;
				return 0;
			}
		}
		else uf.unite(l, r, d);
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

signed main() {
	int a, b;
	cin >> a >> b;
	cout << max(0LL, a - 2 * b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    int a, b;
    cin >> a >> b;
    int sum = 0;
    for (int i = 0; i < (b - a); i++) {
        sum += i;
    }
    cout << sum - a << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# INPUT
a = input()

if a == "a":
   print("b")
elif a == "b":
   print("c")
elif a == "c":
   print("d")
elif a == "d":
   print("e")
elif a == "e":
   print("f")
elif a == "f":
   print("g")
elif a == "g":
   print("h")
elif a == "h":
   print("i")
elif a == "i":
   print("j")
elif a == "j":
   print("k")
elif a == "k":
   print("l")
elif a == "l":
   print("m")
elif a == "m":
   print("n")
elif a == "n":
   print("o")
elif a == "o":
   print("p")
elif a == "p":
   print("q")
elif a == "q":
   print("r")
elif a == "r":
   print("s")
elif a == "s":
   print("t")
elif a == "t":
   print("u")
elif a == "u":
   print("v")
elif a == "v":
   print("w")
elif a == "w":
   print("x")
elif a == "x":
   print("y")
elif a == "y":
   print("z")


Measured memory_bytes: 3064
from itertools import combinations
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
data = [0]*16002
i = 1
while i**2<=16001:
    data[i**2]=1
    i += 1
res = 0
for a, b in combinations(X,2):
    temp = 0
    for x, y in zip(a, b):
        temp += (x-y)**2
    if data[temp]:
        res += 1
print(res)

Measured memory_bytes: 62560
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n, m = LI()
    print((n-1)*(m-1))
    return

#B
def B():
    s = S()
    print(s[0]+str(len(s)-2)+s[-1])
    return

#C
def C():
    II()
    a = LI()
    a1 = 0
    a2 = 0
    a3 = 0
    for ai in a:
        if not ai % 4:
            a3 += 1
            continue
        if not ai % 2:
            a2 += 1
            continue
        a1 += 1
    if a2:
        print(["No", "Yes"][a3 >= a1])
        return
    print(["No", "Yes"][a3 >= a1 - 1])
    return
"""
    n, m = LI()
    x = -1
    y = -1
    z = -1
    for i in range(n + 1):
        a = m - 9000 * i - 1000 * n
        if a % 4000 == 0 and a >= 0 and n - i - a / 4000 >= 0:
            y = a / 4000
            z = n - i - y
            x = i
            break
    print(int(x),int(y),int(z))
"""

#D
def D():
    move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    h, w = LI()
    II()
    a = LI()
    ans = [[None] * w for i in range(h)]
    x = 0
    y = 0
    diarect = 0
    for num, ai in enumerate(a, start=1):
        for _ in range(ai):
            ans[y][x] = num
            x += move[diarect][0]
            y += move[diarect][1]
            if 0 <= x < w and 0 <= y < h:
                if ans[y][x]:
                    x -= move[diarect][0]
                    y -= move[diarect][1]
                    diarect += 1
                    diarect %= 4
                    x += move[diarect][0]
                    y += move[diarect][1]
                continue
            x -= move[diarect][0]
            y -= move[diarect][1]
            diarect += 1
            diarect %= 4
            x += move[diarect][0]
            y += move[diarect][1]
            
    for a in ans:
        print(" ".join(map(str, a)))
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 42096
[a,b,m] = [int(i) for i in input().split()]
a_p = [int(i) for i in input().split()]
b_p = [int(i) for i in input().split()]
ans = 10**9+7
for i in range(m):
    [x,y,c] = [int(i) for i in input().split()]
    tmp = a_p[x-1] + b_p[y-1] - c
    if tmp < ans:
        ans = tmp

print(min(ans,min(a_p)+min(b_p)))


Measured memory_bytes: 66780
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;



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

	int K, X;
	cin >> K >> X;

	rep(i, 0, 2 * K - 1)
	{
		cout << X - K + 1 + i << " ";
	}

	cout << endl;

	return 0;
}

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

int main(){
  
  ll N,K;
  cin >> N >> K;
  
  ll ans = 0;
  for(ll i = N + 1;i >= K;--i){
    ans += (i * ((N - i + 1) % MOD) + 1);
    ans %= MOD;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3628