akhauriyash/Code-Regression huggingface dataset:
import fractions


def lcm(a, b):
    n = fractions.gcd(a, b)
    return a * b // n if n > 0 else 0


N = int(input())
T = [int(input()) for _ in range(N)]
tmp = 1
for i in range(N):
    tmp = lcm(tmp, T[i])
print(tmp)


Measured memory_bytes: 5048
n = int(input())
s = []
for i in range(n):
    s.append(input())

m = int(input())
t = []
for i in range(m):
    t.append(input())

set_s = set(s) 

max_result = 0
for elem in set_s:
    r = s.count(elem) - t.count(elem)
    max_result = max(r, max_result)

print(max_result)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class A { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long H = GetLong();
		long W = GetLong();
		long h = GetLong();
		long w = GetLong();
		WriteLine((H - h) * (W - w));
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


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

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    long long int a[n],b[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }

    long long int suma = 0;
    long long int sumb = 0;
    for(int i = 0; i < n; i++) {
        suma += a[i];
        sumb += b[i];
    }
    long long int a1 = sumb - suma;
    //2plus
    long long int a2 = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] < b[i]) {
            a2 += ((b[i] - a[i]) + 1LL) / 2LL;
        } else {
            //a2 += (a[i] - b[i]);
        }
    }
    if(a2 <= a1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}





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

typedef long long ll;

int main(){
  int n;
  cin >> n;
  map<long, int> m;
  for(int i = 0; i < n; i++){
    long tmp;
    cin >> tmp;
    if(m.count(tmp) == 0){
      m[tmp] = 1;
    } else { 
      m.erase(tmp);
    }
  }
  int ans = 0;
  for(auto x: m){
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long ll;

int dp[100][2][100];//dp[keta][未満である][0でない数の個数]

struct UnionFind {
  vi parent;
  UnionFind(int N) : parent(N) {
    rep(i, N)parent[i] = i;
  }

  int getRoot(int child){
    return ((parent[child] == child) ? child : parent[child] = getRoot(parent[child]));
  }
  void unite(int x, int y){
    int root_x = getRoot(x);
    int root_y = getRoot(y);
    if(root_x == root_y)return;
    parent[root_x] = parent[root_y];
  }
  bool isSame(int x, int y){
    return getRoot(x) == getRoot(y);
  }
};
int main(){
    int N;cin >> N;
    int ans = 0;
    map<string, int> m;
    rep(i, N){
        string S;cin >> S;
        if(!m.count(S))
            m[S] = 1;
        else
            m[S] += 1;
        if(m[S] % 2)++ans;
        else --ans;
    }
    cout << ans;
}


Measured memory_bytes: 12544
import math 

N, K = map(int, input().split(" "))

M = 7 + 10**9

def comb(n, r):
    ret = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    ret = ret % M
    return ret

def calc(i):
    if N > K:
        blue = comb(K-1, i-1)
        red = 0
        if N-K-1 >= i-2 >= 0:
            red1 = comb(N-K-1, i-2)
            red = (red + red1) % M
        if N-K-1 >= i-1 >= 0:
            red2 = comb(N-K-1, i-1)
            red = (red + red2) % M
            red3 = red2
            red = (red + red3) % M
        if N-K-1 >= i>=0:
            red4 = comb(N-K-1, i)
            red = (red + red4) % M
        out = blue * red % M
    else:
        if i == 1:
            out = 1
        else:
            out = 0
    return out

for i in range(1, K+1):
    out = calc(i)
    print(out)



Measured memory_bytes: 3444
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include <string>
using namespace std;
int main()
{
    int N,M;
    int S;
    cin>>N>>M>>S;
    int a;
    if(N>M)
        a=N;
    else
        a=M;
    if(S%a==0)
    printf("%d",S/a);
    else
        printf("%d",S/a+1);

    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = [int(i) for i in input().split()]

for i in range(n):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j]>v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(" ".join(map(str,A)))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll MOD = ll(1e9) + 7;
constexpr int MAX_N = int(1e5) + 5;

int main() {
    ll n, dp[MAX_N][2]{};  // dp[0][i]:a+b=L, dp[1][i] = a+b<L
    string L;
    cin >> L;
    n = L.size();
    dp[0][0] = 1;
    for(ll i=0; i<n; i++){
        dp[i+1][1] = dp[i][1]*3 % MOD; // i+1桁目は0+0,1+0,0+1の3パターン
        if(L[i]=='1'){
            dp[i+1][0] += dp[i][0]*2; // 0+1,1+0
            dp[i+1][1] += dp[i][0]; // 0+0
        }
        else{
            dp[i+1][0] += dp[i][0]; // 0+0
        }
        dp[i+1][0] %= MOD;
        dp[i+1][1] %= MOD;
    }
    cout << (dp[n][0] + dp[n][1])%MOD << endl;
    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


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

  vector<int> W(N), S(N);
  REP(i, N) {
    cin >> W[i];
    if (i == 0) S[i] = W[i];
    else S[i] = S[i - 1] + W[i];
  }
  int m = S[N - 1];
  REP(i, N - 1){
    int tmp = S[N - 1] - S[i + 1];
    //cout << tmp << endl;
    m = min(m, abs(tmp - S[i + 1]));
  }

  cout << m << endl;



  return 0;
}


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

using namespace std;

int main()
{
    vector<int> antennas(5);
    for(int i = 0; i < 5; i++)
    {
        cin >> antennas[i];
    }
    int k;
    cin >> k;
    for(int i = 0; i < 5; i++)
    {
        for(int j = 4; j > i; j--)
        {
            if(antennas[j] - antennas[i] > k)
            {
                cout << ":(";
                return 0;
            }
        }
    }
    cout << "Yay!";

    return 0;
}


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

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

const int inf = 10000000;
int land[200][200];
int sea[200][200];
int dp[1000][200];

int main() {
    int N,M,R,x,y,i,j,k,t;
  string s;
  while(cin>>N>>M, N|M) {

    rep(i,200) {
      rep(j,200) land[i][j] = sea[i][j] = inf;
      land[i][i] = sea[i][i] = 0;
    }

    rep(i,M) {
      cin>>x>>y>>t>>s;
      x--,y--;
      if(s == "S") {
	sea[x][y] = min(t, sea[x][y]);
	sea[y][x] = sea[x][y];
      }else{
	land[x][y] = min(t, land[x][y]);
	land[y][x] = land[x][y];
      }
    }

    rep(k,N) {
      rep(i,N) {
	rep(j,N) {
	  sea[i][j] = min(sea[i][k]+sea[k][j], sea[i][j]);
	  land[i][j] = min(land[i][k]+land[k][j], land[i][j]);
	}
      }
    }

    cin>>R;
    vector<int> path;
    rep(i,1000) rep(j,200) dp[i][j] = inf;
    rep(i, R) {
      int kt;
      cin>>kt;
      kt--;
      path.push_back(kt);
    }

    dp[0][path[0]] = 0;
    for(i=1; i<R; ++i) {
      for(j=0; j<N; ++j) {
	dp[i][j] = min(dp[i-1][j]+land[path[i-1]][path[i]],dp[i][j]);

	for(k=0; k<N; ++k) {
	  int t = dp[i-1][j]+land[path[i-1]][j]+sea[j][k]+land[k][path[i]];
	  dp[i][k] = min(dp[i][k], t);
	}
	//cout<<i<<": "<<j<<" "<<dp[i][j]<<endl;
      }
    }

    int ans = inf;
    rep(i,N) {
      ans = min(ans, dp[R-1][i]);
      //cout<<i<<" : "<<dp[R-1][i]<<endl;
    }

    cout<<ans<<endl;


  }
}

Measured memory_bytes: 2332
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"Sunny", "Cloudy", "Rainy"};

int main(){
    int A[3];
    cins(A, A + 3);
    sort(A, A + 3);
    cout << A[2] * 10 + A[1] + A[0] << endl;
}


Measured memory_bytes: 256
#include<iostream>

int main(){
    int N, K;
    std::cin >> N >> K;
    int sum = 0;
    for(int i = 0; i < N; i++){
        int x;
        std::cin >> x;
        sum += std::min(std::abs(x), std::abs(K - x)) * 2;
    }

    std::cout << sum << std::endl;


    return 0;
}


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

namespace AtCoder_20190707_1
{    class Program
    {
        static void Main(string[] args)
        {
            string[] NXT = Console.ReadLine().Split();

            int N = int.Parse(NXT[0]);
            int X = int.Parse(NXT[1]);
            int T = int.Parse(NXT[2]);

            int takoyaki = 0;
            int answer = 0;

            while(takoyaki < N)
            {
                takoyaki += X;
                answer += T;
            }

            Console.WriteLine(answer);
        }
    }
}

Measured memory_bytes: 27228
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n;
long long a[55][55],A[55][55],tmp[55][55];
long long k;

void copy(long long x[][55],long long y[][55]){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			x[i][j]=y[i][j];
		}
	}
}

void mul(long long x[][55],long long y[][55],long long z[][55]){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				x[i][j]+=y[i][k]*z[k][j];
				x[i][j]%=mod;
			}
		}
	}
}

void ksm(long long x){
	x--;
	copy(A,a);
	while(x){
		if(x&1){
			memset(tmp,0,sizeof(tmp));
			mul(tmp,A,a);
			copy(A,tmp);
		}
		memset(tmp,0,sizeof(tmp));
		mul(tmp,a,a);
		copy(a,tmp);
		x/=2;
	}
	long long ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			ans+=A[i][j];
			ans%=mod;
		}
	}
	printf("%lld\n",ans);
}

int main(){
	cin>>n;
	cin>>k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
		}
	}
	ksm(k);

	return 0;
}

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

int main(){
  string s;
  cin >> s;

  string ans = "No";
  for (int i = 1; i < s.size(); i ++) {
    if (s[i-1] == 'A' && s[i] == 'C') ans = "Yes";
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<ll>>v;
ll f(ll n,ll w,ll val[],ll wt[]){
    if(n==-1)
        return 0;
    if(v[n][w]!=0)
        return v[n][w];
    if(w<wt[n])
        v[n][w] = f(n-1,w,val,wt);
    else
        v[n][w] = max(f(n-1,w,val,wt),f(n-1,w-wt[n],val,wt)+val[n]);
    return v[n][w];
}
int main() {
	ll n,w;
	cin>>n>>w;
	ll wt[n],val[n];
	vector<ll>tmp(w+1,0);
	for(ll i=0;i<n;i++){
	    cin>>wt[i]>>val[i];
	    v.push_back(tmp);
	}
	cout<<f(n-1,w,val,wt);
	return 0;
}

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

int main() {
	long long N, P;
	cin >> N >>  P;
	long long tmp = 0, max = 0, ans = 1;
	max = exp(log(P) / N)+1;
	for (long long i = max; i > 1; i--) {
		tmp = pow(i, N);
		if (P%tmp == 0) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int N;cin>>N;
    string c;cin>>c;
    int count = 0;
    for(int i=0;i<N;i++){
        if(c[i]=='R') count++;
    }
    int ans = 0;
    for(int i=0;i<count;i++){
        if(c[i]!='R') ans++; 
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long lint;
typedef pair<int, int> pii;

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int h, w;
char B[1010][1010];
int D[1010][1010];
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

bool valid(int x, int y){ return 1<=x && x<=h && 1<=y && y<=w; }

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

	cin>>h>>w;
	for(int i=1; i<=h; i++) cin>>(B[i]+1);


	queue<pii> Q;
	for(int i=1; i<=h; i++) for(int j=1; j<=w; j++)
		if(B[i][j]=='#') D[i][j] = 0, Q.push({i,j});
		else D[i][j] = INF;

	int ans = 0;

	while(!Q.empty()){
		int x,y; tie(x,y) = Q.front(); Q.pop();
		for(int k=0; k<4; k++){
			int u = x + dx[k], v = y + dy[k];
			if(!valid(u,v) || D[u][v] < INF) continue;
			D[u][v] = D[x][y] + 1; ans = max(ans, D[u][v]);
			Q.push({u,v});
		}
	}
	
	cout<<ans<<'\n';
		

	return 0;
}


Measured memory_bytes: 13456
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}

int32_t main()
{
	int t=1;
	while(t--)
	{
		int n;
		cin >> n;
		string s;
		cin >> s;
		int cnt=0;
		set<int,greater<int> > st;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='R')
			st.insert(i);
		}
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='W')
			{
				int x=(*st.begin());
				if(x>i)
				{
					cnt++;
					swap(s[x],s[i]);
					st.erase(st.begin());
				}
				else
				break;
			}
		}
		cout << cnt;		
	}
}




Measured memory_bytes: 12980
#include<stdio.h>

int main(void){
int n[100];
int i,j,s,t,x,z;
int sum=0;


i=0;
do{
scanf("%d",&n[i]);
i++;
}while(n[i-1]!=0);

for(i=0;n[i]!=0;i++){
	s=n[i];
	t=n[i]/10000+1;
	z=0;
		for(j=1;j<t;j++){
			if(s%j==0) sum+=j;
		}
		for(j=2;j<10000;j++){
			if(s%j==0){
				x=s/j;
				if(s%x==0) sum+=x;
			}
		}
    if(sum==n[i]) printf("perfect number\n");
    else if(sum>n[i]) printf("abundant number\n");
    else if(sum<n[i]) printf("deficient number\n");
    sum=0;
}

return 0;
}

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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))



/* constant */
//const int inf = 100100100100100100;
const int mod = 998244353;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
vector<int> cs(vector<int> arr){vector<int> tmp;if(arr.size() == 0) return tmp;tmp.push_back(arr[0]);rep(i,1,arr.size()){tmp.push_back(tmp.back() + arr[i]);}return tmp;}

/* math_library */
int gcd(int a, int b){ if(b == 0) return a; return gcd(b, a % b);}
int lcm(int a, int b){ return a * b / gcd(a,b);}
int ceil(int a, int b){ if(a % b == 0) return a/b; else return a/b + 1;}
int digitlen(int n){int t = n;int cnt = 0;while(t){cnt++;t /= 10;}return cnt;}
bool isprime(int n){if(n < 2) return false;if(n % 2 == 0 || n % 3 == 0 || n % 5 == 0) return false;for(int i = 7; i * i < n + 1; i += 2){if(n % i == 0) return false;}return true;}
int mod_pow(int x, int n, int m){if(n== 0) return 1;int res = mod_pow(x*x%m,n/2,m);if(n&1) res = res*x%m;return res;}
int digitsum(int n){int ret = 0;while(n){ret += n % 10;n /= 10;}return ret;}



/* main */


signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n = input();
    vector<int> arr; rep(i,0,n) arr.push_back(input());

    vector<int> ans;
    rep(i,0,(1 << n)){
        int s = 0;
        rep(j,0,n){
            if(i & (1 << j)){
                s += arr[j];
            }
        }
        ans.push_back(s);
    }

    sort(all(ans));

    int q = input();
    rep(i,0,q){
        int t = input();
        if(*lower_bound(all(ans), t) == t){
            print("yes");
        }else{
            print("no");
        }
    }

    return 0;

}






    










    




    











Measured memory_bytes: 11252
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        Set<String> SList = new HashSet<>();
        for (int i = 0; i < N; i++) {
            SList.add(sc.next());
        }
        System.out.println(SList.size());
    }
}

Measured memory_bytes: 66756
#include<stdio.h>

int main(void)
{
	int n,i,j;
	int b[240],f[240],r[240],v[240];
	int ittou[3][10]={0},nitou[3][10]={0},santou[3][10]={0},yonntou[3][10]={0};
	
	
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&b[i],&f[i],&r[i],&v[i]);
	}
	
	
	
	for(i=0;i<n;i++){
		if(b[i]==1){
			ittou[f[i]-1][r[i]-1]+=v[i];
		}
		else if(b[i]==2){
			nitou[f[i]-1][r[i]-1]+=v[i];
		}
		else if(b[i]==3){
			santou[f[i]-1][r[i]-1]+=v[i];
		}
		else if(b[i]==4){
			yonntou[f[i]-1][r[i]-1]+=v[i];
		}
	}
	
	
	
	for(i=0;i<3;i++){
		for(j=0;j<10;j++){
			printf(" %d",ittou[i][j]);
		}
		printf("\n");
	}
	
	for(i=0;i<20;i++){
		printf("#");
	}
	printf("\n");
	
	for(i=0;i<3;i++){
		for(j=0;j<10;j++){
			printf(" %d",nitou[i][j]);
		}
		printf("\n");
	}
	
	for(i=0;i<20;i++){
		printf("#");
	}
	printf("\n");
	
	for(i=0;i<3;i++){
		for(j=0;j<10;j++){
			printf(" %d",santou[i][j]);
		}
		printf("\n");
	}
	
	for(i=0;i<20;i++){
		printf("#");
	}
	printf("\n");
	
	for(i=0;i<3;i++){
		for(j=0;j<10;j++){
			printf(" %d", yonntou[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 2712
import java.util.Scanner;

/**
 * @author varun on 7/1/2018
 * @project CompetitiveProgramming
 */
public class Main {

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        String input  = scanner.nextLine();
        int count  = 0;
        for (char c : input.toCharArray()) {
            if (c == '1') {
                count++;
            }
        }
        System.out.println(count);
    }

}


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

const long long MOD=1000000007;
long long counta[300000][60][2];

int main(){
    //input
    long long N;
    cin >> N;
    long long A[N];
    long long i,j,k;
    for(i=0; i<N; i++){
        cin >> A[i];
    }

    //calc
    long long nibeki[60];
    nibeki[0]=1;
    for(i=1; i<60; i++){
        nibeki[i]=2*nibeki[i-1];
        nibeki[i]%=MOD;
    }
    for(i=0; i<300000; i++){
        for(j=0; j<60; j++){
            for(k=0; k<2; k++){
                counta[i][j][k]=0;
            }
        }
    }
    for(i=0; i<N-1; i++){
        for(j=0; j<60; j++){
            if((A[i]&((1LL)<<j))>0){
                counta[i+1][j][1]++;
            }else{
                counta[i+1][j][0]++;
            }
        }
    }
    for(i=0; i<N-1; i++){
        for(j=0; j<60; j++){
            for(k=0; k<2; k++){
                counta[i+1][j][k]+=counta[i][j][k];
                counta[i+1][j][k]%=MOD;
            }
        }
    }
    long long ans=0;
    for(i=1; i<N; i++){
        for(j=0; j<60; j++){
            if((A[i]&((1LL)<<j))>0){
                ans+=counta[i][j][0]*nibeki[j];
                ans%=MOD;
            }else{
                ans+=counta[i][j][1]*nibeki[j];
                ans%=MOD;
            }
        }
    }

    //output
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 287140
#include <iostream>
using namespace std;
int main()
{
    double r;
    double p = 3.141592653589;
    double s,l;
    cin >> r;
    s = 1.0 * r * r * p;
    l = 1.0 * r * 2 * p;
    printf("%.6lf %.6lf\n",s,l);
    return 0;
}


Measured memory_bytes: 3276
#include<bits/stdc++.h>
#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
using namespace std;
const int maxn=100010;
int a[maxn],b[maxn],c[maxn];
int dp[maxn][10];
int main()
{
	int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    for(int i=2;i<=n;i++)
    {
        //see(dp[i][1])
        dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
        //see(i)see(dp[i][1])
        dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i];
        //see(i)see(dp[i][2])
        dp[i][3]=max(dp[i-1][1],dp[i-1][2])+c[i];
        //see(i)see(dp[i][3])
    }
    cout<<max(dp[n][3],max(dp[n][1],dp[n][2]));
    return 0;
}


Measured memory_bytes: 8548
#include<iostream>
#include<cmath>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    string sb = to_string(b);
    int c = a * pow(10, sb.size()) + b;
    for (int i = 4; i <= (int)sqrt(c) + 1; i++) {
        if (c == i * i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  string a, b;
  cin >> a >> b;

  if (LEN(a) < LEN(b))
    puts("LESS");
  else if (LEN(a) > LEN(b))
    puts("GREATER");
  else {
    if (a == b) puts("EQUAL");
    else puts(a < b ? "LESS" : "GREATER");
  }
  return 0;
}



Measured memory_bytes: 764
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	long long int arr[n];
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &arr[i]);
		if (arr[i] == 0)
		{
			printf("0\n");
			return 0;
		}
	}
	long long int sum = 1;
	for (int i = 0; i < n; i++)
	{
		if (sum > 1000000000000000000/arr[i])
		{
			printf("-1\n");
			return 0;
		}
		sum *= arr[i];
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 2508
/*
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002
	Digit Number
*/

#include <stdio.h>
int main(void)
{
	int a,b,d,s;

	/* [EOF]??§???????????? */
	while (scanf("%d%d",&a,&b) != EOF){
		s = a + b;
		d = 0;

		while (s!=0){
		s = s / 10;
		d++;
		}
		printf("%d\n", d);

	}

	return 0;
}

Measured memory_bytes: 600
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 998244353

def ddprint(x):
  if DBG:
    print(x)

def modinv2(x,r):
  return pow(x,r-2,r)

def comb(n,a,R):
    return (fact[n]*modinv2(fact[n-a]*fact[a],R))

def factinit(n,R):
    global fact
    fact = [1]*(n+1)
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%R


n,a,b,k = inm()
sm = 0
factinit(n,R)
for pq in range(n+1):
    if k<a*pq or (k-a*pq)%b>0:
        continue
    qr = (k-a*pq)//b
    if qr>n:
        continue
    sm = (sm+comb(n,pq,R)*comb(n,qr,R))%R
print(sm)


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

using namespace std;

int main() {

	int n; cin >> n;
	double arr[n];

	for(int i = 0; i < n; i++)cin >> arr[i];

	sort(arr, arr + n);

	for(int i = 1; i < n; i++) {
		arr[i] = (arr[i]+arr[i-1])/2;
	}

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

	return 0;
}


Measured memory_bytes: 256
N = int(input())
list_mountain_height = list(map(int, input().split()))

count_ocean_view = 0

for i in range(len(list_mountain_height)): 
	count = -1
	for k in list_mountain_height[:i+1]:
		if k > list_mountain_height[i]:
			break
		else:
			count += 1
	if count == i:
		count_ocean_view += 1
	else:
		continue

print(count_ocean_view)

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

bool is_bipartite (const vector<vector<int>>& g) {
    int n = g.size(), ret = 1;
    struct UnionFind {
        vector<int> data;
        UnionFind(int sz) : data(sz, -1) { }
        bool unite(int x, int y) {
            if ((x = root(x)) == (y = root(y))) { return false; }
            if (data[x] > data[y]) { swap(x, y); }
            data[x] += data[y]; data[y] = x; return true;
        }
        bool same(int x, int y) { return root(x) == root(y); }
        int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
        
    } uf(2*n);
    for (int x = 0; x < n; x++) {
        for (auto& y : g[x]) { uf.unite(x, y+n); uf.unite(x+n, y); }
    }
    for (int x = 0; x < n; x++) if (uf.same(x, x+n)) { ret = 0; break; }
    return ret;
}

int main() {
    long long n, m;
    cin >> n >> m;
    long long k = n * (n - 1) / 2;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    
    if (is_bipartite(g)) {
        vector<int> col(n, 0);  col[0] = 1;
        stack<int> sta; sta.emplace(0);
        while (not sta.empty()) {
            int v = sta.top(); sta.pop();
            for (const auto &u : g[v]) {
                if (col[u] == 0) {
                    col[u] = col[v] * -1;
                    sta.emplace(u);
                }
            }
        }
        long long s = 0, t = 0;
        for (const auto &e : col) {
            if (e == 1) s++;
            else t++;
        }
        k = s * t;
    }
    
    cout << k - m << endl;
    return 0;
}

Measured memory_bytes: 6528
s = input()
for _ in range(int(input())):
    cmds = input().split()
    if cmds[0]=='print':
        a, b = map(int, cmds[1:])
        print(s[a:b+1])
    elif cmds[0]=='reverse':
        a, b = map(int, cmds[1:])
        s = s[:a] + s[b:-len(s)+a-1:-1] + s[b+1:]
    elif cmds[0]=='replace':
        a, b = map(int, cmds[1:3])
        p = cmds[3]
        s = s[:a] + p + s[b+1:]


Measured memory_bytes: 5612
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.trim().split(/ |\n/), cid = 0;

console.log(main().toString());


function main() {
    var n = +cin.shift();
    var primes = make_primes(Math.sqrt(n));
    if (n == 1) return 0;
    if (n == 2) return 1;
    let ans = 0;
    for (let p of primes) {
        let e = 0;
        while (n % p == 0) {
            e++;
            n = n / p;
        }
        if (e == 0) continue;
        // e=9 なら 1+2+3+4以下なので、3回割れる。 < 2 **4
        let i = 1;
        let sum = 1;
        while (sum + i + 1 <= e) {
            sum = sum + i + 1;
            i++;
        }
        ans = ans + i;
    }
    if (n > 1) ans++;

    return ans;
}

function make_primes(max) {
    let primes = [2, 3];
    let flg;
    for (let x = 5; x <= max; x += 2) {
        flg = 0;
        for (let j = 0; primes[j] * primes[j] <= x; j++) {
            if (x % primes[j] == 0) { flg = 1; break; }
        }
        if (flg == 0) { primes.push(x); }
    }
    return primes;
}

function next_prime(primes, max) {
    let flg;
    for (let x = primes[primes.length - 1] + 2; x <= max; x += 2) {
        flg = 0;
        for (let j = 0; primes[j] * primes[j] <= x; j++) {
            if (x % primes[j] == 0) { flg = 1; break; }
        }
        if (flg == 0) { primes.push(x); return x; }
    }
    return primes;
}



Measured memory_bytes: 35708
s = {}
s["a"] = input()
s["b"] = input()
s["c"] = input()

cha = "a"
while True:
    if len(s[cha]) == 0:
        print(cha.upper())
        exit()
    tmp_cha = s[cha][0]
    s[cha] = s[cha][1:]
    cha = tmp_cha


Measured memory_bytes: 2940
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <ctime>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> g[100];
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	vector<int> v;
	for (int i = 0; i < n; i++) {
		v.emplace_back(i + 1);
	}
	int ans = 0;
	do {
		if (v[0] != 1)continue;
		int count = 0;
		for (int i = 0; i < n-1; i++) {
			for (int j = 0; j < g[v[i]].size(); j++) {
				if (g[v[i]][j] == v[i+1] )count++;
			}
		}
		if (count == n - 1)ans++;
	} while (next_permutation(v.begin(), v.end()));
	cout << ans << endl;
}





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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;



int main() {

    ll N, M;
    cin >> N >> M;
    vector<ll> a(N);
    ll sum = 0;
    REP(i, N){
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(), a.end(), greater<ll>());

    REP(i, M){
        double tmp = (double)a[i] / (double)sum;
        if(tmp < (1.0/(double)(4*M))){
            cout << "No"<< endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
  
 

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath> 
#include <string>
#include <vector>
#include <queue> 
#include <stack> 
#include <set>
#include <map>
using namespace std;
int main(void)
{
	int a,b,c;
	cin>>a>>b>>c;
	int cnt1=0,cnt2=0;
	if(a==5) cnt1++;
	if(b==5) cnt1++;
	if(c==5) cnt1++;
	if(a==7) cnt2++;
	if(b==7) cnt2++;
	if(c==7) cnt2++;
	if(cnt1==2&&cnt2==1)
	   cout<<"YES"<<endl;
	else
	   cout<<"NO"<<endl;
	return 0;      
}

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

namespace ABC179
{
    public class C
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var count = 0L;

            // a: 1 ~ n - 1
            for (int a = 1; a < n; a++)
            {
                for (int b = 1; b < n; b++)
                {
                    if (n - a * b > 0)
                    {
                        count++;
                    }

                    if (a * b > n)
                    {
                        break;
                    }
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

ll S;
ll N=1e18;
ll n=1e9;

int main(){ 

cin.tie(0);
ios::sync_with_stdio(false);

cin>>S;

//x1 y1 x2 y2 x3 y3
if(S<=n){
	cout<<0<<" "<<0<<" "<<S<<" "<<0<<" "<<0<<" "<<1<<endl;
	return 0;
}
if(S==N){
	cout<<0<<" "<<0<<" "<<n<<" "<<0<<" "<<0<<" "<<n<<endl;
	return 0;
}
if(S>n){
	ll P=S/n;
	ll Q=S%n;
	cout<<0<<" "<<0<<" "<<n<<" "<<1<<" "<<n-Q<<" "<<P+1<<endl;
	return 0;
}



}


Measured memory_bytes: 256
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let lst = Array.to_list (Array.init n (fun i -> Scanf.scanf "%s %d\n" (fun s p -> (i+1,s,p)))) in
  let sort_lst = List.fast_sort
      (fun (ia, sa, pa) (ib, sb, pb) -> if (sa < sb || (sa = sb && pa > pb)) then -1 else if (sa > sb || (sa = sb && pa < pb)) then 1 else 0) lst in
  let print_lst = List.map (fun (i, s, p) -> string_of_int i) sort_lst in
  List.iter print_endline print_lst

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pb push_back
using namespace std;
int dp[3001][3001];
int n;
int solve(int *a, int i, int j)
{
    if(i>j)
        return 0;
    if(i==j)
        return a[i];
    if(dp[i][j]!=-1)
        return dp[i][j];
    return dp[i][j]=max(a[i]+min(solve(a,i+2,j),solve(a,i+1,j-1)),a[j]+min(solve(a,i,j-2),solve(a,i+1,j-1)));
}
int32_t main()
{
    int t;
    //cin>>t;
    //while(t--)
    {   
        int k;
        cin>>n;
        memset(dp,-1,sizeof(dp));
        int a[100001];
        int sum=0;
        for(int i=0;i<n;i++)
            cin>>a[i], sum+=a[i];
        cout<<2*solve(a,0,n-1)-sum;
    }
}


Measured memory_bytes: 74128
import java.util.*;

public class Main {
    private class Node {
        Integer x = null;
        List<Edge> edge = new ArrayList<>();
    }

    private class Edge {
        int src, dst, cost;

        public Edge(int src, int dst, int cost) {
            this.src = src;
            this.dst = dst;
            this.cost = cost;
        }
    }

    public void main(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();

        Node nodes[] = new Node[n];
        for (int i = 0; i < n; i++) {
            nodes[i] = new Node();
        }

        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int d = sc.nextInt();

            nodes[l - 1].edge.add(new Edge(l, r, d));
            nodes[r - 1].edge.add(new Edge(r, l, -d));
        }

        Queue<Node> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            if (nodes[i].x != null) {
                continue;
            }

            queue.add(nodes[i]);
            while (!queue.isEmpty()) {
                Node node = queue.poll();
                if (node.x == null) {
                    node.x = 0;
                }
                for (Edge e : node.edge) {
                    Node next = nodes[e.dst - 1];
                    if (next.x == null) {
                        next.x = node.x + e.cost;
                        queue.add(next);
                    } else if (next.x != node.x + e.cost) {
                        System.out.println("No");
                        return;
                    }
                }
            }
        }

        System.out.println("Yes");
    }

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


Measured memory_bytes: 176508
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 50;
const int M = 1e5+10;
/*=================================================================================*/

int n, a[N][N], con[N];
ll ans, dp[M], tmp[M];

int main() {
   scanf("%d", &n);
   for0(i, n) for0(j, n) scanf("%d", &a[i][j]);

   for0(now, (1<<n)) {
      int cnt = 0;
      for0(i, 16)
         if(now & (1<<i)) {
            con[cnt++] = i;
         }
      ll sum = 0;
      for0(i, cnt) for(int j = i + 1; j < cnt; ++j) {
         sum += a[con[i]][con[j]];
      }
      dp[now] = tmp[now] = sum;
   }

   for0(now, (1<<n)) for(int last = now; last; last = (last-1) & now) {
      dp[now] = max(dp[now], dp[now ^ last] + tmp[last]);
   }

   cout<<dp[(1<<n) - 1]<<endl;
   return 0;
}

/*
now    last
10000  1111  0
10001  10000 00001
10101  10100 00001
11111  11110 00001
11010  11000 00010
*/

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

map<ll, ll> mp;

int main(){
	ll N, M;
	cin >> N >> M;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];

	vector<ll> Asum(N+1);
	Asum[0] = 0;
	REP(i, N) Asum[i+1] = Asum[i] + A[i];
	REP(i, N) A[i] %= M;
	REP(i, N+1) Asum[i] %= M;

	mp[0] = 1;
	ll res = 0;
	REP(i, N){
		if(mp.find(Asum[i+1])==mp.end()){
			mp[Asum[i+1]] = 1;
		}else{
			res += mp[Asum[i+1]];
			mp[Asum[i+1]]++;
		}
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N,K;
    cin>>N>>K;
    vector<int> h(N);
    rep(i,N){
        cin>>h[i];
    }
    sort(all(h));
    //幅Kで見て探索
    int ans=1000000000;
    rep(i,N-K+1){
        ans=min(ans,h[i+K-1]-h[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
int n;
double dp[301][301][301];
double calc(int i, int j, int k){
  if(i < 0 || j < 0 || k < 0)return 0.;
  if(i == 0 && j == 0 && k == 0)return 0.;
  if(dp[i][j][k] >= 0.)return dp[i][j][k];
  double res = 1.;
  res += (double)i / n * calc(i-1, j, k);
  res += (double)j / n * calc(i+1, j-1, k);
  res += (double)k / n * calc(i, j+1, k-1);
  res = res * (double)n / double(i+j+k);
  return dp[i][j][k] = res;
}

int main(int argc, char const* argv[])
{
  cin >> n;
  vector<int> a(n);
  rep(i, n)cin >> a[i];
  int x[3] = {0, 0, 0};
  rep(i, n){
    x[a[i]-1]++;
  }
  rep(i, 301){
    rep(j, 301){
      rep(k, 301){
        dp[i][j][k] = -1.;
      }
    }
  }
  cout << setprecision(12);
  cout << calc(x[0], x[1], x[2]) << endl;
	return 0;
}


Measured memory_bytes: 213376
N, M = map(int, input().split())
KA = [list(map(int, input().split())) for _ in range(N)]
foods = [0]*(M+1)
ans = 0
for ka in KA:
    for i in range(ka[0]):
        foods[ka[i + 1]] += 1

for food in foods:
    if food == N:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int N; cin >> N;
    string S; cin >> S;
    
    vector<bool> Used(N);
    for(int i=0; i<N; i++){
        if(S[i]=='('){
            bool f = false;
            for(int j=i+1; j<N; j++){
                if(S[j]==')' && Used[j]==false){
                    Used[j] = true;
                    f = true;
                    break;
                }
            }
            if(!f){
                S.push_back(')');
            }
        }
    }

    int M = (int)S.size();
    Used.clear();
    Used.resize(M);
    reverse(S.begin(), S.end());
    for(int i=0; i<M; i++){
        if(S[i]==')'){
            bool f = false;
            for(int j=i+1; j<M; j++){
                if(S[j]=='(' && Used[j]==false){
                    Used[j] = true;
                    f = true;
                    break;
                }
            }
            if(!f){
                S.push_back('(');
            }
        }
    }
    
    reverse(S.begin(), S.end());
    cout << S << endl;
    return 0;
}



Measured memory_bytes: 256
public class Main{
	public void run(java.io.InputStream in,java.io.PrintStream out){
	java.util.Scanner sc = new java.util.Scanner(in);
/*????????§Input*/
	int N, i, j;
	int[][] a;

	N = sc.nextInt();
	a = new int[N][3];

	for(i = 0;i < N;i++){
		for(j = 0;j < 3;j++){
			a[i][j] = sc.nextInt();
		}
	}		
	sc.close();

/*answer*/
	for(i = 0;i < N;i++){
		if(a[i][0] * a[i][0] + a[i][1] * a[i][1] == a[i][2] * a[i][2]){
			System.out.println("YES");
		}else if(a[i][0] * a[i][0] + a[i][2] * a[i][2] == a[i][1] * a[i][1]){
			System.out.println("YES");
		}else if(a[i][2] * a[i][2] + a[i][1] * a[i][1] == a[i][0] * a[i][0]){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}

	}
	public static void main(String[] args){
		(new Main()).run(System.in,System.out);
	}
}

Measured memory_bytes: 24012
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let c_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%c " (fun a -> a)) in
  let res = List.sort_uniq compare c_lst |> List.length in
  Printf.printf "%s\n" @@ if res = 4 then "Four" else "Three"



Measured memory_bytes: 2432