akhauriyash/Code-Regression huggingface dataset:
//encoding:utf-8
#include <iostream> //c++
#include<time.h> //時間にかんして
#include<stack> //スタックに関して　最新のデータから捨てる
#include<queue> //キューに関して　最古のデータから捨てる
#include<math.h>
// #include<vector>
#include<algorithm>

#define ll long long
using namespace std;

vector<char>s(3);

int main(){
  for(int i=0;i<3;i++){
    cin>>s[i];
  }
  sort(s.begin(),s.end());
  if(s[0]=='a' && s[1]=='b' && s[2]=='c'){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
import bisect
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()


two_bekis = []
tmp = 1
while tmp < 2*10**9:
    two_bekis.append(tmp)
    tmp *= 2

ans = 0
cnt = Counter(A)
seta = set(A)
for i, a in enumerate(reversed(A)):
    idx = bisect.bisect_right(two_bekis, a)
    two_beki = two_bekis[idx]
    b = two_beki - a
    if b not in seta:
        continue

    if a == b and cnt[a] >= 2:
        ans += 1
        cnt[a] -= 2
    elif a != b and cnt[a] >= 1 and cnt[b] >= 1:
        ans += 1
        cnt[a] -= 1
        cnt[b] -= 1
print(ans)


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

int main(){
    int N; cin >> N;
    vector<int> a(N+1);
    vector<int> b(N+1);

    for(int i=1; i<=N; i++){
        cin >> a[i];
        b[i] = a[i];
    }

    for(int i=N; i >=1; i--){
        for(int j=2; j*i <=N; j++){
            b[i] += b[j*i];
        }
    }

    for(int i=1; i<=N; i++){
        b[i] = b[i]%2;
    }

    for(int i=1; i<=N; i++){
        m += b[i];
    }

    cout << m << endl;

    for(int i=1; i<=N; i++){

        if(b[i]){
            cout << i << " ";
        }

    }
    
}



Measured memory_bytes: 2432
#include<bits/stdc++.h> 
using namespace std;
list<int>l;

int main(){
	int n,a;
	int t=1;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(t) l.push_back(a);
		else l.push_front(a);
		t=!t;
	}
	
	if(!t)l.reverse();
	for(auto i=l.begin();i!=l.end();++i)
		cout<<*i<<" ";
	return 0;
}

Measured memory_bytes: 8448
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


class UnionFind:
    def __init__(self, n):
        #親要素のノード番号を格納　xが根のとき-(サイズ)を格納
        self.par = [-1 for i in range(n)]
        self.n = n

    def find(self, x):
        #根ならその番号を返す
        if self.par[x] < 0:
            return x
        else:
            #親の親は親
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def is_same(self, x, y):
        #根が同じならTrue
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y: return

        #木のサイズを比較し、小さいほうから大きいほうへつなぐ
        if self.par[x] > self.par[y]:
            x, y = y, x

        self.par[x] += self.par[y]
        self.par[y] = x

    def size(self, x):
        return -self.par[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.par) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __repr__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = NMI()
    uf = UnionFind(N)
    for i in range(M):
        a, b = NMI()
        a, b = a-1, b-1
        uf.unite(a, b)
    print(uf.group_count() - 1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 78692
import os
import sys

import numpy as np


def solve(inp):
    def bitree_sum(bit, t, i):
        s = 0
        while i > 0:
            s += bit[t, i]
            i ^= i & -i
        return s

    def bitree_add(bit, n, t, i, x):
        while i <= n:
            bit[t, i] += x
            i += i & -i

    def bitree_lower_bound(bit, n, d, t, x):
        sum_ = 0
        pos = 0
        for i in range(d, -1, -1):
            k = pos + (1 << i)
            if k <= n and sum_ + bit[t, k] < x:
                sum_ += bit[t, k]
                pos += 1 << i
        return pos + 1

    def initial_score(d, ccc, sss, ttt):
        bit_n = d + 3
        bit = np.zeros((26, bit_n), dtype=np.int64)
        INF = 10 ** 18
        for t in range(26):
            bitree_add(bit, bit_n, t, bit_n - 1, INF)

        last = np.full(26, -1, dtype=np.int64)
        score = 0

        for i in range(d):
            t = ttt[i]
            score += sss[i, t]
            for u in range(26):
                if u == t:
                    continue
                score -= ccc[u] * (i - last[u])
            last[t] = i
            bitree_add(bit, bit_n, t, i + 2, 1)

        return bit, score

    def update_score(bit, bit_n, bit_d, ccc, sss, ttt, d, q):
        diff = 0
        t = ttt[d]
        k = bitree_sum(bit, t, d + 2)
        c = bitree_lower_bound(bit, bit_n, bit_d, t, k - 1) - 2
        e = bitree_lower_bound(bit, bit_n, bit_d, t, k + 1) - 2
        b = ccc[t]
        diff -= b * (d - c) * (e - d)
        diff -= sss[d, t]

        k = bitree_sum(bit, q, d + 2)
        c = bitree_lower_bound(bit, bit_n, bit_d, q, k) - 2
        e = bitree_lower_bound(bit, bit_n, bit_d, q, k + 1) - 2
        b = ccc[q]
        diff += b * (d - c) * (e - d)
        diff += sss[d, q]

        return diff

    d = inp[0]
    ccc = inp[1:27]
    sss = np.zeros((d, 26), dtype=np.int64)
    for r in range(d):
        sss[r] = inp[27 + r * 26:27 + (r + 1) * 26]
    ttt = inp[27 + d * 26:27 + d * 27] - 1
    m = inp[27 + d * 27]
    ddd = inp[28 + d * 27::2] - 1
    qqq = inp[29 + d * 27::2] - 1

    bit, score = initial_score(d, ccc, sss, ttt)
    bit_n = d + 3
    bit_d = int(np.log2(bit_n))

    buf = np.zeros(m, dtype=np.int64)

    for i in range(m):
        cd = ddd[i]
        ct = qqq[i]
        diff = update_score(bit, bit_n, bit_d, ccc, sss, ttt, cd, ct)
        score += diff
        bitree_add(bit, bit_n, ttt[cd], cd + 2, -1)
        bitree_add(bit, bit_n, ct, cd + 2, 1)
        ttt[cd] = ct
        buf[i] = score

    return buf


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print('\n'.join(map(str, ans)))


Measured memory_bytes: 37212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

string s;
int n,g=0,p=0;

int main() {
    cin >> s;
    n = s.size();
    REP(i,n){
        if(s[i]=='g'){
            g++;
        }else{
            p++;
        }
    }
    put((g-p)/2);
    return 0;
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		solver();
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		int M = sc.nextInt();
		int N = sc.nextInt();
		int m0 = sc.nextInt();
		int md = sc.nextInt();
		int n0 = sc.nextInt();
		int nd = sc.nextInt();
		int[] m = new int[M];
		int[] n = new int[N];
		m[0] = m0;
		n[0] = n0;

		for (int i = 1; i < M; ++i) {
			m[i] = (m[i - 1] * 58 + md) % (N + 1);
		}
		for (int i = 1; i < N; ++i) {
			n[i] = (n[i - 1] * 58 + nd) % (M + 1);
		}

		m = sort(m, N);
		n = sort(n, M);
		
		long[] accumN = new long[N + 1];
		long[] accumM = new long[M + 1];
		for (int i = 0; i < N; ++i) {
			accumN[i + 1] = accumN[i] + n[i];
		}
		for (int i = 0; i < M; ++i) {
			accumM[i + 1] = accumM[i] + m[i];
		}
		
		int cur = N;
		long sum = accumM[0] + accumN[cur] + (N - cur) * (M - 0);
		for (int i = 0; i <= M; ++i) {
			while (cur >= 1 && accumM[i] + accumN[cur] + (long)(N - cur) * (M - i) >= accumM[i] + accumN[cur - 1]
					+ (long)(N - (cur - 1)) *(M - i))
				--cur;
			sum = Math.min(sum, accumM[i] + accumN[cur] + (long)(N - cur) * (M - i));
		}
		
		System.out.println(sum);
		sc.close();
	}

	int[] sort(int[] a, int max) {
		int[] counter = new int[max + 1];
		for (int i = 0; i < a.length; ++i) {
			counter[a[i]]++;
		}
		int pos = 0;
		for (int i = 0; i < counter.length; ++i) {
			while (counter[i]-- > 0) {
				a[pos++] = i;
			}
		}
		return a;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

using namespace std;

#define ll long long int
#define get(a) ll a; cin >> a;
#define show(a) cout << a << endl;
#define full(p) p.begin(), p.end()
#define sz(a) (ll)(a.size())
#define pb push_back

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	////////////////////////////////
	get(a);
	get(b);
	get(c);

	std::vector<int> v;
	v.push_back(a);	
	v.push_back(b);	
	v.push_back(c);

	sort(full(v));
	if(v[0] == 5 and v[1] == 5 and v[2] == 7){
		cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;



	return 0;
}

Measured memory_bytes: 3656
def binary_search(lst, e, mode):
    l, u = 0, len(lst)
    mid = len(lst) // 2

    while l <= u-1:
        if lst[mid] < e and mode == "l" or lst[mid] <= e and mode == "u":
            l = mid + 1
        else:
            u = mid
        mid = (l+u) // 2

    return u


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

com = 0

for i in b:
    j = binary_search(a, i, "l")
    k = len(c) - binary_search(c, i, "u")
    com += j * k

print(com)


Measured memory_bytes: 23328
// 2
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

class PowerSocket {
 private:
  int A, B;
  int socket = 1;
  int count = 0;

 public:
  PowerSocket() {
    std::scanf("%d", &A);
    std::scanf("%d", &B);
    while (socket < B) {
      socket -= 1;
      socket += A;
      count++;
    }
    std::printf("%d\n", count);
  }
};

int main() {
  PowerSocket ps;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,ans;
    char ch;

    cin>>a>>ch>>b;

    if(ch == '+')
    {
        ans = a+b;
    }

    else
        ans = a-b;

    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<long long> a(n);
	cin >> a;
	for (int i = 0; i < n - 1; ++i) {
		if (a[i] < 0) {
			a[i] *= -1;
			a[i + 1] *= -1;
		}
	}
	if (a[n - 1] < 0) {
		long long sum = 0;
		long long res = inf;
		for (int i = 0; i < n; ++i) {
			mins(res, (long long)abs(a[i]));
			sum += abs(a[i]);
		}
		sum -= 2 * res;
		cout << sum << endl;
	}
	else {
		long long sum = 0;
		for (int i = 0; i < n; ++i) sum += abs(a[i]);
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N),F(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> F[i];
    sort(A.begin(),A.end());
    sort(F.begin(),F.end());
    reverse(F.begin(),F.end());
    ll lb=-1,ub=IINF;
    while(ub-lb>1){
        ll mid=(lb+ub)/2;
        ll sum=0;
        rep(i,N){
            ll L=mid/F[i];
            if (L>=A[i]) continue;
            else sum+=A[i]-L;
        }
        if (sum<=K) ub=mid;
        else lb=mid;
    }
    cout << ub << endl;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long int ll;
const int MAXN=105;
char s[MAXN];
ll k;
int len,num=0;
int main(){
	scanf("%s%lld",s+1,&k);
	len=strlen(s+1);
	for(int i=1;i<=len;++i)
		if(s[i]=='1') ++num;
		else break;
	if(num>=k) printf("1");
	else{
		for(int i=1;i<=len;++i)
			if(s[i]!='1'){
				printf("%c",s[i]);
				break;
			}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
char c[5] = {'M', 'A', 'R', 'C', 'H'};
int main() {
  int N;
  cin >> N;
  ll cnt = 0;
  unordered_map<char, ll> mp{};
  REP(i, N) {
    string s;
    cin >> s;
    if (s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' &&
        s[0] != 'H') {
      continue;
    }
    mp[s[0]]++;
  }
  ll ans = 0;
  /*for (auto s : mp) {
    for (auto t : mp) {
      for (auto u : mp) {
        if (s.first == t.first || t.first == u.first || u.first == s.first)
          continue;
        if (s.second == 0 || t.second == 0 || u.second == 0) continue;
        ans += s.second * t.second * u.second;
      }
    }
  }*/
  REP(i, 3) {
    for (int j = i + 1; j < 4; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += mp[c[i]] * mp[c[j]] * mp[c[k]];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
import sys

input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N=int(input())
c=list(map(int,input().split()))
for i in range(N):
    c[i]-=1
edge=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

subtree=[1]*N
def size(v,pv):
    for nv in edge[v]:
        if nv!=pv:
            size(nv,v)
            subtree[v]+=subtree[nv]

size(0,-1)

data=[[] for i in range(N)]
Parent=[[0] for i in range(N)]
parent=[0]*N
def dfs(v,pv,nop):
    pp=parent[nop]
    parent[nop]=v
    Parent[nop].append(v)
    data[c[v]].append((parent[c[v]],v))
    for nv in edge[v]:
        if nv!=pv:
            dfs(nv,v,c[v])
    parent[nop]=pp

dfs(0,-1,0)

for i in range(N):
    dic={v:subtree[v] for v in Parent[i]}
    for p,ch in data[i]:
        dic[p]-=subtree[ch]

    res=N*(N+1)//2
    for p in dic:
        res-=dic[p]*(dic[p]+1)//2
    print(res)

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define en '\n'
#define fs first
#define sd second

const ll INF = INT64_MAX;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    bool res = false;
    for(int i = a; i <= b; ++i){
        if(i % n == 0){
            res = true;
            break;
        }
    }
    cout << (res ? "OK" : "NG") << endl;
}

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

int kosu[5];

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

    int hidari_e = 0;
    int hidari_w = 0;
    int migi_e = 0;
    int migi_w = 0;

    REP(i, n) {
        if(s[i] == 'E') migi_e++;
        else migi_w++;
    }

    int ans = INF, tmp = 0;

    REP(i, n) {
        int tmp = 0;
        if(s[i] == 'E') {
            tmp += migi_e - 1;
            tmp += hidari_w;
            migi_e--;
            hidari_e++;
        } else {
            tmp += migi_e + hidari_w;
             migi_w--;
             hidari_w++;
        }

        ans = min(ans, tmp);

    }

    cout << ans << endl;

    return 0;
}
 

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

int main(){
long long int N,M,a,b,count=0;
cin >>N>>M;
tuple<long long int,long long int>drink[N];
for(int i=0;i<N;i++){
   cin >>a >>b;
   drink[i]=make_pair(a,b);
}
sort(drink,drink+N);
for(long long int i=0;i<N;i++){
   if(get<1>(drink[i])<=M){
      count+=get<1>(drink[i])*get<0>(drink[i]);
      M-=get<1>(drink[i]);
   }else if(get<1>(drink[i])>M){
      count+=get<0>(drink[i])*M;
      M=0;
   }
   if(M==0)break;
}
cout <<count;
 }



Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
road = [0] + a + [0]
allcost = 0
for i in range(n+1):
    allcost += abs(road[i+1] - road[i])

for i in range(1, n+1):
    ans = allcost - abs(road[i]-road[i-1]) - abs(road[i+1] - road[i]) + abs(road[i+1] - road[i-1])
    print(ans)

Measured memory_bytes: 65132
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		int ans=0;
		rer(i,1,6) ans+=n/pow(5,i);
		o(ans);
	}
}

Measured memory_bytes: 1204
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);


void solve() {
   string s;cin>>s;
   deque<char> v;
   for(auto x:s)v.EB(x);
   int q;cin>>q;
   int cnt=1 ;//0 means front
   int rev=0;
   while(q--){
       int t;cin>>t;
       if(t==1){
           cnt=3-cnt;
           rev++;
       } else{
            int type;
            char c;cin>>type>>c;
            if(type==cnt){
                v.push_front(c);
            } else{
                v.EB(c);
            }
       }
   }
   string ans;
   for(auto x:v){
      ans.PB(x);
   }
   if(rev%2){
       reverse(ALL(ans));
   }
   cout<<ans;
}

int32_t main() {
    IOS;
    int test = 1;
    //cin >> test;
    while (test--) {
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
/*
 * 3 3
9 9 4
 6 6 8
2 1 1
 */

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

using namespace std;
typedef long long ll;

int main() {
	string s,t;
    cin >> s >> t;

    vector<int> char_ind[26];

    for(int i=0; i < s.length(); i++) {
        char_ind[s[i]-'a'].push_back(i);
    }

    int cur_pos = 0;
    bool first = true;
    int total_rounds = 0;
    for(int i=0; i < t.length(); i++) {
        int c_int = t[i]-'a';
        auto& arr = char_ind[c_int];

        if(arr.size() == 0) {
            cout << "-1";
            return 0;
        }

        auto ptr = lower_bound(arr.begin(), arr.end(), first ? 0 : cur_pos+1);
        if(ptr == arr.end()) {
            total_rounds++;
            cur_pos = arr[0];
        }
        else {
            int ind = ptr - arr.begin();
            cur_pos = arr[ind];
        }

        first = false;
    }

    cout << total_rounds * s.length() + cur_pos + 1;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,q;
vvi g;
vi a;

void dfs(int v,int p){
	for(auto u:g[v]) if(u!=p){
		a[u]+=a[v];
		dfs(u,v);
	}
}

int main(){
	cin>>n>>q;
	g=vvi(n);
	a=vi(n);
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=0;i<q;i++){
		int v,x;
		cin>>v>>x;
		a[v-1]+=x;
	}
	dfs(0,-1);
	for(int i=0;i<n;i++) cout<<a[i]<<" \n"[i==n-1];
}

Measured memory_bytes: 23424
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<string> a;

bool cmp(string s, string t) {
    if (s.length() != t.length()) return s.length() < t.length();
    return s < t;
}

void sol(string s) {
    a.push_back(s);
    if (s.length() == 10) return;
    if (s.back() != '0') {
        s += (s.back() - 1);
        sol(s);
        s.pop_back();
    }
    s += (s.back());
    sol(s);
    s.pop_back();
    if (s.back() != '9') {
        s += (s.back() + 1);
        sol(s);
        s.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(false);
    int n, m, a[102] = {}, b = 0, c = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i], b += a[i];
    for (int i = 0; i < n; i++) if (a[i] * 4 * m >= b) c++;
    if (c >= m) cout << "Yes";
    else cout << "No";
}


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

using namespace std;

int main ()
{
    string str;
    cin>>str;

    int n = str.length();
    bool ans = true;
    for(int i=0; i<n; i++) {
        if(str[i]=='R' && (i+1)%2==0) {
            ans = false;
            break;
        }
        if(str[i]=='L' && (i+1)%2!=0) {
            ans = false;
            break;
        }
    }

    if(ans) cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 256
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")


class SegmentTree:
    def __init__(self, size, f=lambda x, y: x + y, default=0):
        self.size = 2 ** (size - 1).bit_length()
        self.default = default
        self.dat = [default] * (self.size * 2)
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1])

    def query(self, l, r):
        """return f([l,r))
        """
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res


N = int(input())
A = list(map(int, input().split()))
s = SegmentTree(N, gcd, 0)
for i, a in enu(A):
    s.update(i, a)

res = 0
for i in range(N):
    val = gcd(s.query(0, i), s.query(i + 1, N))
    if res < val:
        res = val
print(res)



Measured memory_bytes: 94080
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = Integer.parseInt(sc.nextLine().replace(" ", ""));
		if ((int)(Math.sqrt(x)) * (int)(Math.sqrt(x)) == x) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   string s;
           cin>>s;
           int n=s.size();
           for(char c='a';c<='z';c++){
             bool ok=true;
             rep(i,0,n)if(s[i]==c)ok=false;
             if(ok){
              cout<<c<<endl;
               return 0;
             }
           }
           cout<<"None"<<endl;
}

Measured memory_bytes: 3736
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        String n=sc.nextLine();
        String ans="";
        for(int i=0;i<n.length();i++){
            if(n.charAt(i)=='1'){
                ans+='9';
            }else{
                ans+='1';
            }
        }
        System.out.print(ans+"\n");
        
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
int main()
{
    int n, tc = 0, hc = 0;
    char t[101], h[101];
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%s %s", t, h);
        if (strcmp(t, h) > 0)
        {
            tc = tc + 3;
        }
        else if(strcmp(t, h) < 0)
        {
            hc = hc + 3;
        }
        else
        {
            tc = tc + 1;
            hc = hc + 1;
        }
    }
    printf("%d %d\n", tc, hc);
    return 0;
}


Measured memory_bytes: 2088
//02
#include<iostream>
#include<string>

using namespace std;

int main(){
  int t;
  cin>>t;
  cin.ignore();
  while(t--){
    string s;
    getline(cin,s);
    int c=0;
    int m;
    cin>>m;
    while(m--){
      string ca,cb;
      cin>>ca;
      getline(cin,cb);
      if(ca=="forward"){
	if(cb==" char"){
	  if(c<s.size()){
	    c++;
	  }
	}else{
	  while(c<s.size()&&s[c]==' '){
	    c++;
	  }
	  while(c<s.size()&&s[c]!=' '){
	    c++;
	  }
	}
      }else if(ca=="backward"){
	if(cb==" char"){
	  if(c!=0){
	    c--;
	  }
	}else{
	  while(c-1>=0&&s[c-1]==' '){
	    c--;
	  }
	  while(c-1>=0&&s[c-1]!=' '){
	    c--;
	  }
	}
      }else if(ca=="insert"){
	s.insert(c,cb.substr(2,cb.size()-3));
	c+=cb.size()-3;
      }else{
	if(cb==" char"){
	  if(c!=s.size()){
	    s.erase(c,1);
	  }
	}else{
	  bool a=false;
	  for(int i=c;i<s.size();i++){
	    a|=s[i]!=' ';
	  }
	  if(a){
	    while(c!=s.size()&&s[c]==' '){
	      s.erase(c,1);
	    }
	    while(c!=s.size()&&s[c]!=' '){
	      s.erase(c,1);
	    }
	  }
	}
      }
    }
    for(int i=0;i<s.size();i++){
      if(i==c){
	cout<<'^';
      }
      cout<<s[i];
    }
    if(c==s.size()){
      cout<<'^';
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int N = sc.nextInt(), H = sc.nextInt(), W = sc.nextInt();
		int ans = 0;
		for(int i = 0; i < N; i++) {
			int A = sc.nextInt(), B = sc.nextInt();
			if(H <= A && W <= B) ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 25324
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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; }

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

    int n; cin >> n;
    vector<int> p (n);
    rep(i, n) cin >> p[i];
    int cnt = 0;
    for(int i = 1; i < n - 1; i++) {
        if((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1])) {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define ld long double
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1000005,mod=998244353;
ll n,m,fac[N],ni[N],ans;
inline int ksm(ll a,int b){
	int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
inline ll c(int a,int b){
	return fac[a]*ni[a-b]%mod*ni[b]%mod;
}
signed main(){
	for(int i=fac[0]=1;i<N;i++)fac[i]=fac[i-1]*i%mod; ni[N-1]=ksm(fac[N-1],mod-2); for(int i=N-1;i;i--)ni[i-1]=ni[i]*i%mod;
	n=read(); m=read();
	for(int i=1;i<=n&&i<=m;i++)ans=(ans+c(2*i,i)*c(m+n-2*i,n-i))%mod; 
	ans=(ans*ksm(2*c(n+m,n)%mod,mod-2)%mod+max(n,m))%mod;
	cout<<ans<<endl;
}

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

int main() {
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int t=0;
	if (a%2 || b%2 || c%2) {
		printf("%d\n",t);
		return 0;
	}
	while (a!=b || b!=c || a!=c) {
		t++;
		int aa=(b+c)/2,bb=(a+c)/2,cc=(a+b)/2;
		a=aa,b=bb,c=cc;
		if (a%2 || b%2 || c%2) {
			printf("%d\n",t);
			return 0;
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}			
		}
	}
}

void Show(vector<int> N) {
	for (int i = 0; i < N.size(); i++) {
		cout << N[i];
		if (i != N.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	int N;
	cin >> N;
	vector<array<int, 3>> Code;
	Code.resize(N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> Code[i][j];
		}
	}
	int X = 0, Y = 0, T = 0;
	for (int i = 0; i < N; i++) {
		int d = abs(X - Code[i][1]) + abs(Y - Code[i][2]);
		int dt = Code[i][0] - T;
		if (d > dt) {
			cout << "No" << endl;
			return 0;
		} else {
			if ((dt - d) % 2 != 0) {
				cout << "No" << endl;
				return 0;
			}
		}
		X = Code[i][1];
		Y = Code[i][2];
		T = Code[i][0];
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#ABC135B - 0 or 1 Swap
N = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(N):
    if p[i] != i+1:
        count += 1
if count == 0:
    print("YES")
elif count == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }

constexpr int nax = 200 * 1000 + 105;

int n;
int dp[nax];

int main() {
  scanf("%d", &n);
  int naj = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    dp[x] = dp[x - 1] + 1;
    naj = max(naj, dp[x]);
  }
  printf("%d\n", n - naj);
  return 0;
}


Measured memory_bytes: 1532
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>

using namespace std;

#define ll long long
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)

int main()
{
    int a,b;
    cin >> a >> b;
    if (a<10&&a>0)
    {
        if(b<10&&b>0)
        {
            cout << a*b << endl;
        }else
        {
            cout << "-1" << endl;
        }
    }else
    {
        cout << "-1" << endl;
    }
    
    
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.math.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		//int a = sc.nextInt();
		// スペース区切りの整数の入力
		//int b = sc.nextInt();
		//int c = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		//1文字ずつ
		//s.atChar(i);
		//s.charAt(i); for String
		// 出力
		//System.out.println("");
		//int count=0;
		
		int N=sc.nextInt();
		
		
		double[] x;
		String[] u;
		
		double sum =0;
		
		x=new double[N];
		u=new String[N];
		
		for(int i=0;i<N;i++){
			x[i]=sc.nextDouble();
			u[i]=sc.next();
			
			//System.out.println(x[i]*2);
			//System.out.println(sum);
			//System.out.println(u[i]);
			if(u[i].equals("JPY")){
				double ne=x[i];
				//System.out.println(ne);
				sum+=ne;
			}else{
				double ne=x[i] * 380000;
				sum+=ne;
			}
			//System.out.println(i+":"+sum);
		}
		System.out.println(sum);
	
		
	}
	
	
}

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

int main() {
  int a, A, b, B, c, C, d, D;
  cin >> a >> A >> b >> B;

  int dx = b-a; int dy = B-A;
      c = b-dy;
      C = B+dx;
      d = a-dy;
      D = A+dx;
  
  printf("%d %d %d %d\n", c, C, d, D);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q;
ll powermod(ll x,ll n)
{
    if(n==0)  return 1;
    else if(n%2 == 0)return powermod((x*x)%M,n/2);
    else return (x*powermod((x*x)%M,(n-1)/2))%M;
}
int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n;
      cout<<(powermod(10,n)+(M-powermod(9,n))%M+(M-powermod(9,n))%M+powermod(8,n))%M;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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; }

const ll MRINF = 5000000000000000;

int main() {

  ll K;
  cin >> K;
  ll n = 7;
  ll mod = n;
  ll count = 1;

  ll roop = n % K;
   if (K%2 == 0 || K%5 == 0 ) {
       cout << -1 << endl;
       return 0;
   }
  

  while(1){
    mod = mod % K;
    if(mod==0){
      cout << count << endl;
      return 0;
    }

    if(count!=1){
      if(mod==roop){
        cout << -1 << endl;
        return 0;
      }
    }



    
    count++;
    mod = mod*10+7;

  
    
  }



}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3636
import java.util.stream.*;
import java.util.*;

public class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		int h=s.nextInt(),w=s.nextInt(),n=s.nextInt();
		List<Integer> a=new ArrayList<>();
		IntStream.range(1,n+1).forEach(i->a.addAll(Collections.nCopies(s.nextInt(),i)));
		IntStream.range(0,h).forEach(i->System.out.println(IntStream.range(0,w).mapToObj(j->String.valueOf(a.get(i%2==0?i*w+j:i*w+w-j-1))).collect(Collectors.joining(" "))));
	}
}

Measured memory_bytes: 34148
def search(idx, N, mn, mx, cur, cand):
    if idx == N:
        cand.append(cur)
        return
    for i in range(mn, mx+1):
        search(idx+1, N, i, mx, cur+[i], cand)


def main():
    N, M, Q = map(int, input().split())
    conds = [None] * Q
    for i in range(Q):
        a, b, c, d = map(int, input().split())
        conds[i] = (a, b, c, d)
    candidates = []
    search(0, N, 1, M, [], candidates)
    ans = 0
    for A in candidates:
        score = 0
        for i in range(Q):
            a, b, c, d = conds[i]
            if A[b-1] - A[a-1] == c:
                score += d
        ans = max(ans, score)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 94300
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){ cin >> a[i]; }

    vector<ll> updown;
    updown.push_back(a[0]);
    int up = a[1] - a[0];
    up = (up != 0) ? up/abs(up) : 0; 
    up = 0;
    for (int i = 1; i < n; i++)
    {
        int tup = a[i] - a[i-1];
        tup = (tup != 0) ? tup/abs(tup) : 0; 
        if (up != 0){
            if (up != tup && tup != 0){
                //hanten
                updown.push_back(a[i-1]);
                up = tup;
            }
        } else {
            up = tup;
        }
    }
    if (updown[updown.size()-1] != a[n-1] ) updown.push_back(a[n-1]);

    //show(updown);

    if (updown.size() == 1) {
        cout << "1000" << endl;
        return 0;
    }

    bool upst = true;
    if (updown[0] > updown[1]){
        upst = false;
    }
    ll ans = 1000;
    ll kabu = 0;
    rep(i, updown.size()/2){
        if (upst){
            if (i*2+1 >= updown.size()) break;
            kabu = ans/updown[i*2];
            ans -= kabu*updown[i*2];
            ans += kabu*updown[i*2+1];
        } else {
            if (i*2+2 >= updown.size()) break;
            kabu = ans/updown[i*2+1];
            ans -= kabu*updown[i*2+1];
            ans += kabu*updown[i*2+2];
        }     
    }

    cout << ans << endl;
}



Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char c[310][310];
ll dp[101];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	dp[0] = 1000;
	rep(i, n - 1) {
		dp[i + 1] = dp[i];
		rep(j, i+1) {
			ll kabu = dp[j] / a[j];
			dp[i + 1] = max(dp[i + 1], (a[i+1] - a[j]) * kabu + dp[j]);
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h> //AtCoder
#include <iostream> //Codeforces
#include <vector> //Codeforces

#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Vc vector<char>
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}//最大公約数
int lcm(int a,int b){return a/gcd(a,b)*b;}//最小公倍数

const int MOD = 1000000007; // 10^9 + 7
struct mint{int x;mint(int x=0):x((x%MOD+MOD)%MOD){}
mint operator-()const{return mint(-x);}
mint& operator+=(const mint a){if((x+=a.x)>=MOD)x-=MOD;return*this;}
mint& operator-=(const mint a){if((x+=MOD-a.x)>=MOD)x-=MOD;return*this;}
mint& operator*=(const mint a){(x*=a.x)%=MOD;return*this;}
mint operator+(const mint a)const{return mint(*this)+=a;}
mint operator-(const mint a)const{return mint(*this)-=a;}
mint operator*(const mint a)const{return mint(*this)*=a;}
mint pow(int t)const{if(!t)return 1;mint a=pow(t>>1);a*=a;if(t&1)a*=*this;return a;}
mint inv()const{return pow(MOD-2);}
mint& operator/=(const mint a){return*this*=a.inv();}
mint operator/(const mint a)const{return mint(*this)/=a;}};
ostream& operator<<(ostream& os, const mint& a) {return os << a.x;}
/****************************** START ******************************/

signed main(){
  int N;
  cin >> N;
  Vi A(N);
  int mod = 1000000007;
  rep(i,0,N){
    cin >> A.at(i);
  }
    
  mint sum = 0;
  rep(i,0,N){
    sum += A.at(i);
  }
  mint sqsum = 0;
  rep(i,0,N){
    sqsum += A.at(i) * A.at(i);
  }
  
  cout << (sum * sum - sqsum) / 2;
}



Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    string s; cin >> s;
    int ans = 7;

    if(s == "MON")ans = 6;
    if(s == "TUE")ans = 5;
    if(s == "WED")ans = 4;
    if(s == "THU")ans = 3;
    if(s == "FRI")ans = 2;
    if(s == "SAT")ans = 1;

    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll a,b;
    cin>>a>>b;
    if(b%a==0){
        cout<<a+b<<endl;
    }
    else{
        cout<<b-a<<endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
c=eval('[0]*50,'*50)
r=0
for a in[*open(0)][1:]:
 a=round(float(a)*1e9);y=1
 while a%5**y<1:y+=1
 x=len(bin(a&-a));r+=sum(sum(d[max(0,20-y):])for d in c[max(0,24-x):]);c[x][y]+=1
print(r)

Measured memory_bytes: 89580
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  vector<int> cnt(3, 0);
  rep(i, n) {
    if (p[i] <= a) cnt[0]++;
    else if (p[i] <= b) cnt[1]++;
    else cnt[2]++;
  }
  cout << min({cnt[0], cnt[1], cnt[2]}) << endl;



  
  return 0;
}

Measured memory_bytes: 256