akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, Y; cin >> N >> Y;
    for(int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++) {
            int k = N - (i + j);
            if (i * 10000 + j * 5000 + k * 1000 == Y) {
                cout << i << " " << j << " " << k << endl;
                return;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[] a = new int[h];
        int[] b = new int[h];

        for(int i=0; i<h; i++) {
            a[i] = Integer.parseInt(sc.next())-1;
            b[i] = Integer.parseInt(sc.next())-1;
        }

        TreeMap<Integer, Integer> map = new TreeMap<>();
        Counter counter = new Counter();

        for(int i=0; i<w; i++) {
            map.put(i, 0);
        }
        counter.map.put(0, w);
        counter.map.put(w, 1);
        for(int i=0; i<h; i++) {
            Integer key;
            int rmin = w;
            while((key = map.ceilingKey(a[i])) != null && key <= b[i]) {
                rmin = Math.min(rmin, map.get(key) + b[i]+1-key);
                counter.remove(map.get(key));
                map.remove(key);
            }
            if(b[i]+1<w) {
                if (map.containsKey(b[i] + 1)) {
                    counter.remove(map.get(b[i] + 1));
                    int num = Math.min(rmin, map.getOrDefault(b[i] + 1, w));
                    map.put(b[i] + 1, num);
                    counter.add(num);
                } else {
                    map.put(b[i] + 1, rmin);
                    counter.add(rmin);
                }
            }
            int min = counter.head();
            if(min == w) {
                out.println(-1);
            } else {
                out.println(min + i + 1);
            }
        }
        out.flush();

    }

    static class Counter {
        TreeMap<Integer, Integer> map = new TreeMap<>();

        void add(Integer key) {
            map.put(key, map.getOrDefault(key, 0)+1);
        }
        void remove(Integer key) {
            int num = map.get(key);
            if(num == 1) {
                map.remove(key);
            } else {
                map.put(key, num-1);
            }
        }

        Integer head() {
            return map.firstKey();
        }
    }



}




Measured memory_bytes: 82200
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Int64Array []int64

func (a Int64Array) Len() int           { return len(a) }
func (a Int64Array) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Int64Array) Less(i, j int) bool { return a[i] > a[j] }

func main() {
	N := nextInt()
	M := nextInt()
	total := int64(0)
	discounts := make([]int64, 0)
	for i := 0; i < N; i++ {
		v := nextInt64()
		total += v
		for {
			if v < 1 {
				break
			}
			d := v / 2
			discounts = append(discounts, v-d)
			v = d
		}
	}
	var i64a Int64Array
	i64a = discounts
	sort.Sort(i64a)
	for i := 0; i < Min(M, len(i64a)); i++ {
		total -= i64a[i]
	}
	fmt.Println(total)
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func Max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Min(s, v)
	}
	return s
}

func MaxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Max(s, v)
	}
	return s
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 85760
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  string S;
  cin >> S;
  int dom=0, over=0; // 国内と海外の学生の数
  for (int i=0; i<N; i++) {
    if (S[i]=='a') {
      if (dom+over<A+B) {
        dom++;
        cout << "Yes" << endl;
      }
      else cout << "No" << endl;
    }
    else if (S[i]=='b') {
      if (dom+over<A+B&&over<B) {
        over++;
        cout << "Yes" << endl;
      }
      else cout << "No" << endl;
    }
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 896
N,K = map(int,input().split())
A = []
for i in range(K):
    d = int(input())
    A.append(list(map(int,input().split())))

snuke = [0]*N
for AA in A:
    for a in AA:
        snuke[a-1]+=1

ans = 0
for s in snuke:
    if s==0:
        ans += 1
print(ans)

Measured memory_bytes: 67752
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  int f[n][10], p[n][11];
  for(int i = 0; i < n; i++)
    for(int j = 0; j < 10; j++) cin >> f[i][j];
  for(int i = 0; i < n; i++)
    for(int j = 0; j < 11; j++) cin >> p[i][j];
  int res = -(1 << 30);
  for(int b = 1; b < (1 << 10); b++){
    int cc = 0;
    for(int i = 0; i < n; i++){
      int c = 0;
      for(int j = 0; j < 10; j++)
        if((b >> j & 1) && f[i][j]) c++;
      cc += p[i][c];
    }
    res = max(cc, res);
  }
  cout << res << endl;
  return 0;
}

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

using namespace std;

struct UnionFind {
  UnionFind(size_t size) : v(size, -1) {}
  vector<int> v;

  int root(int x) {
    return (v[x] < 0 ? x : v[x] = root(v[x]));
  }

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

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (v[x] > v[y]) swap(x, y);
      v[x] += v[y];
      v[y] = x;
    }
  }

  int size(int x) {
    return -v[x];
  }
};

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

  // bool s = false;
  // if (a < b) {
  //   swap(a, b);
  //   s = true;
  // }

  int ans[100][100] = {};

  for (int i = 50; i < 100; ++i) {
    for (int j = 50; j < 100; ++j) {
      ans[i][j] = 1;
    }
  }

  a--;
  b--;

  for (int i = 0; i < 50 && a; i += 2) {
    for (int j = 0; j < 50 && a; j += 2) {
      ans[i][j] = 1;
      a--;
    }
  }
  for (int i = 51; i < 100 && b; i += 2) {
    for (int j = 51; j < 100 && b; j += 2) {
      ans[i][j] = 0;
      b--;
    }
  }

  cout << 100 << " " << 100 << endl;
  for (int i = 0; i < 100; ++i) {
    for (int j = 0; j < 100; ++j) {
      cout << (ans[i][j] ? "." : "#");
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        int num1;
        int num2;
        String operation;

        Scanner input = new Scanner(System.in);
        while (true) {
            num1 = input.nextInt();
            //Scanner op = new Scanner(System.in);
            operation = input.next();

            num2 = input.nextInt();
            if (operation.equals("?")) {
                break;
            }

            if (operation.equals("+")) {
                System.out.println(num1 + num2);
            }
            if (operation.equals("-")) {
                System.out.println(num1 - num2);
            }
            if (operation.equals("*")) {
                System.out.println(num1 * num2);
            }
            if (operation.equals("/")) {
                System.out.println(num1 / num2);
            }
        }
    }
}


Measured memory_bytes: 26436
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

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

        Arrays.sort(a);

        for(int i = N-1;i >= 0;i -= 2){
            alice += a[i];
        }

        for(int i = N-2;i >= 0;i -= 2){
            bob += a[i];
        }
        System.out.println(alice - bob);
    }
}

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

using namespace std;

int main()
{
    set<int> s;
    for(int i = 0; i < 3; i++){
        int a;
        cin >> a;
        s.insert(a);
    }
    if(s.size() == 2){
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N;
    cin >> N;
    vector<int> t(N + 1), x(N + 1), y(N + 1);

    t[0] = 0;
    x[0] = 0;
    y[0] = 0;

    REP(i, N){
        cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
    }

    string ans = "Yes";

    REP(i, N){
        int dist = llabs(x[i + 1] - x[i]) + llabs(y[i + 1] - y[i]);
        int t0 = t[i + 1] - t[i];
        if(dist > t0 || (t0 - dist) % 2 == 1) ans = "No";
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 2560
import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w = map(int, read().split())
    s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int)
    left = s.copy()
    right = s.copy()
    up = s.copy()
    down = s.copy()
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print((left + right + up + down).max() - 3)


if __name__ == '__main__':
    main()


Measured memory_bytes: 228840
#include <iostream>
#include <algorithm>
#include <limits>
using namespace std;

static const int N = 1000;

int main() {
  int n, m[N+1][N+1], p[N+1];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i-1];
    cin >> p[i];
  }
  for (int i = 1; i <= n; i++) {
    m[i][i] = 0;
  }
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n-1; i++) {
      int j = i + l - 1;
      m[i][j] = numeric_limits<int>::max();
      for (int k = i; k <= j-1; k++) {
        m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k]* p[j]);
      }
    }
  }
  cout << m[1][n] << endl;
  return 0;
}



Measured memory_bytes: 3440
#include <stdio.h>
#define N 10000
int main(void)
{
    int n, a[N], i, j, max, min;
    long int sum=0;
     
    scanf("%d", &n);
     
    for(i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        sum = sum + a[i];
    }
    min = a[0];
    max = a[0];
    for(i = 0; i < n-1; i++) {
        if(min > a[i+1]) {
            min = a[i+1];
        }
        if(max < a[i+1]) {
            max = a[i+1];
        }
    }
    printf("%d %d %ld\n", min, max, sum);
    return 0;
}

Measured memory_bytes: 640
/*input
1 100 1
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{int res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(int* a, int* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	int l, r, d;
	cin >> l >> r >> d;
	int lo = 0;
	while(lo < l) {
		lo += d;
	}
	int hi = 100 * d;
	while(hi > r) {
		hi -= d;
	}
	if(lo <= hi) {
		cout << (hi - lo) / d + 1 << endl;
	}
	else {
		cout << "0" << endl;
	}
	return 0;
}




















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

int main() {
  long long x, k, d;
  cin >> x >> k >> d;
  
  if(x == 0) {
    if(k % 2 == 0) cout << 0 << endl;
    else cout << d << endl;
  }
  
  else if(d == 1 && x > 0) {
    if((x - k) >= 0) cout << x - k << endl;
    else if((x - k) < 0) {
      if((k - x) % 2 == 0) cout << 0 << endl;
      else cout << 1 << endl;
    }
  }
  
  else if(d == 1 && x < 0) {
     if((x + k) <= 0) cout << llabs(x + k) << endl;
    else if((x + k) > 0) {
      if((x + k) % 2 == 0) cout << 0 << endl;
      else cout << 1 << endl;
    }
  }
    
  else if(x > 0) {
    if(k < x / d) cout << x - (k * d) << endl;
    else {
      k -= (x / d);
      x %= d;
      if(llabs(x) < llabs(x - d)) {
        if(k % 2 == 0) cout << x << endl;
        else cout << llabs(x - d) << endl;
      }
      else {
        if(k % 2 == 1) cout << llabs(x - d) << endl;
        else cout << x << endl;
      }
    }
  }
    
    else if(x < 0) {
      if(k < llabs(x / d)) cout << llabs(x + (k * d)) << endl;
    else {
      k -= llabs(x / d);
      x %= d;
      if(llabs(x) < llabs(x + d)) {
        if(k % 2 == 0) cout << llabs(x) << endl;
        else cout << llabs(x + d) << endl;
      }
      else {
        if(k % 2 == 1) cout << llabs(x + d) << endl;
        else cout << llabs(x) << endl;
      }
    }
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll x;
    set < ll > s;
    int n;
    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> x;
        s.insert(x);
    }
    if(s.size() == n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
    cin>>n;
    ll a[n];
    ll freq[200001]={0};
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        freq[a[i]]++;
    }
    ll ans=0;
    for(i=0;i<200001;i++)
    {
        ans+=(freq[i]*(freq[i]-1))/2;
    }
    for(i=0;i<n;i++)
    {
        ll curr=ans+(1-freq[a[i]]);
        cout<<curr<<"\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 6792
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  vector<ll>a(n),f(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>f[i];
  ll suma=0;
  rep(i,n)suma+=a[i];

  ll ng=0,ok=2e18;
  if(suma<=k){
    cout<<0<<endl;
    return 0;
  }
  sort(all(a),greater<ll>());
  sort(all(f));
  auto check=[&](ll num){
    vector<ll>ta(n);
    rep(i,n){
      ta[i]=num/f[i];
    }
    ll res=0;
    rep(i,n){
      if(ta[i]>a[i])continue;
      res+=a[i]-ta[i];
    }
    return res<=k;
  };
  while(ok-ng>1){
    ll nn=(ok+ng)/2;
    if(check(nn))ok=nn;
    else ng=nn;
  }
  cout<<ok<<endl;
  return 0;

}


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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const int MAXN = 1e5 + 10;

int n;
vector<ll> a, neg, pos;

ll cntn = 0, cntp = 0, cnt0 = 0;

ll check(ll x) {
    if (x == 0) return cntn * cntp;
    if (x > 0) {
        ll ans = 0;
        int j = cntn - 1;
        for (int i = 0; i < cntn; i++) {
            while (j >= 0 && neg[i] * neg[j] >= x) j--;
            ans += max(0, j - i);
        }
        j = cntp - 1;
        for (int i = 0; i < cntp; i++) {
            while (j >= 0 && pos[i] * pos[j] >= x) j--;
            ans += max(0, j - i);
        }
        return ans + cntp * cntn + (cntp + cntn) * cnt0 + cnt0 * (cnt0 - 1) / 2;
    }
    int j = cntp;
    ll ans = 0;
    for (int i = 0; i < cntn; i++) {
        while (j > 0 && neg[i] * pos[j - 1] > -x) j--;
        ans += (cntp - j);
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll k;
    cin >> n >> k;
    a.resize(n);
    for (auto &c : a) {
        cin >> c;
        if (c < 0) {
            cntn++;
            neg.pb(-c);
        } else if (c == 0) {
            cnt0++;
        } else {
            cntp++;
            pos.pb(c);
        }
    }
    sort(all(neg));
    sort(all(pos));
    ll left = -INFLL, right = INFLL;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        if (check(mid) <= k - 1) left = mid;
        else right = mid;
    }
    cout << left;
    return 0;
}


Measured memory_bytes: 6656
n, a, b = map( int, input().split())

if n <= a:
    print(n)
elif n<=a+b:
    print(a)
else:
    count = a*(n//(a+b))
    amari = n%(a+b)
    if amari <= a:
         print(count+ amari)
    else:
        print(count+a)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#define N 20000
typedef struct Data{
  int area,posi;
}Data;
  
Data t[N];
int u[N],n,i,T,U,ans,A;
char str1[N+1];
  
Data X,Y;
  
void Dpush(Data data)
{
  t[T++]=data;
}
Data Dpop()
{
  return t[--T];
}
void push(int x)
{
  u[U++]=x;
}
int pop()
{
  return u[--U];
}
void init()
{
  ans=U=T=0;
}
  
Data mkData(int x,int y)
{
  Data res;
  res.area=x;
  res.posi=y;
  
  return res;
}
  
int main(){
  init();
  scanf("%s",str1);
  n=strlen(str1);
  
  for(i=0;i<n;i++){
  
    if(str1[i]=='/'){
      if(U==0)
    continue;
    A=pop();
    X=mkData(i-A,A);
    ans+=i-A;
    while(T>0){
      Y=Dpop();
      if(Y.posi<A){
        Dpush(Y);
        break;
      }
      X.area+=Y.area;
      if(Y.posi<X.posi)
        X.posi=Y.posi;
    }
    Dpush(X);
    }
    else if(str1[i]=='\\'){
      push(i);
    }
  }
  printf("%d\n%d",ans,T);
  for(i=0;i<T;i++){
    printf(" ");
    printf("%d",t[i].area);
  }
  printf("\n");
  return 0;
}

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

using namespace std;

int A[100005], B[100005], H[100005];

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n, m;
	cin >> n >> m;
	unordered_map<int, vector<int>> roads;
	for (int i = 1; i <= n; ++i) {
		cin >> H[i];
	}
	for (int i = 1; i <= m; ++i) {
		cin >> A[i] >> B[i];
		roads[A[i]].push_back(B[i]);
		roads[B[i]].push_back(A[i]);
	}
	int cnt = 0;
	bool good;
	for (int i = 1; i <= n; ++i) {
		if (roads.count(i)) {
			good = true;
			for (int j = 0; j < roads[i].size(); ++j) {
				if (H[i] <= H[roads[i][j]]) {
					good = false;
					break;
				}
			}
			if (good) {
				cnt++;
			} 
		}
		else {
			cnt++;
		}
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 12408
n=int(input())
s=list(input())
w=[0]*n
for i in range(n):
    if s[i]=="E":
        w[i]=1
from itertools import accumulate    
d=list(accumulate([0]+w))
ans=n
cnt=0
for i in range(n):
    cnt=i-d[i]+d[-1]-d[i+1]
    ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 84924
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

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

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N, M;
    cin >> N >> M;
    int maxgcd = M/N;
    while (maxgcd > 1) {
        int rest = M - maxgcd*N;
        if (rest % maxgcd == 0) break;
        else maxgcd--;
    }
    cout << maxgcd << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll k, x;
    cin >> k >> x;

    if (500*k >= x)
        cout << "Yes" << endl; 
    else
        cout << "No" << endl; 

    return 0;
}


Measured memory_bytes: 764
#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 a,b;
    cin>>a>>b;
    if(a+b>=10)cout<<"error"<<endl;
    else cout<<a+b<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()

	ans := 0
	for i := 1; i <= n; i++ {
		ans += i
	}

	fmt.Println(ans)
}

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

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, M, A, B;
    cin >> N >> M >> A >> B;
    char ans[N][M];
    fill(ans[0], ans[N], '.');
    if(M == 1 && A > 0) {cout << "NO" << endl; return 0;}
    if(N&1){
        rep(i, M/2){
            if(A <= 0) break;
            ans[N-1][2*i] = '<', ans[N-1][2*i+1] = '>';
            A--;
        }
    }
    if(!(A&1) || !(M&1) || !(N&1)){
        rep(i, N/2){
            if(A <= 0) break;
            rep(j, M/2){
                if(A <= 0) break;
                rep(k, 2){
                    if(A <= 0) break;
                    ans[2*i+k][2*j] = '<', ans[2*i+k][2*j+1] = '>';
                    A--;
                }
            }
        }
    }
    else{
        rep(i, N/2){
            if(A <= 1) break;
            rep(j, (M-3)/2){
                if(A <= 1) break;
                rep(k, 2){
                    if(A <= 1) break;
                    ans[2*i+k][2*j] = '<', ans[2*i+k][2*j+1] = '>';
                    A--;
                }
            }
        }
        rep(i, N-1){
            if(A <= 0) break;
            ans[i][M-2] = '<', ans[i][M-1] = '>';
            A--;
        }
    }
    if(A > 0) {cout << "NO" << endl; return 0;}
    rep(j, M){
        if(B <= 0) break;
        rep(i, N){
            if(B <= 0) break;
            if(i+1 < N && ans[i][j] == '.' && ans[i+1][j] == '.'){
                ans[i][j] = '^', ans[i+1][j] = 'v';
                B--;
            }
        }
    }
    if(B > 0) {cout << "NO" << endl; return 0;}
    cout << "YES" << endl;
    rep(i, N){
        rep(j, M) cout << ans[i][j]; cout << endl;
    }
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    string s;
    cin >> s;
    ll n = s.size();

    string t;
    rep(i, n) {
        if(i < n-1 && s[i] == 'B' && s[i+1] == 'C') {
            t.pb('D');
            i++;
        }
        else {
            t.pb(s[i]);
        }
    }

    ll m = t.size();
    ll ans = 0;
    ll cntA = 0;
    rep(i, m) {
        if(t[i] == 'A') {
            cntA++;
        } 
        else if(t[i] == 'D') {
            ans += cntA;
        }
        else {
            cntA = 0;
        }
    }

    out(ans);
    re0;
}

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

pair< int, int > a[111];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, t; cin >> n >> t;
	for(int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
	sort(a, a + n);
	for(int i = 0; i < n; ++i) if(a[i].second <= t) return cout << a[i].first , 0;
	cout << "TLE\n";
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;++i)
    {
        if(i%3!=0&&i%5!=0)
        sum+=i;
    }
    cout<<sum<<"\n";

}


Measured memory_bytes: 3572
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

const long long MOD = (long long)1e9 + 7;

int main(){
    int n, m;
    cin >> n >> m;
    vector<long long> x(n), y(m);
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < m; i++){
        cin >> y[i];
    }
    long long a = 0, b = 0;
    for(int i = 1; i < n; i++){
        a += i * x[i] - (n - i) * x[i - 1];
        if(a < 0){
            a += MOD * (long long)((abs(a) + MOD - 1) / MOD);
        }
        a %= MOD;
    }
    for(int i = 1; i < m; i++){
        b += i * y[i] - (m - i) * y[i - 1];
        if(b < 0){
            b += MOD * (long long)((abs(b) + MOD - 1) / MOD);
        }
        b %= MOD;
    }
    cout << (a * b) % MOD << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
int num;
int res;

int main() {
	cin >> n;
	while(n--) {
		cin >> num;
		while(!(num & 1)) {
			num /= 2;
			res++;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int64_t N, a = 10000000000000;
    cin >> N;
    for (int64_t i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            a = min(a, N / i + i);
        }
    }
    cout << a - 2 << endl;
}


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

int main()
{
    int n;
    double x1,y1,x2,y2,x3,y3,x4,y4;

    cin >> n;

    //a(x1,y1) b(x2,y2) c(x3,y3) d(x4,y4)
    for( int i = 0; i < n; i++ )
    {   
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;

        double px, py, qx, qy;
        px = x2 - x1;
        py = y2 - y1;
        qx = x4 - x3;
        qy = y4 - y3;

        if( fabs( px * qy - py * qx ) < 1e-10 )
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
N,x=map(int,input().split())
A=sorted(list(map(int,input().split())))
num=0
ans=0
for i in range(N):
    num=num+A[i]
    if x<num:
        ans=i
        break
    elif i!=N-1:
        continue
    elif num==x:
        ans=N
    else:
        ans=i
print(ans)

Measured memory_bytes: 3064
/* ----------------------- reclone_rk --------------------------------------------*/ 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mod=1e9+7;

#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define prq priority_queue<int>
#define prqp priority_queue<pair<int,int>>
#define vtr vector<int>
#define INF INT_MAX
#define NINF INT_MIN
#define endl "\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pvtr vector<pair<int,int>>
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)

int gcd(int a, int b){ if(a == 0) return b; return gcd(b%a, a);}
int MOD(int n){ return ((n%mod)+mod)%mod;}
int power(int a,int b){ if(b==0)return 1LL;int s=power(a,b/2LL);s*=s;s%=mod;if(b&1LL)return (s*a)%mod;return s;}
int inv(int a){return power(a,mod-2);}
int nCr(int n,int r){if(r>n)return 0LL;if(n-r<r)r=n-r;int ans=1;for(int i=0;i<r;i++){ans*=(n-i);ans=MOD(ans);ans*=inv(i+1);ans=MOD(ans);}return ans;}

const double pi = 3.14159265358979323846;
signed main()
{   
   int n;
   cin>>n;
   vector<int>a(n);
   int sum = 0;
   for(int i=0; i<n; i++)
   {
      cin>>a[i];
      sum += a[i];
   }
   if(sum%n == 0)
   {
      int ans = sum/n;
      int val = 0;
      for(int i=0; i<n; i++)
      {
         val += abs(ans - a[i]) * abs(ans - a[i]);
      }
      cout<<val<<endl;
   }
   else
   {
      int ans1 = sum/n;
      int ans2 = ans1 + 1;
      int val1 = 0;
      int val2 = 0;
      for(int i=0; i<n; i++)
      {
         val1 += abs(ans1 - a[i]) * abs(ans1 - a[i]);
         val2 += abs(ans2 - a[i]) * abs(ans2 - a[i]);

         
      }
      cout<<min(val1, val2)<<endl;
   }
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int a[100000+5],n;

void swp(int x,int y){
	int t=a[x];
	a[x]=a[y];
	a[y]=t;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]==i){
			swp(i,i+1);
			ans++;
		}
	}
	printf("%d",ans);
	return 0;
}	 


Measured memory_bytes: 512
#include<cstdio>
#include<cmath>

int min(int a,int b){ return a>b?b:a; }

int get_time(int u,int k){
    int L = 0, R = 20;
    int ans = -1;
    while(L<=R){
        int M = (L+R)/2;
        if(u*pow(2,M)>=k){ 
            ans = M;
            R = M-1;
        }
        else {
            L = M+1;
        }
    }
    return ans;
}

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    long double ans = 0;
    for(int i = 1; i <= n; i++){
        if(i>=k){
            ans += (1.0/n);
        }
        else {
            int t = get_time(i,k);
            ans += (1.0/n)*pow(0.5,t);
        }
    }
    printf("%.9Lf\n",ans);
    return 0;
}

Measured memory_bytes: 128
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
int mn[200005], mx[200005], par[200005], p[200005], v[200005];
vi G[200005];
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		mx[i] = INT_MAX/10, mn[i] = INT_MIN/10; par[i]=-1;
	}
	for(int i=1, u, v; i<=n-1; i++)
	{
		cin>>u>>v;
		G[u].eb(v);
		G[v].eb(u);
	}
	int k;
	cin>>k;
	for(int i=1; i<=k; i++) 
	{
		cin>>v[i]>>p[i];
		mx[v[i]] = mn[v[i]] = p[i];
	}
	priority_queue<ii> q1;
	for(int i=1; i<=k; i++)	q1.push({mn[v[i]], v[i]});
	while(!q1.empty())
	{
		int u = q1.top().se, d = q1.top().fi; q1.pop();
		if(d!=mn[u]) continue;
		for(auto v: G[u]) if(mn[v]<mn[u]-1)
		{
			mn[v] = mn[u]-1;
			q1.push({mn[v], v});
		}
	}
	priority_queue<ii, vii, greater<ii> > q2;
	for(int i=1; i<=k; i++) q2.push({mx[v[i]], v[i]});
	while(!q2.empty()) 
	{
		int u = q2.top().se, d = q2.top().fi; q2.pop();
//		cout<<u<<": "<<mx[u]<<endl;
		if(d!=mx[u]) continue;
		for(auto  v: G[u])
		{
//			cout<<mx[v]<<" "<<mx[u]<<endl;
			if(mx[v]>mx[u]+1) 
			{
				mx[v] = mx[u]+1;
				q2.push({mx[v], v});
			}
		}
	}
	par[v[1]] = p[1]%2;
	queue<int> q3; q3.push(v[1]);
	while(!q3.empty()) 
	{
		int u = q3.front(); q3.pop();
		if(mx[u]<mn[u] or (mx[u]==mn[u] and mx[u]%2!=(par[u]))) return cout<<"No", 0; 
		for(auto v: G[u])
		{
			if(par[v]<0) 
			{
				par[v] = par[u]^1;
				q3.push(v);
			}
			else 
			{
				if(par[v]!=(par[u]^1)) return cout<<"No", 0;
			}
		}
	}
	cout<<"Yes\n";
	for(int i=1; i<=n; i++) cout<<mn[i]<<endl;
}




Measured memory_bytes: 15504
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

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

int main() {
	unsigned ll n;
	cin >> n;
	
	string s = "";
	while(n) {
		n--;
		s.pb((char)('a' + n%26));
		n /= 26;
	}
	reverse(s.begin(), s.end());
	cout << s << endl;
	
	return 0;
}

Measured memory_bytes: 3596
use strict;
use warnings;

main();

sub main{

	my $line = <STDIN>;
	my $line2 = <STDIN>;
	chomp($line);
	chomp($line2);

	my @array = split(/ /,$line2);

	@array = sort {$b <=> $a} @array;

	my $scoreA = 0;
	my $scoreB = 0;
	my $cnt = 0;

	foreach my $in (@array){
		if($cnt%2 == 0){ $scoreA += $in }
		else           { $scoreB += $in }
		$cnt++;
	}

	print $scoreA-$scoreB."\n";
   
}


1;

Measured memory_bytes: 640
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)


int Len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}


int Sint(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int Svec(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}


int GCD(int a,int b){
  int r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


int LCM(int a,int b){
  int c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


int Factorial(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}


/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  long long int n;
  cin>>n;
  vector<long long int> c(5);
  rep(i,5) c[i]=0;
  rep(i,n){
    string s;
    cin>>s;
    if(s[0]=='M'){
      c[0]++;
    }else if(s[0]=='A'){
      c[1]++;
    }else if(s[0]=='R'){
      c[2]++;
    }else if(s[0]=='C'){
      c[3]++;
    }else if(s[0]=='H'){
      c[4]++;
    }
  }
  
    long long int ans=0;
    for(int i=0;i<3;i++){
      for(int j=i+1;j<4;j++){
        for(int k=j+1;k<5;k++){
          ans+=c[i]*c[j]*c[k];
        }
      }
    }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

bool bo[510][510];
ll tatenum[510];
ll yokonum[510];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    bool allwhite = true;
    REP(i, 0, N) {
        string s;
        cin >> s;
        REP(j, 0, N) {
            if (s[j] == '.') {
                bo[i][j] = false;
            } else {
                bo[i][j] = true;
                allwhite = false;
            }
        }
    }
    if (allwhite) {
        cout << -1 << endl;
        return 0;
    }
    fill(tatenum, tatenum + N, 0);
    REP(i, 0, N) {
        REP(j, 0, N) {
            if (bo[j][i]) {
                tatenum[i]++;
            }
        }
    }
    fill(yokonum, yokonum + N, 0);
    REP(i, 0, N) {
        REP(j, 0, N) {
            if (bo[i][j]) {
                yokonum[i]++;
            }
        }
    }
    ll yokoans = N;
    ll tateans = N;
    REP(i, 0, N) {
        if (tatenum[i] == N) {
            tateans--;
        }
        if (tatenum[i] == 0) {
            yokoans = min(yokoans, N - yokonum[i] + 1);
        } else {
            yokoans = min(yokoans, N - yokonum[i]);
        }
    }
    // cout << yokoans << " " << tateans << endl;
    ll ans = yokoans + tateans;
    cout << ans << endl;
}


Measured memory_bytes: 512
while 1:
    h,w=map(int,raw_input().split())
    if h==w==0: break
    ans=[['.' for v in range(w)] for x in range(h)]
    for i in range(h):
        for j in range(i%2,w,2):
            ans[i][j]='#'
    for i in range(h):
        print ''.join(ans[i])
    print ''

Measured memory_bytes: 4464
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if(s[0] != s[s.size()-1]) {
        s += s[0];
    }
    char c = s[0];
    int num = 0;
    for(int i = 1; i < s.size(); i++) {
        while(s[i] != c) {
            i++;
            num++;
        }
        num--;
    }
    cout << (num&1?"First":"Second") << endl;
}

Measured memory_bytes: 3760
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;

struct edge{
	int d,k,od,ok;
	double data;
}e[100000];
int pre[1000],id[1000],vis[1000];
double in[1000],tmp;
double a[120][120];
double d[120];
int n,m,nn,root;
double ans2;

double cal2(int p,int q,double k){
	for (int i=1;i<=m;++i) d[i]=a[p][i]-a[q][i]*k;
	double tmp = 0;
	for (int i=1;i<=m;++i) tmp+=d[i]*d[i];
	return tmp;
}

double cal(int p,int q){
	double l = -10000,r = 10000,mid1,mid2;
	while (r-l>1e-6){
		double tmp = (r-l)/3;
		mid1=l+tmp;
		mid2=mid1+tmp;
		if (cal2(p,q,mid1)<cal2(p,q,mid2)) r=mid2;
		else l=mid1;
	}
//	printf("%d %d %.2f\n",p,q,cal2(p,q,mid1));
	return cal2(p,q,mid1);
}

void addedge(int p,int q,double k,int od,int ok){
	e[++nn].k=q;
	e[nn].d=p;
	e[nn].od=od;
	e[nn].ok=ok;
	e[nn].data=k;
}

double work(int root){
	int sum=n;
	ans2=1e50;
	int oldroot=root;
	double res=0;
	while (1){
		for (int i=1;i<=sum;++i) in[i]=1e50;
		for (int i=1;i<=nn;++i){
			int u=e[i].d,v=e[i].k;
			if (e[i].data<in[v] && u!=v){
				if (e[i].od == oldroot) ans2=e[i].ok;
				pre[v]=u;
				in[v]=e[i].data;
			}
		}
		for (int i=1;i<=sum;++i){
			if (i==root) continue;
			if (in[i]>1e40) return -1;
		}
		int cntnode = 0;
		memset(id,-1,sizeof(id));
		memset(vis,-1,sizeof(vis));
		in[root] = 0;
		for (int i=1;i<=sum;++i){
			res+=in[i];
			int v=i;
			while (vis[v]!=i && id[v]==-1 && v!=root){
				vis[v]=i;
				v=pre[v];
			}
			if (v!=root && id[v]==-1){
				for (int u=pre[v];u!=v;u=pre[u]) id[u]=cntnode+1;
				id[v]=++cntnode;
			}
		}
		if (!cntnode) break;
		for (int i=1;i<=sum;++i)
			if (id[i]==-1) id[i]=++cntnode;
		for (int i=1;i<=nn;++i){
			int v=e[i].k;
			e[i].d=id[e[i].d];
			e[i].k=id[e[i].k];
			if (e[i].d!=e[i].k) e[i].data-=in[v];
		}
		sum=cntnode;
		root = id[root];
	}
	return res;
}
			
double cal3(int k){
	double tmp = 0;
	for (int i=1;i<=m;++i) tmp+=a[k][i]*a[k][i];
	return tmp;
}
			
int main(){
	while (scanf("%d%d",&m,&n)==2){
		nn=0;
		for (int i=1;i<=n;++i)
			for (int j=1;j<=m;++j) scanf("%lf",&a[i][j]);
		double tt = 0;
		for (int i=1;i<=n;++i)
			for (int j=1;j<=n;++j){
				addedge(i,j,cal(j,i),i,j);
//				printf("%d %d %.2f\n",i,j,e[nn].data);
			}
		++n;
		for (int i=1;i<n;++i){ 
			addedge(n,i,cal3(i),n,i);
//			printf("%d: %.2f\n",i,cal3(i));
		}
		root = n;
		printf("%.12f\n",work(root));
	}
	return 0;
}
			

Measured memory_bytes: 1196
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    dict = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
    for _ in range(N):
        c = input()
        dict[c] += 1
    print("AC x {}".format(dict['AC']))
    print("WA x {}".format(dict['WA']))
    print("TLE x {}".format(dict['TLE']))
    print("RE x {}".format(dict['RE']))



if __name__ == "__main__":
    main()


Measured memory_bytes: 73564
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a<b && c<d)
        printf("%d",a+c);
   else if(b<a && d<c)
        printf("%d",b+d);
       else if(a<b && d<c)
        printf("%d",a+d);
       else if(b<a && c<d)
        printf("%d",b+c);
        else if (a==b && c==d)
            printf("%d",a+c);
            else if (a==b && c<d)
            printf("%d",a+c);
            else if (a==b && d<c)
            printf("%d",a+d);
            else if (a<b && c==d)
            printf("%d",a+c);
            else if (b<a && c==d)
            printf("%d",c+b);

        return 0;
}


Measured memory_bytes: 1684
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int H=scan.nextInt();
    int W=scan.nextInt();
    int N=scan.nextInt();
    int[] a=new int[N];
    for(int i=0;i<N;i++){
      a[i]=scan.nextInt();
    }
    int[][] b=new int[H][W];
    int k=0,l=0;
    int line=1;
    for(int i=0;i<N;i++){
      for(int j=0;j<a[i];j++){
        if(line%2!=0){
          b[k][l]=i+1;
          k++;
        }else{
          k--;
          b[k][l]=i+1;
        }
        
        if(k==0||k==H){
          l++;
          line++;
        }
      }
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        System.out.print(b[i][j]+" ");
      }
      System.out.println();
    }
  }
}

Measured memory_bytes: 32528