akhauriyash/Code-Regression huggingface dataset:
use std::io;


fn main() {
    let n = read_one::<usize>();
    let mut pn = read::<usize>();

    let mut cnt = 0;
    for i in 0..n - 1 {
        if pn[i] == i + 1 {
            cnt += 1;
            let tmp = pn[i + 1];
            pn[i + 1] = pn[i];
            pn[i] = tmp;
        }
    }
    if pn[n - 1] == n { cnt += 1; }
    println!("{}", cnt);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

int main()
{
    //入力を受け取る
    int n, m;
    cin >> n >> m;
    int a[n],b[n];
    vector<pair<int, int> > pairs(n);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
        pairs[i] = make_pair(a[i],b[i]);
    }
    sort(pairs.begin(),pairs.end());
    int k = 0;
    long cost = 0;
    int num = 0;
    while(num != m){
        if(pairs[k].second == 0){
            k++;
        }
        cost = cost + pairs[k].first;
        num++;
        pairs[k].second = pairs[k].second-1;
    }
    cout << cost << endl;

    return 0;
}

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

int main() {
  string sa, sb, sc, tmp;
  char f;
  cin >> sa >> sb >> sc;
  tmp = sa;
  f = sa.at(0);
  int a = 0, b = 0, c = 0, ans = 0;
  while (true) {
    if (f == 'a') {
      if (a == sa.size()) {
        ans = 0;
        break;
      }
      f = sa.at(a); 
      a++;
    } else if (f == 'b') {
      if (b == sb.size()) {
        ans = 1;
        break;
      }
      f = sb.at(b);
      b++;
    } else if (f == 'c') {
      if (c == sc.size()) {
        ans = 2;
        break;
      }
      f = sc.at(c);
      c++;
    }
  }
  switch (ans) {
    case 0:
      cout << 'A' << endl;
      break;
    case 1:
      cout << 'B' << endl;
      break;
    case 2:
      cout << 'C' << endl;
      break;
  }
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    ll ans = 0;
    rep(i, N) {
        ll temp;
        cin >> temp;
        ans += i != temp - 1;
    }
    if(ans == 0 || ans == 2) cout << "YES";
    else cout << "NO";
    cout << endl;
    return 0;
}


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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	
	if((a==b && c!=a && c!=b) || (a==c && b!=a && b!=c) || (b==c && a!=b && a!=c))
		cout<<"Yes"<< endl;
	else
		cout<<"No"<< endl;
	
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int c0,c1,c2,c3;
  c0 = c1 = c2 = c3 = 0;
  for (int i = 0; i < n; i++){
    string s;
    cin >> s;
    if (s == "AC") c0++;
    else if (s == "WA") c1++;
    else if (s == "TLE") c2++;
    else if (s == "RE") c3++;
  }
  cout << "AC x " << c0 << endl;
  cout << "WA x " << c1 << endl;
  cout << "TLE x " << c2 << endl;
  cout << "RE x " << c3 << endl;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main(){
	unsigned int x,i;
	char a[11];
	while (~fscanf(stdin, "%d", &x),x!=0) {
		sprintf(a, "%o", x);
		for (i = 0; i < strlen(a); i++){
			if (*(a + i) >= '4') *(a + i) += 1;
			if (*(a + i) >= '6') *(a + i) += 1;
		}
		fprintf(stdout, "%s\n",a);
	}
	return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



 
int main(void) {
  ll i, j, k;
  
  string s;
  cin >> s; reverse(s.begin(), s.end());
  ll N=s.size();
  s="z"+s;
  
  ll sum[MAX*2];
  
  ll cnt[2222]={};
  cnt[0]=1;
  
  ll A=1;
  for(i=1; i<=N; i++) {
    sum[i]=((s[i]-'0')*A+sum[i-1])%2019;
    A*=10; A%=2019;
    cnt[sum[i]]++;
  }
  
  ll ans=0;
  for(i=0; i<2222; i++) ans+=cnt[i]*(cnt[i]-1)/2;
  pt(ans);
  
  
  
}
 
 


Measured memory_bytes: 5296
#include<cstdio>
#include<cstdlib>

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

using namespace std;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	static int dp[100000];
	rep(i,n-1) scanf("%d",dp+i+1), dp[i+1]+=dp[i];

	int total=0,pos=0;
	rep(i,m){
		int a; scanf("%d",&a);
		total+=abs(dp[pos+a]-dp[pos]);
		total%=100000;
		pos+=a;
	}
	printf("%d\n",total);

	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

n = int(input())
a = LI()

"""
nCr = n!/(r! * (n-r)!)
なのでnは最大値をとりつつrはnの中間の値を撮るのが良さそう．
"""

a.sort()
o = a[-1]
diff = mod
for i in range(n):
    if diff > abs(a[i] - o / 2):
        p = a[i]
        diff = abs(a[i] - o / 2)
print(o,p)



Measured memory_bytes: 22464
#include <cstdio>
#include <utility>
#include <array>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n';)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;if((c=gcu())=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
	_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int main() {
	for (int n, m {}; scan(n); m++) {
		if (m)
			outl();
		array<array<bool, 5>, 7> a {};
		for (int i {}, t = 10000; t > 0; n %= t, t /= 10, i++) {
			int k = n / t;
			a[!(k / 5)][i] = true;
			a[k % 5 + 2][i] = true;
		}
		for (int i: range(7)) {
			if (i == 2)
				outl("=====");
			for (bool j: a[i])
				out(j ? ' ': '*');
			outl();
		}
	}
}


Measured memory_bytes: 2404
n,m = list(map(int,input().split()))
s = []
c = []
for i in range(m):
    ss,cc = list(map(int,input().split()))
    s.append(ss -1 )
    c.append(cc)

ans = [-1] * n
flag = True
for i in range(m):
    if ans[s[i]] == -1 :
        ans[s[i]] = c[i]
    elif ans[s[i]] != c[i]:
        flag = False

if n !=1 and  ans[0] == 0:
    flag = False

if flag :
    ans = [ str(a) if a != -1 else "0" for a in ans ]
    if n != 1 and ans[0] == "0":
        ans[0] = "1"
    print("".join(ans))
else:
    print(-1) 



Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>

using namespace std;

int main()
{
    int A, B;

    scanf("%d%d", &A, &B);
    printf("%d", A * B);

    return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        string s = to_string(i);
        int len=s.length();
        if(len%2==1){
            cnt++;
        }
        s.clear();
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  let lines = content.trim().split('\n');
  let cur = 0;
  while (lines[cur] !== '0') {
    const numStudents = parseInt(lines[cur++], 10);
    const scores = lines[cur++].split(' ').map(n => parseInt(n, 10));
    const sum = scores.reduce((prev, cur) => prev + cur);
    const avg = sum / numStudents;

    const result = Math.sqrt(
      scores.reduce((prev, cur) => prev + Math.pow(cur - avg, 2), 0) / numStudents
    );

    console.log(result);
  }
});



Measured memory_bytes: 16848
H, W = map(int, input().split())
ans = 0
if H == 1 or W == 1:
    ans = 1
    print(ans)
else:
    if H % 2 == 0:
        ans += (H // 2) * W
    else:
        ans += (H // 2) * W + (W // 2 + W % 2)

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

    print(ans // 2)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    vector<int> v;
    for (int i = 0; i < 3; i++) {
        int task;
        cin >> task;
        v.push_back(task);
    }

    sort(v.begin(), v.end());

    int ans = 0;
    for (int i = 1; i < 3; i++) {
        ans += v[i] - v[i  - 1];
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;


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

    temp = a;
    a = b;
    b = temp;

    temp = a;
    a = c;
    c = temp;

    cout << a << " " << b << " " << c;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int n, A[20];

int solve(int i, int m) {
  if(m == 0) return 1;
  if(i >= n || m < 0) return 0;
  return solve(i + 1, m) || solve(i + 1, m - A[i]);
}

int main() {
  int i, q, m;

  scanf("%d", &n);
  for(i = 0;i < n;i++)
    scanf("%d", &A[i]);

  scanf("%d", &q);
  for(i = 0;i < q;i++) {
    scanf("%d", &m);
    if(solve(0, m))
      printf("yes\n");
    else
      printf("no\n");
  }
}



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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using ll = long long;

using namespace std;

void Main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int k;
  REP(i, N) {
    cin >> k;
    k--;
    A[k] = i + 1;
  }
  FORV(a, A) cout << a << " ";
  cout << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 1280
{-# LANGUAGE BangPatterns #-}
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State
import           Data.Array.IArray
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import           Data.Bits
import           Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.Graph
import           Data.Int              (Int64)
import           Data.List
import           Data.Maybe
import           Data.Proxy
import qualified Data.Set              as S
import           Data.STRef
import           Data.Vector.Unboxed   (Vector)
import qualified Data.Vector.Unboxed   as V
import           Numeric

getAsInt :: IO [Int]
getAsInt =  unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getAsIntLine :: Int -> IO [[Int]]
getAsIntLine n = replicateM n getAsInt

getAsIntArray1Dr :: Int -> IO (UArray Int Int)
getAsIntArray1Dr n = U.listArray (1,n) <$> getAsInt

getAsIntVec1Dr :: IO (Vector Int)
getAsIntVec1Dr = V.fromList <$> getAsInt

getAsIntArray1Dc :: Int -> IO (UArray Int Int)
getAsIntArray1Dc n = U.listArray (1,n) . concat <$> getAsIntLine n

getAsIntVec1Dc :: Int -> IO (Vector Int)
getAsIntVec1Dc n = V.fromList . concat <$> getAsIntLine n

-- n: number of lines
-- m: number of values per a line
getAsIntArray2D :: Int -> Int -> IO (UArray (Int,Int) Int)
getAsIntArray2D n m = U.listArray ((1,1),(n,m)) . concat <$> getAsIntLine n

getAsString :: IO [String]
getAsString = map BS.unpack . BS.words <$> BS.getLine

getAsCharArray1DWithLength :: IO (Int, UArray Int Char)
getAsCharArray1DWithLength = BS.getLine >>= \cs ->
  let n = BS.length cs
      ary = (U.listArray (1,n) $ unfoldr BS.uncons cs) :: UArray Int Char
  in return (n, ary)

-- n: number of lines
-- m: number of chars per a line
getAsCharArray2D :: Int -> Int -> IO (UArray (Int,Int) Char)
getAsCharArray2D n m = U.listArray ((1,1),(n,m)) . unfoldr BS.uncons . BS.concat <$> replicateM n BS.getLine

main :: IO ()
main = do
  [x] <- getAsInt
  print $ (x `div` 500) * 1000 + ((x `mod` 500) `div` 5) * 5


Measured memory_bytes: 380
#include<iostream>
#include<algorithm>
using namespace std;
#define max 200000
#define nuon 1000000000
long long cnt=0;
void merge(int a[],int left,int mid,int right)
{
    int L1[max],n1=mid-left;
    int L2[max],n2=right-mid;
    for(int i=0;i<mid-left;i++) L1[i]=a[left+i];
    for(int i=0;i<right-mid;i++) L2[i]=a[mid+i];
    L1[n1]=nuon;
    L2[n2]=nuon;
    int m=0,n=0;
    for(int i=left;i<right;i++)
    if(L1[m]<=L2[n]) {a[i]=L1[m];m++;}
    else
    {
    a[i]=L2[n];n++;
    if(m!=n1) cnt=cnt+n1-m;
    }
}
void mergeSort(int a[],int left,int right)
{
    if(left<right-1)
    {

        int mid=(left+right)/2;

        mergeSort(a,left,mid);

        mergeSort(a,mid,right);

        merge(a,left,mid,right);
    }
}
int main()
{
    int n;
    int a[max];
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    mergeSort(a,0,n);

    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 4672
#!/usr/bin/env python3

import numpy as np


# def input():
#     return sys.stdin.readline().rstrip()


def main():
    n, k = map(int, input().split())

    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    order_num = np.zeros(len(warps) + 1, dtype=int)
    path_history = []

    node = 1
    while order_num[node] == 0:
        path_history.append(node)
        order_num[node] = len(path_history)
        node = warps[node]

    # print(order_num)
    # print(path_history)
    begin = order_num[node]
    # print(tail)

    if k <= begin:
        print(path_history[k])
    else:
        # path_history = path_history[tail:]
        # print(path_history)
        leng = len(path_history) - order_num[node] + 1
        # print(leng)
        index = (k - (begin - 1)) % leng
        # print(index)
        print(path_history[begin - 1 + index])


main()


Measured memory_bytes: 51012
int h, w, i, j, k;
char C[6]="snuke";
char c[6];
char f;
int main(){
  scanf("%d%d", &h, &w);
  for(i=1; i<=h; i++){
    for(j=0; j<w; j++){
      scanf("%s", c);
      f=1;
      for(k=0; k<5; k++){
        if(c[k]!=C[k]) f=0;
      }
      if(f) printf("%c%d", j+'A', i);
    }
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

constexpr int MOD = /** 1000000007; //*/ 998244353;
/////////////////

void solve(){
  ini(H,W,A,B);
  rep(i,H){
    rep(j,W){
      cout << ((i<B)^(j<A) ? 1 : 0);
    }
    out();
  }
}


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

int main() {
  ll A, B, V, W, T;
  cin >> A >> V >> B >> W >> T;

  if (A > B) { // 鬼のほうが正
    if (V > W && T * (V - W) >= A - B) { // 鬼のほうが速い
      cout << "YES";
    } else {
      cout << "NO";
    }
  } else {
    if (V > W && T * (V - W) >= B - A) {
      cout << "YES";
    } else {
      cout << "NO";
    }
  }
}

Measured memory_bytes: 3636
N=int(input())
a=[]
for i in range(N):
    a.append(int(input()))
ans=0
for i in range(N):
    ans+=a[i]//2
    if(i>0 and a[i-1]%2==1 and a[i]%2==1):
        ans+=1
        a[i]=0
    elif(i<N-1 and a[i+1]>0 and a[i]%2==1):
        ans+=1
        a[i]=0
        a[i+1]-=1
print(ans)


Measured memory_bytes: 7192
#!/usr/bin/env python3
import fractions

n = int(input().split()[0])
n = int(n)

hp_list = list(map(int, input().split()))
hp_list = [int(hp) for hp in hp_list]

hp = hp_list[0]

for h in hp_list[1:]:
    hp = fractions.gcd(hp, h)

print(hp)


Measured memory_bytes: 16280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
int n,k,q,a[2005],c[2005],bit[2005],ans=1e9;
set<int>s;
void upd(int x){for(;x<=n;x+=x&-x)bit[x]++;}
int qry(int x){int r=0;for(;x;x-=x&-x)r+=bit[x];return r;}
bool cmp(int x,int y){return a[x]<a[y];}
int main()
{
	scanf("%d%d%d",&n,&k,&q);
	for(int i=0;i<n;i++)scanf("%d",&a[i]),c[i]=i;
	sort(c,c+n,cmp);
	for(int i=0;i+q<=n;i++)
	{
		int cnt=0;memset(bit,0,sizeof(bit));
		for(int j=i;j<n;j++)
		{
			int x=c[j],lp,rp;
			set<int>::iterator l=s.lower_bound(x),r=l;
			lp=(l!=s.begin()?(*--l):-1);rp=(r!=s.end()?(*r):n);
			if(rp-lp-1-(qry(rp)-qry(lp+1))>=k)upd(x+1),cnt++;
			if(cnt>=q){ans=min(ans,a[c[j]]-a[c[i]]);break;}
		}
		s.insert(c[i]);
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 384
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main {
	public static void main(String[] args){
		int i, q, order, x;
		Set<Integer> set = new HashSet<Integer>();
		try (Scanner sc = new Scanner(System.in)) {
			q = sc.nextInt();
			for(i = 0; i < q; i++) {
				order = sc.nextInt();
				x = sc.nextInt();
				if(order == 0) {
					set.add(x);
					System.out.println(set.size());
				}else {
					if(set.contains(x)) {
						System.out.println(1);
					}else {
						System.out.println(0);
					}
				}
			}
		}
	}
}


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

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


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(3*n);
    for(int i = 0; i < 3*n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    for(int i = 0; i < n; i++) ans += a[3*n-2 - i*2];
    cout << ans << endl;
}


Measured memory_bytes: 5564
fun calc143B(ds: List<Int>): Int {
    var ans = 0
    val indexed = ds.mapIndexed { i, j -> i to j }
    for ((i, d1) in indexed) {
        for ((j, d2) in indexed) {
            if (i == j) continue
            ans += d1 * d2
        }
    }
    return ans / 2
}

fun main(args: Array<String>) {
    val N = readLine()!!
    val ds = readLine()!!.split(" ").map { it.toInt() }
    println(calc143B(ds))
}


Measured memory_bytes: 37744
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 
 
void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
 
double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}
 
ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}
 
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
vec modncrlistp,modncrlistm;
 
ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}
 
ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
 
ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}
 
ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  startupcpp();
  ll i=1,N;
  cin>>N;
  while(N>0){
    N-=i;
    i++;
  }
  cout<<i-1<<endl;
  return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }
template<class T>
inline T upper(T a, T b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	double con = 0.0;
	int water = 0, sugar = 0;

	for (int w = 0; w <= 30; w++) {
		for (int x = 0; x <= 30; x++) {
			for (int y = 0; y <= ceil((double)f / c); y++) {
				for (int z = 0; z <= ceil((double)f / d); z++) {
					int water_weight = a * w + b * x, sugar_weight = c * y + d * z;
					int total = 100 * water_weight + sugar_weight;

					if (total <= f && sugar_weight <= water_weight * e) {
						if (con < (double)sugar_weight / total) {
							con = (double)sugar_weight / total;
							water = 100 * water_weight;
							sugar = sugar_weight;
						}

					}
				}
			}
		}
	}
	if (con == 0) water = 100 * a;

	cout << water + sugar << " " << sugar << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int)n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}
 
int main(){
	//in_o();
	string s;
	cin>>s;
	MPII hsh;
	int n=s.length();
	FOR(i,0,s.length()){
		hsh[s[i]-'a']++;
	}
	FOR(i,0,26){
		if(hsh[i]==0)
			return cout<<(char)(i+'a')<<endl,0;
	}
	cout<<"None"<<endl;
	return 0;
}


Measured memory_bytes: 512
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {


	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		String s1 = sc.next();
		String s2 = sc.next();

		int loopCount = Math.min(s1.length(), s2.length());

		String[] os1 = stringSort(s1);
		String[] os2 = stringRevSort(s2);
		String res = "No";

		if (String.join("", os1).compareTo(String.join("", os2)) < 0) {
			res = "Yes";
		} else {
			res = "No";
		}

		System.out.println(res);
		sc.close();
	}

	public static String[] stringSort(String inString) {

		String[] inStrings = inString.split("");
		String[] outStrings;

		Arrays.sort(inStrings, new Comparator<String>() {

			public int compare(String obj1, String obj2) {
				return obj1.compareTo(obj2);
			}
		});
		outStrings = inStrings;

		return outStrings;
	}

	public static String[] stringRevSort(String inString) {

		String[] inStrings = inString.split("");
		String[] outStrings;

		Arrays.sort(inStrings, new Comparator<String>() {

			public int compare(String obj1, String obj2) {
				return obj2.compareTo(obj1);
			}
		});
		outStrings = inStrings;

		return outStrings;
	}
}


Measured memory_bytes: 23636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int n, x;
		while(true) {
			n = scan.nextInt();
			x = scan.nextInt();
			if (n == 0 && x == 0){break;}
			int i, j, k;
			int count = 0;
			for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			}
			sb.append(count + "\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 27272
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    int n;
    cin >> n;
    int Max = 0;
    vector<ll> a(n);

    REP(i,n) cin >>  a[i];
    Max = *max_element(ALL(a));
    int m = 0,ans = 0;
    for(int i = 0; i < n;i++){
        int tmp = min(a[i],Max-a[i]);
        if(m < tmp){
            m = tmp;
            ans = a[i];
        }
    }

    cout << Max << " " << ans << endl;

    

    return 0;
}

Measured memory_bytes: 1024
//16D8103012G 三品海渡
#include<iostream>
#include<vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> ln(n, vector<int>(n+1, 0));
  vector<vector<int>> m(n,vector<int>(n,0));
  vector<int> rem(n, 0);
  for (int i = 0; i < n; i++)
    {
      cin >> ln[i][0];
      cin >> ln[i][1];
      for (int j = 2; j < ln[i][1]+2; j++)
	{
	  cin >> ln[i][j];
	}
    }
  for (int i = 0; i < n; i++)
    {
      for (int j = 2; j < n+1; j++)
	{
	  if (ln[i][j] != 0 )
	    {
	      m[i][ln[i][j]-1] = 1;
	    }
	}
    }
  for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < n; j++)
	{
	  cout << m[i][j];
	  if(j!=n-1)
	    {
	      cout << " ";
	    }
	}
      cout << endl;
    }
  return 0;
}




Measured memory_bytes: 3224
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
struct Edge {
	int from, to, cost;

	bool operator<(Edge e) {
		return cost < e.cost;
	}
};

int N, M;
vector<Edge> edges;
vi used;

class UnionFind {
public:
	vector<int> par, rank, _size;
	int num;

	UnionFind(int n) {
		par = vector<int>(n);
		rank = vector<int>(n);
		_size = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
			_size[i] = 1;
		}
		num = n;
	}

	// ??¨??????????±???????
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	// x??¨y????±??????????????????????
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;

		if (rank[x] < rank[y]) {
			par[x] = y;
			_size[y] += _size[x];
		}
		else {
			par[y] = x;
			_size[x] += _size[y];
			if (rank[x] == rank[y])rank[x]++;
		}
		num--;
	}

	// x??¨y???????????????????±????????????????
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	int size(int x) {
		return _size[find(x)];
	}
};

int Kruskal(int del) {
	UnionFind uf(N);
	int num = 0;
	int ans = 0;
	bool flag = false;
	rep(i, M) {
		if (i == del)continue;
		int from = edges[i].from;
		int to = edges[i].to;
		int cost = edges[i].cost;
		if (uf.same(from, to))continue;
		if (del == -1) {
			used.push_back(i);
		}
		uf.unite(from, to);
		ans += cost;
		if (uf.num == 1) {
			flag = true;
			break;
		}
	}
	if (!flag) {
		return INF;
	}
	else {
		return ans;
	}
}

int main() {
	cin >> N >> M;
	edges = vector<Edge>(M);
	used = vi();
	rep(i, M) {
		int s, d, c;
		cin >> s >> d >> c;
		s--, d--;
		edges[i] = Edge{ s,d,c };
	}
	sort(all(edges));
	int opt = Kruskal(-1);
	int num = 0;
	int cost = 0;
	rep(i, used.size()) {
		if (Kruskal(used[i]) != opt) {
			num++;
			cost += edges[used[i]].cost;
		}
	}

	cout << num << " " << cost << endl;

	return 0;
}

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

int main(){
    int n;

    cin >> n;

    int a[n];

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

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

    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include  <cassert>
#include <fstream>
#include <codecvt>

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


static const int N = 100;
int G[N][N],d[N],f[N], tt;

#define WHITE 0
#define GRAY 1
#define BLACK 2

int color[N];

void  dfs(int u) {
	color[u] = GRAY;
	d[u] = ++tt;
	rep(v, N) {
		if (G[u][v] and color[v] == WHITE) {
			dfs(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

signed main() {
	ios::sync_with_stdio(true);

	rep(i, N) {
		color[i] = WHITE;
		rep(j, N)
			G[i][j] = 0;
	}

	int n;
	cin >> n;
	rep(i, n) {
		int u, k;
		cin >> u >> k;
		u--;
		rep(j, k) {
			int v;
			cin >> v;
			G[u][--v] = 1;
		}
	}

	tt = 0;
	rep(u, n) {
		if (color[u] == WHITE)
			dfs(u);
	}
	rep(u, n) {
		cout << u + 1 << ' ' << d[u] << ' ' << f[u] << endl;
	}
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int i = N;
  
  string answer = "";
  
  if (N == 0) cout << 0 << endl;
  
  while (N != 0){
    if (N % 2 != 0) {
      answer = answer + '1';
      N = N - 1;
    }else{
      answer = answer + '0';
    }
    N = -(N)/2;
  }
  reverse(answer.begin(), answer.end());
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef vector<char> vc;
typedef vector<vc> vvc;

char grid[10][10];
int h,w;

void fill(char from,char to,int i,int j)
{
	grid[i][j]=to;
	rep(k,4){
		int ni=i+"\xff\x1\0\0"[k],nj=j+"\0\0\xff\x1"[k];
		if(0<=ni && ni<h && 0<=nj && nj<w && grid[ni][nj]==from)
			fill(from,to,ni,nj);
	}
}

bool ok()
{
	rep(i,h) rep(j,w)
		if(grid[i][j]!=grid[0][0])
			return false;
	return true;
}

bool iddfs(int d,int dmax)
{
	if(d>dmax) return false;
	if(ok()) return true;
	
	char g[10][10];
	rep(i,h) rep(j,w)
		g[i][j]=grid[i][j];
	
	rep(k,3){
		char to="RGB"[k];
		if(to==grid[0][0])
			continue;
		fill(g[0][0],to,0,0);
		if(iddfs(d+1,dmax))
			return true;
		
		rep(i,h) rep(j,w)
			grid[i][j]=g[i][j];
	}
	return false;
}

int solve()
{
	for(int i=0;;i++)
		if(iddfs(0,i))
			return i;
}

int main()
{
	while(cin>>w>>h,w|h){
		rep(i,h) rep(j,w)
			cin>>grid[i][j];
		cout<<solve()<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 872
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
string s[10001];
int main(){
	int ans=0;
	cin>>N;
	REP(i,N){
		cin>>s[i];
	}
	REP(i,N){
		REP(j,s[i].size()-1){
			if(s[i][j+1]=='B'&&s[i][j]=='A'){
				ans++;
			}
		}
	}
	int a=0;
	int b=0;
	int c=0;
	REP(i,N){
		if(s[i][0]=='B')b++;
		if(s[i][s[i].size()-1]=='A')a++;
		if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')c++;
	}
	if(a==c&&b==c)b=max(b-1,0);
	cout<<ans+min(N-1,min(a,b))<<endl;
}

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

int main(){
	int a,b;
	cin>>a>>b;
	cout<<(a+b)%24<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  ll x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  priority_queue<ll> p, q, r, px, qy;
  rep(i,a){
    ll t;
    cin >> t;
    p.push(t);
  }
  rep(i,b){
    ll t;
    cin >> t;
    q.push(t);
  }
  rep(i,c){
    ll t;
    cin >> t;
    r.push(t);
  }
  rep(i,x){
    px.push(p.top());
    p.pop();
  }
  rep(i,y){
    qy.push(q.top());
    q.pop();
  }
  px.push(-1), qy.push(-1), r.push(-1);
  ll ans=0, er=0, eg=0;
  rep(i,x+y){
    ll mar=px.top(), mag=qy.top(), manc=r.top();
    ll ma=max(mar, max(mag,manc));
    if(ma==mar){
      ans+=mar;
      px.pop();
    }
    else if(ma==mag){
      ans+=mag;
      qy.pop();
    }
    else{
      ans+=manc;
      r.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4852
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    IOS;
    int n,k;
    fi>>n>>k;
    static int s[1 << 20];
    k /= 2;
    for (int i = 1;i <= n;++i)
        fi>>s[i];
    static int a[1 << 20];
    for (int i = n;i;--i)
        a[i] = max(a[i + 1],s[i]);
    ll mx = 0;
    int cnt = 0;
    for (int i = 1;i < n;++i)
        {
            const ll now = 1ll * k * (s[i] - a[i + 1]);
            if (now < mx)
                mx = now,cnt = 0;
            cnt += mx == now;
        }
    fo << cnt << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-07-26 12:46:01 +0900
# LastModified: 2020-07-26 13:19:34 +0900
#


import os
import sys


def main():
    n, m, k = map(int, input().split())
    for s in range(m+1):
        for t in range(n+1):
            if k == n*s+m*t-2*s*t:
                print("Yes")
                return
    print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9148
import collections
def main(N,S):
    counterS = collections.Counter(S)
    maxcount = max(counterS.values())
    keys = [k for k, v in counterS.items() if v == maxcount]
    keys.sort()
    for j in keys:
        print(j)

N = int(input())
S = [input() for _ in range(N)]
main(N,S)

Measured memory_bytes: 35560
#include <stdio.h>

int main() {
	int i, r, d, x2000, kotae;

	scanf("%d %d %d", &r, &d, &x2000);

	for (i = 0; i < 10; i++) {
		x2000 = r * x2000 - d;
		printf("%d\n", x2000);
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
	int n,x;
	scanf("%d %d",&n,&x);
	int m;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&m);
		a[i]=fabs(m-x);
	}
	sort(a,a+n);
	int cnt=0;
	for(int i=0;i<n;i++)
		if(a[i]%a[0]!=0)
		{
			cnt=1;
			break;
		}	
	if(cnt)
	for(int i=a[0]/2;i>0;i--)
		{
			int j;
			for( j=0;j<n;j++)
				if(a[j]%i!=0)
				{
					break;
				}
			if(j==n)
			{
				cout<<i<<endl;
				return 0;
			}
		}
	cout<<a[0]<<endl; 
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}

int dp[401][401],a[401],cum[401];
void solve()
{
  int n;
  cin >> n;

  forf(i,0,401) forf(j,0,401) dp[i][j] = big;
  forf(i,1,n+1) cin >> a[i],dp[i][i]= 0 ;
  
  
  forf(i,1,n+1)
  {
    cum[i]  = cum[i-1] + a[i];
  }

  
  for(int l=2;l<=n;l++)
  {
    for(int i=1;i<=n-l+1;i++)
    {//i - > i+l-1
      for(int k = i; k<i+l-1 ; k++)
      {

        dp[i][i+l-1] = min(dp[i][i+l-1] , dp[i][k] + dp[k+1][i+l-1] + cum[k] - cum[i-1] + cum[i+l-1] - cum[k]);
      }
    }
  }

  // for(int i=1;i<=n;i++)
  // {
  //   for(int j=1;j<=n;j++) cout<<dp[i][j]<<" ";
  //     cout<<"\n";
  // }

  cout<<dp[1][n];
  
}


int32_t main()
{
  pr_init();
  //fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 4888