akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int winner(vector<int> v,int k,int n){
	int *dp = new int[k+1];
	for(int i = 0;i<k+1;i++)
		dp[i] = 0;
	for(int i = 1;i<=k;i++){
		for(auto x:v){
			if(i>=x && dp[i-x]==0){
				dp[i] = 1;
				break;
				
			}
		}
	}
	return dp[k];
}
int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for(int i = 0;i<n;i++)
		{
			int c;
			cin>>c;
			v.push_back(c);
		}
	if(winner(v,k,n)==1)
		cout<<"First\n";
	else
		cout<<"Second\n";
	return 0;
}

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

typedef long long ll;

int main(){
 int n, m;
 cin >> n >> m;
 vector<int> x(m, 0);
 rep(i, m) cin >> x.at(i);
 sort(x.begin(), x.end());
 vector<int> kyori(m-1,0);
 rep(i, m-1) kyori.at(i) = x.at(i+1) - x.at(i);
// rep(i, m-1) cout << kyori.at(i) << endl;
 sort(kyori.begin(), kyori.end());

 ll ans = 0;
 rep(i, max(m-n, 0)){
   ans += kyori.at(i);
 }
 cout << ans;
}


Measured memory_bytes: 3972
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }

        static int Solve(int N)
        {
            var primes = new List<int>();
            for (int i = 2; i < 100; ++i)
            {
                if (primes.All(prime => i % prime != 0)) { primes.Add(i); }
            }
            var factors = new Dictionary<int, int>();
            for (int i = 2; i <= N; ++i)
            {
                int j = i;
                foreach (int prime in primes)
                {
                    if (j < prime) { break; }
                    while (j % prime == 0)
                    {
                        j /= prime;
                        if (!factors.ContainsKey(prime)) { factors[prime] = 0; }
                        ++factors[prime];
                    }
                }
            }
            var values = factors.Values.ToArray();
            int ans = 0;
            int C = values.Length;
            for (int i = 0; i < C; ++i)
            {
                int x = values[i];
                if (x >= 74) { ++ans; }
                for (int j = i + 1; j < C; ++j)
                {
                    int y = values[j];
                    if (x >= 4 && y >= 14) { ++ans; }
                    if (x >= 14 && y >= 4) { ++ans; }
                    if (x >= 2 && y >= 24) { ++ans; }
                    if (x >= 24 && y >= 2) { ++ans; }
                    for (int k = j + 1; k < C; ++k)
                    {
                        int z = values[k];
                        if (x >= 2 && y >= 4 && z >= 4) { ++ans; }
                        if (x >= 4 && y >= 2 && z >= 4) { ++ans; }
                        if (x >= 4 && y >= 4 && z >= 2) { ++ans; }
                    }
                }
            }
            return ans;
        }

        static void Main(string[] args)
        {
            Console.WriteLine(Solve(ReadInt()));
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 10, INF = 2e18;
int x[MAXN], dp[MAXN];
int n, e, t;
int32_t main () {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> e >> t;
    for (int i =0; i < n; ++i) {
        cin >> x[i];
        dp[i] = INF;
    }
    x[n] = e;
    int mn = INF;
    int point = n;
    for (int i = n - 1; i >= 0; --i) {
        while (x[point - 1] - x[i] > t / 2) {
            mn = min(mn,dp[point] + x[point] + 2 * x[point - 1]);
            --point;
        }
        dp[i] = min(mn - 3 * x[i], dp[point] + x[point] - x[i] + t);
    }
    cout << dp[0] + x[0];
    return 0;
}

Measured memory_bytes: 1792
N, X = map(int, input().split())

burger = [1]
patty = [1]
for i in range(N):
    burger.append(burger[i]*2 + 3)
    patty.append(patty[i]*2 + 1)
    
def f(N, X):
    if N == 0:
        if X <= 0:
            return 0
        else:
            return 1
    elif X <= burger[N-1] + 1:
        return f(N-1, X-1)
    else:
        return patty[N-1] + 1 + f(N-1, X-2-burger[N-1])

ans = f(N, X)
print(ans)

Measured memory_bytes: 9188
n,m,q=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(m)]
PQ=[list(map(int,input().split())) for _ in range(q)]

DP=[[0 for _ in range(n+1)] for _ in range(n+1)]
for l,r in LR:
    DP[l][r] +=1

for i in range(1,n+1):
    for j in range(1,n+1):
        DP[i][j]=DP[i-1][j]+DP[i][j]

for i in range(1,n+1):
    for j in range(1,n+1):
        DP[i][j]=DP[i][j-1]+DP[i][j]
        
for p,q in PQ:
    print(DP[q][q]-DP[q][p-1]-DP[p-1][q]+DP[p-1][p-1])

Measured memory_bytes: 109912
#include <bits/stdc++.h>
#include <algorithm>
// #include <cstdio>
// #include <iomanip>
// #include <iostream>
// #include <queue>
#include <cstdio>
#include <queue>

// 3
// 500 300 200

using namespace std;

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

  std::priority_queue<float, std::vector<float>, std::greater<float>> q;

  for (int i = 0; i < n; i++) {
    float v;
    scanf("%f", &v);
    q.push(v);
  }

  while (true) {
    float v1 = q.top();
    q.pop();
    float v2 = q.top();
    q.pop();

    float v3 = (v1 + v2) / 2.0;

    if (q.empty()) {
      cout << v3 << endl;
      break;
    }

    q.push(v3);
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("02")
#define ll long long
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
struct ios{
    inline char gc(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> _inline ios & operator >> (_Tp &x){
        static char ch,sgn; ch=gc(),sgn=0;
        for(;!isdigit(ch);ch=gc()){if(ch==-1)return *this;sgn|=ch=='-';}
        for(x=0;isdigit(ch);ch=gc())x=x*10+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}inc;
int n,a,b;
int main(){
	inc>>n>>a>>b;
	puts(abs(b-a)%2==0?"Alice":"Borys");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
using namespace std;
long long dis(long long x,long long y){
	return x*x+y*y;
}
long long n,d,x,y,ans;
int main(){
	scanf ("%lld%lld",&n,&d);
	for (register long long i=1;i<=n;++i){
		scanf ("%lld%lld",&x,&y);
		if (dis(x,y)<=d*d) ++ans;
	}
	printf ("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1708
#include <cstdio>

int main()
{
	int a, b, m = -10000;
	scanf("%d %d", &a, &b);
	m = m < a * b ? a * b : m;
	m = m < a + b ? a + b : m;
	m = m < a - b ? a - b : m;
	printf("%d", m);
}

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

int main() {
  int n; cin >>n;
  vector<string> s(n);
  string buf;
  for (int i=0; i<n; i++){
    cin >>buf; sort(buf.begin(), buf.end());
    s.at(i) = buf;
  }
  sort(s.begin(), s.end());
  
  ll ans = 0;
  int cnt = 0;
  for (int i=1; i<n; i++){
    if (s.at(i) == s.at(i-1)){
      if (cnt == 0){
        cnt+=2;
      }else{
        cnt++;
      }
    }else{
      ans += (ll)cnt*((ll)cnt-1)/2;
      cnt = 0;
    }
  }
  ans += (ll)cnt*((ll)cnt-1)/2;
  
  cout <<ans;
  cout <<endl;
}

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

int main(){
  int64_t N, M; cin >> N >> M;
  vector<int64_t> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  priority_queue<int64_t> Q;
  for(int i=0;i<N;i++){
    Q.push(A[i]);
  }  
  for(int i=0;i<M;i++){
    int k=Q.top()/2;
    Q.pop();
    Q.push(k);
  }
  int64_t ans=0;
  for(int i=0;i<N;i++){
    int k=Q.top();
    ans+=k;
    Q.pop();
  }
  cout << ans << endl;
}
    
  

Measured memory_bytes: 2168
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static Reader;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var n = NextInt;
        var m = NextInt;
        var p = NextInt;

        List<Edge>[] graph = Enumerable.Repeat(0, n).Select(_ => new List<Edge>()).ToArray();
        List<Edge>[] revGraph = Enumerable.Repeat(0, n).Select(_ => new List<Edge>()).ToArray();
        for (int i = 0; i < m; i++)
        {
            var s = NextInt - 1;
            var t = NextInt - 1;
            var c = NextInt;
            graph[s].Add(new Edge() { To = t, Cost = c - p });
            revGraph[t].Add(new Edge() { To = s, Cost = c - p });
        }
        var isAchivable = IsAchivable(graph, 0).Zip(IsAchivable(revGraph, n - 1), (x, y) => x & y).ToArray();
        long[] maxScore = Enumerable.Repeat(long.MinValue / 2, n).ToArray();
        maxScore[0] = 0;
        for (int _ = 0; _ < n; _++)
        {
            bool updated = false;
            for (int i = 0; i < n; i++)
            {
                if (!isAchivable[i]) continue;
                var max = revGraph[i].Count != 0 ? revGraph[i].Select(x => maxScore[x.To] + x.Cost).Max() : long.MinValue;
                if (maxScore[i] < max)
                {
                    updated = true;
                    maxScore[i] = max;
                }
            }
            if (!updated) goto end;
        }
        Console.WriteLine(-1);
        return;
        end:;
        Console.WriteLine(Max(0, maxScore.Last()));
    }

    static bool[] IsAchivable(List<Edge>[] graph, int start)
    {
        bool[] res = new bool[graph.Length];
        Stack<int> stack = new Stack<int>();
        stack.Push(start);
        res[start] = true;
        while (stack.Count > 0)
        {
            var elem = stack.Pop();
            foreach (var item in graph[elem])
            {
                if (res[item.To]) continue;
                res[item.To] = true;
                stack.Push(item.To);
            }
        }
        return res;
    }
}

struct Edge
{
    public int To;
    public int Cost;
}

static class Reader
{
    const int BUF_SIZE = 1 << 12;
    static Stream Stream = Console.OpenStandardInput();
    static byte[] Buffer = new byte[BUF_SIZE];
    static int ptr = BUF_SIZE - 1;
    static void Move() { if (++ptr >= Buffer.Length) { Stream.Read(Buffer, 0, BUF_SIZE); ptr = 0; } }


    public static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0; while (Buffer[ptr] < 48) Move();
            do { res = res * 10 + (int)(Buffer[ptr] ^ 48); Move(); } while (48 <= Buffer[ptr]);
            return res;
        }
    }
}


Measured memory_bytes: 20464
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 300010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y;
    cin >> x >> y;
    if (abs(x-y) <= 1) PRINT("Brown");
    else PRINT("Alice");
}


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

    int manhattandist(pair<int, int> x, pair<int, int> y) {
        int a = x.first - y.first;
        if(a < 0) a = 0 - a;
        int b = x.second - y.second;
        if(b < 0) b = 0 - b;
        return a + b;
    }

int main() {
    int sma = -2e9, smi = 2e9, bsma = -2e9, bsmi = 2e9;
    int n = 0;
    int ans = 0;
    cin >> n;
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        sma = max(sma, x + y);
        smi = min(smi, x + y);
        bsma = max(bsma, x - y);
        bsmi = min(bsmi, x - y);

    }
    ans = max(sma - smi, bsma - bsmi);
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    while (n!=0) {
        double score[n];
        double sum = 0,m;
        for (int i = 0; i < n; ++i) {
            cin >> score[i];
            sum +=score[i];
        }
        m = sum / n;
        sum = 0;
        for (int j = 0; j < n; ++j) {
            sum += (score[j]-m)*(score[j]-m);
        }
        cout<<fixed<<setprecision(8)<<sqrt(sum/n)<<endl;
        cin>>n;
    }
    return 0;
}



Measured memory_bytes: 3232
#include <stdio.h>

int main() {

  int x,y,z,z2,y2,x2;
  int m;
  int e,min;
  int i,j;

  while(1) {

    scanf("%d",&e);
    if(e == 0) break;
    x = 10000;
    min  = 1000000;

    for(j=0;j <=100;j++) {
      for(i=0;i<=1000;i++) {

	y2 = i * i;
	z2 = j * j * j;
	x2 = e - (j*j*j + i * i);


	if( x2 + i + j < min && x2 >= 0) {
	  z = j;
	  y  = i;
	  min = i + j + x2;
	  x = x2;
	  //  printf("z = %d\ny = %d\nx = %d\nmin = %d\n",z,y,x,min);
	}
      }
    }


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

  }

  return 0;

}

Measured memory_bytes: 600
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

int main() {
    int m = 13;
    string s;
    cin >> s;
    int n = s.length();
    VVI dp(n + 1, VI(m));
    dp[0][0] = 1;
    REP(i,n) REP(j,m) REP(k,10){
        if (s[i] != '?' && s[i] - '0' != k) continue;
        (dp[i + 1][(10 * j + k) % m] += dp[i][j]) %= mod;
    }
    cout << dp[n][5] << endl;

    return 0;
}


Measured memory_bytes: 8960
import Control.Arrow
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as IM
main=print.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(n:as)=maximum$zipWith(-)bs$reverse cs where
  (a1s,(a2s,a3s))=second(splitAt n).splitAt n$as
  bs=f IM.findMin(>)a1s a2s
  cs=f IM.findMax(<)a3s$reverse a2s
f f1 f2 as bs=(s:).snd.mapAccumL(g f1 f2)(s,m)$bs where
  s=sum as
  m=IM.fromList$map(head&&&length).group.sort$as
g f1 f2(s,m)a
  |f2 a b=let t=s-b+a in((t,IM.insertWith(+)a 1.IM.update(\i->if i>1 then Just(i-1) else Nothing)b$m),t)
  |otherwise=((s,m),s)
  where (b,_)=f1 m

Measured memory_bytes: 110848
#include <iostream>
#include <cmath>
#include <assert.h>
#include <vector>
#include <queue>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  for (int i=0; i<n; i++) {
    int a, b;
    cin >> a >> b;
    if (a > m) continue;
    jobs[m-a].push_back(b);
  }
  priority_queue<int> q;
  long long int ans = 0;
  for (int i = m-1; i >= 0; --i) {
    for (int b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5632
#include<iostream>
#include<cstdio>
using namespace std;
int main ()
{
	int a,b,t;
	scanf("%d%d%d",&a,&b,&t);
	int i,s=0;
	for(i=1;i<=t;++i)
	{
		if(i%a==0) s+=b;
	}
	printf("%d",s);
}

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

using namespace std;
using ll = long long;

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  if ((A<=C && C<=B) || (A>=C && C>=B))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
import sys
N = int(input())
k = input()
a = []
for i in range(N-1):
    a.append(input())
lis = [k]
for words in a:
  if words in lis:
    print('No')
    sys.exit()
  elif k[-1] != words[0]:
    print('No')
    sys.exit()
  else:
    lis.append(words)
    k = words
print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  ll N,K;
  cin>>N>>K;
  
  vector<char>D(K);
  
  rep(i,K){
    cin>>D[i];
  }
  
  
  for(ll i=N;i<=N*10;i++){
    string A=to_string(i);
    bool flag=true;
    for(ll j=0;j<A.size();j++){
for(ll l=0;l<K;l++){
  if(A[j]==D[l]){
    flag=false;
  }
}
    }
if(flag){
cout<<A<<endl;
  break;
}
  }
}

  
    

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

const int MAX_V = 1e2;
vector<int> graph[MAX_V];
bool used_v[MAX_V], used_e[MAX_V][MAX_V];
int ord[MAX_V], lowlink[MAX_V];
int k = 0;
int N, M;

void dfs(int v){
    used_v[v] = true;
    ord[v] = lowlink[v] = k++;
    for(int i = 0; i < graph[v].size(); i++){
        if(!used_v[graph[v][i]]){
            used_e[v][graph[v][i]] = true;
            dfs(graph[v][i]);
            lowlink[v] = min(lowlink[v], lowlink[graph[v][i]]);
        }else if(!used_e[graph[v][i]][v]){
            lowlink[v] = min(lowlink[v], ord[graph[v][i]]);
        }
    }
    return;
}

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b; cin >> a >> b; a--,b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(0);
    int ans = 0;
    for(int v = 0; v < N; v++){
        for(int j = 0; j < graph[v].size(); j++){
            int nv = graph[v][j];
            if(ord[v] < lowlink[nv]) ans++;
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int n, m, x, y, a[100], b[100], i;

   scanf("%d%d%d%d",&n,&m,&x,&y);
   for(i=0;i<n;i++){
      scanf("%d",&a[i]);
      if(x<a[i])
         x=a[i];
   }
   for(i=0;i<m;i++){
      scanf("%d",&b[i]);
      if(y>b[i])
         y=b[i];
   }

   if(x<y)
      printf("No War\n");
   else
      printf("War\n");
   return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    // 'A' = 0, 'G' = 1, 'C' = 2, 'T' = 3 と数を対応させる

    ll dp[n+1][4][4][4] = {};  // dp[i+1][c3][c2][c1] : 長さi(iは0-index)で末尾３文字がc3,c2,c1のときの場合の数のmodでの剰余

    dp[0][3][3][3] = 1LL;
    rep(i, n) {
        rep(c3, 4) {
            rep(c2, 4) {
                rep(c1, 4) {
                    // nextは次に置く文字
                    rep(next, 4) {

                        if(c2 == 0 && c1 == 1 && next == 2) {
                            continue;
                        }

                        if(c3 == 0 && c1 == 1 && next == 2) {
                            continue;
                        }

                        if(c3 == 0 && c2 == 1 && next == 2) {
                            continue;
                        }

                        if(c2 == 1 && c1 == 0 && next == 2) {
                            continue;
                        }

                        if(c2 == 0 && c1 == 2 && next == 1) {
                            continue;
                        }

                        dp[i+1][c2][c1][next] += dp[i][c3][c2][c1]; 
                        dp[i+1][c2][c1][next] %= mod;
                    }
                }
            }
        }
    }

    ll ans = 0;
    rep(c3, 4) {
        rep(c2, 4) {
            rep(c1, 4) {
                ans += dp[n][c3][c2][c1];
                ans %= mod;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

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

int main() {
	//cout<<"GfG!";
	string s,t;
	cin>>s>>t;
	int i=0;
	int mini=INT_MAX;
	while(i<((int)(s.size())-(int)(t.size())+1))
	{
	    int counts=0;
	    int j=i;
	    while(j<i+(int)(t.size()))
	    {
	        if(t[j-i]!=s[j])
	        counts++;
	        j++;
	    }
	    mini=min(mini,counts);
	    i++;
	}
	cout<<mini<<endl;
	return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
int a[3][MAXN],n,tg[3],to[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<3;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	for(int i=1;i<=n;i++)
	{
		to[i]=a[1][i]/3+1;
		if(!((a[0][i]%3==1&&a[1][i]==a[0][i]+1&&a[2][i]==a[0][i]+2)||(a[0][i]%3==0&&a[1][i]==a[0][i]-1&&a[2][i]==a[0][i]-2))||((to[i]&1)!=(i&1)))
		{
			printf("No\n");
			return 0;
		}
		tg[i&1]^=(a[0][i]>a[1][i]);
	}
	for(int i=1;i<=n;i++)
	{
		while(to[i]!=i)
		{
			tg[i&1^1]^=1;
			swap(to[i],to[to[i]]);
		}
	}
	if(tg[0]||tg[1]) printf("No\n");
	else printf("Yes\n");
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;


int main()
{
    int A, B, C, ans;

    cin >> A;
    cin >> B;
    cin >> C;

    int count = B / A;
    
    if (count <= C) {
        ans = count;
    }
    else if(count > C) {
        ans = C;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
start = 1
end = M
while True:
  if start>=end:
    break
  print(start,end)
  start+=1
  end-=1
  
start = M+1
end = 2*M+1
while True:
  if start>=end:
    break
  print(start,end)
  start = start+1
  end = end-1

Measured memory_bytes: 9280
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet<String> a = new HashSet<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.next());
        }
        System.out.println(a.size());
    }
}


Measured memory_bytes: 77084
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    char a, b;
    cin >> a >> b;

    if(a == 'H'){   
        if(b == 'H')
            cout << 'H' << endl;
        else
            cout << 'D' << endl;

    }else{
        if(b == 'D')
            cout << 'H' << endl;
        else
            cout << 'D' << endl;
    }

}

Measured memory_bytes: 256
x=int(input())
if x>=400 and x<=599:
    kyuu=8
elif x<=799:
    kyuu=7
elif x<=999:
    kyuu=6
elif x<=1199:
    kyuu=5
elif x<=1399:
    kyuu=4
elif x<=1599:
    kyuu=3
elif x<=1799:
    kyuu=2
elif x<=1999:
    kyuu=1
print(kyuu)


Measured memory_bytes: 61616
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_054
{
    class C
    {
        static int n;
        static Stack<int> visitPos;
        static Node[] nodes;
        static long cnt;

        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            nodes = new Node[n];
            for (int i = 0; i < n; i++)
            {
                nodes[i] = new Node();
            }
            for (int i = 0; i < m; i++)
            {
                string[] inText = Console.ReadLine().Split(' ');
                int a = int.Parse(inText[0]) - 1;
                int b = int.Parse(inText[1]) - 1;
                nodes[a].to.Add(b);
                nodes[b].to.Add(a);
            }

            /*for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < nodes[i].to.Count; j++)
                {
                    Console.WriteLine(nodes[i].to[j]);
                }
            }*/

            cnt = 0;
            visitPos = new Stack<int>();
            visitPos.Push(0);
            DFS();

            Console.WriteLine(cnt);
        }

        static void DFS()
        {
            if (visitPos.Count == n)//全部行った
            {
                cnt++;
                return;
            }

            //行ける場所探索
            int index = visitPos.Peek();
            for (int i = 0; i < nodes[index].to.Count; i++)
            {
                if (!visitPos.Contains(nodes[index].to[i]))
                {
                    visitPos.Push(nodes[index].to[i]);
                    DFS();
                    visitPos.Pop();
                }
            }
        }
    }

    class Node
    {
        public List<int> to;

        public Node()
        {
            to = new List<int>();
        }
    }
}


Measured memory_bytes: 13404
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int n, m, X, Y, x, y;
	cin >> n >> m >> X >> Y;
	int xmax = INT_MIN, ymin = INT_MAX;
	REP(i, n){
		cin >> x;
		if(x >= xmax) xmax = x;
	}
	REP(i, m){
		cin >> y;
		if(y <= ymin) ymin = y;
    }

    int z = ymin;
    bool piece = true;
    if(X >= z || Y < z) piece = false;

    if(ymin > xmax && piece) cout <<"No War" << endl;
    else cout << "War" << endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, m;
char a[2005][2005], b[2005][2005];

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

  cin >> n >> m;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      cin >> a[i][j];
    }
  }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      cin >> b[i][j];
    }
  }
  int ans = 0;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      if(a[i][j] != b[i][j]) ans++;
    }
  }
  cout<< ans << endl;

  return 0;
}



Measured memory_bytes: 11056
#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>

using namespace std;

int main() {

	long long N,a[5];
	long long sum = 0;
	long long min = 999999999999999999;
	int min_id = 0;

	cin >> N;

	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		if (min > a[i]) {
			min = a[i];
			min_id = i;
		}
	}

	long long  turn = 0;
	turn = N / min+1;

	if (N % min == 0)
		turn--;

	sum = turn + 4;

	
	cout << sum << endl;
}



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

using namespace std;

int N;

using pii = pair<int, int>;

int par[123123];

int get(int x) {
  return par[x] == x ? x : (par[x] = get(par[x]));
}

int main() {
  scanf("%d", &N);
  vector<pii> xs, ys;
  for(int i = 0; i < N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    xs.emplace_back(x, i);
    ys.emplace_back(y, i);    
    par[i] = i;
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());

  vector<tuple<int, int, int>> edges;
  for(int i = 1; i < N; i++) {
    edges.emplace_back(xs[i].first - xs[i-1].first, xs[i-1].second, xs[i].second);
    edges.emplace_back(ys[i].first - ys[i-1].first, ys[i-1].second, ys[i].second);
  }

  sort(edges.begin(), edges.end());
  long long ans = 0;
  for(auto it : edges) {
    int c, u, v; tie(c, u, v) = it;
    u = get(u); v = get(v);
    if(u != v) {
      ans += c;
      par[u] = v;
    }
  }
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 7528
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

int main()
{
    int a, b, c, n;
    string s;
    //cin >> a >> b >> c;
    cin >> a >> c;
    //cin >> a;
    //cin >> s;
    int sum = 3 * a + c;
    cout << sum / 2 << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	boolean[] leap = new boolean[3001];
	setLeap(leap);
	int data = 0;
	while(kbd.hasNext()){
	    int a = kbd.nextInt();
	    int b = kbd.nextInt();
	    if(a!=0 && b!=0 && data>0){
		System.out.println();
    		solve(a, b, leap);
		data++;
	    }
	    else if(a!=0 && b!=0){
		solve(a, b, leap);
		data++;
	    }
	}
    }

    static void solve(int a, int b, boolean[] leap){
	int i, cnt=0;
	for(i=a; i<=b; i++){
	    if(leap[i]){
		System.out.println(i);
		cnt++;
	    }
	}
	if(cnt == 0)
	    System.out.println("NA");
    }

    static void setLeap(boolean[] l){
	int i;
	for(i=0; i<l.length; i++){
	    if(i%4 == 0) l[i] = true;
	    if(i%100 == 0) l[i] = false;
	    if(i%400 == 0) l[i] = true;
	}
    }
}

Measured memory_bytes: 20696
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define arr(n) array<int,n>
#define INF 1e9
typedef long long ll;
typedef pair<int,int> pii;

int main(){
  ll K;
  cin >> K;
  ll x = 0;
  rep(i,30000000){
    x = (x * 10 + 7) % K;
    if (x == 0){
      cout << (i + 1) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int maxn=1e5+5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    char ans[10];
    cin>>ans;
    int flag=0;
    if(ans[0]==ans[1]&&ans[2]==ans[1]) flag=1;
    if(ans[1]==ans[2]&&ans[2]==ans[3]) flag=1;
    if(flag==1) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)

int w,h;
char map[55][55];
int bn=0,wn=0;
bool isb,isw;

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

int dfs(int y,int x){
	int res=0;
	switch(map[y][x]){
	case 0:
		return 0;
	case 'W':
		isw = true;
		return 0;
	case 'B':
		isb = true;
		return 0;
	case '.':
		map[y][x] = 0;
		res++;
		rep(i,4){
			res += dfs(y+dy[i],x+dx[i]);
		}
		return res;
	}
}

void sdfs(int y,int x){
	isb = isw = false;
	int no = dfs(y,x);
	if(isw && (!isb))wn+=no;
	else if(isb && (!isw))bn+=no;
}

int main(void){
	while(1){
		scanf("%d%d",&w,&h);
		if(w==0)break;
		memset(map,0,sizeof(map));
		rep(y,h){
			scanf("%s",map[y+1]+1);
		}
		wn=bn=0;
		reg(y,1,h){
			reg(x,1,w){
				if(map[y][x]=='.'){
					sdfs(y,x);
				}
			}
		}
		printf("%d %d\n",bn,wn);
	}
	return 0;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int flag=0;
    string s1,s2;
    cin>>s1>>s2;
    for(int i=0;i<s1.size();i++)
    {
        if(s1[i]!=s2[i])
        {
            cout<<"No";
            flag=1;
            break;
        }
    }
    if(flag==0)
    cout<<"Yes";    
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
string s,t;
int s_s,t_s;
int dp[3010][3010];
string n;
int main(){
	cin>>s>>t;
	for(int i=0;i<s.size();++i){
		for(int j=0;j<t.size();++j){
			if(s[i]==t[j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
      		dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
      		dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
		}
	}
	s_s=s.size();
	t_s=t.size();
	while(s_s>0 && t_s){
		if(dp[s_s][t_s]==dp[s_s-1][t_s])s_s--;
		else if(dp[s_s][t_s]==dp[s_s][t_s-1])t_s--;
		else {
			n=s[s_s-1]+n;
      		s_s--;
      		t_s--;
		}
	}
	cout<<n<<endl;
	return 0;
}


Measured memory_bytes: 35584
#include <stdio.h>

int main(){
  int N;
  int i,j;
  long int count = 0;
  scanf("%d",&N);
  
  for(i=1;i<N;i++){
    for(j=1;j<N;j++){
      if(i*j < N) count++;
      else break;
    }
  }
  
  printf("%ld\n",count);
  
  return 0;
}

Measured memory_bytes: 1736
#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<long> A(3 * N);
    for (int i = 0; i < 3 * N; ++i)
        cin >> A[i];

    multiset<long> leftSet;
    long leftSum = 0;
    for (int i = 0; i < N; ++i) {
        leftSet.insert(A[i]);
        leftSum += A[i];
    }

    multiset<long> rightSet;
    long rightSum = 0;
    for (int i = N; i < 3 * N; ++i) {
        rightSet.insert(A[i]);
        rightSum += A[i];
    }

    multiset<long> rightRemaining;
    for (int i = 0; i < N; ++i) {
        auto iter = rightSet.end();
        --iter;
        rightRemaining.insert(*iter);
        rightSum -= *iter;
        rightSet.erase(iter);
    }

    long best = leftSum - rightSum;
    for (int i = 0; i < N; ++i) {
        long x = A[N + i];

        if (x > *leftSet.begin()) {
            leftSum -= *leftSet.begin();
            leftSet.erase(leftSet.begin());
            leftSet.insert(x);
            leftSum += x;
        }

        auto remIter = rightRemaining.find(x);
        if (remIter != rightRemaining.end()) {
            rightRemaining.erase(remIter);
        } else {
            auto iter = rightSet.find(x);
            rightSum -= x;
            rightSet.erase(iter);
            remIter = rightRemaining.begin();
            rightSet.insert(*remIter);
            rightSum += *remIter;
            rightRemaining.erase(remIter);
        }

        // cerr << leftSum << " " << rightSum << endl;
        best = max(best, leftSum - rightSum);
    }

    cout << best << '\n';
    return 0;
}


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

template<typename T>
T power(T x, long long k){
  T ret{1};
  while(k > 0){
    if(k&1) ret *= x;
    x *= x;
    k /= 2;
  }
  return ret;
}

int main(){
  int X;
  cin >> X;
  auto sqrt5 = [](long long A){
                   long long ok = -1000, ng = 1000;
                   while(ng-ok > 1){
                     long long m = (ok+ng)/2;
                     long long a = power(m,5);
                     if(a <= A) ok = m;
                     else ng = m;
                   }
                   return ok;
                 };
  
  for(long long B = -1000; B <= 1000; ++B){
    long long X_ = X + power(B,5);
    long long A = sqrt5(X_);
    if(power(A,5) == X_){
      cout << A << " " << B << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// import here

int main(){
    LL n;
    cin >> n;
    vector<LL> a(n), b(n);
    LL total = 0;
    for(LL i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
        total += a[i];
    }

    for(LL i = 0; i < n; ++i){
        if(b[i] > a[i]){
            b[i] -= a[i];
            a[i] = 0;
        }
    }
    LL best = total;
    for(LL i = 0; i < n; ++i){
        if(a[i] - b[i] > 0){
            best = min(best, b[i]);
        }
    }
    cout << total - best << endl;
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    int n,d;
    cin >> n >> d;
    int array[n][d];
    int count = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> array[i][j];
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            float aaa = 0;
            for(int k = 0; k < d; k++){
                float an = pow(array[i][k] - array[j][k],2);
                aaa += an;
                if(k == d-1){
                    float ans = sqrt(aaa);
                    int ceans = ceil(ans);
                    if(ans == ceans){
                        count++;
                    }
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
before = 0, 0, 0
for _ in range(int(input())):
    tt, tx, ty = map(int, input().split())
    bt, bx, by = before
    distance = abs(tx - bx) + abs(ty - by)
    t = tt - bt
    if t < distance or t % 2 != distance % 2:
        break
    before = tt, tx, ty
else:
    print('Yes')
    exit()
print('No')


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

//Function Macros:
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main()
{
    ull N;
    cin >> N;
    cout << (ull)(N * (N-1) / 2) << endl; 
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    
    public static void main(String[] args) {

        Scanner sc = null;
        sc = new Scanner(System.in);
        String n = sc.next();
        sc.close();
        String c = null;
        long sum = 0;
        for (int i=0; i < n.length(); i++) {
            c = n.substring(i, i + 1);
            sum += Long.parseLong(c);

        }
        if (sum % 9 == 0 || sum == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 49700
/*
 * GreatestCommonDivisor.cpp
 *
 *  Created on: 2014/08/15
 *      Author: WanWan1985
 */
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

// for util
#define ALL(a)			(a).begin(), (b).end()
#define FOR(i, a, b) 	for(int i = (a); i < (b); i++)
#define REP(i, n)		FOR(i, 0, n)
#define PB				push_back
#define MP				make_pair
#define CL				clear
#define EXIT			(0)

typedef unsigned int u_int;
typedef long long ll;

int gcd(ll x, ll y);

// 2つの自然数a,bを入力とし、それらの最大公約数を求めるプログラム
int main(void) {

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

	cout << gcd(a, b) << endl;

	return EXIT;
}

int gcd(ll x, ll y) {

	if (x < y) {
		ll tmp = y;
		y = x;
		x = tmp;
	}

	while (y > 0) {
		ll r = x % y;
		x = y;
		y = r;
	}

	return x;
}

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

const long double EPS = 0.0000001;

template<class T> inline void chmax(T& a, T b) { if(b > a + EPS) a = b; }

long double calc() {	
	int n, m;
	cin >> n >> m;

	long double res = 0.0;
	long double sum = 0.0;

	for(int j = 0; j < m; ++j) {
		int v;
		long double r;
		cin >> v >> r;

		res += v * r;
		sum += r;
	}

	res *= 1 / sum;

	return res;
}

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

	int t;
	cin >> t;

	long double e = 0.0;

	for(int i = 0; i < t; ++i)
		chmax(e, calc());

	cout << (calc() + EPS < e ? "YES" : "NO") << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1240
#include <stdio.h>
int main(void){
    int a,b,i;
    char op;
    
    for(i = 1; ; i++){
    scanf("%d %c %d", &a, &op, &b);
    
    if(op == '?')break;
    if(op == '+'){
        printf("%d\n", a + b);
    }
    if(op == '-'){
        printf("%d\n", a - b);
    }
    if(op == '*'){
        printf("%d\n", a * b);
    }
    if(op == '/'){
        printf("%d\n", a / b);
    }
    }
    return 0;
    }



Measured memory_bytes: 2056
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int A, B; scanf("%d %d\n", &A, &B);
    int[] a = readln.chomp.split(" ").map!(to!int).array,
          b = readln.chomp.split(" ").map!(to!int).array;
    int f(int index) {
        int x = 0;
        int c = 0;
        foreach (i; index .. B) {
            while (x < A) {
                if (a[x++] == b[i]) {
                    c++;
                    break;
                }
            }
        }
        return c;
    }
    int ans = 0;
    foreach (int i; 0 .. B) {
        //writeln([i, f(i)]);
        ans = max(ans, f(i));
    }
    ans.writeln;
}

Measured memory_bytes: 1264
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int tmp = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (tmp == a[i]) {
                cnt++;
            } else {
                tmp = a[i];
            }
        }
        long ans = n - ((cnt + 1) / 2) * 2;
        System.out.println(ans);
        sc.close();
    }
}


Measured memory_bytes: 51136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int sum=0;
    if(n>1)
    {
        sum=sum+(n*(n-1))/2;
    }
    if(m>1)
    {
        sum=sum+(m*(m-1))/2;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {
	String s;
	String[] d = { "dream", "dreamer", "erase", "eraser" };

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

	Main(Scanner sc) {
		s = sc.next();
	}

	void solve() {
		boolean[] dp = new boolean[s.length()+1];
		Arrays.fill(dp, false);
		dp[0] = true;
		for(int i=0;i<s.length();i++){
			if(dp[i]){
				for(int j=0;j<4;j++){
					if(i+d[j].length()<=s.length()){
						if(d[j].equals(s.substring(i,i+d[j].length()))){
							dp[i+d[j].length()] = true;
						}
					}
				}
			}
		}
		if(dp[s.length()]){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

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

// DPテーブル
const int MAX_N = 15;
const int MAX_W = 110000;
int dp[MAX_N][MAX_W]; // 12 種類だが余裕をもつ

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

	// 品物を列挙 (価値はすべて 1)
	vector<int> weight;
	for (int i = 1; i <= W; i *= 6) weight.push_back(i);
	for (int i = 9; i <= W; i *= 9) weight.push_back(i); // 1 が重複しないように (しても問題はない)
	int n = (int)weight.size();

	// DP初期条件: dp[i][0] = 0
	for (int i = 0; i < MAX_N; ++i) for (int w = 0; w < MAX_W; ++w) dp[i][w] = 1 << 29; // INF
	for (int i = 0; i <= n; ++i) dp[i][0] = 0;

	// DPループ
	for (int i = 0; i < n; ++i) {
		for (int w = 0; w <= W; ++w) {
			dp[i + 1][w] = min(dp[i + 1][w], dp[i][w]);
			if (w >= weight[i]) dp[i + 1][w] = min(dp[i + 1][w], dp[i + 1][w - weight[i]] + 1);
		}
	}

	cout << dp[n][W] << endl;
}

Measured memory_bytes: 6784
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int inputs[3];
    int temp;
    int i,j;

    scanf("%d %d %d", &inputs[0], &inputs[1], &inputs[2]);

    for(i=0;i<2;i++){
        for(j=i+1;j<3;j++){
            if(inputs[i]>inputs[j]){
                temp=inputs[i];
                inputs[i]=inputs[j];
                inputs[j]=temp;
            }
        }
    }

    printf("%d %d %d\n",inputs[0],inputs[1],inputs[2]);
    return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
struct ashu
{long long int a,b;
};
bool fun(ashu x,ashu y)
{
	return x.a<y.a;
	}
int main()
{
	long long int n,i ;
	ashu arr[100009];
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>arr[i].a;
		arr[i].b=i+1;
	}
	sort(arr,arr+n,fun);
	for(i=0;i<n;i++)
	cout<<arr[i].b<<endl;
	
	
	return 0;
}



Measured memory_bytes: 2432
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

const int N=2e5+5;

typedef long long LL;

int n,m,L,R,hr[N],ans;

priority_queue <int,vector <int> , greater <int> > h;

vector <int> hl[N];

char c;

int read()
{
	int x=0,sig=1;
	for (c=getchar();c<'0' || c>'9';c=getchar()) if (c=='-') sig=-1;
	for (;c>='0' && c<='9';c=getchar()) x=x*10+c-48;
	return x*sig;
}

int main()
{
	n=read(); m=read();
	for (int i=0,l,r;i<n;i++)
	{
		l=read(); r=read(); hl[l].push_back(r);
	}
	L=0;
	for (int i=1,t;i<=m;i++)
	{
		for (vector <int> ::iterator it=hl[i].begin();it!=hl[i].end();it++)
		{
			if (L<i)
			{
				L++; h.push(*it); continue;
			}
			t=h.top();
			if (t>= *it) hr[*it]++;else
			{
				h.pop(); hr[t]++; h.push(*it);
			}
		}
	}
	for (vector <int> ::iterator it=hl[0].begin();it!=hl[0].end();it++) hr[*it]++;
	R=m+1;
	ans=hr[m+1];
	for (int i=m;i;i--)
	{
		for (;hr[i]>0;hr[i]--)
		{
			if (i<R && L<R-1) R--;else ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10108