akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  vector<P> v;
  int key = a[0];
  int c = 1;
  for (int i = 1; i < n; i++){
    if (a[i] == key){
      c++;
    } else {
      P tmp = make_pair(key, c);
      v.push_back(tmp);
      c = 1;
      key = a[i];
    }
  }
  P tmp = make_pair(key, c);
  v.push_back(tmp);

  int ans = 0;
  rep(i, v.size()){
    if (v[i].second < v[i].first){
      ans += v[i].second;
    } else {
      ans += v[i].second - v[i].first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1784
program sample
	implicit none
    integer(8) :: a,b,c
    
    read(*,*) a,b,c
    
    if (a<=b .and. b<=c) then
    	write(*,*) (a*b)/2
    else if (b <=a .and. a<=c) then
    	write(*,*) (a*b)/2
    else if (a <=c .and. c<=b) then
    	write(*,*) (a*c)/2        
    else if (b <=c .and. c<=a) then
    	write(*,*) (c*b)/2
    else if (c <=a .and. a<=b) then
    	write(*,*) (a*c)/2        
    else if (c <=b .and. b<=a) then
    	write(*,*) (c*b)/2   
    end if
    stop
end program sample


Measured memory_bytes: 2832
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}


#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N, K;
    cin >> N >> K;

    int p[N];
    double E[N];
    REP(i, N) {
        cin >> p[i];
        E[i] = double(p[i] + 1) / 2;
    }

    double ans = 0;
    REP(i, K) {
        ans += E[i];
    }

    double s = ans;
    FOR(i, 1, N - K + 1) {
        s = s - E[i-1] + E[i+K-1];
        ans = max(s, ans);
    }
    
    cout << fixed << setprecision(20);
    cout << ans << endl;

}


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

namespace B___Break_Number
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = new List<int> { 1, 2, 4, 8, 16, 32, 64 };
            var quary = a.OrderByDescending(x => x)
                         .ToList();
            for (var i = 0; i < a.Count; i++)
            {
                if (n >= quary[i])
                {
                    Console.WriteLine(quary[i]);
                    return;
                }
            }
        }
    }
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int solve(){
    int n; cin>>n;
    for(int i=-1000; i<=1000; i++){
        for(int j=-1000; j<=1000; j++){
            int x=i*i*i*i*i;
            int y=j*j*j*j*j;
            if(x-y==n){
                cout<<i<<" "<<j;
                return 0;
            }
        }
    }
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

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

#define xin() main()
#define ru(a) if(a)
#define ruguo(a) else if(a)
#define baai(a) while(a)
#define sai(j,n) for(sei j=0;j<sei(n);++j)
#define gsai(j,n) for(sei j=sei(n)-1;j>=0;--j)
#define kan(j,m,n) for(sei j=m;j<sei(n);++j)
#define gkan(j,m,n) for(sei j=sei(n)-1;j>=sei(m);--j)
#define ta else
#define datu break
#define zi continue;
#define hen return
#define zen(h) (h).begin(),(h).end()
#define seiri(h) sort(zen(h))
#define yu(h) h.erase(unique(zen(h)), h.end())
#define gyaku(a) reverse(zen(a))
#define katu &&
#define mata ||
#define nyu(a) cin >> a
#define syutu(a) cout << a << endl
#define tuika(a,b) a.push(b)
#define huka(a,b) a.push_back(b)
#define tou(a) a.top()
#define kuu(a) a.empty()
#define xya(a) a.pop()
#define cyou(a) a.size()
#define tyou(a) a.length()
#define sen first
#define go second
#define sosei(a,b) make_pair(a,b)
#define kouzoutai struct
#define kigou operator
#define sin true
#define gi false
#define tei const
#define mugen 10000000111
#define yo 10000000711
#define kyou 1e-9
#define zetaiti(a) abs(a)

using namespace std;

typedef int seisu;
typedef void mu;
typedef long long sei;
typedef long double xyo;
typedef string moji;
typedef pair<sei, sei> so;
typedef pair<xyo, xyo> sox;
typedef vector<sox> hsox;
typedef vector<sei> hs;
typedef vector<hs> hhs;
typedef vector<xyo> hx;
typedef vector<hx> hhx;
typedef vector<moji> hm;
typedef vector<so> hso;
typedef vector<hso> hhso;
typedef bool singi;
typedef vector<singi>  hsi;
typedef vector<hsi> hhsi;
typedef priority_queue<sei> nibungi;
typedef map<int, int> zisyos;

const seisu h1[8] = {1,1,0,-1,-1,-1,0,1};
const seisu h2[8] = {0,1,1,1,0,-1,-1,-1};

sei dai(sei a, sei b){return max(a,b);}
sei syou(sei a, sei b){return min(a,b);}

sei n, X, d;
hs x(110000);

sei kou(sei a, sei b){
    sei daikou;
    ru(b == 0){
        daikou = a;
    }
    ta{
        daikou = kou(b, a%b);
    }

    hen daikou;
}

seisu xin(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    nyu(n);
    nyu(X);
    sai(j,n){
        nyu(x[j]);
        x[j] = zetaiti(x[j] - X);
    }

    d = x[0];
    kan(j,1,n){
        d = kou(d,x[j]);
    }
    syutu(d);

    hen 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int K;
    cin >> K;

    int A, B;
    cin >> A >> B;

    string ans;
    int temp;
    for (int i = 1;; i++)
    {
        temp = K * i;
        if (temp >= A && temp <= B)
        {
            ans = "OK";
            break;
        }
        else if (temp > B)
        {
            ans = "NG";
            break;
        }
    }

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

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

int main() {
    int n , ans;
    cin>>n;
    ans=(1000 - n % 1000) % 1000;
    // if(ans==1000) cout<<0<<endl;

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

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

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

  int cnt = 0;
  for (int i=1;i<=N;i++){
    if (a[a[i]]==i) cnt++;
  }

  cout << cnt/2 << endl;
  
}

 

Measured memory_bytes: 640
using System;
using System.Linq;
class aoj
{
    static void Main()
    {
        int[] c = new int[8];
        c[0] = 1;c[1] = 2;c[2] = 1;c[3] = 2;c[4] = 1;c[5] = 4;c[6] = 1;c[7] = 4;
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            int[] b = a.Split(' ').Select(int.Parse).ToArray();
            int[] f = new int[3];
            f[0] = 1000000000;
            for (int i = 0; i < 8; i++)
            {
                int e = 0;
                char[] h = new char[8];
                for (int j = 0; j < 8; j++)
                {
                    int d = j + i;
                    if (d >= 8)
                        d -= 8;
                    int g = b[j] - c[d];
                    if (g < 0)
                        g = 0;
                    e += g;
                    h[j] = (char)(c[d] + '0');
                }
                if (f[0] > e)
                {
                    f[0] = e;
                    f[1] = i;
                    string k = new string(h);
                    f[2] = int.Parse(k);
                }
                if (f[0] == e)
                {
                    string k = new string(h);
                    int l = int.Parse(k);
                    if (f[2] > l)
                    {
                        f[1] = i;
                        f[2] = l;
                    }
                }
            }
            int m = f[1];
            for (int i = 0; i < 8; i++)
            {
                int n = m + i;
                if (n >= 8)
                    n -= 8;
                if (i == 0)
                    Console.Write(c[n]);
                else
                    Console.Write(" " + c[n]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9652
// Hint: Don't look, No need, Let'em Play.

#pragma optimize("O2")
#include <bits/stdc++.h>
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

void solve() {
    int n, x, z = 0;
    cin >> n;
    int a[n];
    for (int &x: a) {
        cin >> x;
        z ^= x;
    }
    for (int i = 0; i < n; ++i) {
        cout << (z ^ a[i]) << ' ';
    }
}

signed main() {
    fast;
    int t = 1; // cin >> t;
    while (t--) {
        solve();
    }


  return 0;
}

Measured memory_bytes: 5176
#include<stdio.h>
int main(){
  char s[100001];
  int i,t,n,x;
  scanf("%s",s);
  for(n=0;s[n];n++);
  x=n;for(i=1;i<n;i++)if(s[i]!=s[i-1]){t=i<n-i?n-i:i;x=t<x?t:x;}
  printf("%d",x);
}


Measured memory_bytes: 1832
import java.util.*;
import java.math.*;
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	/*static void sort(int[] A,int l,int r) {
		if(l=r) {
			
		}
		sort(A,0,(l+r)/2);
		sort(A,1+ (l+r)/2,r);
		
	}*/

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		
	
		String s = sc.nextLine();
		
		String s1=s.substring(0, 5);
		String s2=s.substring(6, 13);
		String s3=s.substring(14, 19);
		
		System.out.println(s1+" "+s2+" "+s3);
		
		
	}

}

Measured memory_bytes: 21844
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
a.sort()

b=[0]
for i in range(1,n+1):
  b.append(b[i-1]+a[i-1])
b=b[1:]

ans=1
for i in range(n-2,-1,-1):
  if b[i]*2>=a[i+1]:
    ans+=1
  else:
    break

print(ans)

Measured memory_bytes: 20060
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

typedef long long ll;

const int MAX_N = 1e5 + 5;
int n, m, num;
int Arr[MAX_N];

bool cmp1 (int a, int b) {
	if (a & 1)
		return true;
	return false;
}

bool cmp2 (int a, int b) {
	if (b & 1)
		return true;
	return false;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> Arr[i];
		num += (Arr[i] & 1);
	}

	if (n == 1) {
		cout << "1\n1\n1";
		return 0;
	}
	
	if (m == 1) {
		cout << Arr[0] << "\n2\n";
		cout << Arr[0] - 1 << " " << 1 << "\n";
		return 0;
	}

	if (2 < num) {
		cout << "Impossible\n";
		return 0;
	}

	sort(Arr, Arr + m, cmp1);
	sort(Arr + 1, Arr + m, cmp2);
    
    cout << Arr[0];
	for (int i = 1; i < m; i++)
		cout << " " << Arr[i];
	cout << "\n";

	cout << m - (Arr[0] == 1) << "\n";
	Arr[0]--, Arr[m - 1]++;
	for (int i = 0; i < m; i++)
		if (Arr[i])
			cout << Arr[i] << " ";
	return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long k=sc.nextLong();
		int q=sc.nextInt();
		long[] a=new long[n];
		Arrays.fill(a, k);
		int count=0;
		for(int i=0;i<q;i++) {
			a[sc.nextInt()-1]++;
		}
		for(int i=0;i<n;i++) {
			if(a[i]>q) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}
}



Measured memory_bytes: 59664
#include <stdio.h>
#include <string.h>
 
int main(void){
	int a , i;
	char s[100000],ans[100000];
	
	scanf("%s",s);
	a = strlen(s);
	
	for(i = 0;i*2 < a;i++){
		ans[i] = s[i*2];
	}
	printf("%s",ans);
	
	return 0;
}

Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]
    ans = 0

    if W == 1 or H == 1:
        print(1)
        return

    if W % 2 == 0:
        ans = (W // 2) * H
    else:
        ans += -(-W // 2) * -(-H // 2)
        ans += (W // 2) * (H // 2)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
from collections import deque
q=deque()
def MI(): return map(int, input().split())
N,M=MI()
g=[[] for _ in range(N+1)]
for _ in range(M):
  a,b=MI()
  g[a].append(b)
  g[b].append(a)
check=[0]*(N+1)
check[1]=1
ans=[0]*(N+1)
q.append(1)
while len(q)>0:
  v=q.popleft()
  for u in g[v]:
    if check[u]==0:
      check[u]=1
      ans[u]=v
      q.append(u)
print('Yes')
for i in range(2,N+1):
  print(ans[i])


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

int main(){
    int h,w,n;scanf("%d%d%d",&h,&w,&n);
    int sr,sc;scanf("%d%d",&sr,&sc);
    string s,t;cin>>s>>t;
    bool flag=false;
    int x=sr,y=sc;
    //L R U D
    for(int i=0;i<s.size();i++){
        if(s[i]=='L'){
            y--;
        }
        if(y==0) flag=true;
        if(t[i]=='R'&&y<w){
            y++;
        }
    }
    x=sr;y=sc;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R'){
            y++;
        }
        if(y>w) flag=true;
        if(t[i]=='L'&&y>1){
            y--;
        }
    }x=sr;y=sc;
    for(int i=0;i<s.size();i++){
        if(s[i]=='U'){
            x--;
        }
        if(x==0) flag=true;
        if(t[i]=='D'&&x<h){
            x++;
        }
    }x=sr;y=sc;
    for(int i=0;i<s.size();i++){
        if(s[i]=='D'){
            x++;
        }
        if(x>h) flag=true;
        if(t[i]=='U'&&x>1){
            x--;
        }
    }
    if(flag) puts("NO");
    else puts("YES");
    return 0;
}


Measured memory_bytes: 776
#include <iostream>

using namespace std;

const int MAX_N = 500000;
int par[MAX_N];
int rn[MAX_N];
long cnt[MAX_N];

void init(int n){
    for(int i=0; i<n; i++){
        par[i] = i;
        rn[i] = 0;
        cnt[i] = 1;
    }
}

int find(int x){
    if(par[x] == x) {
        return x;
    } else{
        par[x] = find(par[x]);
        return par[x];
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x==y) return;

    if(rn[x] < rn[y]){
        par[x] = y;
    } else{
        par[y] = x;
        if(rn[x] == rn[y]) rn[x]++;
    }
    cnt[x] += cnt[y];
    cnt[y] = cnt[x];
}

bool same(int x, int y) {
    return find(x) == find(y);
}


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

    int A[M], B[M];
    for(int i=0; i<M; i++){
        cin >> A[i] >> B[i];
        A[i]--;B[i]--;
    }

    long ans[M+1];
    ans[M] = N*(N-1)/2;

    init(N);
    for(int i=M-1; i>=0; i--){
        int ra = find(A[i]);
        int rb = find(B[i]);
        if(!same(A[i], B[i])) ans[i] = ans[i+1] - cnt[ra]*cnt[rb];
        else ans[i] = ans[i+1];
        unite(A[i], B[i]);
    }

    for(int i=1; i<M+1; i++){
        printf("%-18ld\n", ans[i]);
    }

    return 0;
}

Measured memory_bytes: 8704
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>

using namespace std;

#define rep(i, a, n) for (int i = (a); i < (n); ++i)

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  int n;
  cin>>n;
  vector<int> h(n);
  rep(i,0,n) cin>>h[i];
  reverse(h.begin(),h.end());
  int ans=0,val=0;
  for(int i=1;i<n;i++){
    if(h[i-1]<=h[i]) val++;
    else val=0;
    ans=max(ans,val);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)




int main() {
    ll n;
    cin >> n;
    
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    
    ll k = 1, ans = a[0] - 1;
    for(int i = 1; i < n; i++){
        if(k + 1 < a[i]){
            ans += (a[i] - 1) / (k + 1);
        }
        else{
            k = max(k, a[i]);
        }
        // cout << ans << ' ' << k << endl;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main() {
	int a,b,i,j;
	i = 0;
	while(1) {
		scanf("%d %d", &a, &b);
		if(a == 0 && b == 0) break;
		for(i = 0; i < a; i++) {
			for(j = 0; j < b; j++) {
				if(i == 0 || i == a-1 || j == 0 || j == b-1) {
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    int n; cin >> n;
    vector<int> b(n);
    for(int i = 0; i < n; i++) cin >> b[i];
    vector<int> ans;

    while(1){

        if(ans.size() == n) break;
        bool flag = false;

        int cnt = (int)ans.size();
        for(int i = n - 1; i >= 0; i--){
            if(b[i] == -1){   
                cnt--;
                continue;
            }

            int num = i + 1 - cnt;
            if(b[i] == num){
                ans.push_back(b[i]);
                b[i] = -1;
                flag = true;
                break;
            }
        }

        if(!flag){
            cout << -1 << endl;
            return 0;
        }
    }

    for(int i = n - 1; i >= 0; i--){
        cout << ans[i] << endl;
    }
    return 0;
}

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

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

void LCM(const vector<long long>& vec,map<long long,long long>& lcm) {
  for(int i = 0;i < vec.size();i++) {
    long long num = vec.at(i);
    for(int j = 2;j*j <= vec.at(i);j++) {
      long long cnt = 0;
      while(num % j == 0) {
        num /= j;
        cnt++;
      }
      lcm[j] = max(lcm[j],cnt);
    }
    lcm[num] = max(lcm[num],1LL);
  }
}

int main() {

  int N;
  cin >> N;

  vector<long long> A(N);
  map<long long,long long> lcm;
  for(int i = 0;i < N;i++) cin >> A.at(i);
  LCM(A,lcm);

  const int MAX = 2000100;
  vector<long long> fac(MAX,1),finv(MAX,1),inv(MAX,1);
  for(int i = 2;i < MAX;i++) inv.at(i) = MOD - inv.at(MOD%i) * (MOD/i) % MOD;
  
  
  long long ans = 0,num = 1;
  for(auto e:lcm) {
    while(e.second--) {
      num *= e.first;
      num %= MOD;
    }
  }

  for(int i = 0;i < N;i++) {
    ans += num*inv.at(A.at(i));
    ans %= MOD;
  }
  

  cout << ans << endl;
  
}


Measured memory_bytes: 47872
#include "bits/stdc++.h"
using namespace std;
int a[10000], c[100][100];
int main() {
	int H, W;
	int N;
	cin >> H >> W >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int x = 0, y = 0;
	int dx = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < a[i]; j++) {
			c[y][x] = (i + 1);
			x += dx;
			if (0 > x || x >= W) y++, x -= dx, dx *= (-1);
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << c[i][j] << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,n) for(int i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int main() {

    int n, k, q;
    cin >> n >> k >> q;

    vector<int> vec(n);  

    for(int i ; i < q; i++){
        int a;
        cin >> a;
        vec.at(a-1) ++;
    }

    for(int i = 0; i < n; i ++){
        if(k-q+vec.at(i) > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        //cout << vec.at(i) << endl;
    }


}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  t=1;
  while(t--){
  long long n,i,c=0,x;
  cin>>n;
  for(i=1;i<=n;i++)
   {
    cin>>x;
     if(i%2==1&&x%2==1)
     {
      c++;
     }
   }
   cout<<c<<endl;
  }

}

Measured memory_bytes: 3600
#include<stdio.h>
#define MAX 100000
#include<string.h>

typedef struct card{
 char mark[2];
 int num;
}card;





void swap(card C[],int a,int b){

card temp=C[a];
C[a]=C[b];
C[b]=temp;

return;
}




int partition(card C[],int p,int r){
int x=C[r].num;
int i=p-1;
int j;

for(j=p;j<r;j++){
  if(C[j].num<=x){
    i++;
    swap(C,i,j);
  }
}

swap(C,i+1,r);

return i+1;
}

void quicksort(card C[],int p,int r){
int q;

 if(p<r){
  q=partition(C,p,r);
  quicksort(C,p,q-1);
  quicksort(C,q+1,r);
 }

return;
}


void bubblesort(card D[],int p,int r){
int i,j;

for(i=0;i<r;i++){
 for(j=r;j>i;j--){
  if(D[j].num < D[j-1].num)swap(D,j,j-1);
 }
}

return;
}


void isStable(card C[],card D[],int n){
int i;
for(i=0;i<n;i++){
 if(strcmp(C[i].mark,D[i].mark)!=0){
   printf("Not stable\n");
   return;
 }
}

printf("Stable\n");

return;
}


int main(){
int i,n,j;
int A[MAX];
card C[MAX];
card D[MAX];

scanf("%d",&n);

for(i=0;i<n;i++){
 scanf("%s %d",C[i].mark,&C[i].num);
 D[i]=C[i];
}

quicksort(C,0,n-1);

for(i=0;i<n-1;i++){
 for(j=n-1;j>i;j--){
  if(D[j].num < D[j-1].num)swap(D,j,j-1);
 }
 if(strcmp(D[i].mark,C[i].mark)!=0){printf("Not stable\n");break;}
}


if(i==n-1)printf("Stable\n");


for(i=0;i<n;i++)printf("%s %d\n",C[i].mark,C[i].num);

return 0;
}


Measured memory_bytes: 3244
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int taxi_fee = sc.nextInt();
        int train_fee = N*A;
        if (taxi_fee > train_fee) {
            System.out.println(train_fee);
        } else {
            System.out.println(taxi_fee);
        }
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

int w, h;
int sy, sx, gy, gx;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

bool can(int y,int x) {
	if(0 <= y && y < h && 0 <= x && x < w) return true;
	return false;
}

vector<string> s;
char c;
bool used[55][55], visited[55][55];

bool check() {
	REP(i, sy, gy+1){
		REP(j, sx, gx+1) {
			if(s[i][j] == c || used[i][j]) continue;
			return false;
		}
	}
	return true;
}

void f() {
	REP(i, sy, gy+1) {
		REP(j, sx, gx+1) {
			used[i][j] = true;
		}
	}
}

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

	rep(q, n) {
		cin >> h >> w;
		s.resize(h);
		rep(i, h) cin >> s[i];

		memset(used, 0, sizeof(used));
		set<char> S;

		bool flag = true, update = true;
		while(update) {
			update = false;
			rep(i, h) {
				rep(j, w) {
					if(s[i][j] == '.') continue;

					if(used[i][j]) continue;

					sy = i;
					sx = j;
					gy = i;
					gx = j;
					c = s[i][j];
					memset(visited, 0, sizeof(visited));

					rep(k, h) {
						rep(l, w) {
							if(s[k][l] == c) {
								sy = min(sy, k);
								sx = min(sx, l);
								gy = max(gy, k);
								gx = max(gx, l);
							}
						}
					}

					if(S.find(c) == S.end() && check()) {
						f();
						S.insert(c);
						update = true;
					}
				}
			}
		}

		rep(i, h) {
			rep(j, w) {
				if(used[i][j]) continue;
				if(s[i][j] == '.') continue;
				flag = false;
			}
		}

		if(flag) cout << "SAFE" << endl;
		else cout << "SUSPICIOUS" << endl;

	}

	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn=1e5+5;

long long a[maxn],n,A,B;

bool check(long long x)
{
    long long  sum=0;
    for(long long i=1;i<=n;i++)
    {
        if(a[i]-x*B<=0)continue;
        sum=sum+(a[i]-x*B)/(A-B);
        if((a[i]-x*B)%(A-B)!=0)
			sum++;
    }
    return sum<=x;
}

int main()
{
    long long l,r,mid;
    scanf("%lld%lld%lld",&n,&A,&B);
    for(long long i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    //cout<<"!!"<<endl;
    l=1;
	r=1e9;
    while(r-l>1)
    {
        mid=(l+r)/2;
        if(check(mid))
			r=mid;
        else l=mid;
    }
    printf("%lld\n",check(l)?l:r);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define MAX 5000005
using namespace std;

int n;
string s;

int main()
{
    cin >> s;
    int flag = 1;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '7')flag = 0;
    }
    if(flag) puts("No");
    else puts("Yes");

    return 0;
}


Measured memory_bytes: 3576
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] adj = new int[n][n];
		for(int i = 0; i < m; i++){
		    int a = sc.nextInt()-1;
		    int b = sc.nextInt()-1;
		    adj[a][b] = 1;
		    adj[b][a] = 1;
		}
		
		// 計算
		int result = 0;
		Permutation p = new Permutation(n-1);
		for(String s : p.list){
		    int from = 0;
		    boolean flg = true;
		    for(int i = 0; i < s.length(); i++){
		        int to = s.charAt(i)-'0';
		        if(adj[from][to] != 1){
		            flg = false;
		            break;
		        }
		        from = to;
		    }
		    if(flg) result++;
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}

class Permutation {
	int n;
	String s;
	ArrayList<String> list;
	long cnt = 0;
	
	public Permutation(String s){
		this.n = s.length();
		this.s = s;
		
		boolean[] used = new boolean[n];
		ArrayList<String> list = new ArrayList<String>();
		dfs("", used, list);
		this.list = list;
	}
	
	public Permutation(int n){
		this.n = n;
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n; i++){
			sb.append(i+1);
		}
		this.s = sb.toString();
		
		boolean[] used = new boolean[n];
		ArrayList<String> list = new ArrayList<String>();
		dfs("", used, list);
		this.list = list;
	}
	
	private void dfs(String s, boolean[] used, ArrayList<String> list){
		this.cnt++;
		if(s.length() == used.length){
			list.add(s);
			return;
		}
		for(int i = 0; i < used.length; i++){
			if(used[i]) continue;
			used[i] = true;
			dfs(s + this.s.charAt(i), used, list);
			used[i] = false;
		}
	}
}


Measured memory_bytes: 30476
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void solve(){
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k-1];
}
int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

ll cost(vector<int>& xs, int p) {
    ll cost = 0;
    for (int i = 0; i < xs.size(); i++) {
        cost += (xs[i] - p) * (xs[i] - p);
    }
    return cost;
}

int main()
{
    int n;
    cin >> n;
    vector<int> xs(n);
    for (int i = 0; i < n; i++) {
        cin >> xs[i];
    }
    ll ans = numeric_limits<ll>::max();
    for (int i = 1; i <= 100; i++) {
        ans = min(ans, cost(xs, i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <limits>
#include <cmath>
#include <typeinfo>
 
 
using namespace std; 
 
 
// ||    



int firstDigit(int n) 
{ 
    // Remove last digit from number 
    // till only one digit is left 
    while (n >= 10)  
        n /= 10; 
      
    // return the first digit 
    return n; 
} 

int lastDigit(int n) 
{ 
    // return the last digit 
    return (n % 10); 
} 


void sortString(string &str) 
{ 
   sort(str.begin(), str.end()); 
}
 
void reverseStr(string& str) 
{ 
	reverse(str.begin(), str.end()); 
} 
  
int main() {
	int n = 0, k = 0;
	cin >> n >> k;
	if(n <= 9 && k <= 9) {
		cout << n * k << endl;
	}
	else {
		cout << -1 << endl;
	}
   
    return 0;
}














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

using namespace std;

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	int n;
	string s;

	scanf("%d", &n);

	cin >> s;

	if (n%2==1){
		printf("No\n");
	} else {
		for (int i = 0, j = n/2; i < n/2 && j < n; i++, j++){
			if (s[i] != s[j]){
				printf("No\n");
				return 0;
			}
		}
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n; cin >> n;
    
    vi a(n);
    rep(i, n){
        cin >> a[i];
        a[i]--;
    }
    vi b(n);
    rep(i,n) cin >> b[i];

    vi c(n);
    rep(i,n-1) cin >> c[i];

    lli sum = 0;
    rep(i, n){
        sum += b[a[i]];
        if(i>0 && a[i]-a[i-1] == 1) sum += c[a[i-1]];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,a,b;
vpi edges;
vvpi children;
vi ret;

void bfs(int x, int par, int parid){
    int i = 1;
    if(i == parid) i++;
    for (auto ch: children[x]){
        if (ch.first == par) continue;
        ret[ch.second] = i;
        bfs(ch.first, x, i);
        i++;
        if(i == parid) i++;
    }
}

signed main(){
    I(n);
    children.resize(n);
    ret.resize(n-1);
    REP(i,n-1){
        I(a); I(b);
        a--; b--;
        edges.eb(a,b);
        children[a].eb(b,i);
        children[b].eb(a,i);
    }
    bfs(0,-1,0);
    cout << *max_element(all(ret)) << endl;
    for(auto p: ret) cout << p << "\n";
}

Measured memory_bytes: 10224
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>
#include <map>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  map<string, int> mp;
  mp[s] = a;
  mp[t] = b;
  mp[u]--;
  cout << mp[s] << " " << mp[t] << endl;
  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}

vector<pair<ll, int>> factorize(ll n){
  vector<pair<ll, int>> ret;
  for(ll i=2; i*i <= n; i++){
    if(n%i) continue;
    ret.emplace_back(i, 0);
    while(n%i == 0){
      n /= i;
      ret.back().second++;
    }
  }
  if(n != 1) ret.emplace_back(n, 1);
  return ret;
}

int main(int argc, const char * argv[]) {
  ll A, B; cin >> A >> B;
  
  ll d = gcd(A, B);
  auto v = factorize(d);
  cout << v.size() + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc072/tasks/arc082_a

import itertools
import collections
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))

    c = collections.Counter()
    for a in A:
        c[a-1] += 1
        c[a] += 1
        c[a+1] += 1
    print(c.most_common()[0][1])


if __name__ == '__main__':
    main()


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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

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

    ll n,k,s;
    cin >> n >> k >> s;

    if (s == 1e9){
        for (ll i = 0; i < k; i++){
            cout << s << " ";
        }
        for (ll i = k; i < n; i++){
            cout << s-1 << " ";
        }
        cout << endl;
    }
    else{
        for (ll i = 0; i < k; i++){
            cout << s << " ";
        }
        for (ll i = k; i < n; i++){
            cout << s+1 << " ";
        }
        cout << endl;
    }

}

Measured memory_bytes: 3616
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
int pi=3.14159;
char a[101][51]= {};
int cp[50][2];
ll N,K;
int M;
int i;
double z;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c)
	printf("No\n");
	else if(a==b||a==c||b==c)
	printf("Yes\n");
	else 
	printf("No\n");
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];


int main(){
    ll N,A,B;
    // int ans = 0;
    cin >> N >> A >> B;
    ll ans = (N /(A+B))*A;
    ans += min(A,N%(A+B));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  #define int long long int
  #define vi vector<int>
  #define pii pair<long long ,long long>
  #define pll pair<int,int>
  #define mod 1000000007
  #define all(x) x.begin(),x.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define eb push_back
  #define ff first
  #define ss second
  #define rep(n) for(int i=0;i<n;i++)
  #define lb lower_bound
  #define up upper_bound
   
  
  using namespace std;
  int dp[3005][3005];
 
  void solve()
  { 
 
  string s,t;
  cin>>s>>t;
  int a=s.length();
  int b=t.length();
   string ans;
  for(int i=1;i<=a;i++)
  {
     for(int j=1;j<=b;j++)
     {
        if(s[i-1]==t[j-1])
          {dp[i][j]=dp[i-1][j-1]+1;
            
          }
        else
          {

            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
          }


     }

  }
  while(a>=1 && b>=1)
  {
     if(s[a-1]==t[b-1])
       {ans.eb(s[a-1]);
        a--;
        b--;
       }
     else
      if(dp[a-1][b]>dp[a][b-1])
      {
          a--;
      }
      else
        b--;

  }
  reverse(all(ans));
  cout<<ans<<endl;
    
    


   
   }

  signed main()
  {
   /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    T=1;
    
    while(T--)
    {
      solve();
    }
    return 0;
  }


Measured memory_bytes: 70656
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define pb push_back
#define mp make_pair
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;



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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n, m;
	cin >> n >> m;

	Array d(n);
	REP(i, n) {
		cin >> d[i];
	}

	Graph g(n);
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		add_edge(g, a, b, i, true, i);
	}

	string color(n, '.');//頂点の色
	Array l(m, 1000000000);//辺の長さ

	vector<P> dd(n);
	REP(i, n) dd[i].first = d[i], dd[i].second = i;
	sort(all(dd));

	for (auto i : dd) {
		ll dd = i.first;
		ll v = i.second;
		if (color[v] != '.') continue;
		bool flag = false;
		for (auto e : g[v]) {
			if (dd >= d[e.to]) {
				if (color[e.to] == '.') {
					color[e.to] = 'W';
					color[v] = 'B';
				}
				else if (color[e.to] == 'W') {
					color[v] = 'B';
				}
				else {
					color[v] = 'W';
				}
				l[e.cap] = d[v];
				flag = true;
				break;
			}
		}
		if (!flag) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << color << endl;
	REP(i, m) cout << l[i] << endl;

	return 0;
}


Measured memory_bytes: 22656
from operator import mul
N, M = map(int, input().split())
p = [0]*M
S = [None]*M

for i in range(M):
    p[i], S[i] = input().split()

p = list(map(int, p))
clear_flag = [0]*(N+1)
correct_N = 0
wrong_N = [0]*(N+1)

for i in range(M):

    if clear_flag[p[i]] == 0:
        if S[i] == 'AC':
            correct_N += 1
            clear_flag[p[i]] = 1
        else:
            wrong_N[p[i]] += 1

wa =  sum(map(mul, clear_flag, wrong_N))
print(correct_N, wa)

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    int32 ans = 0;
    REP(i,3){
        if(s[i] == t[i])ans++;
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string s, t;
  cin >> s >> t;
  vector<long> base(26, -1);
  vector<vector<long>> data(s.size() + 1, vector<long> (26, -1));
  for(int i = s.size(); i >= 0; i--){
    for(int j = 0; j < 26; j++)data.at(i).at(j) = base.at(j);
    if(i != 0)base.at(s.at(i - 1) - 'a') = i;
  }
  for(int i = s.size(); i >= 0; i--){
    for(int j = 0; j < 26; j++){
      if(data.at(i).at(j) == -1)data.at(i).at(j) = base.at(j);
    }
  }
  long ans = 0, pl = 0;
  for(int i = 0; i < t.size(); i++){
    if(data.at(pl).at(t.at(i) - 'a') != -1){
      if(data.at(pl).at(t.at(i) -'a') <= pl){
        ans += s.size();
      }
      pl = data.at(pl).at(t.at(i) -'a');
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans + pl << endl;
  return 0;
}

Measured memory_bytes: 24704
N = int(input())
a = list(map(int, input().split()))

count2 = 0
count4 = 0

for ai in a:
    if ai % 4 == 0:
        count4 += 1
    elif ai % 2 == 0:
        count2 += 1

if count4*2 + count2 >= N or (count4*2+1) >= N:
    print("Yes")
else:
    print("No")

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

#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define brep(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define xrep(i,n) for(ll i=1,i##_len=(n);i<=i##_len;i++)
#define Yes(n) cout<<((n)?YES:NO)<<'\n'
#define rYes(n) cout<<((n)?YES:NO)<<'\n';return
#define Sort(v) sort(all(v))
#define rSort(v) sort(all(v)); reverse(all(v))
#define Unique(v) (v).erase(unique(all(v)),(v).end())
#define eb emplace_back

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vint = vector<int>;
using vvll = vector<vll>;
using vstr = vector<string>;

// --- functions which take 1 argument ---
static inline void ignore_ret(int x){x++;}
template<class T> inline int sgn(T x){return (x>0)-(x<0);}
template<class T> inline ll factorial(T n){if(n==0)return 1;ll r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline map<T,T> factorize(T n){map<T,T>r;for(T i=2;i*i<=n;i++){while(n%i==0){r[i]++;n/=i;}}if(n!=1)r[n]=1;return r;}

// --- functions which take 2 arguments ---
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline T nPr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;for(T i=n-k+1;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}

// --- functions which take vector(s) as argument(s) ---
template<class T> inline void print(vector<T>v){cout<<"[ ";for(auto x:v)cout<<x<<' ';cout<<"]\n";}
template<class T> inline T min(vector<T>v){return *min_element(all(v));}
template<class T> inline T max(vector<T>v){return *max_element(all(v));}
template<class T> inline ll sum(vector<T>v){return reduce(all(v),0LL);}
template<class T> inline T gcd(vector<T>v){T r=v[0];for(T i=1;i<v.size();i++)r=gcd(r,v[i]);return r;}
template<class T> inline T lcm(vector<T>v){T r=v[0];for(T i=1;i<v.size();i++)r=lcm(r,v[i]);return r;}
template<class T> inline double abs(vector<T>v){return sqrt(reduce(all(v),0.0,[](int s,int v){return s+=v*v;}));}
template<class T> inline T vector_add(T u,T v){ll s=u.size();if(s>v.size())return {};T r;rep(i,s)r.eb(u[i]+v[i]);return r;}
template<class T> inline T vector_subtract(T u,T v){ll s=u.size();if(s>v.size())return {};T r;rep(i,s)r.eb(u[i]-v[i]);return r;}
template<class T> inline T dot_product(vector<T>u,vector<T>v){if(u.size()<v.size())return 0;T r=0;for(T i=0;i<u.size();i++)r+=u[i]*v[i];return r;}
template<class T> inline T cross_product(T u,T v){T r(3);r[0]=u[1]*v[2]-u[2]*v[1];r[1]=u[2]*v[0]-u[0]*v[2];r[2]=u[0]*v[1]-u[1]*v[0];return r;}

// --- Template ends here ---

void solve(ll K, ll A, ll B) {
  if (A % K == 0 || (A / K != B / K)) cout << "OK" << endl;
  else cout << "NG" << endl;
}

int main() {
  ll K;
  ignore_ret(scanf("%lld",&K));
  ll A;
  ignore_ret(scanf("%lld",&A));
  ll B;
  ignore_ret(scanf("%lld",&B));
  solve(K, A, B);
  return 0;
}


Measured memory_bytes: 3700