akhauriyash/Code-Regression huggingface dataset:
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x: x, y = x.left if key < x.key else x.right, x
    if y is None: root = Node(key)
    elif key < y.key: y.left = Node(key)
    else: y.right = Node(key)

def find(target):
    result = root
    while result and target != result.key:
        result = result.left if target < result.key else result.right
    return result is None

def delete(target):
    def remove_node(p, c, a):
        if p.left == c: p.left = a
        else: p.right = a
    p, c = None, root
    while c.key != target: p, c = c, c.left if target < c.key else c.right
    if c.left is None:
        remove_node(p, c, c.right)
    elif c.right is None:
        remove_node(p, c, c.left)
    elif c.right.left is None:
        c.right.left = c.left
        remove_node(p, c, c.right)
    else:
        g = c.right
        while g.left.left: g = g.left
        c.key = g.left.key
        g.left = g.left.right

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

input()
for e in sys.stdin:
    if e[0] == 'i': insert(int(e[7:]))
    elif e[0] == 'd': delete(int(e[7:]))
    elif e[0] == 'f': print(['yes','no'][find(int(e[5:]))])
    else: print(inorder(root)); print(preorder(root))


Measured memory_bytes: 56372
import heapq

N, M = list(map(int, input().split()))
A = list(map(lambda x: -int(x), input().split()))

heapq.heapify(A)

for i in range(M):
    _ = -heapq.heappop(A)
    _ = int(_ / 2)
    heapq.heappush(A, -_)

print(-sum(A))


Measured memory_bytes: 14180
import numpy as np

N, M=map(int, input().split())
matrix=np.zeros((M, N))

for i in range(M):
  temp=np.array(list(map(int, input().split())))
  temp-=1
  matrix[i, temp[1:]]=1
  
p=np.array(list(map(int, input().split())))

counter=0
for i in range(pow(2, N)):
  s=np.array(list(map(int, list(format(i, '0'+str(N)+'b')))))
  if all(np.dot(matrix, s)%2==p)==True:
    counter+=1
    
print(counter)

Measured memory_bytes: 15796
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a, n) priority_queue<int>a(n)
#define PQmin(a, n) priority_queue< int, std::vector<int>, std::greater<int> >a(n)

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n,m;
    cin>>n>>m;
    priority_queue< int, std::vector<int>, std::greater<int> >a;
    vector<pair<int, int> > pairs(m);
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        a.push(x);
    }
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        pairs[i] = make_pair(b, a);
    }
    sort(pairs.rbegin(), pairs.rend());
    ll ans=0;
    bool flag = true;
    for(int i=0;i<m;i++){
        for(int j=0;j<pairs.at(i).second;j++){
            if(a.top()<pairs.at(i).first){
                a.pop();
                ans+=pairs.at(i).first;
            }
            else{
                break;
            }
            if (a.size()==0){
                flag=false;
                break;
            }
        }
        if (flag==false){
            break;
        }

    }
    while(a.size()>0){
        ans+=a.top();
        a.pop();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
 
using namespace std;
int main() {
  string S;
  cin>>S;
  
  if(S=="AAA" ||S=="BBB"){
    cout<<"No";
  }
  else{
    cout<<"Yes";
  }
}
  

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  map<int, int> cnt;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
  }
  if (cnt.size() == 1) {
    puts(cnt.begin()->first == 0 ? "Yes" : "No");
    return 0;
  }
  if (n % 3) {
    puts("No");
  } else {
    if (cnt.size() == 2) {
      vector<int> a;
      bool found = false;
      for (auto& it : cnt) {
        if (!((it.second == n / 3 && it.first == 0) ||
              (it.second == n / 3 * 2 && it.first != 0))) found = true;
      }
      puts(found ? "No" : "Yes");
    } else if (cnt.size() == 3) {
      bool found = false;
      vector<int> a;
      for (auto& it : cnt) {
        if (!(it.first && it.second == n / 3)) found = true;
        a.push_back(it.first);
      }
      if ((a[0] ^ a[1]) != a[2]) found = true;
      puts(found ? "No" : "Yes");
    } else {
      puts("No");
    }
  }
  return 0;
}


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

int main() {
	int M, D;
	cin >> M >> D;
	int cnt = 0;

	for (int i = 4; i <= M; i++) {
		for (int j = 22; j <= D; j++) {
			if (i == (j % 10)*(int)(j / 10) && (j % 10) >= 2) cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
n,m,k=map(int,input().split())
cnt=0
flag =0
for i in range(n+1):
    for j in range(m+1):
        cnt = (m*i) - (i*j) + (j*(n-i))
        if cnt == k:
            flag=1
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 40684
unittest
{
	assert( [ "4 4", "1 1", "4 4", "..#.", "..#.", ".#..", ".#.." ].solve == 1 );
	assert( [ "4 4", "1 4", "4 1", ".##.", "####", "####", ".##." ].solve == -1 );
	assert( [ "4 4", "2 2", "3 3", "....", "....", "....", "...." ].solve == 0 );
	assert( [ "4 5", "1 2", "2 5", "#.###", "####.", "#..##", "#..##" ].solve == 2 );
}



import std.container;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto h = 0L;
	auto w = 0L;
	input.front.formattedRead!"%s %s"( h, w );
	auto cy = 0L;
	auto cx = 0L;
	input.popFront;
	input.front.formattedRead!"%s %s"( cy, cx );
	cy--;
	cx--;
	auto dy = 0L;
	auto dx = 0L;
	input.popFront;
	input.front.formattedRead!"%s %s"( dy, dx );
	dy--;
	dx--;
	auto sss = new dchar[][]( h, w );
	foreach( ref ss; sss )
	{
		input.popFront;
		ss = input.front.to!( dchar[] );
	}
	
	auto dss = bfsGrid01Ex( sss, cy, cx );
	return ( dss[ dy ][ dx ] == long.max ) ? -1 : dss[ dy ][ dx ];
}

// グリッドマップの始点指定最短経路探索（0-1幅優先探索）
auto bfsGrid01Ex( T, T W = '#' )( T[][] css, long sy, long sx )
{
	auto dss = new long[][]( css.length, css[ 0 ].length );
	foreach( ref ds; dss ) ds[] = long.max;
	dss[ sy ][ sx ] = 0;
	
	auto queue = make!DList( tuple( sy, sx ) );
	while( !queue.empty )
	{
		auto fy = queue.front[ 0 ];
		auto fx = queue.front[ 1 ];
		queue.removeFront();
		
		// 徒歩
		foreach( d; [ [ -1, 0 ], [ 1, 0 ], [ 0, -1 ], [ 0, 1 ] ] )
		{
			auto ty = fy + d[ 0 ];
			auto tx = fx + d[ 1 ];
			
			if( ty < 0 || css.length <= ty || tx < 0 || css[ ty ].length <= tx ) continue;		// マップ外
			if( css[ ty ][ tx ] == W ) continue;												// 壁
			if( dss[ ty ][ tx ] <= dss[ fy ][ fx ] ) continue;									// 探索済
			
			dss[ ty ][ tx ] = dss[ fy ][ fx ];
			queue.insertFront( tuple( ty, tx ) );		// 優先的に処理するため前からキューに入れる
		}
		
		// ワープ
		foreach( dy; -2 .. 3 )
		{
			foreach( dx; -2 .. 3 )
			{
				auto ty = fy + dy;
				auto tx = fx + dx;
				
				if( ty < 0 || css.length <= ty || tx < 0 || css[ ty ].length <= tx ) continue;		// マップ外
				if( css[ ty ][ tx ] == W ) continue;												// 壁
				if( dss[ ty ][ tx ] <= dss[ fy ][ fx ] + 1 ) continue;								// 探索済
				
				dss[ ty ][ tx ] = dss[ fy ][ fx ] + 1;
				queue.insertBack( tuple( ty, tx ) );
			}
		}
	}
	return dss;
}


Measured memory_bytes: 29772
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <math.h>
#include <complex>
using namespace std;

int main() {
    int n, r;
    scanf("%d%d", &n, &r);
    if (n >= 10) {
        printf("%d\n", r);
    } else {
        printf("%d\n", r + (10-n) * 100);
    }
}


Measured memory_bytes: 888
H,W = map(int, input().split())
input()
A = list(map(int, input().split()))
s = [[0] * W for _ in range(H)]
index = 0
for i in range(H):
    r = range(W)
    if i % 2 == 1: r = reversed(r)
    for j in r:
        if A[index] == 0:
            index += 1
        s[i][j] = index + 1
        A[index] -= 1

for i in range(H):
    print(' '.join(map(str, s[i])))


Measured memory_bytes: 3572
#include <stdio.h>

void insertSort(int *arr, int n) {
    for(int i=1; i<n; i++) {
        int tmp = arr[i];
        int j = i-1;
        while(j>=0 && arr[j]>tmp) {
            arr[j+1] = arr[j];
            j--;
        }
        arr[j+1] = tmp;
        for(int k=0; k<n; k++) {
            if(k == n-1) {
                printf("%d\n", arr[k]);
            } else {
                printf("%d ", arr[k]);
            }
        }
    }
}
int main() {
    int n, arr[100];
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        scanf("%d", &arr[i]);
    }
    for(int k=0; k<n; k++) {
        if(k == n-1) {
            printf("%d\n", arr[k]);
        } else {
            printf("%d ", arr[k]);
        }
    }
    insertSort(arr, n);
    return 0;
}


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

#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

signed main(){
    int n,m; cin >> n>>m;
    vector<int> s(m);
    vector<char>c(m);
    rep(i,m) {cin >> s[i]>>c[i]; s[i]--;}
    
    for(int i=0; i<pow(10,n); i++){
    //for(int i=pow(10,n-1)-1; i<pow(10,n); i++){
        bool can=true;
        string str=to_string(i);
        if(str.size()<n) continue;
        rep(j,m){
            if(str[s[j]]!=c[j]){
                can=false;
                break;
            }
        }
        if(can){
            cout<<str<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    
}

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

namespace competitive_programming
{
    class Program
    {
        static void Main(string[] args)
        {
            var main = new Program();
            main.solve();
        }

        void solve()
        {
            long[] ny = Console.ReadLine().Split(' ').Select(val => long.Parse(val)).ToArray();
            var n = ny[0];
            var y = ny[1];

            for(long i = 0;i <= y/10000 && i <= n; i++)
            {
                for(long j = 0;j + i <= n; j++)
                {
                    long k = n - j - i;
                    //Console.WriteLine(i + " " + j + " " + k + " " + (10000 * i + 5000 * j + 1000 * k));
                    if (10000 * i + 5000 * j + 1000 * k == y)
                        {
                            Console.WriteLine(i + " " + j + " " + k /*+ " " + (10000 * i + 5000 * j + 1000 * k)*/);
                            return;
                        }
                }
            }
            Console.WriteLine(-1 + " " + -1 + " " + -1);
        }
    }
    struct Vector2
    {
        public Vector2(long x, long y)
        {
            this.x = x;
            this.y = y;
        }
        public long x;
        public long y;
    }

    struct Vector3
    {
        public int x;
        public int y;
        public int z;
    }
}


Measured memory_bytes: 13396
#include<cstdio>
#include<algorithm>
#define MAXN 100006
using namespace std;
int n,m,u,v,du[MAXN];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		du[u]++;
		du[v]++;
	}
	for(int i=1;i<=n;i++)
		if(du[i]%2==1)
		{
			printf("NO");
			return 0;
		}
	printf("YES");
}

Measured memory_bytes: 512
n = int(input())
s = [list(map(int,input().split())) for i in range(n-1)]

def kaisuu(s,i):
    t = s[i][0] + s[i][1]
    if i != n-1:
        for j in range(i+1,n-1):
            if  t <= s[j][1]:
                t = s[j][0] + s[j][1]
            elif t % s[j][2] == 0:
                t = t + s[j][0]
            else:
                t = t + s[j][0] + (s[j][2] - t % s[j][2])
    return t

for i in range(0,n-1):
    print(kaisuu(s,i))

print(0)

Measured memory_bytes: 3188
class Integer
  def divisor_list
    require 'prime'

    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..k).map { |n| base ** n }
    }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort
  end
end

N = gets.to_i

ans = Float::INFINITY

N.divisor_list.each do |n|
  m = N / n
  s = (m + n) - 2

  ans = s if s < ans
end

puts ans


Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
int main()
{
    int N, M,a,b;
    cin >> N >> M;
 //   vint a(N), b(N);
    priority_queue<int> que;
    vvint tmp(1e5 + 1);
    rep(i, N)
    {
        cin >> a >> b;
        tmp[a].push_back(b);
    }
    ll ans = 0;
    for (int i = 1; i <= M; i++)
    {
        for (auto j : tmp[i])
            que.push(j);

        if (!que.empty())
        {
            ans += que.top();
            que.pop();
        }
    }
    cout << ans;
    return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll a, b;
  cin >> a >> b;

  cout << (a > 2 * b ? a - 2 * b : 0) << "\n";
}

Measured memory_bytes: 256
def sumdigits(n):
    result=0
    while n!=0:
        result+=n%10
        n=int(n/10)
    return result

N=int(input())

result=10**10
for i in range(1,int(N/2)+1):
    result=min(sumdigits(i)+sumdigits(N-i),result)


print(result)


Measured memory_bytes: 3060
<?php
fscanf(STDIN,"%d %d",$N,$X);
$input=explode(' ',trim(fgets(STDIN))); //inputの数は$N
 
$count = 0;
$out = 0;
for ($i = 0; $i < $N; $i++) {
  $out = $out + intval($input[$i]);
  if($out <= $X) {
    $count ++;
  }
}
echo $count+1;

Measured memory_bytes: 4604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T & a, const T & b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	int ans = 1e9;
	int dis = 0;
	REP(i, SZ(S)) {
		if (S[i] != '0' + (i % 2))dis++;
	}
	chmin(ans, dis);
	dis = 0;
	REP(i, SZ(S)) {
		if (S[i] != '0' + ((i + 1) % 2))dis++;
	}
	chmin(ans, dis);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
import java.math.*;
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] np = scanner.nextLine().split(" ", 2);
        long n = Long.parseLong(np[0]);
        long p = Long.parseLong(np[1]);
        long remP = p;
        long limit = (long)Math.sqrt(p) + 1;

        if (n == 1) {
            System.out.println(p);
            return;
        }

        long answer = 1;

        for (long i = 2; i <= limit; i++) { // prime
            long cnt = 0;
            while (remP % i == 0) {
                remP /= i;
                cnt++;
            }
            for (long j = 0; j < cnt / n; j++) {
                answer *= i;
            }
            if (remP == 1) {
                break;
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23252
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Main {

    public static void swap(int x, int y) {
        int tmp = x;
        x = y;
        y = tmp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n;
        n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        boolean flg = true;
        int cnt = 0;

        while (flg) {
            flg = false;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    int tmp = a[i];
                    a[i] = a[i-1];
                    a[i-1] = tmp;
                    flg = true;
                    cnt++;
                }
            }
        }

        for (int i = 0; i < n - 1; i++) {
            System.out.printf("%d ", a[i]);
        }
        System.out.println(a[n - 1]);
        System.out.println(cnt);

        sc.close();
    }
}


Measured memory_bytes: 26600
evens :: [a] -> [a]
evens (x:xs) = x:odds xs
evens _ = []

odds :: [a] -> [a]
odds (_:xs) = evens xs
odds _ = []

easyToTap :: String -> Bool
easyToTap s = isOddsEasy s && isEvensEasy s
    where
        isOddsEasy  s = and . map (\c -> c == 'L' || c == 'U' || c == 'D') $ odds s
        isEvensEasy s = and . map (\c -> c == 'R' || c == 'U' || c == 'D') $ evens s

main = do
    easy <- easyToTap <$> getLine
    putStrLn $ if easy then "Yes" else "No"

Measured memory_bytes: 508
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>
#include <cassert>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e) != (s).end())
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i,0,n)

const int MAX = (int)ceil(sqrt(20000));

int main()
{
	int N;
	cin >> N;
	REP(i, N) {
		ll p, q;
		cin >> p >> q;

		bool prime = true;
		for(ll m = -MAX; m <= MAX; m++) {
			for(ll n = -MAX; n <= MAX+1; n++) {
				ll bunbo = m*m + n*n;
				if(bunbo <= 1 || 20000 <= bunbo) {
					continue;
				}
				
				ll bunshi1 = m*p+n*q;
				ll bunshi2 = m*q-n*p;

				if(bunshi1%bunbo == 0 && bunshi2%bunbo == 0) {
					if(m == p && n == q) {
						continue;
					}
					if(-n == p && m == q) {
						continue;
					}
					if(-m == p && -n == q) {
						continue;
					}
					if(n == p && -m == q) {
						continue;
					}
					prime = false;
					goto show;
				}
			}
		}
		show:
		cout << (prime ? 'P' : 'C') << endl;
	}
}

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

using namespace std;

int main(){
    vector<vector<int>>vec;
    int n;
    cin>>n;
    vector<int>q;
    for(int i = 1; i<=n; ++i)q.push_back(i);
    vector<int>vec1;
    do {
        vec1.clear();
        for(int i = 0; i<n; ++i)vec1.push_back(q[i]);
        vec.push_back(vec1);
    }while(next_permutation(q.begin(), q.end()));
    vector<int>a,b;
    for(int i = 0; i<n; ++i){
        int x;
        cin>>x;
        a.push_back(x);
    }
    for(int i = 0; i<n; ++i){
        int x;
        cin>>x;
        b.push_back(x);
    }
    auto it = lower_bound(vec.begin(), vec.end(), a);
    auto it1 = lower_bound(vec.begin(), vec.end(), b);
    cout<<abs(distance(it,it1));
    return 0;
}


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

char str[100005];

int main()
{
	int a1, a2;
	int len;
	a1 = a2 = 0;

	scanf("%s", str);

	len = strlen(str);

	for (int i = 0; i < len; i++) {
		if (i & 1) {
			if (str[i] == '1') {
				a1++;
			}
			else {
				a2++;
			}
		}
		else {
			if (str[i] == '0') {
				a1++;
			}
			else {
				a2++;
			}
		}
	}

	if (a1 < a2) {
		printf("%d\n", a1);
	} 
	else {
		printf("%d\n", a2);
	}
}



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

int N;
int s[100];

int main() {
    cin >> N;
    rep(i, N) cin >> s[i];

    int sum = accumulate(s, s + N, 0);
    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }
    sort(s, s + N);
    int target = 0;
    rep(i, N) {
        int one = s[i] % 10;
        if (one != 0) {
            target = s[i];
            break;
        }
    }

    cout << (target == 0 ? 0 : sum - target) << endl;
}

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

int main(){
	int n;
	cin>>n;
	bool isok=true;
	int acnt=0;
	int uncnt=0;
	for(int i=0;i<n;i++){
		string buf;
		cin>>buf;
		if(buf=="A") acnt++;
		else uncnt++;
		if(acnt<uncnt) isok=false;
	}
	if(acnt!=uncnt) isok=false;
	if(isok) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    string s;
    int n; cin >> n;
    vi p(n); rep(i,n)cin >> p[i];

    int mini = p[0];
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        if(p[i]<=mini) {
            cnt++;
            mini = p[i];
        }
    }
    cout << cnt << '\n';
}

Measured memory_bytes: 1024
s = list(input())
k = int(input())
abc = "abcdefghijklmnopqrstuvwxyz"
c = 0
for e,i in enumerate(s):
    # print(26-abc.index(i))
    if k-26+abc.index(i)>=0 and i!='a':
        s[e] = 'a'
        k-=26-abc.index(i)
    # print(k)  
k+=abc.index(s[-1])
k%=26
s[-1] = abc[k]

print("".join(s))

Measured memory_bytes: 4156
{-
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1142&lang=jp
?????????: Organize Your Train part II
????\???????:
20:02:00 C++??????????????????
20:03:00 ????????????????????????
20:03:30 ?????????Haskell??§?????????????????????????????¨??????
20:04:30 Haskell????????????????????? 
20:12:31 ???????????????
20:13:10 ??????????????????
-}
import Control.Monad
import qualified Data.Set as S

main = do
 m <- fmap read getLine
 sequence_ $ replicate m action

action = do
 str <- getLine
 print $ solve str

solve :: String -> Int
solve = S.size . S.fromList . cands 

cands :: String -> [String]
cands str = do
 (a,b) <- splitter str
 a' <- [a, reverse a]
 b' <- [b, reverse b]
 [a' ++ b', b' ++ a']

splitter :: String -> [(String, String)]
splitter [] = [([],[])]
splitter (x:xs) = ([], x:xs) : [(x:a, b) | (a,b) <- splitter xs]

Measured memory_bytes: 5764
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(all(l));
    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int a = l[i], b = l[j];
            int k = lower_bound(all(l), a + b) - l.begin();
            sum += max(k - (j + 1), 0);
        }
    }
    cout << sum << endl;
    return 0;
}


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

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

  vector<int> A(N);
  rep(i, N) cin >> A[i];

  ll ans = 0;
  int maxh = 0;
  rep(i, N) {
    maxh = max(maxh, A[i]);
    ans += maxh - A[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3988
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <map>
#include <set>
#include <vector>
#include <string.h>
#include <cmath>
#include <climits>
#include <queue>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
const int N = 500015;
const ll oo = 1e18 + 15;

int n, m, tmp, x;
ll res;
int a[N];
ll ss[N], an[N];
priority_queue <int> q2;
priority_queue <int, vector<int>, greater<int> > q1;

int main()
{
    #define file "ss"
    //freopen(file".inp", "r", stdin);
    //freopen(file".out", "w", stdout);
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n;
    m = 3 * n;
    for (int i = 1; i <= m; i++) cin >> a[i];
    for (int i = 1; i <= n; i++)
        q1.push(a[i]), ss[n] += 1LL*a[i];
    for (int i = n + 1; i <= 2 * n; i++)
    {
        x = q1.top();
        if (x < a[i])
        {
            ss[i] = ss[i - 1] + 1LL * a[i] - 1LL * x;
            q1.pop(), q1.push(a[i]);
        }
        else ss[i] = ss[i - 1];
    }
    for (int i = m; i > 2 * n; i--)
        q2.push(a[i]), an[2 * n + 1] += 1LL*a[i];
    for (int i = 2 * n; i > n; i--)
    {
        x = q2.top();
        if (a[i] < x)
        {
            an[i] = an[i + 1] + 1LL * a[i] - 1LL * x;
            q2.pop(), q2.push(a[i]);
        }
        else an[i] = an[i + 1];
    }
    //for (int i = 1; i <= m; i++)
    //    cout << i <<" "<< ss[i] <<" "<< an[i] << endl;
    res = -oo;
    for (int i = n; i <= 2*n; i++)
        res = max(res, ss[i] - an[i + 1]);
    cout << res;

    return 0;
}


Measured memory_bytes: 6904
n = gets.to_i
hs = Hash.new(0)
m = 0
n.times do |_|
  s = gets.chomp
  hs[s] += 1
  m = hs[s] if hs[s] > m
end

res = []
hs.each do |k, v|
  res << k if v == m
end
puts res.sort!

Measured memory_bytes: 33000
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        n: usize,
        a: [i64;n],
    }

    let mut dic = HashMap::new();

    for i in 0..n {
        if dic.contains_key(&a[i]) {
            *dic.get_mut(&a[i]).unwrap() += 1;
        } else {
            dic.insert(a[i], 1);
        }
    }

    let mut temp: i64 = dic.iter().map(|x| (x.1) * (x.1 - 1) / 2).sum();
    /*
        for e in dic.iter() {
            println!("{:?}", e);
        }
    */
    for i in 0..n {
        let mut ans = 0;
        let t = *dic.get(&a[i]).clone().unwrap();
        if t == 1 {
            ans = 0;
        } else {
            ans = t * (t - 1) / 2 - (t - 1) * (t - 2) / 2;
        }

        println!("{}", temp - ans);
    }
}


Measured memory_bytes: 17172
sub f{my($u,$t,$p)=@_;push@$t,$u;$_-$p&&f($_,$t^R,$u)for@$u}@a=$,=$";$#a=<>;map{push@$_,$u-$_+$;for($u,$;)=split}<>;f 1,b;@b>$./3&@0>$./3?(map$a[$_]=$#x+=3,@b)+map$a[$_]=++$y*3-2,@0:map$a[$_]=$#x+=$#x%3,@b>@0?@b:@0;print map$_<=$.&&$_||3*++$z,@a

Measured memory_bytes: 280832
n, k = map(int,input().split())

pedras = list(map(int,input().split()))

INF = 1e12

dp = [INF] * n

dp[0] = 0
dp[1] = abs(pedras[1] - pedras[0])

for i in range(2,n):
    pulo = 0
    for j in range(i-1,-1,-1):
        pulo += 1
        if pulo > k:
            break
        else:
            dp[i] = min(dp[i], dp[j] + abs(pedras[i] - pedras[j]))


print(dp[n-1])


Measured memory_bytes: 85868
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	string a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += (a[i] == b[i] && b[i] == c[i]) + (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]);
	}
	cout << 2 * n - ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }
}

#endif

// main.cpp

int main() {
  i64 A, B, C, D;
  std::cin >> A >> B >> C >> D;
  std::cout << std::min(A, B) + std::min(C, D) << std::endl;
  return 0;
}

Measured memory_bytes: 256
def cutting(str, startpoint)
  if str[startpoint] == str[startpoint+1]
    str.slice!(startpoint)
  else
    false
  end
end

n = gets.to_i
s = gets.chomp
startpoint = 0

n.times do
  if cutting(s, startpoint) == false
    startpoint += 1
    next 
  end
  cutting(s,startpoint)
end

puts s.length

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

using namespace std;
typedef long long ll;

int main(void)
{

 ll H,N,A,sum=0;

 cin>>H>>N;
 {
     while(N--)
     {
         ll x;
         cin>>x;
         sum+=x;
     }
     if(sum>=H)
     {
         cout<<"Yes"<<endl;
     }
     else
     {
         cout<<"No"<<endl;
     }
 }


}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
struct UnionFind {
    int n;
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> group;
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
        n=N;
    }
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void calc(){
        group.resize(n,0);
        for(int i=0;i<n;i++){
            group[root(i)]++;
        }
    }
    int size(int x){
        return group[root(x)];
    }
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
 
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
 
};

signed main(){
  int n,m;cin>>n>>m;
  UnionFind tree(n+1);
  vector<int> p(n+1,1);
  rep1(i,n)cin>>p[i];
  rep(i,m){
    int a,b;cin>>a>>b;
    tree.unite(p[a],p[b]);
  }
  int res=0;
  for(int i=n;i>0;--i){
    if(tree.same(p[i],i)){
      res++;
    }
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll d, c[30] = {}, s[370][30] = {}, last[30] = {}, ans[370] = {};

int main() {
	cin >> d;
	rep(i, 26)cin >> c[i];
	rep(i, d) {
		rep(j, 26)cin >> s[i][j];
	}
	rep(i, d) {
		ll satisfaction = -1000000, contest = 0;
		rep(j, 26) {
			if (satisfaction < s[i][j] + c[j] * (i - last[j])) {
				satisfaction = s[i][j] + c[j] * (i - last[j]);
				contest = j;
			}
			ans[i] = contest;
			last[contest] = i;
		}
	}
	rep(i, d)cout << ans[i] + 1 << endl;
	return 0;
}

Measured memory_bytes: 3724
h,w = map(int,input().split())
board = [input() for _ in range(h)]
dx = [-1,-1,-1, 0,0, 1,1,1]
dy = [-1, 0, 1,-1,1,-1,0,1]
ans_board = [[0 for _ in range(w)] for _ in range(h)]

for x in range(h):
    for y in range(w):
        cnt = 0
        if board[x][y] == '#':
            ans_board[x][y] = '#'
        else:
            for d in range(len(dx)):
                n_x = x+dx[d]
                n_y = y+dy[d]

                if 0 <= n_x < h and 0 <= n_y < w:
                    if board[n_x][n_y] == '#':
                        cnt += 1
            ans_board[x][y] = str(cnt)

for ans in ans_board:
    print('' .join(ans))


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

int main() { 
    string s;
    cin >> s;
    int size = s.size();
    cout << s.at(0) << size - 2 <<  s.at(size-1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<cstring>
#define maxn 2007
#define SDOI2020 RP++ 
using namespace std;
int a[maxn],b,c,n,maxx,ans,now; 
inline int read()
{
	int x=0;
	int flag=0;
	char ch;
	ch=getchar();
	while(!isdigit(ch)) 
	{
		if(ch=='-') flag=1;
	ch=getchar();	
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
		}
		if(flag==1) x=-x;	
		return x;
}

inline int sqr(int x)
{
	return x * x;
}

int main()
{
	n = read();
	ans = 1e9 + 7;
	for(register int i = 1;i <= n;i++)
	{
		a[i] = read();
		maxx = max(maxx,a[i]);
	}
	for(register int i = 1;i <= maxx;i++)
	{
		now = 0;
		for(register int j = 1;j <= n;j++)
		{
			now += sqr(a[j] - i);
		}
		ans = min(ans,now);
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> [Int] -> Int
solve n as = j
  where
    s = sum as
    (_, j) = minimum $ zip (map f as) [0..]
      where
        f a = abs (a * n - s)


readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      line2:remLines2 = remLines1
      as = map readBInt line2
  in solve n as

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 508
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int H, W, A, B;	
	cin >> H >> W >> A >> B;
	
	REP(i, H) {
		REP(j, W) {
			
			if (i < H - B && j < W - A) {
				cout << 0;
			}
			else if (j < W - A) {
				cout << 1;
			}
			else if (i>=(H-B)&&j>=(W-A)) {
				cout << 0;
			}
			else {
				cout << 1;
			}
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 1280
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

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

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

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    ll l, r;
    cin >> l >> r;

    if (r - l >= 2019)
        cout << 0 << endl;
    else
    {
        ll ans{3000};
        for (ll i = l; i <= r; ++i)
            for (ll j = i + 1; j <= r; ++j)
                ans = min({ ans, (i * j) % 2019ll });

        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int n,tot=1,bp[100010]/*break point */,ans[100010];
//r1l0
inline void work(int l,int r,int bpt){
    //cout<<l<<" "<<r<<" "<<bpt<<endl;
    if((r-l+1)%2==0){
        ans[bpt]=(r-l+1)/2;
        ans[bpt+1]=(r-l+1)/2;
    }else{
        if((bpt-l+1)%2==0){
            ans[bpt]=(r-l+1)/2;
            ans[bpt+1]=(r-l+2)/2;
        }else{
            ans[bpt]=(r-l+2)/2;
            ans[bpt+1]=(r-l+1)/2;
        }
    }
}
int main(){
    cin>>s;
    n=s.size();
    if(n==2){
        cout<<"1 1"<<endl;
        return 0;
    }
    //fill(ans,ans+n,1);
    bp[0]=-1;
    for(int i=0;i<n-1;i++){
        if(s[i]!=s[i+1]){
            bp[tot++]=i;
        }
    }
    bp[tot++]=n-1;
    for(int i=0;i<tot-1;i+=2){
        work(bp[i]+1,bp[i+2],bp[i+1]);
    }
    for(int i=0;i<n;i++)cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
int main(void)
{	
	int t=0,i=0,T=0;
	char  s[101];

	scanf("%s",&s);
	t=strlen(s)-1;

	while(s[i]!='\0'){
		if(s[i]!=s[t]){
			s[i]=s[t];
		    T++;
	}
		i++;
		t--;
}

	printf("%d\n",T);
	return 0;

	}




Measured memory_bytes: 128
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
const int INF = (1 << 30);

//毎回変える定数
#define N_MAX 200


//ライブラリコンテンツ
class UnionFind {
public:
	vector<int>rank, parent;
	//初期化
	UnionFind(int size) {
		rank.resize(size,0);
		parent.resize(size, 0);
		REP(i, size)parent[i] = i;
	}
	//木の根を求める
	int find(int x) {
		if (parent[x] == x)return x;
		else return parent[x] = find(parent[x]);
	}
	//xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y])
			parent[x] = y;
		else {
			parent[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	//xとyが同じ集合に属するか否か
	bool same(int x, int y) {
		return (find(x) == find(y));
	}
	//parentの内容を出力
	void debug() {
		for (auto num : parent) {
			cout << num << " ";
		}
		cout << "more:" << endl;
		REP(i, parent.size()) {
			cout << find(i) << " ";

		}
		cout << endl << "more:" << endl;
		for (auto num : parent) {
			cout << num << " ";
		}
		cout << endl;
	}
};


























//デバッグ
void debug(){
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	int n, q;
	cin >> n >> q;
	UnionFind unionFind(n);
	REP(i, q) {
		int a, b, c;
		cin >> a >> b >> c;
		if (a) {
			cout << unionFind.same(b, c) << endl;
		}
		else {
			unionFind.unite(b, c);
		}

		//unionFind.debug();
		//cout << endl;
	}
	debug();
	return 0;
}



Measured memory_bytes: 3172
// AOJ 1384 Rendezvous on a Tetrahedron
// 2018.4.6 bal4u

#include <stdio.h>
#include <math.h>

#define BASE     100
#define PI180    0.01745329251994329576923690768489    // PI/180
#define tan60	 (sqrt(3))				// tan 60 = sqrt(3)
#define sin60    (sqrt(3)/2)			// sin 60 = sqrt(3)/2

#define A 0
#define B 1
#define C 2
#define D 3
int ans[2][2][2] = { B,A,C,D,D,C,A,B };

int calc(char *edge, int d, int l)
{
	int ix, iy, one;
	double delta, x, y;

	if      (*edge == 'D') d += 60;
	else if (*edge == 'B') d += 120;
	delta = d * PI180;			// d/180*PI

	x = BASE + l * (cos(delta) - sin(delta)/tan60);
	y = l * sin(delta)/sin60;

	ix = (int)x, iy = (int)y;
	one = ((x-ix) + (y-iy)) >= 1;
	return ans[ix&1][iy&1][one];
}

int main()
{
	int d, l, fp, fq;
	char edge[5];

	scanf("%s%d%d", edge, &d, &l);
	fp = calc(edge, d, l);
	scanf("%s%d%d", edge, &d, &l);
	fq = calc(edge, d, l);
	puts(fp == fq? "YES": "NO");
	return 0;
}


Measured memory_bytes: 2136
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using ll = long long int;

int main(int argc,char *argv[])
{
	ll n;
	std::cin >> n;

	std::vector<ll> a(n-1,0);
	for (int i = 0;i < n-1;++i)
	{
		ll tmp;
		std::cin >> tmp;
		++a[tmp-1];
	}

	for (int i = 0;i < n-1;++i) { std::cout << a[i] << std::endl; }
	std::cout << 0 << std::endl;

	return 0;
}

Measured memory_bytes: 4840