akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define all(c) (c).begin(),(c).end()

using namespace std;
int in(){int x;cin>>x;return x;}

#define int long long
main(){
    while(1){
        int m=in(),n=in(),t=in(),p=in();
        if(n==0 and m==0 and t==0 and p==0) break;
        vector<vector<int> > v(n,vector<int>(m,1));
        int a = 0,b = 0;
        rep(_,t){
            int d=in(),c=in();
            if(d==2){
                vector<vector<int> > w(n,vector<int>(m));
                rep(i,c){
                    rep(j,m)w[c-1-i][j]+=v[i][j];
                }
                rep2(i,c,n-1)rep(j,m)w[i-c][j]+=v[i][j];
                v=w;
            }
            else{
                vector<vector<int> > w(n,vector<int>(m));
                rep(i,n)rep(j,c)w[i][c-1-j]+=v[i][j];
                rep(i,n)rep2(j,c,m-1)w[i][j-c]+=v[i][j];
                v = w;
            }
        }
        int ans = 0;
        rep(i,p){
            int x=in(),y=in();
            cout << v[y][x] << endl;
        }
                
    }
}




Measured memory_bytes: 3160
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main(){
  ll n, k;
  cin >> n >> k;
  fac[0] = 1;
  ifac[0] = 1;
  for(ll i = 0; i<300000; i++){
    fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
    ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }
  for(ll i=1; i<=k; i++){
    ll ans = (comb(k-1, i-1) * comb(n-k+1, i)) % M;
    cout << ans << endl;
  }
  return 0;
}
  



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

int main(){
    int N, M, C;
    vector<int> B;
    int b, a;
    int sum = 0;
    int ans = 0;

    //input
    cin >> N >> M >> C;

    for(int i = 0; i < M; i++){
        cin >> b;
        B.push_back(b);
    }
    for(int i = 0; i < N; i++){
        sum = 0;
        for(int j = 0; j < M; j++){
            cin >> a;
            sum += a * B[j];
        }
        sum += C;
        if(sum > 0){
            ans++;
        }
    }

    //output
    cout << ans << endl;

}


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

int n;
typedef pair<int, int> P;
vector<vector<P>> g;
vector<int> ans;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	g.resize(n);
	for(int i=0; i<n-1; ++i){
		int u, v, w;
		cin >> u >> v >> w;
		g[u-1].push_back(P(v-1, w%2));
		g[v-1].push_back(P(u-1, w%2));
	}
	ans.resize(n, -1);
	ans[0] = 0;
	queue<int> q;
	q.push(0);
	while(!q.empty()){
		int p = q.front(); q.pop();
		for(int i=0; i<g[p].size(); ++i){
			int t = g[p][i].first;
			if(ans[t] != -1) continue;
			int d = g[p][i].second;
			ans[t] = (d == 0 ? ans[p] : 1-ans[p]);
			q.push(t);
		}
	}
	for(int i=0; i<n; ++i) cout << ans[i] << "\n";
}

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

int main() {
  int N, Y;
  cin >> N >> Y;
  bool f = false; // 状況がありうるか
  // 10000円札x枚, 5000円札y枚, 1000円札z枚とする
  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= N - x; y++) {
      int z = N - x - y;
      if (10000 * x + 5000 * y + 1000 * z == Y) {
        cout << x << " " << y << " " << z << endl;
        f = true;
        break;
      }
    }
    if (f) break;
  }
  if (f == false)
    cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 256
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0
for i in range(N):
    t = 0
    for i, a in enumerate(input().split()):
        t += B[i] * int(a)
    if t + C > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 9016
def main():
    N, K = map(int, input().split())

    prob = 0
    if K-1 < N:
        prob += (N-K+1)
    sub = 0
    for i in range(1, min(N, K-1)+1):
        count = 0
        v = i
        while v < K:
            v*= 2
            count += 1
        sub += pow(0.5, count)
    return (prob + sub)/N

if __name__ == '__main__':
    print(main())

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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(a > b) { a = b; return true; } return false; }

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

    string s; cin >> s;
    cout << s[0] << s.length()-2 << s[s.length()-1] << endl;
}

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

int main() {
    string t; cin >> t;
    for (auto &c : t) {
        if (c == '?') c = 'D';
    }
    cout << t << endl;
}

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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> L(M), R(M);
    int i;
    for(i = 0; i < M; i++) {
        cin >> L.at(i) >> R.at(i);
    }
    int min = 1, max = 100000;

    for(i = 0; i < M; i++) {
        if(min < L.at(i)) min = L.at(i);
        if(max > R.at(i)) max = R.at(i);
    }
    int result = max - min + 1;
    if(result < 0) result = 0;
    cout << result << endl;
}

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

using namespace std;

int main() {
    int a, b, c, k, ta, tb, tc;
    cin >> a >> b >> c >> k;
    for(int i = 0; i <= k; i++) {
        for(int j = 0; j <= k-i; j++) {
            int l = k - i - j;
            //cout << i << ' ' << j << ' ' << l << endl;
            ta = a * pow(2, i);
            tb = b * pow(2, j);
            tc = c * pow(2, l);
            //cout << a << ' ' << b << ' ' << c << endl;
            if(tc > tb && tb > ta) {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}


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

double calc_temp(int T, int x) {
    return T - x*0.006;
}


int main() {

    int N;
    cin >> N;

    int T, A;
    cin >> T >> A;

    int H[1010];
    for (int i=0; i<N; i++) {
        cin >> H[i];
    }

    int ans;
    double close;
    ans = 1;
    close = abs(calc_temp(T, H[0]) - A);

    for (int i=1; i<N; i++) {
        if (abs(calc_temp(T, H[i]) - A) < close) {
            ans = i+1;
            close = abs(calc_temp(T, H[i]) - A);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
using namespace std;
struct P{
    int st;
    int i;
    bool operator<(const P &a)const{
        return st<a.st;
    }
}p[850];
bool mark[850];
int must[850];
int n,m,tim,we,k=1;
string s;
map<string,int>mymap;
int main()
{
    while(scanf("%d",&n)&&n){
        mymap.clear();
        for(int i=0;i<n;++i)
        {
            cin>>s>>we>>tim;
            mymap[s]=i;
            p[i].i=i;
            p[i].st=we*2400+tim%100+(tim/100)*60;
        }
        cin>>m;
        memset(mark,0,sizeof(mark));
        for(int i=0;i<m;++i){
            cin>>s;
            mark[mymap[s]]=1;
        }
        sort(p,p+n);
        int ans=0,k=1,end;
        bool flag=0;
        must[0]=-1;
        for(int i=0;i<n;++i)
            if(mark[p[i].i]) must[k++]=i;
        for(int i=1;i<k;++i){
            if(i>1&&p[must[i-1]].st+30>p[must[i]].st)
            {
                flag=1;
                break;
            }
            end=p[must[i]].st;
            for(int j=must[i]-1;j>=must[i-1]&&j>=0;--j)
                if(p[j].st+30<=end){
                    ans++;
                    end=p[j].st;
                }
        }
        ans++;
        end=p[must[k-1]].st;
        for(int i=must[k-1]+1;i<n;++i)
            if(end+30<=p[i].st){
                ans++;
                end=p[i].st;
            }
        if(flag) cout<<"-1"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int cnt = 0;
    for(int i=0; i<N; ++i) {
        int a; cin >> a;
        if(a % 2) ++cnt;
    }
    if(cnt % 2) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toLong()


    val sqrtN = Math.sqrt(N.toDouble()).toLong()

    // log_10(x)
    fun digits(x: Long) : Int {
        var num = x
        var count = 0
        while (num > 0) {
            num /= 10
            count++
        }
        return count
    }

    fun F(A: Long, B: Long) : Int {
        return Math.max(digits(A), digits(B))
    }

    var answer = Int.MAX_VALUE
    // O(N^0.5 * log_10 N)
    (1..sqrtN).forEach { A ->
        if (N % A == 0L) {
            val B = N / A
            answer = Math.min(answer, F(A, B))
        }
    }
    println(answer)
}


Measured memory_bytes: 33660
import sys
input = sys.stdin.readline
import numpy as np

def main():
    N, K = map(int,input().split())
    A = np.sort(np.array(list(map(int, input().split())), np.int64))
    z = A[A == 0]
    p = A[A > 0]
    n = A[A < 0]
    
    def count_func(x):
        cnt = 0
        if x >= 0:
            cnt += len(z) * N
        cnt += np.searchsorted(A, x // p, side='right').sum()
        cnt += (N - np.searchsorted(A, -(-x // n), side='left')).sum()
        cnt -= np.count_nonzero(A * A <= x)
        assert cnt % 2 == 0
        return cnt // 2
    
    l = -10 ** 18
    r = 10 ** 18
    while l + 1 < r:
        x = (l + r) // 2
        if count_func(x) >= K:
            r = x
        else:
            l = x
    
    print(r)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 32276
N, @K = gets.chomp.split.map(&:to_i)

summary = 0.0

(1..N).each do |dice|
  summary += if dice >= @K
               1.0 / N
             else
               ((1.0 / 2)**Math.log2(@K / dice.to_f).ceil) * (1.0 / N)
             end
end

puts summary

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int N;
string S;
bool used[1000005];

bool check(int x){
    memset(used,0,N);
    int idx = N-1;
    vector<int> lis;
    for (int i = 0;i < x;i++){
        while(S[idx] != 'I'){
            //cout << S[idx] << endl;
            idx--;
            if(idx < 0) return false;
        }
        used[idx] = true;
        lis.push_back(idx);
        idx--;
    }
    vector<int> lis2;
    idx = N-1;
    for (int i = 0;i < x;i++){
        while(!(idx < lis[i] && S[idx] == 'O') ){
            idx--;
            if(idx < 0) return false;
        }
        used[idx] = true;
        lis2.push_back(idx);
        idx--;
    }
    idx = N-1;
    for (int i = 0;i < x;i++){
        while(!(idx < lis2[i] && (S[idx] == 'I' || S[idx] == 'J') && used[idx] == false) ){
            idx--;
            if(idx < 0) return false;
        }
        used[idx] = true;
        idx--;
    }
    return true;
}

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

    cin >> N >> S;

    int high = N, low = 0;
    while(high-low != 1){
        int mid = (high+low)/2;
        if(check(mid)) low = mid;
        else high = mid;
    }

    cout << low << endl;

    return 0;

}


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

void merge( int* A, int left, int mid, int right, int& c )
{
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1+1], R[n2+1];

    for( int i = 0; i <= n1 - 1; i++ )
        L[i] = A[left + i];
    for( int i = 0; i <= n2 - 1; i++ )
        R[i] = A[mid + i];

    L[n1] = 2000000000;
    R[n2] = 2000000000;

    int i = 0, j = 0;
    for( int k = left; k <= right - 1; k++ )
    {
        c++;
        if( L[i] <= R[j] )
        {
            A[k] = L[i];
            i = i + 1;
        }
        else 
        {
            A[k] = R[j];
            j = j + 1 ;
        }
    }
}

void mergeSort( int* A, int left, int right, int& c )
{
    if( left + 1 < right )
    {
        int mid = ( left + right ) / 2;
        mergeSort( A, left, mid, c );
        mergeSort( A, mid, right, c );
        merge( A, left, mid, right, c );
    }
}

int main()
{
    int n, cnt = 0;

    cin >> n;

    int s[n];

    for( int i = 0; i < n; i++ )
        cin >> s[i];
    
    mergeSort( s, 0, n, cnt );

    for( int i = 0; i < n - 1; i++ )
        cout << s[i] << " ";
    cout << s[n-1] << "\n" << cnt << endl;

    return 0;
}


Measured memory_bytes: 6924
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  ll n;
  cin>>n;
   ll r=10;
  ll x=0;
  ll ans=0;
  if(n%2==1) cout<<0<<endl;
 else  {
   rep(i,26){
    x=n/r;  
      ans+=x;
      r*=5;  
}
cout<<ans<<endl;
 }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MOD = 1000000007;

int mpow(long long x, int n) {
	if (n == 0) return 1;
	if (n & 1) return x * mpow(x, n - 1) % MOD;
	return mpow(x * x % MOD, n >> 1);
}

int main() {
	int n; cin >> n;
	long long ans = mpow(10, n);
	ans = (ans - 2 * mpow(9, n) % MOD + MOD) % MOD;
	ans = (ans + mpow(8, n)) % MOD;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>

int main()
{
  	char b;
  	scanf("%c",&b);
  	if(b == 'A')
      printf("T");
    else if(b == 'C')
      printf("G");
    else if(b == 'G')
      printf("C");
    else if(b == 'T')
      printf("A");
	return 0;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string s;
int main()
{
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='C')
        {
            for(int j=i+1;j<s.length();j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  string ans = "No";
  for(int i = 0; i <= 25; i++){
    for(int j = 0; j <= 15; j++){
      if(i*4 + j*7 == N){
        ans = "Yes";
        break;
      }
    }
  }  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  while(A>0 && C>0){
    C=C-B;
    if(C<=0){
      cout << "Yes"<<endl;
      return 0;
    }
    A=A-D;
    if(A<=0){
      cout << "No" <<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3628
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    d = dict()
    for a in A: d[a] = d.get(a, 0) + 1

    if len(d) == 1:
        a = list(d.keys())[0]
        if a == 0:
            return "Yes"
    elif len(d) == 2:
        a, b = list(d.keys())
        if a == 0 or b == 0:
            if d[a] == d[b]:
                return "Yes"
            if N % 3 == 0 and (d[a] == 2*d[b] or d[b] == 2*d[a]):
                return "Yes"    
    elif len(d) == 3:
        a, b, c = list(d.keys())
        if d[a] == d[b] == d[c]:
            if (a^b == c and b^c == a and c^a == b) or (a^c == b and c^b == a and b^a == c):
                return "Yes"
    return "No"

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 14704
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n;
    std::cin >> n;
    i64 sum = 0;
    while (n--) {
        i64 x;
        std::cin >> x;
        sum -= x;
    }
    std::cout << (sum%2?"NO":"YES") << '\n';
}


Measured memory_bytes: 256
yama=input()
kisuu=yama[0::2]      
guusuu=yama[1::2]
iti=kisuu.count("0")
ni=guusuu.count("1")
kari=iti+ni
zentai=len(yama)

if kari*2>zentai:
  kari=zentai-kari
print(kari)

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

using namespace std;

typedef long long ll;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    string t = "keyence";
    int a = 0, b = 0;
    for (int i = 0; i < t.size(); i++) if (s[i] == t[i]) a++; else break; reverse(s.begin(), s.end()); reverse(t.begin(), t.end());
    for (int i = 0; i < t.size(); i++) if (s[i] == t[i]) b++; else break; reverse(s.begin(), s.end()); reverse(t.begin(), t.end());
    if (a + b >= 7) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 3000;

int r, c, k;
long long g[N + 1][N + 1] = {};
long long dp[N + 1][N + 1][4];
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> r >> c >> k;
    
    for (int i = 0; i < k; i++)
    {
        int x, y, v;
        cin >> x >> y >> v;
        g[x][y] = v;
    }
    
    for (int j = 0; j <= c; j++)
    {
        dp[0][j][0] = 0;
        dp[0][j][1] = dp[0][j][2] = dp[0][j][3] = -1e18;
    }
    for (int i = 1; i <= r; i++)
    {
        dp[i][0][0] = 0;
        dp[i][0][1] = dp[i][0][2] = dp[i][0][3] = -1e18;
        for (int j = 1; j <= c; j++)
        {
            dp[i][j][0] = 0;
            for (int k = 1; k <= 3; k++)
                dp[i][j][k] = -1e18;
        }
    }
    
    for (int i = 1; i <= r; i++)
    {
        for (int j = 1; j <= c; j++)
        {
            for (int k = 0; k <= 3; k++)
                dp[i][j][0] = max(dp[i][j][0], max(dp[i - 1][j][k], dp[i][j - 1][0]));

            for (int k = 0; k <= 3; k++)
                dp[i][j][1] =  max(max(dp[i - 1][j][k] + g[i][j], dp[i][j][1]), max(dp[i][j - 1][0] + g[i][j], dp[i][j - 1][1]));
            for (int k = 2; k <= 3; k++)
                dp[i][j][k] = max(max(dp[i][j - 1][k], dp[i][j][k]), dp[i][j - 1][k - 1] + g[i][j]);
        }
    }
    
    cout << max(dp[r][c][0], max(max(dp[r][c][1], dp[r][c][2]), dp[r][c][3]));
    
    return 0;
}


Measured memory_bytes: 355384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, K;
  cin >> N >> K;
 
  vector<int> A(N);
  
  
  for(int j = 0; j < K; j++){
    int d;
  	cin >> d;  
    
  	for(int i = 0; i < d; i++){
      int a;
      cin >> a;
      A.at(a-1)++;
    }
  }
  
  int cnt = 0;
  
  for(int i = 0; i < A.size(); i++){
    if(A.at(i) == 0){
      cnt++;
    }
  }
 
  cout << cnt << endl;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

typedef pair<int,int> P;

int H,W;

P nxt(int a, int b){
  if(a%2==1){
    if(b==0) return P(a+1,0);
    else return P(a,b-1);
  }
  else {
    if(b==W-1) return P(a+1,W-1);
    else return P(a,b+1);
  }
}

int main(){
  cin >> H >> W;
  int N;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++) cin >> a[i];

  int grd[H][W];
  P now = P(0,0);

  for(int i=0;i<N;i++){
    for(int j=0;j<a[i];j++){
      grd[now.first][now.second] = i + 1;
      now = nxt(now.first,now.second);
    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << grd[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}

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

int main(void)
{
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    int mx = *max_element(x.begin(), x.end());
    int mn = *min_element(y.begin(), y.end());
    string ans = "War";
    for (int z = -99; z <= 100; z++)
    {
        if (X < z && z <= Y && mx < z && z <= mn)
            ans = "No War";
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=310;
const int inf=2147483647;
const int mod=1000000007;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
void upd(int&x,int y){x+=y;if(x>=mod)x-=mod;}
int n,a[Maxn<<1],c[Maxn<<1],f[Maxn<<1][Maxn][Maxn];//0 1
int main()
{
	n=read();
	for(int i=1;i<=(n<<1);i++)
	{
		a[i]=read();
		if(a[i]!=-1)c[a[i]]=1;
	}
	int cnt=0,m=n<<1;
	for(int i=1;i<=(n<<1);i+=2)
	{
		if(a[i]==-1||a[i+1]==-1)
		{
			if(a[i]==-1&&a[i+1]==-1)cnt++;
		}
		else c[a[i]]=c[a[i+1]]=-1,m-=2;
	}
	int t=0;
	for(int i=1;i<=(n<<1);i++)
	if(c[i]!=-1)c[++t]=c[i];
	f[m+1][0][0]=1;
	int ans;
	for(int i=m;i;i--)
	{
		if(c[i]==-1)continue;
		for(int j=0;j<=min(m-i+1,n);j++)
		for(int k=0;k<=min(m-i+1,n);k++)
		{
			if(c[i]==0)
			{
				upd(f[i][j][k],(LL)f[i+1][j][k+1]*(k+1)%mod);
				upd(f[i][j][k],f[i+1][j+1][k]);
				if(j)upd(f[i][j][k],f[i+1][j-1][k]);
			}
			else
			{
				upd(f[i][j][k],f[i+1][j+1][k]);
				if(k)upd(f[i][j][k],f[i+1][j][k-1]);
			}
//			if(f[i][j][k])printf("%d %d %d %d\n",i,j,k,f[i][j][k]);
		}
	}
	ans=f[1][0][0];
	for(int i=2;i<=cnt;i++)ans=(LL)ans*i%mod;
	printf("%d",ans);
}

Measured memory_bytes: 227200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


const int Max=10000000;
bool prime[Max];
int main(void){
    int in;
    for(int i=0;i<Max;i++)prime[i]=true;
    prime[1]=false;
    for(int i=2;i<Max;i++){
        if(prime[i]){
            for(int s=i*2;s<=Max;s+=i)prime[s]=false;
        }
    }
    while(cin>>in){
        int cnt=0;
        for(int i=1;i<=in;i++){
            if(prime[i])cnt++;
        }
        cout << cnt << "\n";
    }
    return 0;
}

Measured memory_bytes: 12756
/*-------property of the half blood prince-----*/

#include <bits/stdc++.h>
#include <dirent.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define MIN(X,Y) X<Y?X:Y
#define MAX(X,Y) X>Y?X:Y
#define ISNUM(a) ('0'<=(a) && (a)<='9')
#define ISCAP(a) ('A'<=(a) && (a)<='Z')
#define ISSML(a) ('a'<=(a) && (a)<='z')
#define ISALP(a) (ISCAP(a) || ISSML(a))
#define MXX 10000000000
#define MNN -MXX
#define ISVALID(X,Y,N,M) ((X)>=1 && (X)<=(N) && (Y)>=1 && (Y)<=(M))
#define LLI long long int
#define VI vector<int>
#define VLLI vector<long long int>
#define MII map<int,int>
#define SI set<int>
#define PB push_back
#define MSI map<string,int>
#define PII pair<int,int>
#define PLLI pair<LLI,LLI>
#define PDD pair<double,double>
#define FREP(i,I,N) for(int (i)=(int)(I);(i)<=(int)(N);(i)++)
#define eps 0.0000000001
#define RFREP(i,N,I) for(int (i)=(int)(N);(i)>=(int)(I);(i)--)
#define SORTV(VEC) sort(VEC.begin(),VEC.end())
#define SORTVCMP(VEC,cmp) sort(VEC.begin(),VEC.end(),cmp)
#define REVV(VEC) reverse(VEC.begin(),VEC.end())
#define INRANGED(val,l,r) (((l)<(val) || fabs((val)-(l))<eps) && ((val)<(r) || fabs((val)-(r))<eps))
#define INRANGEI(val,l,r) ((val)>=(l) && (val)<=(r))
#define MSET(a,b) memset(a,b,sizeof(a))
using namespace std;
using namespace __gnu_pbds;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction


//typedef tree < int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
LLI arr[103];

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


LLI findlcm(int n)
{
    LLI ans = arr[0];

    for (int i=1; i<n; i++)
        ans = (arr[i]/gcd(arr[i],ans))*ans;

    return ans;
}

int main()
{
    int n;
    cin>>n;
    FREP(i,0,(n-1))cin>>arr[i];
    cout<<findlcm(n)<<"\n";
    return 0;
}


Measured memory_bytes: 256
a,b,c = map(int,input().split())

if a%2 == 1 or b%2 == 1 or c%2==1:
    print(0)
elif a==b and b==c and c==a:
    print(-1)
else:
    for i in range(10**9):
        ans = i
        if a % 2 == 1:
            break
        else:
            tmpa = b/2 + c/2
        if b % 2 == 1:
            break
        else:
            tmpb = c/2 + a/2
        if c % 2 == 1:
            break
        else:
            tmpc = a/2 + b/2
        a = tmpa
        b = tmpb
        c = tmpc
    print(ans)

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    private static int n;
    private static int m;
    private static int q;
    private static List<int> aList = new List<int>();
    private static List<int> bList = new List<int>();
    private static List<int> cList = new List<int>();
    private static List<int> dList = new List<int>();
    private static int ans;
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var n = int.Parse(input[0]);
        var k = int.Parse(input[1]);

        var dict = new Dictionary<int, bool>();
        for (int i = 0; i < k; i++)
        {
            var d = int.Parse(Console.ReadLine());
            var input2 = Console.ReadLine().Split(' ');
            for (int j = 0; j < input2.Length; j++)
            {
                dict[int.Parse(input2[j])] = true;
            }
        }

        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (dict.ContainsKey(i + 1) != true)
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 18596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf INT_MAX
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 0.00001

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x,a;cin>>x>>a;
    if(x<a){cout<<"0";}
    else
    {
        cout<<"10";
    }

    return 0;
    // check for long long or int
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var a = Convert.ToInt32(input[0]);
        var b = Convert.ToInt32(input[1]);
        var c = Convert.ToInt32(input[2]);

        var result = c >= a && c <= b ? "Yes" : "No";
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 11220
/*
Author : Vidish Joshi
*/

#include <bits/stdc++.h>
using namespace std;

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define v(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)

void re() {}
template <typename T, typename... args>
void re(T &x, args &... tail)
{
    cin >> x;
    re(tail...);
}
void pr() {}
template <typename T>
void pr(const T &x)
{
    cout << x;
}
template <typename T, typename... args>
void pr(const T &x, const args &... tail)
{
    cout << x << " ";
    pr(tail...);
}
template <typename... args>
void prln(const args &... tail)
{
    pr(tail...);
    cout << "\n";
}


int main(){
	FIO;
	int n, m;
	cin>>n>>m;
	
	if(n==m){
		for(ll i=0; i<n; i++){
			cout<<n;
		}
	}
	else if(n<m){
		for(ll i=0; i<m; i++){
			cout<<n;
		}
	}
	else{
		for(ll i=0; i<n; i++){
			cout<<m;
		}
	}


	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let b = read::<String>().chars().collect::<Vec<char>>()[0];
    let ans = match b {
        'A' => 'T',
        'T' => 'A',
        'C' => 'G',
        'G' => 'C',
        _ => '_',
    };
    println!("{}", ans);
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

ll h[100010], dp[100010];

ll cost(ll n){
  	if (dp[n] < 10000000000) {
      	return dp[n];
    }
  
  	if (n == 0){
      	return 0;
    }
  
  	dp[n] = min(dp[n], cost(n-1) + abs(h[n] - h[n-1]));
    if (n > 1) {
      	dp[n] = min(dp[n], cost(n-2) + abs(h[n] - h[n-2]));
    }
  
  	return dp[n];
}

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

  	REP(i, n){
      	cin >> h[i];
      	dp[i] = 10000000000;
    }
	dp[0] = 0;
  
    cout << setprecision(20) << cost(n-1) << endl;

    return 0;
}

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

int main(void){
	string s, t, u;
	int a, b;

	cin >> s >> t;
	cin >> a >> b;
	cin >> u;

	if(u == s)a--;
	else b--;

	cout << a << " " << b << endl;

	return 0;
}


Measured memory_bytes: 256
//12-4-20
#define _CRT_SECURE_NO_WARNINGS 1

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using namespace std :: chrono;

#define scu(n)                       scanf("%u",&n)
#define scl(n)                       scanf("%d",&n)
#define scll(n)                      scanf("%lld",&n)
#define  maxN                        1005
#define uu                           first
#define vv                           second
#define ll                           unsigned long long
#define U                            unsigned
#define pb                            push_back
#define mp                            make_pair
#define pii                           pair<int,int>
#define vi                            vector<int>
#define mii                           map<int,int>
#define Pi                            acos(-1.0)
#define endl                         "\n"
#define pqb                           priority_queue<int>
#define pqs                           priority_queue<int,vi,greater<int> >
#define setbits(x)                    __builtin_popcountll(x)
#define zrobits(x)                    __builtin_ctzll(x)
#define mod                           1000000007
#define inf                           1e18
#define ps(x,y)                       fixed<<setprecision(y)<<x
#define mk(arr,n,type)                type *arr=new type[n];
#define w(x)                          int x; cin>>x; while(x--)
mt19937                               rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//Vector Macros
#define pb                            push_back
#define eb                            emplace_back
#define ALL(v)                        v.begin(),v.end()
#define UNIQUE(v)                     v.erase(unique(ALL(v)),v.end())
#define MIN(c)                        *min_element(ALL(c))
#define MAX(c)                         *max_element(ALL(c))
#define SUM(c)                         accumulate(ALL(c),0)

//Loop Macros
#define FOR(i,a,b)                     for(ll i=a;i<=b;i++)
#define rep(i,a,b)                     for(int i=a;i<=b;i++)
#define For(i,n)                       for(int i=0;i<n;i++)

//Debug Macros
#define deb(a)                         cout << #a << " : " << a << " ";
#define debln(a)                       cout<< #a <<" : " << a << endl;
//Print Macros
#define print(v)  for(auto x : v) {  cout<<x<<" ";   }  cout<<endl;
#define PRINT(v)  for(auto x : v) { cout<<x.uu<<" "<<x.vv<<endl;

/*
Time Calculation :
auto st = high_resolution_clock::now();
auto en = high_resolution_clock::now();
auto duration = duration_cast < milliseconds > (en-st);
cout<< "consumed time in ms " << duration.count() <<endl;
*/


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

    ll i,j,k,n;
    cin>>n;

    ll sum=0;

    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            for(k=1; k<=n; k++)
            {
                sum+= __gcd(__gcd(i,j),k);
            }
        }
    }

    cout<<sum<<endl;

    return 0;
}






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

int main()
{
    int x,y,nodes,edges;
    cin>>nodes>>edges;
    nodes++;
    vector <int> v[nodes];
    for(int i=0;i<edges;i++){
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int s=1,vis[nodes]={0},level[nodes]={0};
    queue <int> q;
    q.push(s);
    level[1]=0;
    vis[1]=1;
    while(!q.empty()){
        int p=q.front();
        q.pop();
            for(int i=0;i<v[p].size();i++){
                if(vis[ v[p][i] ] == 0){
                        level[ v[p][i] ]=p;
                        vis[ v[p][i] ]=1;
                        q.push(v[p][i]);
                }
            }
    }
    int k=0;
    for(int i=2;i<nodes;i++){
        if(level[i]==0){
            k=-1;
            break;
        }

    }
    if(k==-1)
        cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        for(int i=2;i<nodes;i++)
                cout<<level[i]<<endl;
    }

}


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


// Useful container manipulation / traversal macros
#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define forni(i,a,b)    for(int i=a;i<b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(a,b)       ( (b).find(a) != (b).end())
#define tr(c,i)       for(auto i = (c).begin(); i != (c).end(); i++)
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb             push_back
#define fill(a,v)      memset(a, v, sizeof a)

typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    int n;
    cin>>n;

    vlli a(n);

    fori(i, 0, n-1)
        cin>>a[i];

    vlli b(n), c(n);

    fori(i, 0, n-1){
        if(i == 0)
            b[i] = c[i] = 0;
        else {
            b[i] = gcd(a[i-1], b[i-1]);
            c[i] = gcd(a[n-i], c[i-1]);
        }
    }

    lli ans = 1;
    fori(i, 0, n-1){
        ans = max(ans, gcd(b[i], c[n-i-1]));
    }

    cout<<ans;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
# define MOD 1000000000+7
# define INF 1000000000
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13) {
		cout << b << endl;
	}
	else if(a >= 6) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}


}



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

int main(void)
{
    int a,b;
    cin >> a >> b;
    if(a <= 8 && b <= 8)
    {
        cout << "Yay!" << endl;
    }else
    {
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int N;
  int a[110];
  int count = 0;
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> a[i];
  }

  for(int i = 1; i < N; i++) {
    if (a[i] == a[i-1]) {
      count++;
      i++;
    }
  }
  cout << count << endl;
}


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

int main() {
  int N, J;
  J = 0;
  cin >> N;
  rep(i , N){
    string A;
    cin >> A;
    if(A == "Y")
      J += 1;
  }
  if(J > 0)
    cout << "Four" << endl;
  if(J == 0)
    cout << "Three" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int p[100001];
int parent[100001];
int findparent(int x)
{
	if(parent[x]!=x)
		parent[x]=findparent(parent[x]);
	return parent[x];
}
void unionset(int a,int b)
{
	if((a=findparent(a))==(b=findparent(b)))
		return;
	parent[a]=b;
	return;
}
int main()
{
	int n,m,i,ans=0,b,c;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)
		parent[i]=i;
	for(i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for(i=0;i<m;i++)
	{
		scanf("%d %d",&b,&c);
		unionset(p[b],p[c]);
	}
	for(i=1;i<=n;i++)
	{
		if(findparent(p[i])==findparent(i))
			ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin>>N;
    vector<vector<int>> dp(2,vector<int>(N,0));
    vector<vector<int>> a(2,vector<int>(N,0));
    cin>>a;
    dp[0][0]=a[0][0];
    REP(i,2) {
        REP(j,N) {
            if(i==0) chmax(dp[i+1][j],dp[i][j]+a[i+1][j]);
            if(j!=N-1) chmax(dp[i][j+1],dp[i][j]+a[i][j+1]);
        }
    }
    cout<<dp[1][N-1]<<endl;
    return 0;
}


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

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> p(n, 0);
    for(int i=0; i<n; i++) std::cin >> p[i];

    int count = 0;
    for(int i=1; i<n-1; i++){
        if(p[i-1] < p[i] && p[i] < p[i+1]) count++;
        else if(p[i-1] > p[i] && p[i] > p[i+1]) count++;
    }
    std::cout << count << std::endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        sb.Append("A"+str[1][0]+"C\n");
    }
}

Measured memory_bytes: 2648
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define endl "\n"
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
#define sz(x) ((int)x.size())

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
const int N = 1e5+5;
typedef vector<int> vi;

 
int32_t main()
{
   int n, k;
   cin >> n >> k;
   set<int> s;
   for(int i = 0; i < k; i++)
   {
      int x;
      cin >> x;
      s.insert(x);
   }
   for(int i = n; i <= 100000; i++)
   {
      string st = to_string(i);
      bool flag = true;
      for(auto it : st)
      {
         if(s.find(it-'0') != s.end())
         {
            flag = false;
         }
      }
      if(flag)
         return cout << i, 0;
   }
   return 0;
}

Measured memory_bytes: 256
#169A

#1.入力をちゃんと受け取る。
#ex:[2 5] a=2,b=5とする
a, b = map(int, input().split())
#print(a)
#print(b)


#2.目的通りの計算（二つの整数の計算）を行う
answer = a * b
#3.計算の結果を出力する

print(answer)

Measured memory_bytes: 9084
#include<bits/stdc++.h>
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 INF=1LL<<60 ;
const ll MOD=1e9+7 ;
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; }

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    // input part

    ll n;cin >> n;

    cout << n*(n-1)/2 << endl;
    // main part

    // output part

}


Measured memory_bytes: 256
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let n: usize = s.trim().parse().ok().unwrap();

    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let a: Vec<usize> = t
        .trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();
        
    let mut ans: u64 = 1;
    let mut cnt = vec![0; n + 1];
    let modulo: u64 = 1000000007;

    cnt[0] = 3;
    for i in 0..n {
        ans = ans * cnt[a[i]] % modulo;
        cnt[a[i] + 1] += 1;
        cnt[a[i]] -= 1;
    }
    println!("{}", ans);
}

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

int main(void){
    int a,b,c,d,e,f,resW=0,resS=0;
    cin>>a>>b>>c>>d>>e>>f;
    bitset<3010> bsW(1),bsS(1);
    rep(i,3001){
        bsW |= bsW<<(100*a*i) | bsW<<(100*b*i);
        bsS |= bsS<<(c*i) | bsS<<(d*i);
    }
    double rate=0;
    rep(w,f+1)rep(s,f)if(bsW[w] && bsS[s]){
        if(w+s<=f && w>0 && e*w >= s*100 && rate <= 1.0*s/w){
            rate = 1.0*s/w;
            resW = w;
            resS = s;
        }
    }
    cout<<resS+resW<<" "<<resS<<endl;
    return 0;
}


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

int main() {
   	long long int n; 
  	string ans = "No";
  	int count = 0;
	cin >> n;
	int a[n];
  	int b[n];
	for(int i=0; i<n; i++) 
 	 {
      cin >> a[i] >> b[i];
    	if(a[i] == b[i])
        {count ++;}
      else
      {count = 0;}
      if(count == 3)
      {ans = "Yes";}
    }
  

	cout << ans << endl;
}



Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(){
    long long w,h,n;
    cin >> w >> h >> n;
    long long tempw = w;
    long long temph = h;
    int num[4]={};
    num[1]=1000000;
    num[3]=1000000;
    bool flag[4]={1,1,1,1};
    flag[0]=flag[1]=flag[2]=flag[3]=false;
    for(int i=0;i<n;i++){
        int x,y,a;
        cin >> x >> y >> a;
        if(a==1){
            num[0]=max(num[0],x);
            flag[0]=true;
        }else if(a==2){
            num[1]=min(num[1],x);
            flag[1]=true;
        }else if(a==3){
            num[2]=max(num[2],y);
            flag[2]=true;
        }else{
            num[3]=min(num[3],y);
            flag[3]=true;
        }
    }
    for(int i=0;i<4;i++){
        if(flag[i] == true){
        if(i==0){
            w = w-num[i];
        }else if(i==1){
            w = w - (tempw - num[i]); 
        }else if(i==2){
            h = h-num[i];
        }else{
            h = h - (temph - num[i]);
            
        }
        }
        
    }
    long long ans = h*w;
    if(h<=0||w<=0){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256