akhauriyash/Code-Regression huggingface dataset:
/// 11:57 AM 03/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template<typename T>
void ContainerError(T &v);

ll powmod(ll base, ll exp, ll MOD);

ll mpow(ll base, ll exp);

ll gcd(ll a, ll b);

void brute(vector<ll> &v) {
    ll n = v.size();
    for(ll i=0;i<n;i++) {
        for(ll j=i+1;j<n;j++) {
            if(abs(i-j) == v[i]+v[j]) {
                cout << i << ' ' << j << endl;
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> v(n);
    for(auto &x:v) {
        cin >> x;
    }
    ll ans = 0;
    map<ll,ll> m;
    for(ll i=0;i<n;i++) {
        ans += m[i-v[i]];
        m[i+v[i]]++;
    }
    cout<<ans;
    return 0;
}

template<typename T>
void ContainerError(T &v) {
    cout << "{";
    for (auto &x:v) { cout << x << ','; }
    cout << "}" << endl;
    return;
}

ll powmod(ll base, ll exp, ll MOD) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return (res % MOD);
}

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base);
        base = (base * base);
        exp /= 2;
    }
    return (res);
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }



Measured memory_bytes: 27472
#include <bits/stdc++.h>
using namespace std;
const int N = 400000;
int n;
vector <int> bi[N];
int fa[N], siz[N], dis[N];
void dfs(int t)
{
    siz[t] = 1;
    for (int i = 0; i < bi[t].size(); ++ i)
        if (fa[t] != bi[t][i])
        {
            dis[bi[t][i]] = dis[t] + 1;
            fa[bi[t][i]] = t;
            dfs(bi[t][i]);
            siz[t] += siz[bi[t][i]];
        }
}
int main()
{
    cin >> n;
    for (int i = 1; i < n; ++ i)
    {
        int u, v;
        cin >> u >> v;
        bi[u].push_back(v);
        bi[v].push_back(u);
    }
    dfs(1);
    int w = n;
    for (int i = 1; i <= (dis[n] - 1) / 2; ++ i) w = fa[w];
    if (siz[w] >= n - siz[w]) cout << "Snuke" << endl;
    else cout << "Fennec" << endl;
}


Measured memory_bytes: 20864
n = gets.chomp.to_i
nn = 10.times.map { Array.new(10, 0) }
n.times do |i|
  i += 1
  bottom_digit = i % 10
  top_digit = i.to_s[0].to_i
  nn[top_digit][bottom_digit] += 1
end

ans = 0

10.times do |i|
  10.times do |j|
    ans += nn[i][j] * nn[j][i]
  end
end

puts ans

Measured memory_bytes: 3836
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N;
    while(cin >> N) {
        vector<LL> A(N);
        REP(i, N) cin >> A[i];
        sort(A.begin(), A.end());
        vector<LL> sum(N + 1);
        REP(i, N) sum[i + 1] = sum[i] + A[i];
        int ans = 1;
        for(int i = N-2; i >= 0; i--) {
            if(2 * sum[i+1] < A[i+1]) {
                break;
            }
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}



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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr ll MOD = (ll)1e9 + 7;
constexpr ll MOD2 = 998244353;
constexpr ll HIGHINF = (ll)1e18;
constexpr ll LOWINF = (ll)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
    ll L,R; cin >> L >> R;
    for(ll i = L; i <= R && i <= L + 2019; ++i) corner(i%2019==0,0);
    L %= 2019;
    R %= 2019;
    ll ans = 2019;
    for(ll i = L; i <= R; ++i){
        for(ll j = i + 1; j <= R; ++j){
            chmin(ans,(i*j)%2019);
        }
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 256
let is_palindrome n =
  if n / 10000 = n mod 10 then
    let m = (n - 10000 * (n / 10000)) / 10 in
    if m / 100 = m mod 10 then true else false
  else false


let f a b =
  let rec g a' count =
    if a' > b then count
    else if is_palindrome a' then g (a' + 1) (count + 1)
    else g (a' + 1) count
  in
  g a 0


let () =
  let a, b = Scanf.scanf "%d %d" (fun x y -> (x, y)) in
  f a b |> Printf.printf "%d\n"
  
 

Measured memory_bytes: 4480
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)



int main(){
    long long n;
    long long mod=1000000007;
    cin>>n;
    if(n==1) cout<<0<<endl;
    else if(n==2) cout<<2<<endl;
    else{
        long long ans=0;
        long long a=1,b=1,c=1;
        for(int i=1;i<=n;i++){
            a=(a*10)%mod;
            b=(b*9)%mod;
            c=(c*8)%mod;
        }
        b=(2*b)%mod;
        ans=(a-b)%mod;
        ans=(ans+c)%mod;
        if(ans<0) cout<<ans+mod<<endl;
        else cout<<ans<<endl;
    }
}

Measured memory_bytes: 3584
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

class pass
{
public:
	ll t;
	ll c;
	ll p;
};

class scale
{
private:
	ll v, e;

	pass* p;

	vector<ll>* node;
	bool* used;
	ll* nowin;
public:
	void set(ll vw, ll ew)
	{
		v = vw;
		p = new pass[ew * 2];
		node = new vector<ll>[v];
		used = new bool[v];
		nowin = new ll[v];
		e = 0;
	}

	void add(ll f, ll t, ll c)
	{
		p[e].t = t;
		p[e].c = c;
		p[e].p = e + 1;
		p[e + 1].t = f;
		p[e + 1].c = 0;
		p[e + 1].p = e;
		node[f].push_back(e);
		node[t].push_back(e + 1);
		e += 2;
	}

	ll solve()
	{
		ll nn = 0;
		for (auto i : node[0])
		{
			nn = max(nn, p[i].c);
		}
		while (nn > 0)
		{
			stack<ll> st;
			queue<ll> q;
			for (ll i = 0; i < v; i++)
			{
				used[i] = false;
				nowin[i] = 0;
			}
			q.push(0);
			used[0] = true;
			while (!q.empty())
			{
				ll np = q.front();
				q.pop();
				st.push(np);
				for (auto i : node[np])
				{
					if (p[i].c > 0)
					{
						ll t = p[i].t;
						nowin[t] += p[i].c;
						if (nowin[t] >= nn && !used[t])
						{
							if (t == v - 1)
							{
								st.push(t);
								goto aa;
							}
							q.push(t);
							used[t] = true;
						}
					}
				}
			}
		aa:
			if (st.top() != v - 1)
			{
				nn /= 2;
				continue;
			}
			while (!q.empty())
			{
				used[q.front()] = false;
				q.pop();
			}
			for (int i = 0; i < v; i++)
			{
				nowin[i] = 0;
			}
			nowin[v - 1] = nn;
			while (st.size() > 1)
			{
				ll np = st.top();
				st.pop();
				for (auto i : node[np])
				{
					ll h = p[i].p;
					if (used[p[i].t] && p[h].c > 0)
					{
						ll w = min(p[h].c, nowin[np]);
						p[h].c -= w;
						p[i].c += w;
						nowin[np] -= w;
						nowin[p[i].t] += w;
						if (nowin[np] == 0)
						{
							break;
						}
					}
				}
				used[np] = false;
			}
		}
		ll all = 0;
		for (auto i : node[0])
		{
			if (i % 2 == 0)
			{
				all += p[p[i].p].c;
			}
		}
		return all;
	}

	void del()
	{
		delete[] p;
		delete[] node;
		delete[] used;
		delete[] nowin;
	}
};

ll dn[2000];
ll dm[2000];

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return b;
	}
	return gcd(b, a % b);
}

int main()
{
	while (1)
	{
		scale a;
		ll n, m;
		scanf("%lld%lld", &n, &m);
		if (n == 0)
		{
			break;
		}
		a.set(n + m + 2, n * m * 2);
		for (ll i = 0; i < n; i++)
		{
			scanf("%lld", &dn[i]);
			a.add(0, 1 + i, 1);
		}
		for (ll i = 0; i < m; i++)
		{
			scanf("%lld", &dm[i]);
			a.add(n + 1 + i, n + m + 1, 1);
		}
		for (ll i = 0; i < n; i++)
		{
			for (ll ii = 0; ii < m; ii++)
			{
				if (1 < gcd(dn[i], dm[ii]))
				{
					a.add(1 + i, n + 1 + ii, 1);
				}
			}
		}
		printf("%lld\n", a.solve());
		a.del();
	}
	return 0;
}

Measured memory_bytes: 17620
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int w = sc.nextInt();
        if(w >= s)
            System.out.println("unsafe");
        else
            System.out.println("safe");
    }
}

Measured memory_bytes: 35584
A,B, K = map(int,input().split())

for i in range(K):
    if i%2==0:
        if A%2!=0:
            A -= 1
        B += A//2
        A -= A//2
    else:
        if B%2!=0:
            B -= 1
        A += B//2
        B -= B//2

print(A,B)


Measured memory_bytes: 2940
import numpy as np

n = int(input())
tmp = [int(input()) for _ in range(n)]

c = [tmp[0]]
for x in tmp[1:]:
    if x != c[-1]:
        c.append(x)

c = np.array(c)

MOD = 10**9 + 7

# dpテーブル
dp = np.zeros(c.shape[0], dtype=np.int64)
dp[0] = 1

used = np.full(c.max() + 1, -1, dtype=np.int64)
used[c[0]] = 1

for i in range(1, c.shape[0]):
    if used[c[i]] == -1:
        dp[i] = dp[i - 1]
    else:
        dp[i] = (dp[i - 1] + dp[used[c[i]]]) % MOD
    used[c[i]] = i

print(dp[-1])

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

using namespace std;

#define ll long long

ll power(ll a,ll p)
{
	int m=1e9+7;
	ll res=1;
	for(int i=0;i<p;i++)
	{
		res=((res%m)*(a%m))%m;
	}
	return res%m;
}

int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif // ONLINE_JUDGE
	ll times=1;
	// cin>>times;
    int m=1e9+7;
	while(times--)
	{
		int n;
		cin>>n;
        ll p1=power(10,n)%m;
        ll p2=(2*power(9,n))%m;
        ll p3=power(8,n)%m;
		cout<<(p1-p2+p3+m)%m;
	}
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
string s,t,ans;
int main()
{
    cin>>s;
    cin>>t;
    int n=s.size();
    string ans=s+s;
    //cout<<ans<<endl;
    int flag=1;
    for(int i=0; i<2*n; i++)
    {
        int k=0;
        for(int j=i,p=0; j<i+n&&j<2*n; j++)
        {
            if(ans[j]!=t[p])
                break;
            else
                k++,p++;
        }
        if(k==n)
        {
            flag=0;
            break;
        }
    }
    if(flag==0)
        printf("Yes\n");
    else
        printf("No\n");
}


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

using namespace std;
typedef long long int ll;

int main()
{
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>>v(m);
    for(int i = 0; i < m; i++)
    {
        int a,b;
        cin >> a >> b;
        v[i] = pair(b,a);
    }
    sort(v.begin(),v.end());
    int count = 0;
    int x = 0;
    for(int i = 0; i < m; i++)
    {
        int a = v[i].second;
        int b = v[i].first;
        if(a <= x) continue;
        x = b - 1;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 4020
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, X;
	cin >> N >> X;
	vector<int> A(N);
	int res = -1;
	vector<int> sum(N + 1);
	sum[0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum[i + 1] = sum[i] + A[i];
	}
	int k = 0;

	for (int i = 0; i < N; i++) {
		k += A[i] * 5;
	}
	for (int i = (N + 1) / 2; i >= 1; i--) {
		k = 0;
		for (int j = 0; j < N; j += i) {
			k += (sum[N - j] - sum[max((int)0, N - (j + i))]) * max((int)5, (2 * (j/i) + 3));
			//cerr << i << " " << N - j << " " << max((int)0, N - (j + i)) <<" " << max((int)5, (2 * j + 3)) << endl;
		}
		int ans = k + X*i + N*X;
		//cerr << i << " " << ans << endl;
		if (res == -1 || res > ans) {
			res = ans;
		}
		else {
			break;
		}


	}

	cout << res << endl;
}

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

int main() {
  vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  int K;
  cin >> K;
  
  cout << vec.at(K - 1) << endl;
  
}


Measured memory_bytes: 256
dice = STDIN.gets.chomp().split(" ")
# p dice
q = STDIN.gets.to_i
newdice = []
for i in 0..q-1 do
  line = STDIN.gets.split(" ")
  d = [line[0], line[1]]
  newdice << d
end
# p newdice
result = Array.new(q){|i| Array.new(6)}
# p result

def move(direction, dice)
  case direction
  when "S" then
    temp = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = temp
  when "N" then
    temp = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = temp
  when "E" then
    temp = dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = temp
  when "W" then
    temp = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = temp
  end
  return dice
end

def getDrection(ran)
  case ran
  when 0
    return "S"
  when 1
    return "N"
  when 2
    return "E"
  when 3
    return "W"
  end
end

while true
  direction = getDrection(rand(4))
  dice = move(direction, dice)
  # p "dice = #{dice}"
  # p "newdice = #{newdice}"
  count = 0
  newdice.each do |x|
    # p "x[0] = #{x[0]}"
    # p "dice[0] = #{dice[0]}"
    # p "x[1] = #{x[1]}"
    # p "dice[1] = #{dice[1]}"
    if x[0] == dice[0] && x[1] == dice[1] then
      result[count][2] = dice[2]
    end
    count += 1
  end
  flag = true
  # puts "result = #{result}"
  result.each do |x|
    if x[2] == nil then flag = false end
  end
  if flag == true then break end
end

result.each do |x|
  puts x[2]
end

Measured memory_bytes: 6120
#include <iostream>
#include <map>
#include <cmath>
#include <cassert>
using namespace std;

long long N, M, A[100009], B[100009], C[100009], D[100009][5], dp[100009][16], mod = 998244353;
map<long long, long long>Map[100009];

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 60; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

int main() {
	cin >> N >> M; long long ret = (N - 2)*(N - 3) / 2;
	//assert(N != 2);

	for (int i = 0; i < N; i++) { for (int j = 0; j < 5; j++) D[i][j] = -1; }
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i] >> C[i]; A[i]--; B[i]--;
		if (A[i] - B[i] == +2) D[A[i]][0] = C[i];
		if (A[i] - B[i] == +1) D[A[i]][1] = C[i];
		if (A[i] - B[i] == +0) D[A[i]][2] = C[i];
		if (A[i] - B[i] == -1) D[A[i]][3] = C[i];
		if (A[i] - B[i] == -2) D[A[i]][4] = C[i];

		if (abs(A[i] - B[i]) >= 3) {
			if (Map[B[i]][A[i]] >= 1 && (C[i] + (Map[B[i]][A[i]] - 1)) % 2 == 1) {
				cout << "0" << endl;
				return 0;
			}
			Map[A[i]][B[i]] = C[i] + 1;
			if (Map[B[i]][A[i]] == 0) ret--;
		}
	}
	for (int i = 0; i < 16; i++) {
		int bit[4]; for (int j = 0; j < 4; j++) bit[j] = (i / (1 << j)) % 2;

		bool ok1 = true;
		if (bit[0] != D[0][2] && D[0][2] != -1) ok1 = false;
		if (bit[1] != D[0][3] && D[0][3] != -1) ok1 = false;
		if (bit[2] != D[1][1] && D[1][1] != -1) ok1 = false;
		if (bit[3] != D[1][2] && D[1][2] != -1) ok1 = false;
		if ((bit[0] + bit[1] + bit[2] + bit[3]) % 2 == 1) ok1 = false;
		if (ok1 == true) dp[0][i] = true;
	}
	for (int i = 0; i < N - 2; i++) {
		for (int j = 0; j < 16; j++) {
			if (dp[i][j] == 0) continue;

			int c[3][3] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };
			int bita[4]; for (int k = 0; k < 4; k++) bita[k] = (j / (1 << k)) % 2;
			c[0][0] = bita[0]; c[0][1] = bita[1]; c[1][0] = bita[2]; c[1][1] = bita[3];

			for (int k = 0; k < 32; k++) {
				int bitb[5]; for (int l = 0; l < 5; l++) bitb[l] = (k / (1 << l)) % 2;
				c[0][2] = bitb[0]; c[1][2] = bitb[1]; c[2][0] = bitb[2]; c[2][1] = bitb[3]; c[2][2] = bitb[4];

				bool ok1 = true;
				if (c[0][2] != D[i + 0][4] && D[i + 0][4] != -1) ok1 = false;
				if (c[1][2] != D[i + 1][3] && D[i + 1][3] != -1) ok1 = false;
				if (c[2][0] != D[i + 2][0] && D[i + 2][0] != -1) ok1 = false;
				if (c[2][1] != D[i + 2][1] && D[i + 2][1] != -1) ok1 = false;
				if (c[2][2] != D[i + 2][2] && D[i + 2][2] != -1) ok1 = false;
				if (((c[1][1] + c[1][2] + c[2][1] + c[2][2]) & 1) == 1) ok1 = false;
				if (((c[0][0] + c[0][1] + c[0][2] + c[1][0] + c[1][1] + c[1][2] + c[2][0] + c[2][1] + c[2][2]) & 1) == 1) ok1 = false;

				if (ok1 == true) {
					int mask = c[1][1] + 2 * c[1][2] + 4 * c[2][1] + 8 * c[2][2];
					dp[i + 1][mask] += dp[i][j];
					dp[i + 1][mask] %= mod;
				}
			}
		}
	}
	long long sum = 0;
	for (int i = 0; i < 16; i++) sum += dp[N - 2][i];
	sum %= mod;
	sum *= modpow(2, ret, mod); sum %= mod;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 29440
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define repr(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(),(x).end()

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

	double c = (a + b) / 2.0;
	int ans = c + 0.9999999999;

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2708>
 問題文============================================================
 =================================================================
 解説=============================================================
 
 ================================================================
 */

string replace(string S,string from,string to){
    auto pos = S.rfind(from);
    while(pos != string::npos){
        S.replace(pos,from.size(),to);
        pos = S.rfind(from);
    }
    return S;
}

bool rec(string s){
    if(s.length() <= 2) return false;
    if(s == "ABC") return true;
    string tmpS = replace(s,"ABC","@");
    for(int i = 0; i < 3;i++){
        if(!count(tmpS.begin(),tmpS.end(),"ABC"[i])){
            string tmpS2 = replace(tmpS,"@",string(1,"ABC"[i]));
            if(tmpS2 == s) continue;
            if(rec(tmpS2)) return true;
        }
    }
    return false;
}
string solve(){
    string res;
    string S; cin >> S;
    res = rec(S)?"Yes":"No";
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 15784
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int N,M,Q;
vint node[SIZE];
int painted[SIZE]={};
int color[SIZE]={};
void DFS(int NODE,int DIS,int COL){
	if(color[NODE]==0)
		color[NODE]=COL;
	if(painted[NODE]>=DIS)
		return;
	painted[NODE]=DIS;
	for(int i=0;i<node[NODE].size();i++){
		DFS(node[NODE][i],DIS-1,COL);
	}
}
int main(){
	cin>>N>>M;
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		a--,b--;
		node[a].pb(b);
		node[b].pb(a);
	}
	cin>>Q;
	vector<tint> query;
	for(int i=0;i<Q;i++){
		int v,d,c;
		cin>>v>>d>>c;
		v--;
		query.pb(mt(v,d,c));
	}
	reverse(query.begin(),query.end());
	for(int i=0;i<Q;i++){
		int v,d,c;
		tie(v,d,c)=query[i];
		DFS(v,d,c);
	}
	for(int i=0;i<N;i++)
		cout<<color[i]<<endl;
	return 0;
}

Measured memory_bytes: 8816
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[100010], pr[100010], af[100010], pr1[100010], af1[100010];
vector<pair<ll, int>>b;
int main(){
  ll n;
  while(cin>>n){
        for(int i=1; i<=n; ++i){
            scanf("%lld",a+i);
            b.push_back(mk(a[i],i));
        }
        multiset<int> st;
        st.insert(0);
        st.insert(n+1);
        st.insert(0);
        st.insert(n+1);
        sort(b.begin(), b.end());
        reverse(b.begin(), b.end());
        set<int>::iterator it1, it;
        for(int i=0; i<n; ++i){
            st.insert(b[i].sc);
            it=st.find(b[i].sc);
            it1=it;
            --it1;
            pr[b[i].fs]=*it1;
            --it1;
            pr1[b[i].fs]=*it1;
            ++it;
            af[b[i].fs]=*it;
            ++it;
            af1[b[i].fs]=*it;
//            cout<<b[i].fs<<" "<<pr[b[i].fs]<<" "<<af[b[i].fs]<<endl;
        }
        a[n+1]=n+1;
        a[0]=0;
        pr[0]=0;
        af[n+1]=n+1;
        ll ans=0, tmp1, tmp2, tmp3, tmp4;
        for(int i=1; i<=n; ++i){
            tmp1=pr[a[i]];
            tmp2=af[a[i]];
            tmp3=pr1[a[i]];
            tmp4=af1[a[i]];
            ans+=a[i]*(tmp1-tmp3)*(tmp2-i);
            ans+=a[i]*(tmp4-tmp2)*(i-tmp1);
        }
        cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 10352
#include<stdio.h>
#include<stdlib.h>
int fun(int ,int );
int fun(int s,int k)
{
    int i,j,t,ans=0;
    for(i=0;i<=k;i++)
    {
        for(j=0;j<=k;j++)
        {
            t=s-i-j;
            if(t>=0&&t<=k)
            {
                ans++;
            }
        }
    }
    return ans;
}
int main()
{
    int s,k;
    scanf("%d%d",&k,&s);
    printf("%d\n",fun(s,k));
    return 0;
}

Measured memory_bytes: 256
import math

def main():
    A,B,H,M=map(int,input().strip().split())
    round_hour=12*60
    round_min=60
    
    #digree to radian
    degree_hour=(60*H+M)/round_hour*360
    degree_min=M/round_min*360
    radian_hour=math.radians(degree_hour)
    radian_min=math.radians(degree_min)
    
    #distance
    d1=A*math.cos(radian_hour)-B*math.cos(radian_min)
    d2=A*math.sin(radian_hour)-B*math.sin(radian_min)
    
    return math.sqrt(d1**2+d2**2)

if __name__=="__main__":
    print(main())

Measured memory_bytes: 9584
#include <iostream>

using namespace std;

int main() {
  int A, B, C, D;
  int result1, result2;

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

  if(A < B) {
    result1 = A;
  } else {
    result1 = B;
  }

  if(C < D) {
    result2 = C;
  } else {
    result2 = D;
  }
  
  cout << (result1 + result2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n, k; cin >> n >> k;
    vector<int> height(n);
    REP(i, n) cin >> height[i];
    whole(sort, height);

    int ans = INF;
    FOR(i, k - 1, n){
        int sa = height[i] - height[i - (k - 1)];
        ans = min(ans, sa);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var d, t, s int
	fmt.Scanf("%d %d %d", &d, &t, &s)

	m := float64(d) / float64(s)

	if m <= float64(t) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


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

constexpr int C=9;

int N,V[(1<<18)+1],W[(1<<18)+1],Q;
vector<pair<int,int>>WV[(1<<C)+1];

int main(){
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>V[i]>>W[i];
	}
	WV[1].push_back({0,0});
	WV[1].push_back({W[1],V[1]});
	for(int i=2;i<(1<<C);i++){
		WV[i]=WV[i/2];
		for(auto p:WV[i/2]){
			WV[i].push_back({p.first+W[i],p.second+V[i]});
		}
		sort(WV[i].begin(),WV[i].end());
		for(int j=0;j<WV[i].size()-1;j++){
			WV[i][j+1].second=max(WV[i][j].second,WV[i][j+1].second);
		}
	}
	cin>>Q;
	while(Q--){
		int v,L;
		cin>>v>>L;
		vector<pair<int,int>>vp;
		vp.push_back({0,0});
		while(v>=(1<<C)){
			for(int i=vp.size()-1;i>=0;i--){
				vp.push_back({vp[i].first+W[v],vp[i].second+V[v]});
			}
			v/=2;
		}
		int res=0;
		for(auto a:vp){
			if(a.first>L)continue;
			auto it=lower_bound(WV[v].begin(),WV[v].end(),pair<int,int>{L-a.first+1,-1});
			it--;
			res=max(res,a.second+it->second);
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 7020
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
#include <cmath>
#include <numeric>
#include <iomanip>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int64_t W, H, x, y;
    cin >> W >> H >> x >> y;

    cout << fixed << setprecision(9) << (W * H) / 2.0;
    cout << " " << ((W == (x + x)) && (H == (y + y))) << endl;

    return 0;
}

Measured memory_bytes: 256
function main()
    N,K = reads(Int,Int)
    a = readvec(Int, N)
    for i in K+1:N
        println(a[i] > a[i-K] ? "Yes" : "No")
    end
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


Measured memory_bytes: 212328
fun main(args: Array<String>) {
    val c = 0.until(3).map {
        readLine()?.split(" ")?.map(String::toInt) ?: return
    }
    0.until(c[0].min()!! + 1).forEach {
        val a1 = it
        val b1 = c[0][0] - a1
        val b2 = c[0][1] - a1
        val b3 = c[0][2] - a1

        val s1 = c[1][0] - b1
        val s2 = c[1][1] - b2
        val s3 = c[1][2] - b3
        if (s1 == s2 && s2 == s3) {
            val t1 = c[2][0] - b1
            val t2 = c[2][1] - b2
            val t3 = c[2][2] - b3
            if (t1 == t2 && t2 == t3) {
                println("Yes")
                return
            }
        }
    }
    println("No")
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

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

    map<char,int> cnt1,cnt2;
    for (char i = 'a'; i <= 'z'; i++){
        cnt1[i] = 0;
    }

    for (int i = 0; i < (int)s[0].size(); i++){
        cnt1[s[0][i]]++;
    }
    for (int i = 1; i < N; i++){
        for (char i = 'a'; i <= 'z'; i++){
            cnt2[i] = 0;
        }
        for (int k = 0; k < (int)s[i].size(); k++){
            cnt2[s[i][k]]++;
        }
        for (char k = 'a'; k <= 'z'; k++){
            if (cnt1[k] > cnt2[k]){
                cnt1[k] = cnt2[k];
            }
        }
    }
    for (char i = 'a'; i <= 'z'; i++){
        while(cnt1[i] != 0){
            cout << i;
            --cnt1[i];
        }
    }
    cout << endl;






    return 0;
}


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

using namespace std;

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

    if (n == 1) cout << "Hello World";
    else {
        int a, b;
        cin >> a >> b;
        cout << a + b;
    }



    return 0;
}



Measured memory_bytes: 256
#include<cstdio>  
#include<iostream>  
#include<algorithm>  
#include<cstdlib>  
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#define LL long long
 
using namespace std;

LL n,m;

 
int main()
{
    cin>>n>>m; 
    LL x,y,z;
    vector<LL> a(m+10);
    for(int i=0;i<n;i++)
	{
		cin>>x>>y;
        z=y-x+1;a[0]+=1;a[z]-=1;
        LL t=z+1,s;
        while(t<=m)
		{
            LL v=((x+t-1)/t);
			if(v <= 0) break;
            s=y/v;
            if(s >= t)
			{
                a[t-1] += 1;
                a[s] -= 1;
            }
            if(v <= 1) break;
            t = max(s+1, (x + (v-1)-1) / (v-1));
        }
    }
    LL ans=0;
    for (int i=0;i<m;i++)
    	ans+=a[i],cout<<ans<<endl;
    return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int A,B;
    cin >> A >> B;
    for( int i = 1; i < 10001;i++)
    {
        if( (int)(i*0.08) == A && (int)(i *0.1) == B )
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;


}


Measured memory_bytes: 256
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    [a, b, c] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
    let l = take (b `div` gcd a b) [n * a `mod` b | n <- [1..]]
    putStrLn $ case find (\x -> x `mod` b == c) l of
                Just _ -> "YES"
                Nothing -> "NO"


Measured memory_bytes: 380
#include <iostream>
#include <string>

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

  for (int i = 1; i < b; i++) {
    if ((a*i)%b == c) {
      std::cout << "YES" << std::endl;
      return 0;
    }
  }
  std::cout << "NO" << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <memory.h>
using namespace std;
const int MAXN = 2000 + 10;
int nums[MAXN*2], tree[MAXN*2];
int costw[MAXN][MAXN], costb[MAXN][MAXN], dp[MAXN][MAXN];
int lowbit(int i) {
    return i&(-i);
}
void add (int i) {
    int n = MAXN*2;
    while (i < n) {
        tree[i]++;
        i += lowbit(i);
    }
}
int query (int i) {
    int ret = 0;
    while (i > 0) {
        ret += tree[i];
        i -= lowbit(i);
    }
    return ret;
}
int query (int i, int j) {
    if (i > j) return 0;
    if (i == 0) return query(j);
    return query(j) - query(i-1);
}

void solve(int i, int j) {
    if (dp[i][j] != -1) return;
    int val = INT_MAX;
    if (i > 0) {
        solve(i-1, j);
        val = min(val, dp[i-1][j] + costw[i][j]);
    }
    if (j > 0) {
        solve(i, j-1);
        val = min(val, dp[i][j-1]+ costb[i][j]);
    }
    dp[i][j] = val;
}


int main() {
//    freopen("test.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    char c;
    for (int i = 1; i <= 2*n; i++) {
        cin >> c >> nums[i];
        if (c == 'B') nums[i] += 2000;
    }
    for (int i = 0; i <= n; i++) {
        memset(tree, 0, sizeof(tree));
        for (int j = 1; j <= 2*n; j++) {
            add(nums[j]);
            if (nums[j] > 2000) {
                costb[i][nums[j]-2000] = query(nums[j]+1, 2000 + n);
                costb[i][nums[j]-2000] += query(i+1, 2000);
            }
        }
    }
    for (int i = 0; i <= n; i++) {
        memset(tree, 0, sizeof(tree));
        for (int j = 1; j <= 2*n; j++) {
            add(nums[j]);
            if (nums[j] <= 2000) {
                costw[nums[j]][i] = query(nums[j]+1, 2000);
                costw[nums[j]][i] += query(2000+i+1, 2000+n);
            }
        }
    }
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    solve(n, n);
    cout << dp[n][n] << endl;
    return 0;
}


Measured memory_bytes: 47744
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int dp[1<<12],a,b;
int main(){
    MS1(dp);
    dp[0]=0;
    int N,M;
    auto mii = [](auto& x,auto y){if(x>y)x=y;};
    R(N,M);
    FOR(i,1,M){
        R(a,b);
        int me=0;
        REP(j,b){
            int x; R(x);
            me|=1<<(x-1);
        }
        REP(j,1<<N){
            if(dp[j]>=0){
                if(dp[j|me]==-1)dp[j|me]=dp[j]+a;
                else mii(dp[j|me],dp[j]+a);
            }
        }
    }
    if(dp[(1<<N)-1]==-1)W(-1);
    else{
        W(dp[(1<<N)-1]);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
ll n,q,a[100010],ans[100010],res=0;
signed main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		ll v;cin>>v; a[v]++;res+=v;
	}
	cin>>q;
	for(ll i=0;i<q;i++){
		ll c,b;cin>>c>>b;
		if(a[c]==0||c==b){ans[i]=res;continue;
		}
		ll calc=(b-c)*a[c];
		res+=calc;
		ans[i]=res;
		a[b]+=a[c];a[c]=0;
	}
	for(ll i=0;i<q;i++){
		cout<<ans[i]<<endl;
	}
}

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

a.sort()
a_max = a.pop(-1)
r = 0
for i in range(n-1):
    if abs((a_max/2) - a[i]) < abs((a_max/2) - r):
        r = a[i]
print(a_max, r)

Measured memory_bytes: 14428
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n, h, w;
	scanf("%d%d%d", &n, &h, &w);
	h = max(0, n - h + 1);
	w = max(0, n - w + 1);
	printf("%d\n", h * w);	
}

Measured memory_bytes: 256
from collections import deque

def bfs():
    d = [[inf]*(w+1) for _ in range(h+1)]
    que = deque()
    que.append((0,0))
    d[0][0] = 0

    while que:
        cx,cy = que.popleft()
        if cx == w and cy == h:
            break
        for dx,dy in [[1,0],[-1,0],[0,1],[0,-1]]:
            nx, ny = cx+dx, cy+dy
            if 0 <= nx <= h and 0 <= ny <= w and s[nx][ny] != "#" and d[nx][ny] == inf:
                que.append((nx,ny))
                d[nx][ny] = d[cx][cy] + 1
    return d[h][w]

h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
inf = float("inf")
h,w = h-1,w-1
cnt = bfs()
dot = 0
for i in s:
    dot += i.count(".")
if 0 < cnt < inf:
  print(dot-cnt-1)
else:
  print(-1)

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    vector<int>d(3);
    d[0]=a; d[1]=b; d[2]=c;
    sort(d.begin(),d.end());
    int cnt=0;
    int sa1=d[1]-d[0];
    int sa2=d[2]-d[1];
    if(sa1%2==0){
        rep(i,1000){
            sa1-=2;
            if(sa1>=0)cnt+=1;
            else break;
        }
        cnt+=sa2;
        cout<<cnt<<endl;
        return 0;
    }
    else{
        cnt+=1;
        sa1+=1;
        rep(i,1000){
            sa1-=2;
            if(sa1>=0)cnt+=1;
            else break;
        }
        cnt+=sa2;
        cout<<cnt<<endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N, M; cin >> N >> M;
  vector<vector<bool>> sw(M, vector<bool>(N, false));
  for (int m = 0; m < M; ++m) {
    int K; cin >> K;
    for (int k = 0; k < K; ++k) {
      int s; cin >> s; --s;
      sw[m][s] = true;
    }
  }
  vector<int> p(M);
  for (int m = 0; m < M; ++m) cin >> p[m];

  int ok_cnts = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bitset<10> b(i);
    vector<int> cnts(M, 0);
    for (int n = 0; n < N; ++n) {
      if (b.test(n)) {
        for (int m = 0; m < M; ++m) {
          if (sw[m][n]) ++cnts[m];
        }
      }
    }

    bool ok = true;
    for (int m = 0; m < M; ++m) {
      if (cnts[m] % 2 != p[m]) {
        ok = false;
        break;
      }
    }
    if (ok) ++ok_cnts;
  }

  cout << ok_cnts << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
	ll N , P;
	cin >> N >> P;
	ll dp[N+1][2]={};
	dp[0][0] = 1;
	FOR(i,1,N+1){
		ll k;
		cin >> k;
		if(k%2){
			dp[i][1] = dp[i-1][1] + dp[i-1][0];
			dp[i][0] = dp[i-1][1] + dp[i-1][0];
		}else{
			dp[i][1] = dp[i-1][1]*2;
			dp[i][0] = dp[i-1][0]*2;
		}
	}
	cout << dp[N][P] << endl;
}

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

int main(){
	int r;
	cin >> r;
	string ans="ABC";
	if(1200<=r && r<2800){
		ans = "ARC";
	}
	else if(2800<= r){
		ans = "AGC";
	}
	cout << ans << endl;
	return 0;



}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
void print(ll x){
	char y=x%10+'0';
	if(x>=10)print(x/10);
	putchar(y);
}
ll n,ab=1,ans,sum,mod=1e9+7,a[100005],s[100005];
ll power(ll x,ll y){
	ll res=1;
	for(;y;x=x*x%mod,y>>=1)
		if(y&1)res=res*x%mod;
	return res;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		ab=ab*i%mod,a[i]=read();
		s[i]=(power(i,mod-2)+s[i-1])%mod;
	}
	for(int i=1;i<=n;i++)
		sum=(sum+a[i]*s[n-i+1])%mod;
	ans=ab*sum%mod;
	reverse(a+1,a+n+1);
	sum=0;
	for(int i=1;i<=n;i++)
		sum=(sum+a[i]*s[n-i+1])%mod;
	ans=(ans+ab*sum)%mod;
	for(int i=1;i<=n;i++)
		ans=(ans-a[i]*ab%mod+mod)%mod;
	print(ans);
	return 0;
}

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

using namespace std;

typedef long long int lli;

int main() {
    int a, b;

    cin >> a >> b;

    if (a <= 5) cout << 0 << endl;
    else if (a <= 12) cout << b/2 << endl;
    else cout << b << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

// template<typename T>
// void print(T &arr){
//     ll sz = sizeof(arr)/sizeof(arr[0]);
//     for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
//     cout << arr[sz-1] << endl;
// }


// void print(P x){
//     cout << x.first << " " << x.second << endl;
//     return ;
// };

int main(){
    int k; cin >> k;
    vector<ll> a(k);
    rep(i,k) cin >> a[i];
    vector<pair<ll, ll>> res(k);

    // mを超えない，xで割るとr余る最大の数
    auto remaind = [](ll m, ll x, ll r){
        ll temp = (m / x)*x + r;
        if(m < temp)temp -= x;
        // print("remaind");
        // print(m,x,r,temp);
        assert(m >= temp);
        return temp;
    };

    // mを超える，xで割るとr余る最大の数
    auto over = [](ll m, ll x, ll r){
        ll temp = (m / x)*x + r;
        if(m > temp)temp += x;
        // print("over");
        // print(m,x,r,temp);
        assert(m <= temp);
        return temp;
    };
    bool ok = true;
    if(a[k-1] == 2){
        res[k-1] = Pll(2,3);
    }else{
        ok = false;
    }
    for(int i = k-2; 0 <= i; --i){
        ll mi,ma;
        ma = remaind(res[i+1].second + a[i]-1, a[i], a[i]-1);
        mi = over(res[i+1].first, a[i], 0);
        if(mi > ma){ok = false;break;}
        res[i] = Pll(mi,ma);
    }
    if(ok) print(res[0].first, res[0].second);
    else cout << -1 << endl;
    return 0;

}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double;  using vld = vector<ld>; 

int main(void) {
	ll a,b;	cin >>a>>b;
	vll c(3);
	c[0]=a+b;
	c[1]=a-b;
	c[2]=a*b;
	
	sort(all(c));

	cout <<c[2]<<endl;
	
	
    return 0;
}

Measured memory_bytes: 256