akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

struct SegTree(alias fun, alias E, T)
if (is(typeof(E) : T))
{
    import std.functional : binaryFun;
    alias OP = binaryFun!fun;

    ///
    this(size_t n, T[] ts) {
        this.n = 1;
        while (this.n < n) this.n *= 2;
        this.tree.length = this.n * 2 - 1;
        foreach (ref e; this.tree) e = E;
        foreach (i, e; ts) this.update(i, e);
    }

    ///
    void replace(size_t i, T e) {
        i += this.n - 1;
        this.tree[i] = e;
        while (i > 0) {
            i = (i-1) / 2;
            this.tree[i] = OP(this.tree[i*2+1], this.tree[i*2+2]);
        }
    }

    ///
    void update(size_t i, T e) {
        replace(i, OP(e, tree[i + this.n - 1]));
    }

    ///
    T query(size_t a, size_t b) {
        T impl(size_t i, size_t l, size_t r) {
            if (r <= a || b <= l) return E;
            if (a <= l && r <= b) return this.tree[i];
            return OP(
                impl(i*2+1, l, (l+r)/2),
                impl(i*2+2, (l+r)/2, r)
            );
        }
        return impl(0, 0, this.n);
    }

private:
    size_t n;
    T[] tree;
}

///
auto seg_tree(alias f, alias E, T)(size_t n, T[] arr = [])
{
    return SegTree!(f, E, T)(n, arr);
}

///
auto seg_tree(alias f, alias E, T)(T[] arr)
{
    return SegTree!(f, E, T)(arr.length, arr);
}

auto min_seg_tree(T)(size_t n, T[] arr = [])
{
    return seg_tree!("a < b ? a : b", T.max, T)(n, arr);
}

auto min_seg_tree(T)(T[] arr)
{
    return min_seg_tree!T(arr.length, arr);
}

void main()
{
    auto nx = readln.split.to!(int[]);
    auto N = nx[0];
    long x = nx[1];
    auto AS = readln.split.to!(long[]);

    alias SEGT = typeof(min_seg_tree!long(N));
    auto ss = new SEGT[](N);
    foreach (i; 0..N) {
        ss[i] = min_seg_tree!long(N);
        foreach (j; 0..N) ss[i].update(j, AS[(i+j)%N]);
    }

    auto res = long.max;
    foreach (i; 0..N) {
        long rr = x * i;
        foreach (j; 0..N) rr += ss[j].query(0, i+1);
        res = min(res, rr);
    }
    writeln(res);
}

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

int main() {
    int l, r;
    cin >> l >> r;

    if (r - l >= 2019) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = 2018;
    for (int n = l; n <= r; n++) {
        for (int m = n + 1; m <= r; m++) {
            ans = min(ans, (long long)n * m % 2019);
        }
    }

    cout << ans << endl;
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	long long sum=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	cout<<sum-n;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using  namespace std;
#define ll      long long int
#define pai     pair<int,int>
#define vi      vector<int>
#define vd      vector<double>
#define vs      vector<string>
#define vp      vector< pair <string,int> >
#define mpi     map<int,int>
#define mps     map<char,int>
#define sti     stack<int>
#define stc     stack<char>
#define sei     set<int>
#define ses     set<string>
#define multii  multiset<int>
#define forn(i,n)    for (int i = 0; i < n; i++)
#define fork(i,k,n)  for (int i = k; i <= n; i++)
#define forkr(i,k,n) for (int i = k; i >= n; i--)

 int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 char s;
  cin>>s;
  if(isupper(s)){
    cout<<"A"<<endl;
  }
else{
   cout<<"a"<<endl;
}
}






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

int main(){
  int N,M; cin >> N >> M;
  tuple<int,int,int> city[100000];
  for(int i=0; i<M; i++){
    cin >> get<0>(city[i]) >> get<1>(city[i]);
    get<2>(city[i])=i;
  }
  sort(city,city+M);
  int pref=0; int num=1;
  for(int i=0; i<M; i++){
    if(pref!=get<0>(city[i])){
      pref=get<0>(city[i]);
      num=1;
    }
    get<1>(city[i])=num;
    num++;
  }
  for(int i=0; i<M; i++){
    int temp=get<0>(city[i]);
    get<0>(city[i])=get<2>(city[i]);
    get<2>(city[i])=get<1>(city[i]);
    get<1>(city[i])=temp;
  }
  sort(city,city+M);
  for(int i=0; i<M; i++){
    cout << setw(6) << setfill('0') << get<1>(city[i]);
    cout << setw(6) << setfill('0') << get<2>(city[i]) << endl;
  }
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;

int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);

  int a, b;
  vector<int> *p = new vector<int>[n];
  REP(i, m) {
    scanf("%d", &a);
    scanf("%d", &b);
    --a;
    --b;
    p[a].emplace_back(b);
    p[b].emplace_back(a);
  }


  int *dist = new int[n];   // 距離
  int *dir = new int[n];    // 道標
  dist[0] = 0;
  for (int i = 1; i < n; ++i) {
    dist[i] = -1;
    dir[i] = -1;
  }

  vector<int> current;
  vector<int> next;
  current.emplace_back(0);

  int distance = 1;

  while(current.size() > 0) {
    for(auto itr = current.begin(); itr != current.end(); ++itr) {
      // printf("%d\n", *itr);
      REP(i, p[*itr].size()) {
        int second = p[*itr][i];
        if (dist[second] == -1) {
          dist[second] = distance;
          dir[second] = *itr;
          next.emplace_back(second);
        }
      }
    }
    swap(current, next);
    next.clear();
    ++distance;
  }

  bool perfect = true;
  REP2(i, 1, n) {
    if (dist[i] == -1) {
      perfect = false;
    }
  }

  if (perfect) {
    printf("Yes\n");
    REP2(i, 1, n) {
      printf("%d\n", dir[i] + 1);
    }
  } else {
    printf("No\n");
  }

  return 0;
}


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

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

    if(n % 2 == 0){
        cout << (n/2) -1 << endl;
    }else{
        cout << (n/2) << endl;
    }

    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n;
	char s[10003];

	scanf("%d %s",&n, s);
	for (int i = 0; i < strlen(s); ++i)
	{
		printf("%c", (s[i] - 'A' + n) % 26 + 'A');
	}
}


Measured memory_bytes: 128
l, r = map(int, input().split())
rng = r - l
ans = float("inf")
if rng >= 2018:
    ans = 0
else:
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            ans = min(ans, (i * j) % 2019)
print(ans)

Measured memory_bytes: 3060
import           Control.Applicative
import           Control.Monad
import           Data.List

main :: IO ()
main = do
  [a,b,theta] <- map (read::String->Double) . words <$> getLine
  let t=theta/180.0*pi
  let h=b*sin t
  let s=0.5*a*h
  let c=sqrt (a*a+b*b-2.0*a*b*cos t)
  let l=a+b+c
  print s
  print l
  print h


Measured memory_bytes: 4204
#include <stdio.h>

int main(void){
	int W, H, x, y, r;
	
	scanf("%d %d %d %d %d %d", &W, &H, &x, &y, &r);

	/* 円中央＋半径が長方形の上下左右からはみ出しているか判定 */
	if ((W < (x+r)) || (0 > (x-r)) || (H < (y+r)) || (0 > (y-r))){
		printf("No\n");
	}/* それぞれはみ出してない場合は入っている*/
	else{
		 printf("Yes\n");
	}
	
		
	return 0;
}

Measured memory_bytes: 584
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int A =nextInt();
		int B = nextInt();

		if(A>=13){

		}else if(6<=A&&A<=12){
			B=B/2;
		}else{
			B=0;
		}
		System.out.println(B);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21204
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.Split.Int;
            var X = line[0];
            var A = line[1];

            return X < A ? 0 : 10;
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader()).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader { public class SplitLine { string[] splited; public SplitLine(string line) { splited = line.Split(); } public string[] String => splited.ToArray(); public int[] Int => splited.Select(int.Parse).ToArray(); public long[] Long => splited.Select(long.Parse).ToArray(); public ulong[] ULong => splited.Select(ulong.Parse).ToArray(); public double[] Double => splited.Select(double.Parse).ToArray(); } public class RepeatLine { ConsoleReader reader; int num; public RepeatLine(ConsoleReader reader, int num) { this.reader = reader; this.num = num; } public IEnumerable<string> String { get { for (int i = 0; i < num; i++) yield return reader.String; } } public IEnumerable<int> Int { get { for (int i = 0; i < num; i++) yield return reader.Int; } } public IEnumerable<long> Long { get { for (int i = 0; i < num; i++) yield return reader.Long; } } public IEnumerable<string[]> Split { get { for (int i = 0; i < num; i++) yield return reader.Split.String; } } public IEnumerable<int[]> SplitInt { get { for (int i = 0; i < num; i++) yield return reader.Split.Int; } } } public virtual string String => Console.ReadLine(); public int Int => int.Parse(String); public long Long => long.Parse(String); public ulong ULong => ulong.Parse(String); public double Double => double.Parse(String); public SplitLine Split => new SplitLine(String); public RepeatLine Repeat(int count) => new RepeatLine(this, count); }
}

Measured memory_bytes: 13396
using System;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            B.Polygon();
        }
    }

    class B
    {
        public static void Polygon()
        {
            int n = Input.getInt();
            int[] l = Input.getIntArray();

            int max = l.Max();
            int length = 0;
            for (int i = 0; i < n; i++)
            {
                length = length + l[i];
            }
            
            if(length-max>max)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
        

    }

    class Input
    {
        public static int getInt()
        {
            int i = int.Parse(Console.ReadLine());
            return i;
        }

        public static string getString()
        {
            string s = Console.ReadLine();
            return s;
        }
        public static int[] getIntArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] num = s.Select(x => int.Parse(x)).ToArray();
            return num;
        }
        public static long[] getLongArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            long[] num = s.Select(x => long.Parse(x)).ToArray();
            return num;
        }
    }
}


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

using namespace std;

typedef long long ll;
#define p(x) cout << x << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    vector<ll> a(n), b(m), c(m);
    map<int, int> count{};
    rep(i, n)
    {
        cin >> a[i];
    }
    rep(i, m)
    {
        cin >> b[i] >> c[i];
        if (count[c[i]] > 0)
        {
            count[c[i]] += b[i];
            c[i] = 0;
        }
        count[c[i]] += b[i];
    }

    sort(all(a), greater<int>());
    sort(all(c), greater<int>());

    ll ans = 0;
    int a_i = 0, c_i = 0;
    rep(i, n)
    {
        if (count[c[c_i]] == 0)
        {
            c_i++;
        }

        if (a[a_i] > c[c_i])
        {
            ans += a[a_i];
            a_i++;
            continue;
        }
        ans += c[c_i];
        count[c[c_i]]--;
    }
    p(ans);
    return 0;
}


Measured memory_bytes: 7296
import java.util.Scanner;

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

		int n = sc.nextInt();

		if (n == 1) {
			System.out.println("Hello World");
		} else if (n == 2) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int ans = a + b;
			System.out.println(ans);
		}

		sc.close();

	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
using namespace std;

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int i, j;
	int a, b;
	cin >> a >> b;
	int k_2 = (a+b);
	if (k_2 % 2 == 0) {
		cout << k_2 / 2 << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		char[] sChar = s.toCharArray();
		char[] tChar = t.toCharArray();

		int cnt = 0;
		for (int i = 0; i < 3; i++) {
			if (sChar[i] == tChar[i]) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21588
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
N = int(input())
 
testimony = [[] for _ in range(N)]
 
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1, state])
        
honest = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if (i>>j)&1 == 1: # j番目は正直と仮定
            for x,y in testimony[j]:
                if (i>>x)&1 != y: # j番目は正直だが矛盾を発見
                    flag = 1
                    break
    if flag == 0:  # 矛盾がある場合はflag == 1になる
        honest = max(honest, bin(i)[2:].count('1'))  # 1の数をカウントし最大となるものを選択
print(honest)

Measured memory_bytes: 9252
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    printf( "%d\n",max(max(a-b,a+b),a*b));
    return 0;   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll a,b,c;
	cin>>a>>b>>c;
	if(a+b>=c)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    ll n;
    cin>>n;
    ll ans=0;
    rep(i,1,n+1)
    {
        if(i%3!=0&&i%5!=0)
            ans+=i;
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
ll a,b;
int main(){
	cin>>a>>b;
	a%=b;
	cout<<min(a,b-a)<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BFizzBuzzSum solver = new BFizzBuzzSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class BFizzBuzzSum {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long sum = 0;
            for (int i = 1; i <= n; i++) if (i % 3 != 0 && i % 5 != 0) sum += i;
            out.println(sum);
        }

    }
}



Measured memory_bytes: 35860
<?php
$Arraylength = trim(fgets(STDIN));
$stdins = explode(" ",trim(fgets(STDIN)));

selectionSort($stdins,$Arraylength);

function selectionSort($Array, $N){
    $count = 0;
    for ($i=0; $i<$N; ++$i){
        $mini = $i;
        for ($j=$i; $j<$N; ++$j){
            if ($Array[$j] < $Array[$mini]){
                $mini = $j;
            }
        }
        if($mini!=$i){
            $tmp = $Array[$i];
            $Array[$i] = $Array[$mini];
            $Array[$mini] = $tmp;
            $count++;
        }
    }
    echo implode(" ",$Array) . PHP_EOL;
    echo $count . PHP_EOL;
}

?>


Measured memory_bytes: 9308
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long int t[200];
    long long int sum=0;
    for(int i=0;i<n;i++){
        cin>>t[i];
        sum+=t[i];
    }
    //cout<<sum<<endl;
    int m;
    cin>>m;
    int p;
    long int x;
    for(int i=0;i<m;i++){
        cin>>p>>x;
        cout<<sum-t[p-1]+x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define f(a) for (ll i = 0; i < a; i++)
#define fio                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);



int main()
{
    fio;
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    f(n){cin>>arr[i];}
    ll f[n];
    f[0]=0;
    ll mn;
    for(ll i=1;i<n;i++)
    {
        ll m=min(k,i);
        mn=10000000000000;
        ll j=i-1;
        while(m--)
        {
          mn=min(mn,abs(arr[i]-arr[j])+f[j]);
          j--;
        }
        f[i]=mn;

    }
    cout<<f[n-1];



    return 0;
}



Measured memory_bytes: 5136
import pprint

def main():
    h, w, k = list(map(int, input().split()))
    # c_is_black_matrix = []
    black_num_in_each_row = [0 for _ in range(h)]
    black_num_in_each_column = [0 for _ in range(w)]
    black_num = 0
    black_coords = []

    match_condition_count = 0

    for hi in range(h):
        chars = input()
        black_num_in_each_row[hi] = chars.count("#")
        for wi, c in enumerate(chars):
            if c == "#":
                black_num_in_each_column[wi] += 1
                black_coords.append((hi, wi))
                black_num += 1

    # pprint.pprint(c_is_black_matrix)
    # pprint.pprint(black_num_in_each_row)
    # pprint.pprint(black_num_in_each_column)
    # pprint.pprint(black_coords)

    for hi in range(2 ** h):
        for wi in range(2 ** w):
            h_bin = '{0:0b}'.format(hi).zfill(h)
            w_bin = '{0:0b}'.format(wi).zfill(w)
            current_pattern_black_num = black_num

            # print("{0} {1}".format(h_bin, w_bin))
            for ri, r in enumerate(h_bin):
                if r == "1":
                    current_pattern_black_num -= black_num_in_each_row[ri]
            for ci, c in enumerate(w_bin):
                if c == "1":
                    current_pattern_black_num -= black_num_in_each_column[ci]
            
            for r, c in black_coords:
                if h_bin[r] == "1" and w_bin[c] == "1":
                    current_pattern_black_num += 1

            # print("{0} {1}".format(black_num, current_pattern_black_num))
            
            if current_pattern_black_num == k:
                match_condition_count += 1

    print(match_condition_count)


if __name__ == "__main__":
    main()


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

int main(){
  int N;
  long cost=0;
  int max=0;
  cin>>N;
  for(int i=0; i<N; i++){
    int p; cin >> p;
    if(max<p) max=p;
    cost+=p;
  }
  cost = cost-max/2;
  cout << cost << endl;
  return 0;
}

Measured memory_bytes: 256
from math import sqrt, sin, cos

def readinput():
    n=int(input())
    return n

def apex3(x1,y1,x2,y2):
    '''正三角形の残りの頂点(x3,y3)を求める
    
    1->2->3の順に反時計回り
    '''
    x3 = 1.0/2.0 *(x2-x1) -sqrt(3.0)/2.0 * (y2-y1) +x1
    y3 = sqrt(3.0)/2.0 * (x2-x1) + 1.0/2.0 * (y2-y1) +y1
    return x3,y3

def koch(x1,y1,x2,y2,l,lmax):
    #print('l:{}, lmax:{}'.format(l,lmax))
    if(l==lmax):
        return

    x3,y3=(x2-x1)/3 +x1, (y2-y1)/3 +y1
    x4,y4=(x2-x1)/3*2 +x1, (y2-y1)/3*2 +y1
    x5,y5 = apex3(x3,y3,x4,y4)

    koch(x1,y1,x3,y3,l+1,lmax)
    print('{:.10f} {:.10f}'.format(x3,y3))
    koch(x3,y3,x5,y5,l+1,lmax)
    print('{:.10f} {:.10f}'.format(x5,y5))
    koch(x5,y5,x4,y4,l+1,lmax)
    print('{:.10f} {:.10f}'.format(x4,y4))
    koch(x4,y4,x2,y2,l+1,lmax)

    return

def main(n):
    x0=0;y0=0
    x1=100;y1=0
    print('{:.10f} {:.10f}'.format(x0,y0))
    koch(x0,y0,x1,y1,0,n)
    print('{:.10f} {:.10f}'.format(x1,y1))


if __name__=='__main__':
    n=readinput()
    main(n)



Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}

Measured memory_bytes: 3608
S = list(input())
is_yymm = False
is_mmyy = False
yymm_month = int(''.join(S[2:]))
mmyy_month = int(''.join(S[:2]))

if 1 <= yymm_month and yymm_month <= 12:
    is_yymm = True
if 1 <= mmyy_month and mmyy_month <= 12:
    is_mmyy = True

ans = 'NA'
if is_yymm and is_mmyy:
    ans = 'AMBIGUOUS'
elif is_yymm:
    ans = 'YYMM'
elif is_mmyy:
    ans = 'MMYY'

print(ans)

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

#define endl "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)

int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) {
        if (b & 1) res = (res * a) % m;
        a = (a * a) % m; b >>= 1;
    } return res;
}

int now() {
    return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now()
    .time_since_epoch()).count();
}

int32_t main() { fastio;
    time_t start = now();

    int h, k;
    cin >> h >> k;
    vector<int> arr(h);
    for (int i = 0; i < h; i++) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    int sum = 0;
    for (int i = 0; i < (h - k); i++) {
        sum += arr[i];
    }
    cout << sum << endl;

    cerr << "TIME => " << now() - start << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int cnt=0;

void selsort(int a[], int n){
  for(int i = 0; i < n; i++){
    int minj = i;
    for(int j = i; j < n; j++)
      if(a[j] < a[minj]) minj = j;
    swap(a[i], a[minj]);
    if(minj!=i)cnt++;
  }
}


int main(){
  
  int n, a[100];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  selsort(a,n);
  for(int i=0;i<n-1;i++)printf("%d ",a[i]);cout<<a[n-1]<<endl;
  cout<<cnt<<endl;
  
  return 0;
}



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

using namespace std;

#define REP(A, H) for(int A = 0; A < H; A++)

int main(void) {
  int n, d; cin >> n >> d;
  vector< vector<int> > ds(n);
  REP(i, n) {
    vector<int> p(d);
    REP(j, d) {
      cin >> p[j];
    }
    ds[i] = p;
  } 
  
  int cnt = 0;
  REP(i, n) {
    for(int j = i + 1; j < n; j++) {
      long long ssum = 0;
      REP(k, d) {
        long long t = (ds[i][k] - ds[j][k]);
        ssum += t * t;
      }

      REP(k, 10000) {
        if (ssum == k * k)
        {
          cnt++;
          break;
        }
      }
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n,m,x,y,d,k,p[10],q[10],a[200006],b[200006];
string str;
//ユークリッドの互除法　a,bは最大公約数を求めたい２つの数
class Euclid_Gojyohou{
    public:
    long long int gcd(long long int a, long long int b) {
        long long int tmp;
        long long int r = 1;
        if (b > a) {
            tmp = a;
            a = b;
            b = tmp;
        }
        r = a % b;
        while (r != 0) {


            a = b;
            b = r;
            r = a % b;

        }
        return b;
    }
};

int main() {
	cout<<setprecision(10);
	Euclid_Gojyohou euc;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	bool key=true;
	while(key){
		key=false;
		for(int i=0;i<n;i++){
			if(a[i]%2!=0){cout<<0<<endl;return 0;}
			a[i]/=2;
			if(a[i]%2==0){key=true;}
		}
	}
	for(int i=0;i<n;i++){
		b[0]=(b[0]*b[i])/euc.gcd(b[0],b[i]);
		if(b[0]>2*m){cout<<0<<endl;return 0;}
	}
	cout<<(b[0]/2+m)/(b[0])<<endl;

} 


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

int main(void)
{
  int n,k,x,y;
  int sum=0;
  cin>>n>>k>>x>>y;
  for(int i=0;i<n;i++){
    if(i<k)
      sum+=x;
    else
      sum+=y;
  }
  cout<<sum<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=350;
int main(){
    int a,b;
    cin>>a>>b;
    int sum=a+b;
    sum=max(sum,2*a-1);
    sum=max(sum,2*b-1);
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100050],a[100050];
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    dp[0]=0;
    
    for(int i=1;i<n;i++){
        dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
        for(int j=1;j<=k;j++){
            if(i-j<0)break;
            dp[i]=min(dp[i],abs(a[i-j]-a[i])+dp[i-j]);
        }
    }
    
    cout<<dp[n-1];
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
 
#define N 8
int a[N],n;
void printQueen(int q[N]) {
    int i, j, b[N][N] = { 0 };
    for (i = 0; i < N; i++) b[i][q[i]]=1;
    for (i = 0; i < N; i++,puts(""))
        for (j = 0; j < N; j++) fprintf(stdout, "%c", b[i][j] == 1 ? 'Q' : '.');
}
 
void cheak(int queen[N])
{
    int i,cnt=0;
    for (i = 0; i < N; i++) 
        if (queen[i] == a[i])cnt++;
    if (cnt == n) printQueen(queen);
}
 
void changeBoard(int board[N][N], int i, int j, int d)
{
    int k;
 
    for (k = 0; k < N; k++) {
        board[i][k] += d;
        board[k][j] += d;
    }
    if (i > j) {
        for (k = 0; k < N - (i - j); k++) {
            board[k + (i - j)][k] += d; 
        }
    }
    else {
        for (k = 0; k < N - (j - i); k++) {
            board[k][k + (j - i)] += d;
        }
    }
    if (i + j < N) {
        for (k = 0; k <= i + j; k++) {
            board[i + j - k][k] += d;
        }
    }
    else {
        for (k = i + j - N + 1; k < N; k++) {
            board[i + j - k][k] += d;
        }
    }
}
 
void setQueen(int queen[N], int board[N][N], int i)
{
    int j;
 
    if (i == N) { 
        cheak(queen);
        return;
    }
 
    for (j = 0; j < N; j++) {
        if (board[i][j] == 0) {
            queen[i] = j;
            changeBoard(board, i, j, +1);
            setQueen(queen, board, i + 1);
            changeBoard(board, i, j, -1);
        }
    }
}
 
void findSolution()
{
    int queen[N];
    int board[N][N];
 
    memset(board, 0, sizeof(board));
    setQueen(queen, board, 0);
}
int main()
{
    int i=0, h,w;
    memset(a, -1, sizeof(a));
    fscanf(stdin, "%d", &n);
    while (i<n) fscanf(stdin, "%d%d", &h, &w), a[h] = w,i++;
    findSolution();
    return 0;
}

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

int main() {
  unsigned H, W;
  std::cin >> H >> W;
  std::string S;
  for (unsigned i = 0; i < H; ++i) {
    for (unsigned j = 0; j < W; ++j) {
      std::cin >> S;
      if (S == "snuke") {
        std::cout << static_cast<char>('A' + j)  << i + 1;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<stack>
#include<set>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cWeightEdges=vector<vector<pair<int,int>>>;
using cEdges=vector<vector<int>>;

int main(){	
	int N,x;
	cin>>N>>x;
	if(x==1 || x==2*N-1){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
		deque<int> deq;
		deq.push_back(x);

		deq.push_back(x-1);
		deq.push_front(x+1);
		int y=(x-1==1?2*N-1:x-2);
		for(int i=1;i<N-1;++i){
			deq.push_front(y);
			if(y==1)y=2*N-1;
			else --y;
			deq.push_back(y);
			if(y==1)y=2*N-1;
			else --y;
		}
		for(const auto& val:deq)
			cout<<val<<"\n";
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}


int main(){
	int n; cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	
	ll money = 1000;
	ll stock = 0;
	bool isup = false;
	rep(i,n-1){
		if(isup){
			if(a[i+1] < a[i]){
				money += stock * a[i];
				stock = 0;
				isup = false;
			}
		}else{
			if(a[i] < a[i+1]){
				stock = money / a[i];
				money -= stock * a[i];
				isup = true;
			}
		}
	}
	money += stock *  a[n-1];
	cout << money << endl;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

struct BIT {
    vector<LL> bit;
    int M;
 
    BIT(int M) : bit(vector<LL>(M + 1, 0LL)), M(M) {}
 
    LL sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i - (i & -i));
    }
 
    void add(int i, LL x) {
        if (i > M) return;
        bit[i] += x;
        add(i + (i & -i), x);
    }
};


void solve(long long N, std::vector<long long> a){
    VLL sort_a(a.size(), 0LL);
    copy(ALL(a), sort_a.begin());
    sort(ALL(sort_a));

    int l = -1;
    int r = a.size();
    LL t = ceil((N * (N + 1)) / 2LL / 2.0);
    while (r - l > 1) {
        int m = l + (r - l) / 2;
        bool ok = false;

        int now = sort_a[m];
        int diff = 0;
        BIT bit(N*2+1);
        LL cnt = 0;
        bit.add(N,1);
        REP(i, a.size()) {
            if(a[i] < now) diff--;
            else diff++;
            cnt += bit.sum(diff+N);
            bit.add(diff+N, 1);
        }

        //cout << cnt << " " << l << "," << r << "  " << m << " " << now << endl;

        if(t <= cnt) {
            l = m;
        } else {
            r = m;
        }
    }

    cout << sort_a[l] << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 3428
while 1:
    try:
        a,b,c,d,e,f = map(float, input().split())  
        y=(c*d-a*f)/(b*d-a*e)
        x=(c-b*y)/a
        print("{0:.3f} {1:.3f}".format(x,y))
    except:
        break


Measured memory_bytes: 5584
#include <iostream>
#include <queue>
using namespace std;
priority_queue<long long> pq;
int main()
{
	long long n ,m ,k;	
	while(cin>>n>>m)
	{
		long long sum = 0;
		for(int i=0 ;i<n ;i++) cin>>k ,pq.push(k);
		while(m--)
		{
			if(!pq.empty())
			{
				int t = pq.top();
				t /= 2;
				pq.pop();
				pq.push(t);
			}
		}
		while(!pq.empty())
		{
			sum += pq.top();
			pq.pop();
		}			
		cout<<sum<<'\n';			
	}
} 

Measured memory_bytes: 3848
#include<iostream>
using namespace std;
const int N=801,X[4]={-1,0,0,1},Y[4]={0,-1,1,0};
bool v[N][N];
int n,m,k,p[N*N],q[N*N],s,t,P,Q,f[N][N],A=N;
string S[N];
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		cin>>S[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(S[i][j-1]=='S')
				v[i][j]=true,p[++t]=i,q[t]=j;
	while(s<t)
	{
		P=p[++s],Q=q[s];
		for(int i=0;i<4;i++)
			if(1<=P+X[i]&&P+X[i]<=n&&1<=Q+Y[i]&&Q+Y[i]<=m&&S[P+X[i]][Q+Y[i]-1]=='.'&&!v[P+X[i]][Q+Y[i]])
				f[P+X[i]][Q+Y[i]]=f[P][Q]+1,v[P+X[i]][Q+Y[i]]=true,p[++t]=P+X[i],q[t]=Q+Y[i];
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(v[i][j]&&f[i][j]<=k)
				A=min(A,(min(min(i-1,n-i),min(j-1,m-j))+k-1)/k);
	cout<<A+1;
	return 0;
}

Measured memory_bytes: 9216
'use strict';
function Main(is) {
  const i = is.split("\n");
  let s = i[0];
  let p = parseInt(i[1]);
  for(let i = 0;i < s.length;i++){
    let code = s[i].charCodeAt(0);
    if (s.length - 1 == i) {
      code += p%26;
      if(code > 122){
        code += (- 122 + 97 - 1);
      }
      let lastLetter = String.fromCharCode(code);
      s = s.slice(0, i) + lastLetter + s.slice(i+1);
    } else {
      if((27 - (code - 97 + 1)) <= p && !(s[i] == "a")){
        p = p - (27 - (code - 97 + 1));
        s = s.slice(0, i) + "a" + s.slice(i+1);
      }
    }
  }
  console.log(s);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37732
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> W(N);
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> W[i];
        sum += W[i];
    }

    int S1 = 0;
    int S2 = sum;
    int ans = abs(S1 - S2);
    for (int i = 0; i < N; i++)
    {
        S1 += W[i];
        S2 -= W[i];
        ans = min(ans, abs(S1 - S2));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s = int(input())
s1 = int(s/10)
s2 = int(s1/10)
s3 = int(s2/10)
a1 = s%10
a2 = s1%10
a3 = s2%10
a4 = s3%10
if a1 == a2 or a2 == a3 or a3 == a4:
	print("Bad")
else:
    print("Good")

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    map<char, char> a;
    char b;
    cin >> b;
    a.insert({'A', 'T'});
    a.insert({'T', 'A'});
    a.insert({'C', 'G'});
    a.insert({'G', 'C'});

    cout << a[b] << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String sentence;
		int[] abc = new int[26];

		while ((sentence = input.readLine()) != null) {
			for (int i = 0; i < sentence.length(); i++) {
				char c = sentence.charAt(i);
				     c = Character.toLowerCase(c);
				char cc = 'a';
				for (int j = 0; j < abc.length; j++) {
					if (cc == c)
						abc[j]++;
					cc++;
				}
			}
		}

		char cc = 'a';
		for (int i = 0; i < abc.length; i++) {
			System.out.println(cc + " : " + abc[i]);
			cc++;
		}
	}

}

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

int main()
{
	int n, num, arr[200], sum;
	
	while (scanf("%d",&n)!=EOF){
		for (int i = 0; i < n; i++){
			scanf("%d", &arr[i]);
		}
		sort(arr, arr + n);
		
		sum = 0;
		for (int i = 0; i < n; i++){
			sum += arr[i]*(n - i);
		}
		printf("%d\n", sum);
	}
	return 0;
}

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

int main(void)
{
  int i, j, k;

  for(i = 1 ; i <= 9 ; i++)
    {
      for(j = 1 ; j <= 9 ; j++)
	{
           k = i*j;
           printf("%dx%d=%d\n", i,j,k);
	}
    }           
}

Measured memory_bytes: 924
class Node:
	def __init__(self, key, pri):
		self.key = key
		self.pri = pri
		self.left = self.right = None
	def __str__(self):
		ret = ''
		ret += 'key=' + str(self.key)
		ret += ',pri=' + str(self.pri)
		ret += ',left='
		if self.left != None: ret += str(self.left.key)
		ret += ',right='
		if self.right != None: ret += str(self.right.key)
		return ret

class Treap:
	def __init__(self):
		self.root = None

	def print(self):
		self.print_in_order()
		self.print_pre_order()

	def print_in_order(self):
		st = []
		cur = self.root
		while cur != None or len(st) != 0:
			if cur != None:
				st.append(cur)
				cur = cur.left
			else:
				cur = st.pop()
				print(' ' + str(cur.key), end='')
				cur = cur.right
		print()

	def print_pre_order(self):
		st = []
		st.append(self.root)
		while len(st) != 0:
			cur = st.pop()
			print(' ' + str(cur.key), end='')
			if cur.right != None:
				st.append(cur.right)
			if cur.left != None:
				st.append(cur.left)
		print()

	def find(self, key):
		cur = self.root
		while cur != None:
			if key == cur.key:
				return cur
			if key < cur.key:
				cur = cur.left
			else:
				cur = cur.right
		return None

	def insert(self, key, pri):
		self.root = self.insert_(self.root, key, pri)

	def insert_(self, node, key, pri):
		if node == None:
			return Node(key, pri)
		if key == node.key:
			return node

		if key < node.key:
			node.left = self.insert_(node.left, key, pri)
			if node.pri < node.left.pri:
				node = self.right_rotate(node)
		else:
			node.right = self.insert_(node.right, key, pri)
			if node.pri < node.right.pri:
				node = self.left_rotate(node)
		return node

	def right_rotate(self, node):
		tmp = node.left
		node.left = tmp.right
		tmp.right = node
		return tmp

	def left_rotate(self, node):
		tmp = node.right
		node.right = tmp.left
		tmp.left = node
		return tmp

	def delete(self, key):
		self.root = self.delete_(self.root, key)

	def delete_(self, node, key):
		if node == None:
			return node
		if key < node.key:
			node.left = self.delete_(node.left, key)
		elif key > node.key:
			node.right = self.delete_(node.right, key)
		else:
			return self.delete__(node, key)
		return node

	def delete__(self, node, key):
		if (node.left == None and node.right == None):
			return None
		elif node.left == None:
			node = self.left_rotate(node)
		elif node.right == None:
			node = self.right_rotate(node)
		else:
			if node.left.pri > node.right.pri:
				node = self.right_rotate(node)
			else:
				node = self.left_rotate(node)
		return self.delete_(node, key)

n = int(input())
treap = Treap()
for i in range(n):
	cmd = list(map(str, input().split()))
	if cmd[0] == 'print':
		treap.print()
	else:
		key = int(cmd[1])
		if cmd[0] == 'insert':
			treap.insert(key, int(cmd[2]))
		elif cmd[0] == 'find':
			if treap.find(key) != None:
				print('yes')
			else:
				print('no')
		else:
			treap.delete(key)



Measured memory_bytes: 52032
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
long double pi=3.141592653589793;
int main(void){
  double a,b,x;
  cin>>a>>b>>x;

  long double high=pi/2;
  long double low=0;
  long double pre=x/a;
  long double h;
  long double r;
  long double men;
  while(high>=low){
    r=(high+low)/2;
    h=b*tan((pi/2)-r);
    if(h<=a){
      men=b*h/2;
    }else{
      men=(b-a*tan(r)+b)*a/2;
    }
    if(men==pre){
      break;
    }else if(men>pre){
       low=r+0.0000000001;
    }else{
      high=r-0.0000000001;
    }
  }//while
  r*=180.0/pi;
  cout<<fixed<<setprecision(6)<<r<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
 
int H, W;
 
std::vector<std::pair<int,int>> dir = {{0,1}, {0,-1}, {1,0}, {-1,0}};
 
int calcLen(int i, int j, const std::vector<std::string>& grid) {
  std::vector<std::vector<int>> dp(H, std::vector<int>(W, -1));
  std::queue<std::pair<int,int>> queue;
  queue.emplace(i,j);
  dp[i][j] = 0;
  int result = 0;
  
  while (!queue.empty()) {
    auto cur = queue.front(); queue.pop();
    result = result > dp[cur.first][cur.second] ? result : dp[cur.first][cur.second];
    
    for (const auto & d : dir) {
      auto newy = cur.first + d.first;
      auto newx = cur.second + d.second;
      if (newy >= 0 && newy < H && newx >=0 && newx < W && grid[newy][newx] == '.' && dp[newy][newx] == -1) {
        queue.emplace(newy, newx);
        dp[newy][newx] = dp[cur.first][cur.second] + 1;
      }
    }
  }
  
  return result;
}
 
int main() {
  std::cin >> H >> W;
  std::vector<std::string> grid(H);
  for (int i=0; i<H; ++i) std::cin >> grid.at(i);
  
  long long result = 0;
  for (int i=0; i<H; ++i) {
    for (int j=0; j<W; ++j) {
      if (grid[i][j] == '#') continue;
      auto len = calcLen(i, j, grid);
      result = result > len ? result : len;
    }
  }
  std::cout << result << "\n";
}

Measured memory_bytes: 256
#include<stdio.h> 
#include<string.h> 
#include<algorithm> 
using namespace std; 
#define rep(i,s,t) for(int i=s;i<=(t);++i)
const int N=205;
struct E{int d,nxt;}es[N*N]; 
int en,n,a[N],b[N],c[N],d[N],ans,vis[N],g[N],mat[N];
void add(int s,int d){ 
	es[++en]=(E){d,g[s]},g[s]=en;
} 
bool dfs(int u){ 
    for(int i=g[u];i;i=es[i].nxt){ 
        int d=es[i].d; 
        if(vis[d])continue; 
        vis[d]=1; 
        if(!mat[d]||dfs(mat[d])){ 
            mat[d]=u; 
            return true; 
        } 
    } 
    return false; 
} 
int main(){ 
	scanf("%d",&n);
	rep(i,1,n)scanf("%d%d",a+i,b+i);
	rep(i,1,n)scanf("%d%d",c+i,d+i);
	rep(i,1,n)rep(j,1,n)if(a[i]<c[j]&&b[i]<d[j])add(i,n+j);
	rep(i,1,n){
		memset(vis,0,sizeof(vis));
		if(dfs(i))++ans;
	}
	printf("%d\n",ans);
    return 0; 
}


Measured memory_bytes: 256
h, w = [int(x) for x in input().split()]
m = [list(input()) for _ in range(h)]

def solve():
    x, y = 0, 0
    while x != w - 1 or y != h - 1:
        m[y][x] = '.'

        if y < h - 1 and m[y + 1][x] == '#':
            if x < w - 1 and m[y][x + 1] == '#':
                return False
            else:
                if '#' in m[y]:
                    return False
                y += 1
        elif x < w - 1 and m[y][x + 1] == '#':
            for i in range(h):
                if '#' == m[i][x]:
                    return False
            x += 1
        else:
            return False

    return True

print('Possible' if solve() else 'Impossible')


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
	int n,k,l;
	cin>>n>>k;
	l=2*k;
	int x[n],y[n],table[k+1][k+1];
	bool black[n];
	char c[n];
	rep(i,k+1)rep(j,k+1)table[i][j]=0;
	rep(i,n){
		cin>>x[i]>>y[i]>>c[i];
		x[i]%=l;
		y[i]%=l;
		black[i]=(c[i]=='B');
		if(x[i]>=k){
			x[i]-=k;
			black[i]=!black[i];
		}
		if(y[i]>=k){
					y[i]-=k;
					black[i]=!black[i];
		}
		if(black[i]){
			table[0][0]++;
			table[0][y[i]+1]--;
			table[x[i]+1][0]--;
			table[x[i]+1][y[i]+1]+=2;
		}
		else{
			table[0][y[i]+1]++;
			table[x[i]+1][0]++;
			table[x[i]+1][y[i]+1]-=2;
		}
	}
	rep(i,k)REP(j,1,k)table[i][j]+=table[i][j-1];
	rep(i,k)REP(j,1,k)table[j][i]+=table[j-1][i];
	int ans=0;
	rep(i,k)rep(j,k){
		table[i][j]=max(table[i][j],n-table[i][j]);
		ans=max(ans,table[i][j]);
	}
	cout<<ans<<endl;
  return 0;
  }

Measured memory_bytes: 5120