akhauriyash/Code-Regression huggingface dataset:
import math

A, B, H, M = map(int, input().split())

ang1 = 360*H/12+30*M/60
ang2 = 360*M/60

x1=B*math.cos(math.radians(ang1))
y1=B*math.sin(math.radians(ang1))

x2=A*math.cos(math.radians(ang2))
y2=A*math.sin(math.radians(ang2))

l=((abs(x1-x2))**2+(abs(y1-y2))**2)**(1/2)

print(l)

Measured memory_bytes: 9476
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    final static long MOD = 1000000007;

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = fs.nextInt();
        int max = fs.nextInt();
        int[] a = fs.nextIntArray(n);
        long[] dp = new long[n+1];

        dp[0] = 0;

        for(int i = 1; i < n; i++) {
            long localmin = Integer.MAX_VALUE;
            for(int k = 1; k <= max; k++) {
                localmin = Math.min(localmin, i - k >= 0 ? dp[i - k] + Math.abs(a[i - k] - a[i]) : dp[i - 1] + Math.abs(a[i - 1] - a[i]));
            }
            dp[i] = localmin;
        }

        out.println(dp[n-1]);

        out.flush();
        out.close();
    }


    public static String rString(String s) {
        return new StringBuilder(s).reverse().toString();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                // br = new BufferedReader(new FileReader("chat.txt"));
                st = new StringTokenizer("");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public String next() {
            if (st.hasMoreTokens())
                return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String line = "";
            try {
                line = br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return line;
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public Integer[] nextIntegerArray(int n) {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        public char[] nextCharArray() {
            return nextLine().toCharArray();
        }
    }
}





Measured memory_bytes: 35928
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<string> S(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> S[i];
	}

	bool isValid[601];
	for (auto i = -N + 1; i < N; ++i)
	{
		isValid[i + N - 1] = true;
		for (auto j = 0; j < N; ++j)
		{
			for (auto k = 0; k < N; ++k)
			{
				auto compOffset = -j + k + i;
				auto compX = (j + compOffset + N) % N;
				auto compY = (k - compOffset + N) % N;
				if (S[k][j] != S[compY][compX])
				{
					isValid[i + N - 1] = false;
				}
			}
		}
	}

	auto result = 0;
	for (auto A = 0; A < N; ++A)
	{
		for (auto B = 0; B < N; ++B)
		{
			if (isValid[-B + A + N - 1])
			{
				++result;
			}
		}
	}
	cout << result << endl;

	return 0;
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!
from collections import defaultdict

def ok(last4):
    for i in range(0, 4):
        t = list(last4)
        if i > 0:
            t[i-1], t[i] = t[i], t[i-1]
        if 'AGC' in ''.join(t):
            return False
    return True

N = int(input())
dp = [defaultdict(int) for i in range(N+1)]
dp[0]['TTT'] = 1

for i in range(1, N+1):
    for last3 in dp[i-1].keys():
        for c in 'ATGC':
            if ok(last3+c):
                dp[i][last3[1:]+c] += dp[i-1][last3] %  (1e9 + 7)
                dp[i][last3[1:]+c] %= (1e9 + 7)
            
ans = 0
for i in dp[N].keys():
    ans += dp[N][i]
    ans %= (1e9 + 7)
    
print(int(ans))

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

int main() {
	int N,M;
	cin>>N>>M;
	for (int i = 0; i < M; i++){
		int a;
		cin>>a;
		N-=a;
	}
	if(N<0)N=-1;
	cout<<N<<endl;
}

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

using namespace std;

int main()
{
    long D, N;

    cin >> D >> N;

    long M = 1;
    for(int i = 0; i < D; i++){
	M *= 100;
    }
    long x = N*M;
    if(N == 100){
	x += M;
    }
    cout << x << endl;
    
}


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

int main() {
    int S;
    cin >> S;
    int h = S / 3600;
    int m = ( S - h * 3600 ) / 60;
    int s = S - h * 3600 - m * 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3080
from itertools import takewhile
from functools import reduce

data_num = int(input())
data_list = [int(num) for num in input().split(' ')]

combine_data = reduce(lambda x, y: x | y, data_list)

results = takewhile(lambda x: x == '0', bin(combine_data)[::-1])

print(len(list(results)))

Measured memory_bytes: 3572
typedef float f;i;f x,z[];f o(f*a,f*b,f*c){return a[1]*(*c-*b)+c[1]*(*b-*a)+b[1]*(*a-*c);}main(){for(;~scanf("%f,",z+i++%8);)i%8||puts(x*o(z+2,z+4,z+6)>0&x*o(z+4,z+6,z)>0&x*o(z+6,z,z+2)>0?"YES":"NO",x=o(z,z+2,z+4));}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	double x, h;
	while (cin >> x >> h) {
		if (!x && !h)
			break;
		double hh = sqrt(pow(x / 2, 2) + pow(h, 2));
		double S = (x * hh / 2) * 4 + pow(x, 2);
		cout << fixed << setprecision(7) << S << endl;
	}
	return 0;
}

Measured memory_bytes: 1276
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{
	auto line = readln().split(); 
	if (line.length < args.length) return;
	foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
//------------------------------
const coin = [10,50,100,500];
void main(){	
	int total;
	read(total);
	while(total){
		auto have = new int[4];
		readArray(have);
		int howMany = int.max; 
		auto uses = new int[4];
		foreach(i0;iota(have[0]+1)){
			foreach(i1;iota(have[1]+1)){
				foreach(i2;iota(have[2]+1)){
					foreach(i3;iota(have[3]+1)){
						auto tmpuses = [i0,i1,i2,i3];
						auto pay = i0 * coin[0] + i1 * coin[1] + i2 * coin[2] + i3 * coin[3];	
						if (pay < total) continue;
						int tmpHowMany = have.sum + howManyCoins(pay - total) - tmpuses.sum;
						if (tmpHowMany < howMany ){
							howMany = tmpHowMany;
							uses = tmpuses;
						}
					}
				}
			}
		}
		foreach(i,u;uses){if(u >0)writeln(coin[i]," ",u);}
		read(total);
		if (total) writeln();
	}
}
int howManyCoins(int pay){
	int res;
	foreach_reverse(i,c;coin){
		while(pay >= c){ 
			pay -= c;res ++;
		}
	} 
	return res;
}

Measured memory_bytes: 3148
import math 
N, K =  list(map(int, input().split(" ")))

total = 0 
for i in range(1,N+1):
    n = math.ceil(math.log2(K/i))
    if n > 0:
        total += 0.5**n
    else:
        total += N+1- i
        break
   

print(total/N)

Measured memory_bytes: 3188
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            List<Integer> ans = new ArrayList<>();

            int i = 1;
            while (true) {
                if (i > a && i > b) break;

                if (a % i == 0 && b % i == 0) ans.add(i);

                i++;
            }

            Collections.sort(ans, Collections.reverseOrder());
            // 出力
            out.println(ans.get(k - 1));

        }

    }
}



Measured memory_bytes: 21332
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;

//input
int n, W;
int weight[110], value[110];

//dp table
int dp[110][10010];

int main(){

	cin >> n >> W;
	for(int i = 0; i < n; i++){
		cin >> value[i] >> weight[i];
	}

	//dp初期条件
	for(int w = 0; w <= W; w++){
		dp[0][w] = 0;
	}

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

	}

	cout << dp[n][W] << "\n";
	
	return 0;
}



Measured memory_bytes: 7040
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        array<int, 10> cnt{};
        for (int i = 0; i < n; ++i) {
            int x; scanf("%d", &x);
            cnt[x]++;
        }
        for (int i = 0; i < 10; ++i) {
            if(!cnt[i]) puts("-");
            else cout << string(cnt[i], '*') << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3064
// AOJ 0385: Bozo Sort
// 2019.2.20 bal4u
 
#include <stdio.h>
#include <stdlib.h>

int a[300002], g[300002];

#define gc() getchar()
int in()
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int cmp(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}

int main()
{
	int i, N, Q, x, y, t, xx, yy;
	int cnt;

	N = in();
	for (i = 1; i <= N; i++) g[i] = a[i] = in();
	qsort(g+1, N, sizeof(int), cmp);
	for (cnt = 0, i = 1; i <= N; i++) {
		if (g[i] != a[i]) cnt++;
	}
	if (cnt == 0) {
		puts("0");
		return 0;
	}
	Q = in();
	for (i = 1; i <= Q; i++) {
		x = in(), y = in();
		xx = a[x], yy = a[y];
		t = a[x], a[x] = a[y], a[y] = t;
		if (xx == g[x] && a[x] != g[x]) cnt++;
		else if (xx != g[x] && a[x] == g[x]) cnt--;
		if (yy == g[y] && a[y] != g[y]) cnt++;
		else if (yy != g[y] && a[y] == g[y]) cnt--;
		if (cnt == 0) {
			printf("%d\n", i);
			break;
		}
	}
	if (cnt) puts("-1");
	return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long A, long long B){
    rep(i,1,1e4+1) {
        if (A == floor((double)i * 0.08) && B == floor((double)i * 0.1)) {
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl;
}

signed main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	int i = 1;
	i64 ans = 1;
	while (1) {
		i++;
		if (i*i > n) {
			i--;
			ans = i * i;
			break;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    W, H = map(int, readline().split())
    S = [readline().strip() for i in range(H)]
    R = [[0]*W for i in range(H)]
    P = []
    cnt = 0
    for i in range(H):
        Si = S[i]
        for j in range(W):
            if Si[j] == 's':
                sx = j; sy = i
                R[i][j] = 1
                cnt += 1
            elif Si[j] == 'g':
                gx = j; gy = i
            elif Si[j] == '*':
                P.append((j, i))
            elif Si[j] == '.':
                cnt += 1
                R[i][j] = 1
    dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
    INF = 10**18

    dist1 = [[INF]*W for i in range(H)]
    que = deque(P)
    for x, y in P:
        dist1[y][x] = 0
    while que:
        x, y = que.popleft()
        c = dist1[y][x]+1
        for dx, dy in dd:
            nx = x + dx; ny = y + dy
            if S[ny][nx] in '*#' or dist1[ny][nx] != INF:
                continue
            dist1[ny][nx] = c
            que.append((nx, ny))

    dist2 = [[INF]*W for i in range(H)]
    que = deque([(gx, gy)])
    dist2[gy][gx] = 0
    while que:
        x, y = que.popleft()
        c = dist2[y][x]+1
        for dx, dy in dd:
            nx = x + dx; ny = y + dy
            if S[ny][nx] in '*#' or dist2[ny][nx] != INF:
                continue
            dist2[ny][nx] = c
            que.append((nx, ny))

    left = 0; right = 10**21
    BASE = 10**9
    for i in range(71):
        mid = (left + right) // 2
        su = 0
        for i in range(H):
            for j in range(W):
                if not R[i][j]:
                    continue
                su += min(dist1[i][j]*BASE + mid, dist2[i][j]*BASE)
        if mid*cnt > su:
            right = mid
        else:
            left = mid
    write("%.16f\n" % min(dist1[sy][sx] + left / BASE, dist2[sy][sx]))
solve()


Measured memory_bytes: 18988
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
sum_A = sum(A)
max_A = max(A)

for i in range(M):
    if A[i] * 4 * M < sum_A:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 2940
primes :: [Integer]
primes = 2 : filter isPrime [3,5..]
  where isPrime n = n > 1 && foldr (\x acc -> x * x > n || (n `mod` x /= 0 && acc)) True primes

solve :: Integer -> (Integer, Integer)
solve n = let (ps1, ps2) = span (<n) primes
              ps3        = dropWhile (<=n) ps2
          in  (last ps1, head ps3)

main :: IO ()
main = getContents >>= mapM_ (printResult . solve . read) . lines
  where printResult (a, b) = putStrLn $ show a ++ " " ++ show b

Measured memory_bytes: 5520
N, M = map(int, input().split())
*A, = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)

from collections import deque
used = set()
ans = 0
cnt = 0
R = []
for i in range(N):
    if i in used:
        continue
    tmp = [A[i]]
    deq = deque([i])
    used.add(i)
    while deq:
        v = deq.popleft()
        for w in G[v]:
            if w in used:
                continue
            tmp.append(A[w])
            deq.append(w)
            used.add(w)
    tmp.sort()
    ans += tmp[0]
    R += tmp[1:]
    cnt += 1
if len(R) + 2 < cnt:
    print("Impossible")
    exit(0)
if cnt == 1:
    print(0)
    exit(0)
R.sort()
ans += sum(R[:cnt-2])
print(ans)


Measured memory_bytes: 32684
#include <iostream>
#include <cstdio>

int main(void){
  double sum;

  int n;
  std::cin >> n;
  for(int i=0; i<n; i++){
    int a;
    std::cin >> a;
    sum += 1.0/a;
  }
  std::printf("%.9lf\n", 1.0/sum); 
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll a,b,c;
    cin>>a>>b>>c;
    Yes(c>=a && c<=b);
    return  0;
}


Measured memory_bytes: 256
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>

#define int long long
//typedef long long ll;
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

int N, M;
vector<int> G[8];
int a, b;
int ans;
bool visited[8];

void dfs(int v, int n)
{
    if (n == N) {
        ans++;
        return;
    }

    visited[v] = true;

    rep(i,G[v].size()) {
        if (visited[G[v][i]]) continue;
        dfs(G[v][i], n + 1);
    }

    visited[v] = false;
}

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> N >> M;
    rep(i,M) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0, 1);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

const ll mod = 1000000007;

ll ka[2000010];

ll c(int x, int y) {
	if (y > x)return 0;
	return ka[x] * mod_pow(ka[x - y], mod - 2, mod) % mod*mod_pow(ka[y], mod - 2, mod) % mod;
}

int k;
string s;
ll ans;

signed main() {
	cin >> k >> s;
	int n = (int)s.size();
	ka[0] = 1;
	for (int i = 1; i <= 2000000; i++)ka[i] = ka[i - 1] * i%mod;
	for (int i = n - 1; i < k + n; i++) ans = (ans + c(i, n - 1)*mod_pow(25, i - (n - 1), mod) % mod*mod_pow(26, n + k - i - 1, mod) % mod) % mod;
	cout << ans << endl;
}

Measured memory_bytes: 20012
def main()
  n, m = gets.chomp.split.map(&:to_i)
  from_1 = []
  from_n = []
  m.times do
    keiro = gets.chomp.split.map(&:to_i)
    from_1 << keiro.last if keiro.first == 1
    from_n << keiro.first if keiro.last == n
  end
  (from_1 & from_n).first ? "POSSIBLE" : "IMPOSSIBLE"
end

puts main

Measured memory_bytes: 9864
#include <iostream>
#include <string>
#include <sstream>
#define _USE_MATH_DEFINES
#include <cmath>
int main()
{
  std::string line;
  double x = 0.0, y = 0.0;
  int dir_deg = 90;
  while (std::cin >> line) {
    int i = line.find(",");
    if (i != -1) line.replace(i, 1, " ");

    std::istringstream iss(line);
    int d, t;
    iss >> d >> t;
    if (d == 0 && t == 0) break;

    double rad = dir_deg * M_PI / 180.0;
    x += std::cos(rad) * d;
    y += std::sin(rad) * d;
    dir_deg -= t;
    if (dir_deg <= -180) dir_deg += 360;
    if (dir_deg >=  180) dir_deg -= 360;
  }
  std::cout << static_cast<int>(x) << std::endl << static_cast<int>(y) << std::endl;
  return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
using namespace std;

int BIT[151];
void update(int a) {//a???1????¶????
while (a <= 150) {
	BIT[a]++;
	a += a&(-a);
   }
}
int n(int a) {
	int sum = 0;
	while (a>0) {
		sum += BIT[a];
		a -= a&(-a);
	}
	return sum;
}
signed main() {
	int a; cin >> a;
	int s[150];
	int sum = 0;
	for (int i = 0; i < a; i++) {
		int k; cin >> k;
		s[i] = k;
		k++;
		sum += i-n(k);
		update(k);
	}
	sort(s, s + a);
	for (int l = 0; l < a; l++) {
		if (l)cout << " ";
		cout << s[l];
	}
	cout << endl;
	cout << sum << endl;
}

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

#define ll long long int
#define pb push_back
#define llu unsigned long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define eb emplace_back
#define M 1000000007
#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>

using namespace std;
ll max(ll x,ll y)
{
	if(x>y)
		return x;
	return y;
}
ll min(ll x,ll y)
{
	if(x<y)
		return x;
	return y;
}
int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0;
    int base = 1; 
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) 
	{ 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
    return dec_value; 
} 
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin.ignore(numeric_limits<streamsize>::max(),'\n');
    //const unsigned ll M=1000000007;
    double d,t,s;
    cin>>d>>t>>s;
    if(d/s <= t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3740
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int N = 5010;

int n, P;

int dp[N];

void add(int& x, int y) {
  if ((x += y) >= P) x -= P;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> P;
  /*
  for (int i = 2; i <= n - i + 2; ++i) {
    memset(tmp, 0, sizeof(tmp));
    for (int j = 1; j <= n; ++j)
      for (int k = 0; k < n; ++k)
        for (int l = 0; l <= min(k, j); ++l)
          tmp[j - l][l] = (tmp[j - l][l] + dp[j][k] * (ll)(k - l + 1)) % P;
    memcpy(dp, tmp, sizeof(dp));
  }*/
//  cerr << vector<int>(dp, dp + n) << '\n';
  int ans = 0;
  if (n & 1) {
    for (int i = 0; i < n; ++i) dp[i] = 1 + i;
    for (int i = 0; i < n; ++i) add(dp[i], dp[i - 1]);
    for (int i = 2; i <= n - i + 2; ++i) {
      for (int j = i; j < n; ++j) add(dp[j], dp[j - i]);
      for (int j = i; j < n; ++j) add(dp[j], dp[j - i]);
    }
    ans = (dp[n - 1] + P - dp[n / 2 - 1]) % P;
  } else {
    for (int i = 0; i < n; ++i) dp[i] = 1;
    for (int i = 1; (i + 1) <= n - (i + 1) + 2; ++i) {
      for (int j = i; j < n; ++j) add(dp[j], dp[j - i]);
      for (int j = i; j < n; ++j) add(dp[j], dp[j - i]);
    }
    ans = dp[n - 1];
  }
  cout << ans << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = []
c = []

for i in range(n):
    a.append([int(i) for i in input().split()])
for i in range(n):
    c.append([int(i) for i in input().split()])

a.sort(key=lambda x:x[1], reverse=True)
c = sorted(c)

count = 0
for i, (tc, td) in enumerate(c):
    for j, (ta, tb) in enumerate(a):
        if ta < tc and tb < td:
            count += 1
            a.pop(j)
            break

print(count)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main (){

char str[21],a[21];
int i,j,r;

scanf ("%s",str);

r=strlen(str);
j=strlen(str)-1;

for (i=0;i<r;i++){

a[i]=str[j];
j--;

}
for (i=0;i<r;i++){

printf("%c",a[i]);
}
printf ("\n");
return 0;
}


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

int main(){
  vector<int> a(3);
  int n,count=0;
  cin>>a[0]>>a[1]>>a[2]>>n;
  sort(a.begin(),a.end());
  for(int x=0;x*a[0]<=n;x++){
    for(int y=0;x*a[0]+y*a[1]<=n;y++){
        if((n-x*a[0]-y*a[1])%a[2]==0) count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int a, b, c, d, p;
  int x = 0, y = 0;
  scanf("%d\n", &a);
  scanf("%d\n", &b);
  scanf("%d\n", &c);
  scanf("%d\n", &d);
  scanf("%d\n", &p);
  x = a * p;
  if(p <= c) {
    y = b;
  } else {
    y = b + d * (p - c);
  }
  if(x <= y) {
    printf("%d\n", x);
  } else {
    printf("%d\n", y);
  }
  return 0;
}

Measured memory_bytes: 600
import bisect
import sys
sys.setrecursionlimit(10 ** 6)
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, M, K, ABs, CDs):
    friend_map = [[] for _ in range(N + 1)]
    for a, b in ABs:
        friend_map[a].append(b)
        friend_map[b].append(a)

    block_map = [[] for _ in range(N + 1)]
    for c, d in CDs:
        block_map[c].append(d)
        block_map[d].append(c)

    # print('friend_map')
    # for i in range(len(friend_map)):
    #     print(friend_map[i])
    #
    # print('block_map')
    # for i in range(len(block_map)):
    #     print(block_map[i])

    def dfs(group_num, members, now_n):
        belongs[now_n] = group_num
        members.append(now_n)
        for f in friend_map[now_n]:
            if belongs[f] == -1:
                members = dfs(group_num, members, f)
        return members

    friend_groups = []
    belongs = [-1] * (N + 1)
    for i in range(1, N + 1):
        if belongs[i] == -1:
            m = dfs(len(friend_groups), [], i)
            m.sort()
            friend_groups.append(m)

    # print('friend_groups')
    # for i in range(len(friend_groups)):
    #     print(friend_groups[i])

    # print('belongs')
    # print(belongs)
    ans = ''
    for n in range(1, N + 1):
        block = 0
        group = friend_groups[belongs[n]]
        for b in block_map[n]:
            # if bisect.bisect_left(group, b) >= len(group):
            #     print(group)
            #     print(n, b)
            #     input()
            x = bisect.bisect_left(group, b)
            # if x < len(group) and b == group[x]:
            #     block += 1
            if belongs[n] == belongs[b]:
                block += 1
        # print('n', n, 'friend_num', len(friend_map[n]), 'block_num', block)
        ans += ' ' + str(len(group) - len(friend_map[n]) - block - 1)
    print(ans[1:])


if __name__ == '__main__':
    # # handmade test
    # N, M, K = 2 * 10 ** 5, 10 ** 5, 10 ** 5
    # ABs = [[1, i] for i in range(2, 10 ** 5 + 2)]
    # CDs = [[i, i + 1] for i in range(2, 10 ** 5 + 2)]
    # while True:
    #     import random
    #     N, M, K = 20, 10, 10
    #     ABs = []
    #     while True:
    #         if len(ABs) == M:
    #             break
    #         a = random.randint(1, N - 1)
    #         b = random.randint(a + 1, N)
    #         if not [a, b] in ABs:
    #             ABs.append([a, b])
    #     CDs = []
    #     while True:
    #         if len(CDs) == K:
    #             break
    #         c = random.randint(1, N - 1)
    #         d = random.randint(c + 1, N)
    #         if not [c, d] in ABs and not [c, d] in CDs:
    #             CDs.append([c, d])
    #     print(N, M, K)
    #     print(ABs)
    #     print(CDs)
    #     solve(N, M, K, ABs, CDs)

    N, M, K = map(int, input().split())
    ABs = [[int(i) for i in input().split()] for _ in range(M)]
    CDs = [[int(i) for i in input().split()] for _ in range(K)]
    solve(N, M, K, ABs, CDs)


Measured memory_bytes: 91740
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/

const int MOD=1000000007;/* 1,000,000,007 で割った余りを出力する　のとき使う*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int N;
int M;
int a[100005];/*1なら移動できる、0なら壊れている*/
int dp[100005];/*実際の場合の数がをここに入れる*/

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

  /*階段の情報*/
  for(int i=0; i<=N; i++){
    a[i]=1;
  }
  int A;
  for(int i=0; i<M; i++){
    cin >> A;
    a[A]=0;
  }

  /*動的計画法*/
  dp[0]=1;
  for(int i=0; i<=N; i++){
    if(a[i]==0){
      dp[i]=0;/*階段が壊れているなら0で上書き(これより後で書き換わることはない)*/
    }
    dp[i+1]=(dp[i+1]+dp[i]) % MOD;
    dp[i+2]=(dp[i+2]+dp[i]) % MOD;
  }
  
  cout << dp[N] << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    map<string, int> m;
    string s;

    for(int i=0;i<n;i++){
        cin >> s;
        m[s]++;
    }
    vector<pair<int , string>> v;
    for(auto p: m){
        v.push_back({p.second, p.first});
    }
    sort(v.begin(), v.end(), [](const pair<int, string> x, const pair<int, string> y){
        if (x.first != y.first) return x.first > y.first;
        else return x.second < y.second;
    });
    int buf = v[0].first;
    for(auto p: v){
        if(p.first != buf) break;
        cout << p.second << endl;
    }
}

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

int main(){
 int H,W,j;
  cin>>H>>W;

  vector<string>b(H);
    for(int i=0;i<H;i++){
   cin>>b[i];
  }
  for(int i=0;i<2*H;i++){
    j=i/2;
    cout<<b[j]<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n;
    int max, min;
    long sum;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    min = a[0];
    max = a[0];
    sum = 0;

    for (int i = 0; i < n; i++) {
        if (min > a[i]) {
            min = a[i];
        } else if (max < a[i]) {
            max = a[i];
        }
        sum += a[i];
    }

    cout << min << " " << max << " " << sum << endl;

    return 0;
}

Measured memory_bytes: 3112
#include <iostream>
using namespace std;
int main() {
    long long a, b, c;
    cin >> a >> b >> c;
    if ((a%2)*(b%2)*(c%2) == 0) {
        cout << 0 << endl;
    } else {
        long long min = 1000000000000000000;
        if (min > a*b) min = a*b;
        if (min > b*c) min = b*c;
        if (min > c*a) min = c*a;
        cout << min << endl;
    }
}

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

int main() {
	int N, X;
	cin >> N >> X;
	vector<int> L(N);

	for (int i = 0; i < N; ++i) {
		cin >> L[i];
	}

	int count = 1;
	vector<long long int>D(N+2);
	D[0]=0;
	for(int i=1;i<N+1;++i){
		D[i] = D[i-1] + L[i-1];
		if (D[i] <= X) count++;
	}

	cout<<count<<endl;

	return 0;
}


Measured memory_bytes: 256
/*
Author: CNYALI_LK
LANG: C++
PROG: abc.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<int,int> pii;
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
int read(){
	int s=0,base=1;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=-base;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	return s*base;
}
char WriteIntBuffer[1024];
template<class T>void write(T a,char end){
	int cnt=0,fu=1;
	if(a<0){putchar('-');fu=-1;}
	do{WriteIntBuffer[++cnt]=fu*(a%10)+'0';a/=10;}while(a);
	while(cnt){putchar(WriteIntBuffer[cnt]);--cnt;}
	putchar(end);
}
int gra[128][128];
int main(){
#ifdef cnyali_lk
	freopen("abc.in","r",stdin);
	freopen("abc.out","w",stdout);
#endif
	int a,b;
	a=read();b=read();
	if(!a){
		printf("1 1\n#\n");
		return 0;
	}	
	if(!b){
		printf("1 1\n.\n");
		return 0;
	}
	printf("100 100\n");
	for(int i=1;i<=100;++i){
		for(int j=1;j<=100;++j)if(i<=50)gra[i][j]=0;else gra[i][j]=1;
	}

	--a;--b;
	for(int i=1;i<=50&&b;i+=2)for(int j=1;j<=100&&b;j+=2)gra[i][j]=1,--b;
	for(int i=1;i<=50&&a;i+=2)for(int j=1;j<=100&&a;j+=2)gra[101-i][j]=0,--a;
	for(int i=1;i<=100;++i,putchar('\n'))for(int j=1;j<=100;++j)printf("%c",gra[i][j]?'#':'.');

	return 0;
}



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

using namespace std;

template <unsigned kMod> class RollingHash {
  using ull = unsigned long long;

private:
  const int _kN;
  std::vector<unsigned> _hash, _pow;
  unsigned _kBase;

public:
  RollingHash(const std::string &s)
      : _kN(s.size()), _hash(_kN + 1), _pow(_kN + 1, 1) {
    std::random_device seed_gen;
    std::mt19937_64 engine(seed_gen());
    _kBase = engine() % (kMod - 2) + 2;
    for (int i = 1; i <= _kN; ++i) {
      _pow[i] = (unsigned)((ull)_pow[i - 1] * _kBase % kMod);
      _hash[i] = (unsigned)(((ull)_hash[i - 1] * _kBase + s[i - 1]) % kMod);
    }
  }

  // 0-indexedで半開区間[l,r)
  ull get(int l, int r) {
    return (_hash[r] - (ull)_hash[l] * _pow[r - l] % kMod + kMod) % kMod;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  RollingHash<1000000009> hashed_str1(s);
  RollingHash<1000000007> hashed_str2(s);
  int r = 1, l = 1;
  set<pair<unsigned, unsigned>> sub;
  for (int i = 0; i < m; ++i) {
    string q;
    cin >> q;
    if (q == "L++") {
      l++;
    }
    if (q == "L--") {
      l--;
    }
    if (q == "R++") {
      r++;
    }
    if (q == "R--") {
      r--;
    }
    sub.insert({hashed_str1.get(l - 1, r), hashed_str2.get(l - 1, r)});
  }
  cout << sub.size() << endl;
}


Measured memory_bytes: 21788
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    vector<int> prime(MAX_N, 1);
    prime[0] = prime[1] = 0;
    for(int i = 2; i <= MAX_N; i++)
    {
        if(prime[i] == 0) continue;
        for(int j = 2 * i; j <= MAX_N; j += i)
        {
            prime[j] = 0;
        }
    }

    vector<int> like2017(MAX_N, 0);
    for(int i = 0; i < prime.size(); i++)
    {
        if(prime[i] == 0) continue;
        if(prime[(i + 1) / 2] == 0) continue;
        like2017[i] = 1;
    }

    vector<int> sum_like2017(MAX_N + 1, 0);
    for(int i = 0; i < like2017.size(); i++)
    {
        sum_like2017[i + 1] = sum_like2017[i] + like2017[i];
    }

    int q; cin >> q;
    for(int i = 0; i < q; i++)
    {
        int l, r; cin >> l >> r;
        cout << sum_like2017[r + 1] - sum_like2017[l - 1] << "\n";
    }
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 998244353
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



signed main() {

	int N;
	cin >> N;
	vector<int> a(N+1);
	for(int i=1; i<=N; i++) cin >> a[i];
	vector<bool> b(N+1, false);

	for (int i = N; i >= 1; i--) {
		int cnt = 0;
		for (int m = 2*i; m <= N; m += i) {
			if (b[m]) cnt++;
		}
		if (cnt % 2 != a[i])
			b[i] = true;
	}
	int ans = 0;
	for (int i = 1; i <= N; i++) if (b[i]) ans++;
	cout << ans << endl;
	for (int i = 1; i <= N; i++) if (b[i]) cout << i << " ";



	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  map<int, int> difficulty;
  rep(i, N)
  {
    int D;
    cin >> D;
    difficulty[D]++;
  }
  bool is_ok = true;
  int M;
  cin >> M;
  rep(i, M)
  {
    int T;
    cin >> T;
    difficulty[T]--;
    if(difficulty[T] < 0)
      is_ok = false;
  }

  if(is_ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

short G[5001][5001];
int N,M;
int lose[5001];
int res[5001];

int main(){
  scanf("%d%d",&N,&M);
  int x,y;
  rep(i,M){
    scanf("%d%d",&x,&y); x--; y--;
    G[x][y] = 1; G[y][x] = -1;
    lose[y]++;
  }


  int f = 0;
  int cnt,t;
  rep(i,N){
    cnt=0;
    rep(j,N) if(lose[j]==0){
      if(!cnt){
	t = j;
	lose[j] = -1;
      }
      cnt++;
    }
    if(cnt>1) f = 1;
    res[i] = t;
    rep(j,N){
      if(G[j][t]==-1) lose[j]--;
    }
  }

  rep(i,N) printf("%d\n", res[i]+1);
  printf("%d\n", f);
  return 0;
}

Measured memory_bytes: 50064
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

const int MAX = 0x3f3f3f3f;
const int maxn = 100000 + 5;

struct Card
{
    char suit;
    int val;
};
Card a[maxn], b[maxn], L[(maxn >> 1) + 5], R[(maxn >> 1) + 5];

int partition(int left, int right)
{
    Card x = a[right];
    int i = left - 1;
    for (int j = left; j < right; j++)
    {
        if (a[j].val <= x.val)
        {
            i++;
            swap (a[i], a[j]);
        }
    }
    swap(a[i+1], a[right]);
    return i + 1;
}

void quickSort(int left, int right)
{
    int selected;
    if (left < right)
    {
        selected = partition(left, right);
        quickSort(left, selected - 1);
        quickSort(selected + 1, right);
    }
}

void merge(int left, int mid, int right)
{
    int x = mid - left;
    int y = right - mid;
    for (int i = 0; i < x; i++)
        L[i] = b[left + i];
    for (int i = 0; i < y; i++)
        R[i] = b[mid + i];

    L[x].val = R[y].val = MAX;
    int i = 0, j = 0;
    for (int k = left; k < right; k++)
    {
        if (L[i].val <= R[j].val)
            b[k] = L[i++];
        else
            b[k] = R[j++];
    }
}

void MergeSort(int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) >> 1;
        MergeSort(left, mid);
        MergeSort(mid, right);
        merge(left, mid, right);
    }
}

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

    char tempS[2];
    int tempV;
    for (int i = 0; i < n; i++)
        {
            scanf("%s %d", tempS, &tempV);
            a[i].suit = b[i].suit = tempS[0];
            a[i].val = b[i].val = tempV;
        }

    quickSort(0, n - 1);
    MergeSort(0, n);

    bool stable = true;
    for (int i = 0; i < n; i++)
        if (a[i].suit != b[i].suit)
        {
            stable = false;
            break;
        }

    if (stable)
        printf("Stable\n");
    else
        printf("Not stable\n");
    for (int i = 0; i < n; i++)
        printf("%c %d\n", a[i].suit, a[i].val);

    return 0;
}



Measured memory_bytes: 5532
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString.Char8 as C
import Data.List
import Data.Maybe
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM

main = sol <$> get >>= print

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines <$> C.getContents  
 
sol ([_,k]:ab) = fromJust . U.findIndex (k<=) . U.scanl1' (+) $ runST $ do
  v <- UM.replicate (1+10^5 :: Int) (0 :: Int)
  forM_ ab $ \[a,b] -> UM.modify v (+b) a
  U.freeze v

Measured memory_bytes: 5244
#include <iostream>
#include <vector>		
#include <algorithm> // sort
//#include <functional> //降順ソート


using namespace std;

int main() {
	int a, b, c, total, buf;

	cin >> a >> b >> c;

	total = a + b + c;

	std::vector<int> prices;

	buf = total - a;

	// 配列に要素を追加
	prices.push_back(buf);

	buf = total - b;

	// 配列に要素を追加
	prices.push_back(buf);

	buf = total - c;

	// 配列に要素を追加
	prices.push_back(buf);


	// 配列の昇順にソート
	std::sort(prices.begin(), prices.end());

	cout << prices[0] << endl;
}

Measured memory_bytes: 256