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

void main()
{
	while (1) {
		auto x = readln.chomp.split.map!(to!int);
		if (!x[0]) break;
		auto area = new char[][](x[1], x[0]);
		foreach (i; 0..x[1]) {
			area[i] = readln.chomp.map!(to!char).array;
		}
		int num[2];
		auto hu = ['W', 'B'];

		void solve(int i, int j, int type) {
			if (area[i][j] == '.') {
				num[type]++;
				area[i][j] = (hu[type] + 32).to!char;
			} else if (area[i][j] == hu[!type] + 32) {
				num[(!type).to!int]--;
				area[i][j] = 'd';
			}
			foreach (a; iota(-1, 2, 2)) {
				if (i + a >= 0 && i + a < x[1]) {
					if (area[i+a][j] != 'W' && area[i+a][j] != 'B' && area[i+a][j] != (hu[type] + 32).to!char && area[i+a][j] != 'd') {
						solve(i + a, j, type);
					}
				}
				if (j + a >= 0 && j + a < x[0]) {
					if (area[i][j+a] != 'W' && area[i][j+a] != 'B' && area[i][j+a] != (hu[type] + 32).to!char && area[i][j+a] != 'd') {
						solve(i, j + a, type);
					}
				}
			}
		}

		foreach (i; 0..x[1]) {
			foreach (j; 0..x[0]) {
				if (area[i][j] != 'W' && area[i][j] != 'B') continue;
				if (area[i][j] == 'W') solve(i, j, 0);
				else solve(i, j, 1);
			}
		}
		writeln(num[1], " ", num[0]);
	}
}

Measured memory_bytes: 2044
from collections import defaultdict
import queue

INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
	def __init__(self, graph, s, N):
		self.judge = "Yes"
		self.g = graph.graph
		self.Q = queue.Queue()
		self.dist = [INF] * N
		self.visit = ["No"] * N
		self.visit[s] = "Yes"
		self.dist[s] = 0
		self.Q.put(s)
		while not self.Q.empty():
			v = self.Q.get()
			for i in self.g[v]:
				if self.visit[i] == "No":
					self.dist[i] = self.dist[v] + 1
					self.Q.put(i)
					self.visit[i] = "Yes"
				else:
					if (self.dist[i] - self.dist[v]) % 2 == 0:
						self.judge = "No"

	def ans(self):
		return max(self.dist)

#処理内容
def main():
	#初期化
	N = int(input())
	L = []
	for i in range(N):
		S = list(input())
		L.append(S)
	G = Graph()
	for i in range(N):
		for j in range(i + 1, N):
			if L[i][j] == "1":
				G.add_edge(i, j)
				G.add_edge(j, i)
	#BFS
	jud = "Yes"
	A = - INF
	for i in range(N):
		bfs = BFS(G, i, N)
		A = max(bfs.ans(), A)
		if bfs.judge == "No":
			jud = "No"
	if jud == "No":
		print(-1)
	else:
		print(A + 1)

if __name__ == '__main__':
	main()

Measured memory_bytes: 52072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
   string s;cin>>s;
   int ans=0;
   for (int i = 0; i < s.size(); i++)
   {
      /* code */
      if (s[i]=='+')
      {
         ans++;

      }
      else
      {
         ans--;
      }
      
      
   }
   cout<<ans<<endl;
   }
   


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int k, n, a;
	cin >> k >> n;
	vector<int>v;
	int z = n;
	while (z--) {
		cin >> a;
		v.push_back(a);
	}
	int sum = 0;
	int x = v[0], y = v[v.size() - 1];
	for (int i = 0; i < n - 1; i++) {
		v[i] = v[i + 1] - v[i];
	}
	v[v.size() - 1] = 0;
	v.push_back(k - y + x);
	
	sort(v.begin(), v.end());
	v[v.size() - 1] = 0;
	for (int x : v)sum += x;
	cout << sum << endl;
}

Measured memory_bytes: 1400
use std::io;
use std::str::FromStr;
use std::collections::VecDeque;

type Point = (usize, usize);

fn input_tuple() -> (usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn push_queue(x: usize, y: usize, queue: &mut VecDeque<Point>, count: &mut Vec<Vec<usize>>, field: &mut Vec<Vec<char>>) {
    if field[y][x-1] == '.' {        
        queue.push_back((y, x-1));
        count[y][x-1] = count[y][x] + 1;
        field[y][x-1] = '#';
    }
    if field[y][x+1] == '.' {
        queue.push_back((y, x+1));
        count[y][x+1] = count[y][x] + 1;
        field[y][x+1] = '#';
    }
    if field[y-1][x] == '.' {
        queue.push_back((y - 1, x));
        count[y-1][x] = count[y][x] + 1;
        field[y-1][x] = '#';
    }
    if field[y+1][x] == '.' {
        queue.push_back((y + 1, x));
        count[y+1][x] = count[y][x] + 1;
        field[y+1][x] = '#';
    }
}

fn bfs(goal: Point, grid: &Vec<Vec<char>>, count: &mut Vec<Vec<usize>>) {
    let mut queue: VecDeque<Point> = VecDeque::new();
    let mut grid_buf: Vec<Vec<char>> = grid.to_vec();
    queue.push_back(goal);
    while (queue.len() > 0) {
        let point = queue.pop_front().unwrap();
        grid_buf[point.0][point.1] = '#';
        push_queue(point.1, point.0, &mut queue, count, &mut grid_buf);
    }
}

fn main() {
    let (h, w) = input_tuple();
    let mut grid: Vec<Vec<char>> = Vec::new();
    grid.push(vec!['#'; (w+2)]);
    for _ in 0..h {
        let s: String = input();
        let mut s: Vec<char> = s.chars().collect();
        s.insert(0, '#');
        s.push('#');
        grid.push(s);
    }
    grid.push(vec!['#'; (w+2)]);
    // println!("{:?}", grid);

    let mut max = 0;
    for i_g in 1..(h+1) {
        for j_g in 1..(w+1) {
            // println!("{}, {}", i_g, j_g);
            if grid[i_g][j_g] == '#' {
                continue;
            }
            let mut count: Vec<Vec<usize>> = vec![vec![0; grid[0].len()]; grid.len()];
            bfs((i_g, j_g), &grid, &mut count);        
            // println!("{:?}", count);
            for i in count {
                for j in i {
                    if j > max {
                        max = j;
                    }
                }
            }
        }
    }
    println!("{}", max);    
}


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

int n,m,q;
int a[50][4];
int b[10];

int dfs(int c) {
    if (c==n) {
        int sum=0;
        for (int i=0;i<q;i++)
            if (b[a[i][1]-1]-b[a[i][0]-1]==a[i][2])
                sum+=a[i][3];
        return sum;
    }
    int ans=0;
    for (int i=c==0?1:b[c-1];i<=m;i++) {
        b[c]=i;
        ans=max(ans,dfs(c+1));
    }
    return ans;
}

int main() {
    cin>>n>>m>>q;
    for (int i=0;i<q;i++)
        for (int j=0;j<4;j++)
            cin>>a[i][j];
    cout<<dfs(0)<<endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	public static void main(String[] __){
		String str=s.next();
		HashMap<Character,ArrayList<Integer>> h=new HashMap<>();
		for(char c='a';c<='z';c++){
			h.put(c,new ArrayList<>());
			h.get(c).add(-1);
		}
		
		for(int i=0;i<str.length();i++){
			final char c=str.charAt(i);
			h.get(c).add(i);
		}
		
		for(char c='a';c<='z';c++){
			h.get(c).add(str.length());
		}
		System.out.println(h.values().stream().mapToInt(o->{
			int max=-114514;
			for(int i=1;i<o.size();i++)
				max=Math.max(max,o.get(i)-o.get(i-1));
			return max;
		}).min().getAsInt()-1);
	}
}


Measured memory_bytes: 28756
n, m = map(int, input().split())

m //= 1000

k = min((m - n) // 4, m // 5)
if 9 * k >= 2 * (m-n):
    x = (m-n) - 4 * k
    y = 9 * k - 2 * (m-n)
    z = m - 5 * k
    print(x, y, z)
else:
    print(-1, -1, -1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

 long long modpow(long long n, long long k,long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
     int n,m,q;
     cin >> n >> m >> q;
     vector<vector<int>>a(600,vector<int>(600,0));
     vector<vector<int>>sum(600,vector<int>(600,0));
     for(int i = 0;i<m;i++){
        int l,r;cin >> l >> r;
        a[l][r]++;
     }
     for(int i = 0;i<=n;i++){
        for(int j = 1;i+j<=n;j++){
            sum[j][i+j] = a[j][i+j]+sum[j+1][i+j]+sum[j][i+j-1]-sum[j+1][i+j-1];
        }
     }
     while(q--){
        int l,r;cin >> l >> r;
        cout << sum[l][r] <<endl;
     }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    string copy = "abcdefghijklmnopqrstuvwxyz";
    rep(i,copy.size()) {
        bool flag = false;
        rep(j,s.size()) {
            if (copy[i] == s[j]) {
                flag = true;
            }
        }
        if (!flag) {
            cout << copy[i] << endl;
            return 0;
        } 
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))

codd = 0
cfour = 0

for i in range(n):
	if a[i]%2 != 0:
		codd += 1
	if a[i]%4 == 0:
		cfour += 1
ceven = n - cfour - codd

if cfour >= codd:
	print('Yes')
elif ceven == 0 and cfour + 1 == codd:
	print('Yes')
else:
	print('No')

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  ll x=0;
  rep(i,n){
    if(i%2==0) x+=a[i];
    else x-=a[i];
  }
  cout<<x<<" ";
  x/=2;
  rep(i,n-1){
    x=a[i]-x;
    cout<<x*2<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 2176
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	int resa,resb;
	while(n=in()){
		resa=0;resb=0;
		int a,b;
		int i;
		for(i=0;i<n;i++){
			cin>>a>>b;
			if(a>b)resa+=a+b;
			else if(a<b)resb+=a+b;
			else{resa+=a;resb+=b;}
		}
		cout<<resa<<" "<<resb<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <cstdio>
#include <numeric>

using namespace std;


int main()
{
	int n;

	cin >> n;

	cout << n * 2.0f * 3.14159265f << endl;

	return 0;
}

Measured memory_bytes: 3776
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
typedef long long ll;
#define N (1000000000+7)
using namespace std;
typedef pair<int, int> P;

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll prime[100010];
ll kaijo[200010];
void init() {
	kaijo[0] = 1;
	for (ll i = 1;i <= 200000;i++)kaijo[i] = (kaijo[i - 1] * i) % N;
}

ll inv(ll x) {
	ll res = 1;
	ll k = N - 2;
	ll y = x;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}

ll Comb(ll n, ll k) {
	ll b = kaijo[n];
	ll c = kaijo[n - k];
	ll d = kaijo[k];
	ll cd = (c*d) % N;
	return ((b%N)*(inv(cd)%N) + N) % N;
}


int main(void) {
	ll n, a, b, ans = 0;
	cin >> n >> a >> b;
	for (int i = 1;i <= n;i++) {
		int num = 0, object = 0;
		object = i;
		while (object > 9) {
			num += object % 10;
			object /= 10;
		}
		num += object;
		if (num >= a) {
			if (num <= b)ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
#define pb push_back
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; }

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)
cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

  ll n, m, count=0, ans=0;
  string s,t;
 
  cin >> s >> t;

  n= t.length();
  t= t.substr(0,n-1);

  if( s==t ){ cout << "Yes" << endl; }
  else { cout << "No" << endl; }

}

Measured memory_bytes: 3632
N, M, Q = map(int,input().split())

a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q
A = [0] * (N + 1)

ans = 0

def dfs(n):
  global N, M, Q, a, b, c, d, A, ans
  if n == N:
    sum_now = 0
    for i in range(Q):
      if (A[b[i]] - A[a[i]] == c[i]):
        sum_now += d[i]
    ans = max(ans, sum_now)
    return ans
  for i in range(min(A[n], M), M + 1):
    A[n + 1] = i
    dfs(n + 1)



for i in range(Q):
  a[i], b[i], c[i], d[i] = map(int, input().split())

A[0] = 1
dfs(0)

print(ans)


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll h,w;cin>>h>>w;
  vector<string> s(h),t(2*h);
  for(i=0;i<h;i++)cin>>s[i];
  for(i=0;i<2*h;i++){
    t[i]=s[i/2];
  }
  for(i=0;i<2*h;i++){
    cout<<t[i]<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  if(n % 2 == 0) {
    cout << 0.5 << endl;
  } else {
    double tmp = n;
    cout << ((n/2 + 1)/ tmp) << endl;
  }
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    ans = 0
    cumsum = [0] * (n + 1)
    for i in range(len(l)):
        cumsum[i+1] = cumsum[i] + l[i]
    for i in cumsum:
        if i <= x:
            ans += 1
        else:
            break
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9140
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

int main(void) {
	wchar_t S[4];

	wscanf(L"%ls", S);

	uint32_t price = 700;

	for (size_t idx = 0; idx < 3; idx++) {
		if (S[idx] == L'o') {
			price += 100;
		}
	}

	printf("%"PRIu32, price);

	return 0;
}


Measured memory_bytes: 128
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x-3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3), (x - n3 + 1) / 2 - 1, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Measured memory_bytes: 6328
from collections import deque

def getInts():
    return [ int(x) for x in input().split() ]

cache = {}
def f(x,y,z):
    if (x,y,z) in cache:
        return cache[(x,y,z)]
    
    v =  x**2+y**2+z**2+x*y+y*z+z*x
    cache[(x,y,z)] = v
    return v

[N] = getInts()
Q = deque([(0,0,0)])
V = set()
l = [f(0,0,0)]
ans = {}
while Q:
    x,y,z = Q.pop()
    l = list(filter(lambda x: x not in V and x[0]>=1 and x[1]>=1 and x[2]>=1 and f(*x) <= N, [ (x+1,y,z),(x,y+1,z),(x,y,z+1),(x+1,y+1,z+1) ]))
    for x in l:
        V.add(x)
        Q.appendleft(x)
        v = f(*x)
        if v not in ans:
            ans[v] = 1
        else:
            ans[v] += 1
for i in range(1, N+1):
    if i not in ans:
        print(0)
    else:
        print(ans[i])

Measured memory_bytes: 69736
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

vector<ll> to[200005];
vector<ll> ans;

void dfs(ll i, ll p = -1) {
  for (auto v : to[i]) {
    if (p == v) continue;
    ans[v] += ans[i];
    dfs(v, i);
  }
}

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

  for (ll i = 0; i < n-1; i++)  {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  for (ll i = 0; i < q; i++)  {
    ll p, x;
    cin >> p >> x;
    ans[p-1] += x;
  }
  dfs(0);
  for (ll i = 0; i < n; i++) {
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 24320
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val cArray = s.toCharArray()

    var max = 0
    for (i in 1..(cArray.size - 1)) {
        val countSame = countSame(cArray.slice(0..i), cArray.slice((i + 1)..(cArray.size - 1)))
        if (max < countSame) max = countSame
    }
    println(max)
}

fun countSame(ca1: List<Char>, ca2: List<Char>): Int {
    var count = 0
    for (c in 'a'..'z') {
        if (ca1.contains(c) && ca2.contains(c)) count++
    }
    return count
}

Measured memory_bytes: 35940
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int inf=1e9+7;
signed main(){
    int n,m,a,b;
    while(cin>>n>>m,n){
vector<int>G[500];
    for(int i=0;i<m;i++){
        cin>>a>>b;
        G[--a].push_back(--b);
        G[b].push_back(a);
    }
    vector<int>vec;
    set<int>st;
    st.insert(0);
    for(auto x:G[0]){
        vec.push_back(x);
        st.insert(x);
    }
    for(auto x:vec)
        for(auto y:G[x])
            st.insert(y);
    cout<<st.size()-1<<endl;}
}



Measured memory_bytes: 3168
#include <stdio.h>
#define N 100000
#define Q 50000
int binarySearch(int);
int n,S[N];
int main() {
  int i,q,c=0,T[Q],k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++) {
    k=binarySearch(T[i]);
    if(k > 0) c++;
  }
  printf("%d\n",c);
  return 0;
}

int binarySearch(int key) {
  int l,m,r;
  l = 0;
  r = n;
  while(l < r) {
    m = (l + r) /2;
    if(S[m] == key) return 1;
    else if(key < S[m]) r = m;
    else l = m + 1;
  }
  return 0;
}

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

int main() {
    long long int N, K, tmp, sum = 0;
    std::vector<long long int> H;
    std::cin >> N >> K;
    for (int i = 0; i < N; i++) {
        std::cin >> tmp;
        H.push_back(tmp);
    }
    std::sort(H.begin(), H.end(), std::greater<int>());
    for (long long int i = K; i < N; i++)sum += H[i];
    std::cout << sum << std::endl;

    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
void alert(vector<double> vec){
  for(int i=0; i<vec.size()-1; i++) cout << vec.at(i) << " ";
  cout << vec.at(vec.size()-1) << endl;
}

int main(){
  int64_t N, M; cin >> N >> M;
  priority_queue<double> A;
  double a;
  for(int64_t i=0; i<N; i++){
    cin >> a;
    A.push(a);
  }
  for(int64_t i=0; i<M; i++){
    a = A.top();
    A.pop();
    A.push(a/2.0);
  }
  int64_t sum = 0;
  for(int64_t i=0; i<N; i++){
    a = A.top();
    A.pop();
    sum += floor(a);
  }
  cout << sum << endl;
}

Measured memory_bytes: 1400
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;

  string n;
  cin >> n;

  bool flg = false;

  for(ii=0;ii<n.size();ii++){
    
    if(n[ii] == '7'){
      flg = true;
    }
    
  }

  if(flg){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3560
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io;
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::mem::{replace, swap};


// abcde
fn read_string() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line
}

// -3.2
fn read_as_primitive<T: FromStr>() -> T {
    let s = read_string();
    s.trim().parse().ok().expect("failed to parse input")
}

// 1 -3 0 999
fn read_as_collection<U: FromStr, T: FromIterator<U>>() -> T {
    let s = read_string();
    s.trim().split_whitespace().map(|s| s.parse().ok().expect("failed to parse")).collect()
}

// #.#.###..
fn read_as_chars<T: FromIterator<char>>() -> T {
    let s = read_string();
    s.trim().chars().collect()
}

// 1 abc
fn read_as_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let s = read_string();
    let elems: Vec<_> = s.trim().split_whitespace().collect();
    (
        elems[0].parse().ok().expect("failed to parse"),
        elems[1].parse().ok().expect("failed to parse"),
    )
}

// 1.5 -2 abc
fn read_as_triple<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let s = read_string();
    let elems: Vec<_> = s.trim().split_whitespace().collect();
    (
        elems[0].parse().ok().expect("failed to parse"),
        elems[1].parse().ok().expect("failed to parse"),
        elems[2].parse().ok().expect("failed to parse"),
    )
}

fn main() {
    let (ab, bc, ca): (i32, i32, i32) = read_as_triple();
    println!("{}", ab * bc / 2);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define all(x) (x).begin(), (x).end()

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif
    ull n, m;
    while (cin >> n >> m) {
        cout << (min(n, m) == 1? 1 : (n * m + 1) / 2) << endl;
    }

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define debug(x) cout << #x << '=' << x << '\n'
const long long MOD=1e9+7;
//const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C,K; cin >> A >> B >> C >> K;
    int ans=0;
    ans+=min(A,K); K-=min(A,K);
    K-=min(B,K);
    ans-=min(C,K);
    cout << ans << '\n';
}

Measured memory_bytes: 3600
N=int(input())
L=[]
for i in range(N):
    a,b=map(int,input().split())
    L.append([a+b,a-b])
L.sort()
#print(L)
ans=0
X=-10**9
for i in range(N):
    if L[i][1]>=X:
        ans+=1
        X=L[i][0]
print(ans)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int h,w;
    cin>>h>>w;
    vector<string>ans;
    ans.pb(string(w+2,'#'));
    rep(i,h){
        string s;
        cin>>s;
        s="#"+s+"#";
        ans.pb(s);
    }
    ans.pb(string(w+2,'#'));
    for(auto &s:ans)cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int r,c,i,j,s=0,f=0;
    int a[100][100],b[100]={0};
    scanf("%d %d",&r,&c);
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            printf("%d ",a[i][j]);
            s+=a[i][j];
            b[j]+=a[i][j];
        }
        printf("%d\n",s);
        s=0;
    }
    for(i=0;i<c;i++){
        printf("%d ",b[i]);
        f+=b[i];
    }
    printf("%d\n",f);
    return 0;
}


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

int main()
{
  int a, b, c, x;
  int s = 0, ans = 0;

  scanf("%d %d %d %d", &a, &b, &c, &x);

  for (int k = 0; k <= a; k++)
  {
    for (int i = 0; i <= b; i++)
    {
      for (int t = 0; t <= c; t++)
      {
        s = k * 500 + i * 100 + t * 50;
        if (s == x)
        {
          ans++;
        }
      }
    }
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string s1,s2,s3;
int def = 'A' - 'a';
int main(){
    cin >> s1 >> s2 >> s3;
    cout << (char)(s1[0] + def) << (char)(s2[0] + def) << (char)(s3[0] + def) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 200005
#define MAXM 4005
#define INF 1000000000
#define MOD 1000000007
#define INV 500000004
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int offset=2000;
int n,a[MAXN],b[MAXN],fact[2*MAXM],invf[2*MAXM];
int dp[MAXM][MAXM],coef[MAXM][MAXM];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;}
int pow_mod(int a,int i)
{
    int s=1;
    while(i)
    {
        if(i&1) s=1LL*s*a%MOD;
        a=1LL*a*a%MOD;
        i>>=1;
    }
    return s;
}
int comb(int n,int k)
{
    if(n<k) return 0;
    return 1LL*fact[n]*invf[k]%MOD*invf[n-k]%MOD;
}
int main()
{
    fact[0]=invf[0]=1;
    for(int i=1;i<=8000;i++) fact[i]=1LL*fact[i-1]*i%MOD;
    invf[8000]=pow_mod(fact[8000],MOD-2);
    for(int i=7999;i>=1;i--) invf[i]=1LL*invf[i+1]*(i+1)%MOD;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        add(dp[offset-a[i]][offset-b[i]],1);
        add(coef[offset+a[i]][offset+b[i]],1);
    }
    int ans=0;
    for(int i=0;i<=4000;i++)
        for(int j=0;j<=4000;j++)
        {
            add(ans,1LL*coef[i][j]*dp[i][j]%MOD);
            add(dp[i+1][j],dp[i][j]);
            add(dp[i][j+1],dp[i][j]);
        }
    for(int i=1;i<=n;i++) dec(ans,comb(2*a[i]+2*b[i],2*a[i]));
    ans=1LL*ans*INV%MOD;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 96384
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)

function PriorityQueue(){
    this.heap = [];
}
 
PriorityQueue.prototype = {
    push : function(x){
        var h = this.heap, i = h.length++, j;
        while(i){
            j = i-1 >> 1;
            if(h[j] <= x)break;
            h[i] = h[j];
            i = j;
        }
        h[i] = x;
    },
    pop : function(){
        var h = this.heap, r = h[0], x = h.pop();
        var i = 0, k = h.length >> 1, j;
        while (i < k) {
            j = (i << 1) + 1;
            if(h[j+1] < h[j])++j;
            if(x <= h[j])break;
            h[i] = h[j];
            i = j;
        }
        if(h.length)h[i] = x;
        return r;
    },
    size : function(){return this.heap.length;},
    top : function(){return this.heap[0];},
};

const Main = () => {
    let [N, M] = nextIntArray()
    const a = nextIntArray()
    a.sort((a,b) => b-a)
    let pq = new PriorityQueue()
    for(let i = 0;i<a.length;i++){
        pq.push(-a[i])
    }
    while(M>0){
        let tmp = -pq.pop()
        tmp = Math.floor(tmp/2)
        pq.push(-tmp)
        M--
    }
  let sum = 0
    while(pq.size()>0){
        sum += -pq.pop()
    }
    console.log(sum)
}
Main()



Measured memory_bytes: 45816
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
      Scanner scanner = new Scanner(System.in);
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      if (a>b) {
    	  System.out.println(  "a > b"  );
      } else if (a<b) {
    	  System.out.println(  "a < b"  );
      } else if (a==b) {
    	  System.out.println(  "a == b"  );
      }
      scanner.close();
  }
}


Measured memory_bytes: 26316
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}


void solve()
{
	map<string, int> st;
	int mx = 0;
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		string s;
		cin >> s;
		st[s]++;
		mx = max(mx, st[s]);
	}
	for(auto it : st){
		if(it.S == mx) cout << it.F << endl;
	}
}
 
 
 
 
int main()
{
    Red;
  	//int T; cin >> T; while(T--)
    solve();
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    
    int count =0;
    for(int i = 0; i<3 ; ++i){
        if(s[i] == '1'){
            ++count;
        }
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;

using ll = long long;
const int N = 1e5+5;

int main()
{
    ios_base::sync_with_stdio(0);

    char ch;
    cin >> ch;
    if(ch == 'A') cout << "T\n";
    if(ch == 'T') cout << "A\n";
    if(ch == 'C') cout << "G\n";
    if(ch == 'G') cout << "C\n";
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
using namespace std;

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}
int combination(int n, int k) {
	if (n > k && k > 0) {
		return (combination(n - 1, k) + combination(n - 1, k - 1));
	}
	else
		return 1;
}

int main() {
	long long int n, k;
	int a[2000];

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

	long long int s1 = 0, s2 = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			if (a[i] < a[j]) {
				s1++;
			}
		}
	}
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] < a[j]) {
				s2++;
			}
		}
	}
	long long int c1, c2;
	c1 = (k * (k + 1) / 2) % 1000000007;
	c2 = ((k - 1) * k / 2) % 1000000007;
	long long int x = (s1 * c1) % 1000000007;
	x += (s2 * c2) % 1000000007;
	x = x % 1000000007;
	cout << x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int BASE = 1e9 + 7;
const int LIM = 31622;

long long f[111][LIM + 5], g[111][LIM + 5];

int main()
{
  int n, k, m = 1;
  cin >> n >> k;
  while ((m + 1) * (m + 1) <= n)
    m++;

  for (int j = 1; j <= m; j++)
  {
    f[0][j] = 1;
    g[0][j] = n;
    f[1][j] = j;
    g[1][j] = (g[1][j - 1] + n / j) % BASE;
  }

  for (int i = 2; i <= k + 1; i++)
    for (int j = 1; j <= m; j++)
    {
      long long curF = (f[i - 1][m] + f[i - 2][j] * (n / j - m)) % BASE;
      long long difG = (g[i - 2][m] - g[i - 2][j] + BASE) % BASE;
      long long difF = (f[i - 2][m] - f[i - 2][j] + BASE) % BASE;
      long long toAdd = (difG - difF * m % BASE + BASE) % BASE;
      curF = (curF + toAdd) % BASE;
      g[i][j] = (g[i][j - 1] + curF * (n / j)) % BASE;
      f[i][j] = (f[i][j - 1] + curF) % BASE;
    }

  cout << f[k + 1][1] << endl;
}


Measured memory_bytes: 53504
#include<stdio.h>
int main()
{
  int N;
  scanf("%d",&N);
  int A[N],i;
  for(i=0;i<N;i=i+1)
  {
    scanf("%d",&A[i]);
  }
  
  int max,k,l;
  max=A[0]-A[1];
  for(k=0;k<N;k=k+1)
    for(l=0;l<N;l=l+1)
    {
      if(max<A[k]-A[l])
      {
        max=A[k]-A[l];
      }
    }
  printf("%d",max);
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  int m=n/2;
  vector<int> a(m);
  vector<int> b(m);
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i];
  }
  int cnt1=0;
  int cnt2=0;
  map<int,int> p;
  map<int,int> q;
  vector<pair<int,int>> p1;
  vector<pair<int,int>> q1;
  for(int i=0;i<m;i++){
    p[a[i]]++;
    q[b[i]]++;
  }
  for(pair<int,int> x:p){
    p1.push_back(make_pair(x.second,x.first));
  }
  for(pair<int,int> x:q){
    q1.push_back(make_pair(x.second,x.first));
  }
  sort(p1.rbegin(),p1.rend());
  sort(q1.rbegin(),q1.rend());
  cnt1=p1[0].first;
  cnt2=q1[0].first;
  if(p1[0].second==q1[0].second){
      if(cnt1>cnt2){
          cnt2=q1[1].first;
      }
      else if(cnt1==cnt2){
          cnt1=max(p1[1].first,q1[1].first);
      }
      else{
          cnt1=p1[1].first;
      }
  }
  cout << n-cnt1-cnt2 << endl;
}

Measured memory_bytes: 6520
#include <iostream>
#include <cmath>

int n;
int x[500];
int l[500*500];//[,)
int r[500*500];//(,]
int a[500*500];

int main()
{
	std::cin >> n;
	for(int i = 0;i < n; ++i){
		std::cin >> x[i];
	}
	
	for(int i = 1;i <= n; ++i){
		auto pos = x[i-1]-1;
		a[pos] = i;
		l[pos] = i-1;
		r[pos] = n - i;
	}
	int space_count = 0;
	int* a_iter = a;
	//lの判定
	for(int i = 0;i < n*n; ++i){
		if(l[i] == 0){
			if(a[i] == 0) ++space_count;
		}
		else{
			if(l[i] <= space_count){
				//左から埋める
				for(int j = 0;j < l[i]; ++j){
					while(*a_iter != 0){++a_iter;}
					*a_iter = a[i];
				}
				space_count -= l[i];
			}
			else{
				//埋められない
				std::cout << "No" << std::endl;return 0;
			}
		}
	}
	space_count = 0;
	a_iter = a+(n*n)-1;
	//rの判定
	for(int i = (n*n)-1;i >= 0; --i){
		if(r[i] == 0){
			if(a[i] == 0) ++space_count;
		}
		else{
			if(r[i] <= space_count){
				//右から埋める
				for(int j = 0;j < r[i]; ++j){
					while(*a_iter != 0){--a_iter;}
					*a_iter = a[i];
				}
				space_count -= r[i];
			}
			else{
				//埋められない
				std::cout << "No" << std::endl;return 0;
			}
		}
	}
	
	std::cout << "Yes" << std::endl;
	for(int i = 0;i < n*n; ++i){
		std::cout << a[i] << ' ';
	}
}


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

int main(){
  int t,s;
  vector<int> a(5);
  for(int i =0;i<5;i++){
    cin>>a.at(i);
  }
  cin>>t;
  s=a.at(4)-a.at(0);
  if(t<s){cout<<":("<<endl;}
  else{cout<<"Yay!"<<endl;}
}
  

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#define rep(i,n) for (int i = 0; i < (n);i++)
typedef long long ll;
using namespace std;
/*#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;*/


void Main()
{
    int n; cin>>n;
    vector<int> b(n-1);
    rep(i,n-1){
        cin>>b.at(i);
    }
    vector<int> a(n,0);
    a.at(0) = b.at(0);
    a.at(1) = b.at(0);
    for(int i=1;i<n-1;i++){
        if(a.at(i)>=b.at(i))
            a.at(i) = b.at(i);
        a.at(i+1)=b.at(i);
    }
    int sum = 0;
    rep(i,n){
        sum+= a.at(i);
    }
    cout << sum << endl;
    
}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){

  string tmp;

  cin >> tmp;

  int pr = 700;

  for (int i = 0; i<3; i++) if(tmp[i] == 'o') pr += 100;

  cout << pr << endl;

  return 0;
}


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

signed main(){
    int a,b;cin>>a>>b;
    int c=b-a;
    cout<<c*(c+1)/2-b<<endl;
}

Measured memory_bytes: 256
// SeeAlso: https://atcoder.jp/contests/abc060/tasks/abc060_b

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int a,b,c;

int main() {
    cin >> a >> b >> c;
    bool flag = false;
    for(int i=1;i<=b;i++) {
        if((i*a)%b==c){
            flag = true;
            break;
        }
    }
    print(flag?"YES":"NO");
    return 0;
}


Measured memory_bytes: 256
# 2019/12/27

h,w=map(int,input().split())
s=[list('#'*(w+2))]
for _ in range(h):
    s+=[list('#'+input()+'#')]
s+=[list('#'*(w+2))]

L,U,R,D=[[[0]*(w+2) for _ in range(h+2)] for _ in range(4)]

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="#":continue
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1

ans=0

for i in range(h,0,-1):
    for j in range(w,0,-1):
        if s[i][j]=="#":continue
        R[i][j]=R[i][j+1]+1
        D[i][j]=D[i+1][j]+1
        lit=L[i][j]+U[i][j]+R[i][j]+D[i][j]-3
        ans=max(ans,lit)
print(ans)

Measured memory_bytes: 308616
#include<stdio.h>
#include<math.h>

int main(void){
  int d,a;
  double x=0,y=0;
  int z=90;
  double i;
  while(1){
    scanf("%d,%d",&d,&a);
    if(d==0&&a==0){
      break;
    }else{
      i=M_PI*(double)z/180;
      x-=d*cos(i);
      y+=d*sin(i);
      z+=a;
    }
  }
  printf("%d\n",(int)x);
  printf("%d\n",(int)y);
  return 0;
}

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

#define ll long long 
#define N 200010
#define pii pair <int, int>
int n;
ll a[N], b[N], f[N], g[N], lazy; 

void Run()
{
	while (scanf("%d", &n) != EOF)
	{ 
		for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
		queue <pii> q; 
		f[n] = 0;
		for (int i = n - 1; i >= 1; --i)
		{
			f[i] = f[i + 1];
			if (a[i] > a[i + 1]) 
			{
				ll tmp = a[i + 1];
				int cnt = 0;
				while (tmp < a[i])
				{
					tmp *= 4;  
					cnt += 2;
				}
				int x = i;
				while (!q.empty())
				{
					f[i] += 1ll * (q.front().second - x) * cnt;
					if (q.front().first <= cnt) cnt -= q.front().first; 
					else
					{
						pii tmpp = q.front();
						tmpp.first -= cnt;
						cnt = 0;
						q.pop();
						q.push(tmpp);
						break;
					}
					x = q.front().second;
					q.pop();
				}
				f[i] += 1ll * (n - x) * cnt;
			}
			else
			{
				ll tmp = a[i];
				int cnt = 0;
				while (tmp * 4 <= a[i + 1])
				{
					tmp *= 4;
					cnt += 2;
				}
				if (cnt) q.push(pii(cnt, i));   
			}
		}
		while (!q.empty()) q.pop();
		g[1] = 1;
		b[1] = -a[1];
		for (int i = 2; i <= n; ++i)
		{
			g[i] = g[i - 1] + 1;
			b[i] = -a[i];
			if (b[i] < b[i - 1])
			{
				ll tmp = b[i - 1];
				int cnt = 0;
				while (tmp > b[i])
				{
					tmp *= 4;
					cnt += 2;
				}
				int x = i;
				while (!q.empty())
				{
					g[i] += 1ll * (x - q.front().second) * cnt; 
					if (q.front().first <= cnt) cnt -= q.front().first;
					else
					{
						pii tmpp = q.front();
						q.pop();
						tmpp.first -= cnt; 
						cnt = 0;
						q.push(tmpp);
						break;
					}
					x = q.front().second;
					q.pop();
				}
				g[i] += 1ll * (x - 1) * cnt;
			}
			else
			{
				ll tmp = b[i];
				int cnt = 0;
				while (tmp * 4 >= b[i - 1])
				{
					tmp *= 4;
					cnt += 2;
				}
				if (cnt) q.push(pii(cnt, i));
			}
		}
		ll res = min(f[1], g[n]);
		for (int i = 1; i < n; ++i) res = min(res, g[i] + f[i + 1]);
		printf("%lld\n", res);
	}
}


int main()
{
	#ifdef LOCAL
		freopen("Test.in", "r", stdin); 
	#endif 

	Run();
	return 0;
}

Measured memory_bytes: 6528