akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

const int Maxn = 1010;

int x[Maxn], y[Maxn];


int main(){
    int n;
    cin >> n;
    REP(i,0,n){
        cin >> x[i] >> y[i];
    }

    ll t = x[0], a = y[0];
    REP(i,1,n){
        ll k = max((t + x[i] - 1) / x[i], (a + y[i] - 1) / y[i]);
        t = x[i] * k;
        a = y[i] * k;
    }

    cout << t + a << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = 0
f = 0
for i in range(n):
    p,x = input().split()
    x = int(x)
    if p == "(":
        s += x
    else:
        s -= x
        if s < 0:
            f = 1
if f or s != 0:
    print("NO")
else:
    print("YES")



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Og")
#pragma GCC push_options
#pragma GCC pop_options
#define bignum string
int sosanh(bignum s1, bignum s2)
{
    if (s1.length() > s2.length())
        return 1;
    if (s2.length() > s1.length())
        return -1;
    if (s1 == s2)
        return 0;
    if (s1 > s2)
        return 1;
    return -1;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    bignum a1, a2, aa, bb;
    aa = to_string(a);
    bb = to_string(b);
    for (int i = 1; i <= b; i++)
    {
        a1 += aa;
    }
    for (int i = 1; i <= a; i++)
    {
        a2 += bb;
    }
    if (sosanh(a1, a2) >= 0)
    {
        cout << a1;
    }
    else
    {
        cout << a2;
    }
}

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

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = input[0];
            var M = input[1];

            var ab = new long[N][];
            for (var i = 0; i < N; i++)
            {
                ab[i] = Console.ReadLine().Split().Select(long.Parse).ToArray();
            }
            Array.Sort(ab, (x, y) => x[0].CompareTo(y[0]));

            var temp = 0L;
            var result = 0L;
            for (var i = 0; i < N; i++)
            {
                if (M - temp > ab[i][1])
                {
                    result += ab[i][0] * ab[i][1];
                    temp += ab[i][1];
                }
                else
                {
                    result += ab[i][0] * (M - temp);
                    break;
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 24504
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int a;
    cin >> a;
    int b[200000];
    int minn;
    int ret=1;
    for(int i=0;i<a;i++)
    {
        cin >> b[i];
        if(i==0)
            minn=b[i];
        else
        {
            if(b[i]<=minn)
            {
                ret++;
                minn=b[i];
            }
        }

    }
    cout << ret;
    return 0;
}


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

int main() {
  int x;
  cin >> x;
  vector<bool> p(2 * x + 1, true);
  for (int i = 2; i < p.size(); i++) {
    if (!p[i]) continue;
    for (int j = 2 * i; j < p.size(); j += i) p[j] = false;
  }
  int r = x;
  while (r < p.size() && !p[r]) r++;
  cout << r << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int N, M;
vector<int> x(100000);
vector<int> y(100000);

void solve(){
	vector<int> table(N, 1);
  	vector<int> exis(N, 0);
  	exis[0] = 1;
  	int ans = 0;
  	for(int i = 0; i < M; ++i){
    	if(exis[x[i] - 1]) {
          	if(table[x[i] - 1] == 1) {
              	exis[x[i] - 1] = 0;
            }
        	exis[y[i] - 1] = 1;
        }
      	table[x[i] - 1]--;
      	table[y[i] - 1]++;
    }
  	for(int i = 0; i < N; ++i){
    	ans += exis[i];
    }
  	cout << ans;
}

int main(){
  	cin >> N >> M;
  	for(int i = 0; i < M; ++i){
    	cin >> x[i] >> y[i];
    }
  	solve();
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  int ans=0;
  cin>>a>>b;
  if(a>b){
    ans+=a;
    a--;
  }
  else{
    ans+=b;
    b--;
  }
  if(a>b){
    ans+=a;
  }
  else{
    ans+=b;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define s second
#define f first
using namespace std;
typedef pair<int,int> P;

struct data{
  int num,used,color;
  data(){};
  data(int a,int b,int c){
    num=a,used=b,color=c;
  }
};
map<P,data> Futon;
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
char dir;
bool ans;

void dfs(int y,int x){
  map<P,data>::iterator F=Futon.find(P(y,x));
  (*F).s.used=1;
  for(int i=0;i<4;i++){
    int ny=y+dy[i],nx=x+dx[i];
    if(!Futon.count(P(ny,nx)))continue;
    map<P,data>::iterator F1=Futon.find(P(ny,nx));
    if((*F1).s.color==-1){
      if((*F1).s.num==(*F).s.num)
	(*F1).s.color=!(*F).s.color;
      else
	(*F1).s.color=(*F).s.color;
    }else{
      if((*F1).s.num==(*F).s.num){
	if((*F1).s.color==(*F).s.color)
	  ans=false;
      }
      else if((*F1).s.color!=(*F).s.color)
	ans=false;
    }
    if(!(*F1).s.used)dfs(ny,nx);
  }
}

int main(){
  int n,x,y;
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin>>x>>y>>dir;
      Futon[P(y,x)]=data(i,0,-1);
      if(dir=='x')Futon[P(y,x+1)]=data(i,0,-1);
      else Futon[P(y+1,x)]=data(i,0,-1);
    }
    ans=true;
    map<P,data>::iterator ite=Futon.begin();
    while(ite!=Futon.end()){
      if(!(*ite).s.used){
	(*ite).s.color=0;
	dfs((*ite).f.f,(*ite).f.s);
      }
      ite++;
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    Futon.clear();
  }
  return 0;
}

Measured memory_bytes: 8736
import fractions
a,b,c,d=map(int,input().split())
g=fractions.gcd(c,d)
e=(c//g)*d
ans=(b//c-((a-1)//c))+(b//d-((a-1)//d))-(b//e-((a-1)//e))
print(b-a+1-ans)

Measured memory_bytes: 66156
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  string s;
  int p;
  multimap<string, int> mm;
  while(cin>>s>>p) {
    mm.insert(make_pair(s,p));
  }
  string mae;
  int f = 0;
  FOR(it, mm) {
    string ima = (*it).first;
    vector<int> v;
    REP(i,mm.count(ima)) {
      v.push_back((*(it++)).second);
    }
    it--;
    sort(ALL(v));
    cout << ima << endl;
    REP(i,v.size()) {
      if (i) cout << " ";
      cout << v[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
N=int(input())
if N==1:
    print(0)
else:
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])

        if temp!=1:
            arr.append([temp, 1])

        if arr==[]:
            arr.append([n, 1])

        return arr

    A=factorization(N)
    total=0
    for i in range(len(A)):
        for j in range(1,10**6):
            if j*(j+1)//2<=A[i][1]<(j+1)*(j+2)//2:
                total+=j
                break
    print(total)


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

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

int main() {
        int X;
        cin >> X;
        if (X >= 30) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
}


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

int main(){
    string s;
    cin >> s;
    
    int n = s.size();
    int ans = 0;
    
    for (int i = 0; i < n; i++){
        int temp = 0;
        for (int j = i; j < n; j++){
            if(s[j] == 'A' || s[j] == 'T' || s[j] == 'G' || s[j] == 'C') temp++;
            else break;
        }
        ans = max(ans, temp);
    }
    cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    int col[4][4];
    vector<int> h(n);
    vector<int> w(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i] >> w[i];
    }
    for (int i = 0; i < 4; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < 4; ++j) {
            if (s[j] == 'R') col[i][j] = 0;
            if (s[j] == 'G') col[i][j] = 1;
            if (s[j] == 'B') col[i][j] = 2;
        }
    }
    int match[4][5][4][5][3] = {};
    int mask[4][5][4][5] = {};
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            for (int k = i + 1; k < 5; ++k) {
                for (int l = j + 1; l < 5; ++l) {
                    for (int r = i; r < k; ++r) {
                        for (int s = j; s < l; ++s) {
                            mask[i][j][k][l] |= 1 << r * 4 + s;
                            match[i][j][k][l][col[r][s]] |= 1 << r * 4 + s;
                        }
                    }
                }
            }
        }
    }
    int dp[1 << 16];
    fill(dp, dp + (1 << 16), 32);
    queue<int> q;
    dp[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (int i = 0; i < n; ++i) {
            for (int j = 1 - h[i]; j < 4; ++j) {
                int m1 = max(j, 0), m3 = min(j + h[i], 4);
                for (int k = 1 - w[i]; k < 4; ++k) {
                    int m2 = max(k, 0), m4 = min(k + w[i], 4);
                    for (int c = 0; c < 3; ++c) {
                        int t = (p & ~mask[m1][m2][m3][m4]) | match[m1][m2][m3][m4][c];
                        if (dp[t] > dp[p] + 1) {
                            dp[t] = dp[p] + 1;
                            if (t == (1 << 16) - 1)
                            {
                                cout << dp[t] << "\n";
                                return 0;
                            }
                            q.push(t);
                        }
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 3560
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
	ll sum = 0, m = INF, n;
	cin >> n;
	REP(i, n) {
		ll a;
		cin >> a;
		sum += a;
		if (a % 2 == 1)m = min(m, a);
	}
	if (sum % 2 == 1)cout << (sum - m) / 2 << endl;
	else cout << sum / 2<< endl;
}





Measured memory_bytes: 3100
import java.util.*;

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

      int N=sc.nextInt();
      int[][] A = new int[N][2];

      for(int i=0;i<N;i++){
        A[i][0]=sc.nextInt();
        A[i][1]=sc.nextInt();
      }

    Arrays.sort(A, (a, b)->a[1]-b[1]);

    int sumA=0;

    for(int i=0;i<N;i++){
      sumA+=A[i][0];
      if(sumA>A[i][1]){
        System.out.println("No");
        break;
      }
      else if(i==N-1){
          System.out.println("Yes");
      }
    }


    }
}


Measured memory_bytes: 108520
import Control.Applicative ((<$>))
import Control.Monad (replicateM)

import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

import Data.List (unfoldr, foldl')
import Data.List (sort)
import Data.Char (isSpace)
import Data.Set (Set)
import qualified Data.Set as S

main :: IO ()
main = do
  n <- readLn
  solve n <$> replicateM n (sort <$> readil B.readInt <$> B.getLine) >>= print

solve :: Int -> [[Int]] -> Int
solve n = g . foldl' f S.empty
  where f st x = S.insert x st
        g st = n - S.size st

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')



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

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

  int a[n];
  double ans = 0.0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ans += 1.0 / a[i];
  }

  ans = 1.0 / ans;

  cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    vector<ll> dp(n,INF);
    dp[0] = 0;

    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            if(i+j >= n){
                break;
            }
            dp[i+j] = min(dp[i+j],dp[i] + abs(a[i+j] - a[i]));
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int INF=1<<30;
int solve(int x,int y){
	if(x<=y) return y-x;
	return INF;
}
signed main(){
	int x,y;
	cin >> x >> y;
	cout << min(min(solve(x,y),solve(-x,-y)+2),min(solve(-x,y)+1,solve(x,-y)+1)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll mod=(int)1e9+7;

int main()
{
	ios;
	ll n,d,x,y,c=0;
	double p;
	cin>>n>>d;
	while(n--)
	{
		cin>>x>>y;
		p=sqrt(x*x + y*y);
		
		
		if(p<=d) c++;
	}
	cout<<c;
		
	
	return 0;
}


Measured memory_bytes: 3664
from itertools import permutations

N = int(input())
P = ''.join(input().split())
Q = ''.join(input().split())

l = sorted(permutations(range(1, N + 1), N))
d = {''.join(map(str, k)): v+1 for v, k in enumerate(l)}
print(abs(d[P]-d[Q]))


Measured memory_bytes: 86884
#include<iostream>
#include<string>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define dist(a,b) max((a)-(b),(b)-(a))
#define yn(i) print((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}



int main(){
  li n,a,b; cin >>n >>a >>b;
  if(((b^a)&1)==0){
    print(dist(a,b)/2);
  }else{
    li x=a+b-1,y=n-a+n-b+1;
    if(x>y)swap(x,y);
    print(x/2);
  }
}





Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

#define mpr make_pair



int main()
{
    ios_base::sync_with_stdio(0);    cin.tie(NULL);    cout.tie(NULL);

    double r; cin>>r;
    cout<<2*M_PI*r;
    return 0;

}


Measured memory_bytes: 3804
#include<stdio.h>
#include <iomanip>

int main(void){
  	int n,k;
 	scanf("%d%d",&n,&k);
  	double prob = 0;
  	for(int j=1;j<=n;j++){
      	int p = j;
      	double c = 1;
  		for(int i=0;p<k;i++){
         	c/=2;
          	p*=2;
        }

      	prob = prob+c;
    }
  	prob /= n;
  
  	printf("%.16lf",prob);
}

Measured memory_bytes: 128
count = gets.to_i

arr = []

count.times { arr << gets.split(" ") }

arr.sort!

arr_c = []; arr_d = []; arr_h = []; arr_s = []

arr.each do |val|
  case val[0]
  when "C"
    arr_c << val[1].to_i
  when "D"
    arr_d << val[1].to_i
  when "H"
    arr_h << val[1].to_i
  else
    arr_s << val[1].to_i
  end
end

arr_c.sort!; arr_d.sort!; arr_h.sort!; arr_s.sort!
ans_c = []; ans_d = []; ans_h = []; ans_s = [];

ans_s << ((1..13).to_a - arr_s).map{ |val| "S" + " " + val.to_s }
ans_h << ((1..13).to_a - arr_h).map{ |val| "H" + " " + val.to_s }
ans_c << ((1..13).to_a - arr_c).map{ |val| "C" + " " + val.to_s }
ans_d << ((1..13).to_a - arr_d).map{ |val| "D" + " " + val.to_s }

puts ans_s
puts ans_h
puts ans_c
puts ans_d

Measured memory_bytes: 6120
N = int(input())

red = []
blue = []

for _ in range(N):
	a, b = map(int, input().split())
	red.append((a, b))

for _ in range(N):
	c, d = map(int, input().split())
	blue.append((c, d))

red.sort()
blue.sort()
count = 0

for b in blue:
	max_red_y = -1
	paired = (-1, -1)

	for r in red:
		# se o x de de red for maior que blue, nao faz nada
		if r[0] > b[0]:
			break
		# para red com o y menor que blue e maior que outros red
		# este sera o novo red com maior y
		# e sera o novo par de blue
		if max_red_y < r[1] < b[1]:
			max_red_y = r[1]
			paired = r
	# se houve atualizacao de pontos pareados
	# incrementa o count
	# e remove este ponto do red, para nao ser varrido nos proximos loops
	if paired != (-1, -1):
		red.remove(paired)
		count += 1

print(count)


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

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {

	int n;
	cin >> n;
	vector<string> w(n);
	FOR(i, n)cin >> w[i];

	bool ans = 1;
	FOR(i, n - 1) {
		if (w[i][w[i].length() - 1] != w[i + 1][0]) {
			ans = 0;
			break;
		}
	}
	FOR(i, n) {
		FOR(j, n) {
			if (i != j && w[i] == w[j])ans = 0;
		}
	}

	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t N, K;

    std::cin >> N >> K;

    std::vector<int64_t> As(N+1);

    for (int64_t i = 0; i < K; ++i) {
        int64_t d;
        std::cin >> d;
        for (int64_t j = 0; j < d; ++j) {
            int64_t a;
            std::cin >> a;
            As.at(a) = 1;
        }
    }

    int64_t ans = 0;
    for (int64_t i = 1; i < As.size(); ++i) {
        if (As.at(i) == 0) ans++;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    ll N;
    cin >> N;
    ll ans = 0;
    rep(i,1, N+1){
        ll tmp = N / i;
        ans += i * tmp * (tmp + 1) / 2;
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

const int BALL_NUM = 10;

static bool
judge_ball(const vector<int> &ball, const int right_head, const int left_head, const int fall_ball) {

	if (10 <= fall_ball) {
		return true;
	}

	if (right_head < ball.at(fall_ball)) {
		if (true == judge_ball(ball, ball.at(fall_ball), left_head, fall_ball + 1)) {
			return true;
		}
	}
	if(left_head < ball.at(fall_ball)) {
		if (true == judge_ball(ball, right_head, ball.at(fall_ball), fall_ball + 1)) {
			return true;
		}
	}

	return false;
}

int main(void) {
	// input
	int data_num;
	cin >> data_num;
	vector<vector<int>> ball_set(data_num, vector<int>(10,0));
	for (int i = 0; i < data_num; i++) {
		for (int j = 0; j < BALL_NUM; j ++) {
			cin >> ball_set.at(i).at(j);
		}
	}

// judge true or false
for (int i = 0; i < data_num; i ++) {
	// int right_head = ball_set.at(i).at(0)
	// int left_head = 0;
	// int fall_ball = 1;

	if (true == judge_ball(ball_set.at(i), ball_set.at(i).at(0), 0, 1)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

return 0;
}



Measured memory_bytes: 3128
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

constexpr int base = 50000;

std::string a, b, c;
bool ab[100000], ac[100000], bc[100000];

bool match( char ch1, char ch2 )
{ return ch1 == '?' || ch2 == '?' || ch1 == ch2; }

int main()
{
  std::cin >> a >> b >> c;

  int A = a.size();
  int B = b.size();
  int C = c.size();
  int ans = 1<<30;

  rep( ai, A ) rep( bi, B ) if( !match( a[ai], b[bi] ) )
    ab[bi-ai+base] = true;
  rep( ai, A ) rep( ci, C ) if( !match( a[ai], c[ci] ) )
    ac[ci-ai+base] = true;
  rep( bi, B ) rep( ci, C ) if( !match( b[bi], c[ci] ) )
    bc[ci-bi+base] = true;
  
  for( int i = -4000; i <= 4000; ++i ) for( int j = -4000; j <= 4000; ++j ) if( !ab[-i+base] && !ac[-j+base] && !bc[i-j+base] )
  {
    int L = std::min( 0, std::min( i, j ) );
    int R = std::max( A, std::max( i+B, j+C ) );

    ans = std::min( ans, R-L );
  }

  printf( "%d\n", ans );

  return 0;
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var d = new int[N];
            var ss = Console.ReadLine().Split();
            for (int i = 0; i < N; i++)
            {
                d[i] = int.Parse(ss[i]);
            }

            Array.Sort(d);

            if (d[N / 2 - 1] == d[N / 2])
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(d[N / 2] - d[N / 2 - 1]);
            }
        }
    }
}

Measured memory_bytes: 18784
module Main where

import Control.Applicative
import Text.Printf
import Numeric

main :: IO ()
main = do
  {[a,b] <- getInts
  ;let(x,y) = a `divMod` b
  ;let z = fromIntegral a / fromIntegral b
  ;putStrLn (unwords [showFFloat Nothing (fromIntegral x) ""
                     , showFFloat Nothing (fromIntegral y)""
                     , showFFloat Nothing  z ""])
   }
  
--

getInts :: IO[Int]
getInts = map read . words <$> getLine

putInt :: [Int] -> IO()
putInt = putStrLn . unwords. map show



Measured memory_bytes: 3996
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> p(m);
    vector<string> s(m);
    for(int i=0;i<m;i++){
        cin>>p[i]>>s[i];
    }
    bool ac[d5];
    bool last[d5];
    for(int i=0;i<d5;i++){
        ac[i]=false;
        last[i]=false;
    }
    for(int i=0;i<m;i++){
        if(s[i]=="AC"){
            last[p[i]]=true;
        }
    }
    int acnt=0,wcnt=0;
    for(int i=0;i<m;i++){
        if(ac[p[i]]){
            continue;
        }else{
            if(s[i]=="AC"){
                ac[p[i]]=true;
                acnt++;
            }else{
                if(last[p[i]]){
                    wcnt++;
                }
            }
        }
    }
    cout<<acnt<<' '<<wcnt<<endl;
}

Measured memory_bytes: 6656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var SN = DigitSum(N);

            Console.WriteLine(N % SN == 0 ? "Yes" : "No");
        }

        public static int DigitSum(int num)
        {
            var sum = 0;

            while (num > 0)
            {
                sum += num % 10;
                num = num / 10;
            }

            return sum;
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define pb push_back
#define pop pop_back
#define ff first
#define ss second
#define vec vector<int>
#define vec2 vector<vector<int> >
#define MOD 1000000007
typedef long long int lld;
#define rep(i,n) for(i=0;i<=n;i++)
#define repb(i,n) for(i=n-1;i>=0;i--)
#define repab(i,a,b) for(i=a;i<b;i++)
#define repba(i,a,b) for(i=b;i>=a;i--)
int gcd(int a,int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
int main()
{
    string s,t;
    cin>>s>>t;
    int a=s.compare(t.substr(0,s.size()));
    if(a==0&&t.size()-s.size()==1)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3632
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin >> n;
  cout << 3 * n * n << endl;  

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s,x;
    cin>>s>>x;
    if(s.size()==x.size())
    {

        for(int i=0;i<s.size();i++)
    {

        cout<<s[i]<<x[i];
    }
     return 0;
    }

    else
    {
        for(int i=0;i<x.size();i++)
    {

        cout<<s.at(i)<<x.at(i);
    }
    cout<<s.at(s.size()-1);

    }
     return 0;



}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n,x,i,j,k,count;

    count=0;
    while(1){
        scanf("%d %d",&n,&x);
        if(n==0 && x==0)break;
        for(i=1;i<=n;i++){
            for(j=i+1;j<=n;j++){
                for(k=j+1;k<=n;k++){
                    if(i+j+k==x)count++;
                }
            }
        }
        printf("%d\n",count);
        count=0;
    }



 return 0;
}

Measured memory_bytes: 600
N=int(input())
S=list(input())

T=[]
c=0
for i in range(10):
  T=S
  i=str(i)
  if i in T[:N-2]:
    indx_i=T.index(i) 
    for j in range(10):
      j=str(j)
      if j in T[indx_i+1:N-1]:
        indx_j=indx_i+T[indx_i+1:].index(j)+1
        for k in range(10):
          k=str(k)
          if k in T[indx_j+1:]:
            c+=1

print(c)

Measured memory_bytes: 3572
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    ev = [e for e in a if e % 2 == 0]
    c = [e for e in ev if e % 3 == 0 or e % 5 == 0]
    print('APPROVED' if len(ev) == len(c) else 'DENIED')
    

Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Deque;//push poll peek
import java.util.ArrayDeque;
import java.util.Queue;//add poll peek
import java.util.ArrayDeque;
import java.math.BigDecimal;

class Main{

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = Integer.parseInt(br.readLine());
		}
		int count = 0;
		int k = 0;
		int l;
		boolean flag = false;
		l = a[0] - 1;
		count += 1;
		while(count <= n){
			if(l == 1){
				flag = true;
				System.out.println(count);
				break;
			}
			l = a[l] - 1;
			count += 1;
		}
		if(!flag){
			System.out.println(-1);
		}
	}
}


Measured memory_bytes: 30764
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
 
using namespace std;
 
int main() {
  string s1, s2;
  cin >> s1;
  cin >> s2;
  int ans = s2.length();
  for (int i = 0; i < s1.length() - s2.length() + 1; ++i) {
    int diff = 0;
    for (int j = 0; j < s2.length(); ++j) {
      if (s1[i + j] != s2[j]) {
        diff += 1;
      }
    }
    ans = min(ans, diff);
  }
  
  printf("%d", ans);
  
  return 0;
}

Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {
	public static final int MAX_HIGHT = 100;

	public static int N;
	public static int[] h;

	public static void main(String[] args) {
		readInput();
		
		int water = 0;
		
		for(int hight = 0; hight < MAX_HIGHT; hight++) {
			for(int i = 1; i <= N; i++) {
				if(h[i] > hight && h[i-1] <= hight) {
					water++;
				}
			}
		}
		
		System.out.println(water);
	}

	public static void readInput() {
		try (Scanner sc = new Scanner(System.in)) {
			N = sc.nextInt();

			h = new int[N+1];

			for(int i = 1; i <= N; i++) {
				h[i] = sc.nextInt();
			}
		}
	}

}


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

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

  // 単純に国ごとのカウントをすればそれが道路の本数となる
  vector<int> counts(N, 0);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    counts[--a]++;
    counts[--b]++;
  }

  for (int c : counts) {
    cout << c << endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n,m,i,j,k,ans,r[200005],c[200005],a,b;
int findint(int i)
{
    if(r[i]==i)
      return i;
    return r[i]=findint(r[i]);
}
int main()
{
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
        r[i]=i;
        c[i]=0;
    }
    for(i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        a=findint(a);
        b=findint(b);
        if(a==b)
          continue;
        if(a<b)
          r[b]=a;
        else
          r[a]=b;
    }
    for(i=1;i<=n;i++){
        r[i]=findint(r[i]);
    }
    int mx=1;
    for(i=1;i<=n;i++){
        c[r[i]]++;
        mx=max(c[r[i]],mx);
    }
    printf("%d\n",mx);
    return 0;
}


Measured memory_bytes: 5396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int r,g,b;

	cin >> r >> g >> b;

	if ((100*r+10*g+b)%4==0) {
		cout << "YES" << endl;
	}

	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int INF=1<<30;

template <class RandomIt>
size_t msort(RandomIt first, RandomIt last) {
    if (first+1 >= last) return 0;

    using T=typename RandomIt::value_type;
    ptrdiff_t lhalf=(last-first)>>1;
    RandomIt mid=first+lhalf;

    size_t count_=0;
    count_ += msort(first, mid);
    count_ += msort(mid, last);

    ptrdiff_t rhalf=last-mid;
    vector<T> L(lhalf+1), R(rhalf+1);

    for (ptrdiff_t i=0; i<lhalf; ++i)
        L[i] = first[i];

    for (ptrdiff_t i=0; i<rhalf; ++i)
        R[i] = mid[i];

    L[lhalf] = R[rhalf] = INF;

    size_t i=0, j=0;
    for (RandomIt it=first; it<last; ++it) {
        if (L[i] <= R[j]) {
            *it = L[i];
            ++i;
        } else {
            *it = R[j];
            ++j;
        }
        ++count_;
    }

    return count_;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> S(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &S[i]);

    size_t t=msort(S.begin(), S.end());
    for (size_t i=0; i<n; ++i)
        printf("%d%c", S[i], i<n-1? ' ':'\n');

    printf("%zu\n", t);
    return 0;
}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10;
int a[N];

int main() {
  int n;
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  int be = a[n], pos = a[n] / 2, tmp = a[n] / 2;
  if(a[n] & 1) tmp = pos + 1;
  int ans = 1e9, ed = 0;
  for(int i = 1; i <= n; ++i) {
    int now = 0;
    if(a[i] >= pos) now = a[i] - pos;
    else now = tmp - a[i];
    if(ans > now) ans = now, ed = a[i];
  }
  printf("%d %d\n", be, ed);
  return 0;
}

/*
5
6 9 4 2 11

11 6
*/

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
	long int x, a;
	long int i, j;
	long int min = 10000;
	long int sum = 0, count = 0;
	long int first = 0, last = 0;
	long int flg;
	
	scanf("%ld%ld", &x, &a);
	
	if(x < a) {
		printf("0\n");
		return 0;
	} else {
		printf("10\n");
		return 0;
	}
	
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)
	var ans string
	if strings.ContainsRune(s, '9') {
		ans = "Yes"
	} else {
		ans = "No"
	}
	fmt.Println(ans)
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e18 + 5);

const int MAX_N = (int)(2e5 + 5);
const ll MAX_K = (int)(1e12 + 5);
const int MAX_LOG_NK = (int)(67);

int n;
ll k;
int a[MAX_N];

ll doubling[MAX_LOG_NK][MAX_N];
vector<int> s;
bool exist[MAX_N];

int make_doubling() {
  unordered_map<int, int> ump;

  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < n; ++j) {
      int ind = i * n + j;

      if (ump.find(a[ind % n]) == ump.end()) {
        ump[a[ind % n]] = ind;
      } else {
        int start = ump[a[ind % n]];
        if (start >= n) continue; // [0, n) is sufficient

        doubling[1][start] = ind + 1 - start;

        ump[a[ind % n]] = ind; // new start
      }
    }
  }

  int upper = min((int)(ceil(log2(n * k))), MAX_LOG_NK);

  for (int i = 2; i < upper; ++i) {
    for (int j = 0; j < n; ++j) {
      ll fst_buff = doubling[i - 1][j];
      int fst_ind = (int)(((ll)(j) + fst_buff) % n);
      ll snd_buff = doubling[i - 1][fst_ind];

      doubling[i][j] = (fst_buff + snd_buff);
      doubling[i][j] = (doubling[i][j] >= INF) ? INF : doubling[i][j]; // anyway, can't jump 
    }
  }

  return upper;
}

ll fast_simulate(int upper) {
  ll last = 0LL;

  while (true) {
    int ind = (int)(last % (ll)(n));
    bool flg = false;

    for (int i = upper - 1; i >= 1; --i) {
      if (last + doubling[i][ind] < (ll)(n) * k) {
        last += doubling[i][ind];
        flg = true; // jumped
        break;
      }
    }

    // printf("%lld\n", last);

    if (!flg) { // can't jump from current pos
      return last;
    }
  }
}

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &k);

  for (int i = 0; i < n; ++i) {
    scanf("%d", &(a[i]));
  }

  int upper = make_doubling();

  ll jump = fast_simulate(upper);

  for (ll j = jump; j < (ll)(n) * k; ++j) {
    int ind = (int)(j % (ll)(n));

    bool flg = false;

    while (exist[a[ind]]) {
      flg = true;
      exist[s.back()] = false;
      s.pop_back();
    }

    if (!flg) {
      s.push_back(a[ind]);
      exist[a[ind]] = true;
    }
  }

  for (auto &e : s) {
    printf("%d ", e);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 99656
#include <stdio.h>
int main(){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    if (x <= y && y <= z){
    printf("%d %d %d\n",x,y,z);
    } else if (x <= z && z <= y){
    printf("%d %d %d\n",x,z,y);
    } else if (y <= z && z <= x){
    printf("%d %d %d\n",y,z,x);
    } else if (y <= x && x <= z){
    printf("%d %d %d\n",y,x,z);
    } else if (z <= x && x <= y){
    printf("%d %d %d\n",z,x,y);
    } else {
    printf("%d %d %d\n",z,y,x);
    } return 0;
}


Measured memory_bytes: 1972
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

ll a[300003];

int main() {
	int n; cin >> n;
	for (int i = 0; i < 3*n; i++) cin >> a[i];
	sort(a, a + 3*n);
	ll ans = 0;
	int r = 3 * n - 1;
	for (int i = 0; i < n; i++) {
		r--;
		ans += a[r];
		r--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n ;
    cin >> n ;
    map<string,int> a , b ;
    for(int i = 0; i < n; i++){
        string x ;
        cin >> x ;
        a[x]++ ;
    }
    int m ;
    cin >> m; 
    for(int i = 0; i < m; i++){
        string x ;
        cin >> x ;
        b[x]++ ;
    }
    int ans = 0 ;
    for(auto &p : a){
        string word = p.first ;
        int cnt = p.second ;
        ans = max(ans, cnt - b[word]) ;
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 3664
import Data.Maybe
import Data.List
import qualified Data.ByteString.Char8 as C

parseInt :: C.ByteString -> Int
parseInt = fst . fromJust . C.readInt

data State = State
  { stOrd :: Ordering,
    stHas :: Bool,
    stOpt :: Integer
  } deriving (Show)

instance Eq State where
  (==) (State o1 h1 _) (State o2 h2 _) = o1 == o2 && h1 == h2

stPlus :: State -> State -> Integer
stPlus (State _ _ v1) (State _ _ v2) = v1 + v2

isOk :: State -> Bool
isOk (State EQ _ _) = True
isOk _ = False

reduceStates :: [State] -> Integer
reduceStates states = maximum $ map stOpt $ filter isOk states

isMatch :: State -> State -> Bool
isMatch (State o1 _ _) (State o2 _ _) =
  case (o1, o2) of
    (EQ, EQ) -> True
    (LT, GT) -> True
    (GT, LT) -> True
    _ -> False

match :: [State] -> [State] -> Integer
match [] [] = 0
match [] ss = match ss []
match ss [] = reduceStates ss
match ss1 ss2 = maximum $ [stPlus s t | s <- ss1, t <- ss2, isMatch s t]

f :: [Integer] -> [[State]]
f [] = []
f [x] = [[State LT False 0, State GT True x]]
f (x : xs) =
  foldl' merge [] (ss' >>= trans) : ss' : sss'
  where
  (ss' : sss') = f xs
  trans (State ord has opt) =
    if has
      then case ord of
        LT -> []
        GT -> [State EQ False opt]
        EQ -> [State LT False opt]
      else case ord of
        LT -> [State EQ True (opt + x)]
        GT -> [State EQ False opt]
        EQ -> [State GT True (opt + x), State LT False opt]
  merge states state =
    case partition (==state) states of
      ([], _) -> state : states
      ([State ord' has' opt'], states') -> State ord' has' (max opt' $ stOpt state) : states'
      _ -> error ""

main :: IO ()
main = do
  n <- parseInt <$> C.getLine
  as <- map (fromIntegral . parseInt) . C.words <$> C.getLine
  let s = f as
      t = reverse $ f $ reverse as
      ans = if n `mod` 2 == 0
        then reduceStates $ head s
        else maximum $ zipWith match (tail s ++ [[]]) ([] : init t)
  putStrLn $ show ans


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

int main() {
  ll n;
  cin >> n;
  ll ans=1e18;
  for(ll i=1; i*i <= n; i++) {
    if(n%i != 0) continue;
    ll j = n/i;
    ans = (ans, i+j-2); 
  }  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	int n, i, p, sum = 0,j;
	cin >> n;
	for (i = 1; i <= n; i++) {
		sum += i;
		if (sum >= n) {
			p = sum - n;
			for (j = 1; j <= i; j++)
				if (j != p)
					cout << j << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define ll long long
#define int ll
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using pii = pair<int, int>;
using cd = int;
const bool debug = 0;
const int mod = 1000000007;
const int rev2 = 5e8+4;
int a, b;
int32_t main()
{
  	usecppio
    int n; cin >> n;
    for (int i = 0; i<n; i++)
    {
        int x; cin >> x;
        a += x;
        b += x*x;
        a %= mod;
        b %= mod;
    }
    cout << ((((a*a)-b+mod)%mod)*rev2)%mod << '\n';
}

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

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

	int A, B, C, X;
	cin >> A >> B >> C >> X;

	int result = 0;
	for( int i = 0; i <= A; ++i ) {
		for( int j = 0; j <= B; ++j ) {
			for( int k = 0; k <= C; ++k ) {
				if( 500*i + 100*j + 50*k == X ) {
					result += 1;
				}
			}
		}
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256