akhauriyash/Code-Regression huggingface dataset:
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = (int)2e5 + 228;

using namespace std;

int n;
ll a[N], b[N], c[N];

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie();
	//cout.tie();		

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	scanf("%d", &n);
	forn(i, n)
	{
		scanf("%lld", &a[i]);
	}	
	if (n == 1)
	{
		cout << "YES" << endl;
		return 0;
	}
	forn(i, n)
	{	
		if (i == 1)
			b[i] = a[n] - a[1];
		else
			b[i] = a[i - 1] - a[i];
	}
	int cur = 0;                           
	for (int i = 1; i <= n; i++)
	{
		b[i] -= cur;
		if (b[i] > 0)
		{
			c[i] += (b[i] + n - 2) / (n - 1);
			c[i + n] += (b[i] + n - 2) / (n - 1);
		}	                                
	}
	ll sum = 0, k = 0;
	for (int i = 1; i <= n + n; i++)
	{	
		k += c[i];
		sum += k;
		if (i >= n)	
			sum -= 1ll * (n + 1) * c[i - n], k -= c[i - n];
		if (i > n && a[i - n] != sum)
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	return 0;
}



Measured memory_bytes: 4352
#include <iostream>

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

    int L[N];

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

    int total_len = 0;
    for (int i = 0; i < N; i++) {
        if (i != max_idx) {
            total_len += L[i];
        }
    }

    if (total_len > L[max_idx]) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
let n = stdin.ReadLine() |> int
let st = Array.init n (fun _ -> stdin.ReadLine().Split())
let x = stdin.ReadLine()

let s = [|for i in 0..(n - 1) -> st.[i].[0]|]
let t = [|for i in 0..(n - 1) -> (st.[i].[1] |> int)|]

let rec f (arr:string[]) (ls:int list) a =
 match ls with
 |[] -> 0
 |hd :: tl -> if (arr.[hd] = a) then hd else (f arr tl a)

let m = f s [0..(n - 1)] x

[0..(n - 1)]
|>List.sumBy (fun p -> if (p > m) then t.[p] else 0)
|>stdout.WriteLine

Measured memory_bytes: 13652
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,temp,total=0;
  cin >> n >> m;
  for(int i=0;i<m;i++){ cin >> temp; total+=temp;}
  if(total<=n) cout << n-total << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 3632
local DBG = false
local function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end
---------------------------------
local function main()
    local N = io.read("n")
    local V = {}
    local mt = {__index = function(t,k)return {k, 0};end}
    local evens = setmetatable({}, mt)
    local odds = setmetatable({}, mt)
    for i=1,N do
        local n = io.read("n")
        V[i] = n
        local ref
        if i % 2 == 0 then
            ref = evens
        else
            ref = odds
        end
        local tup = ref[n]
        tup[2] = tup[2] + 1
        ref[n] = tup
    end
    local evens_array = {}
    for k,v in pairs(evens) do
        table.insert(evens_array, v)
    end
    local odds_array = {}
    for k,v in pairs(odds) do
        table.insert(odds_array, v)
    end
    local function sortfunc(x, y)
        return x[2] > y[2]
    end
    table.sort(evens_array, sortfunc)
    table.sort(odds_array, sortfunc)
    if DBG then
        dbgpr("evens")
        for k,v in pairs(evens_array) do
            dbgpr(k,v[1],v[2])
        end
        dbgpr("odds")
        for k,v in pairs(odds_array) do
            dbgpr(k,v[1],v[2])
        end
    end
    local INF = 1000000000
    local function cost(e, o)
        local cost = INF
        if 1 <= e and e <= #evens_array then
            if 1 <= o and o <= #odds_array then
                local e_tup, o_tup = evens_array[e], odds_array[o]
                if e_tup[1] == o_tup[1] then
                    if e_tup[2] > o_tup[2] then
                        cost = (N//2 - e_tup[2]) + N//2
                    else
                        cost = (N//2 - o_tup[2]) + N//2
                    end
                else
                    cost = (N//2 - e_tup[2]) + (N//2 - o_tup[2])
                end
            end
        end
        return cost
    end
    local ans = 0
    local ptn = {{1,1},{1,2},{2,1},{2,2}}
    local cost_min = INF
    for _,v in pairs(ptn) do
        local e, o = v[1], v[2]
        local c = cost(e, o)
        if c < cost_min then
            cost_min = c
        end
    end
    print(cost_min)
end
main()


Measured memory_bytes: 19412
#include<stdio.h>

int main(void)

{

int a,b ;

scanf("%d",&a) ;

scanf("%d",&b) ;

if(a < b){

printf("a < b\n") ;

}

else if(a > b){

printf("a > b\n") ;

}

else if(a == b){

printf("a == b\n") ;

}

return 0 ;

}
 

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

using namespace std;

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

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N;
  while(cin>>N && N){
    double dp_exp[11] = {};
    double dp_pos[11] = {};
    dp_pos[0] = 1;
    REP(i, N){
      double next_exp[11] = {};
      double next_pos[11] = {};
      REP(j, 10){
        next_pos[j + 1] += dp_pos[j] * pow(0.5, j);
        next_pos[0] += dp_pos[j] * (1.0 - pow(0.5, j));
        next_exp[j + 1] += (dp_exp[j] + 1) * dp_pos[j] * pow(0.5, j);
        next_exp[0] += dp_exp[j] * dp_pos[j] * (1.0 - pow(0.5, j));
      }
      REP(j, 10) if(next_pos[j] != 0) next_exp[j] /= next_pos[j];
      memcpy(dp_pos, next_pos, sizeof(dp_pos));
      memcpy(dp_exp, next_exp, sizeof(dp_exp));
    }
    double ans = 0;
    REP(i, 10) ans += dp_exp[i] * dp_pos[i];
    printf("%.8lf\n", ans);
  }
  return 0;
}

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

using namespace std;

int main() {
    int N, Xor, A;
    scanf("%d", &N);
    while(N--) {
        scanf("%d", &A);
        Xor ^= (A & 1);
    }
    puts(!Xor ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 256
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  let
    modulus = 1000000007 :: Int
    modInv :: Int -> Int -> Int -> Int
    modInv modulus maxArg = (invs VU.!) . (`mod` modulus)
      where
        invs :: VU.Vector Int
        invs = VU.constructN (succ maxArg `min` modulus) rec
          where
            rec v = case VU.length v of
              0 -> 0
              1 -> 1
              l -> let (q, r) = modulus `divMod` l in (modulus - (v VU.! r) * q) `mod` modulus
    modComb :: Int -> Int -> Int
    modComb n = go 1
      where
        go :: Int -> Int -> Int
        go c 0 = c
        go c k = go (c * (n - k') `mod` modulus * modInv' k `mod` modulus) k'
          where
            k' = k - 1 :: Int
        modInv' :: Int -> Int
        modInv' = modInv modulus 666666
    f :: Int -> Int -> Int
    f x y
        | (x + y) `mod` 3 /= 0 || 2 * x < y || 2 * y < x
          = 0
        | otherwise
          = modComb (u + v) (u `min` v)
      where
        u = (2 * y - x) `div` 3 :: Int
        v = (2 * x - y) `div` 3 :: Int
  [x, y] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  print $ f x y

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

//DONT WASTE YOUR TIME
//prove yourself
//remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

const ll N= 1e6+55,mod = 1e9+7;

int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	ll a,b,c,d,i,j,k,x,y,z,ans=0;
	sc(a);sc(b);sc(c);sc(x);
	for(i=0;i<=c;i++){
		for(j=0;j<=b;j++){
			for(k=0;k<=a;k++){
				d=50*i+100*j+500*k;
				if(d==x){
					ans++;
				}
			}
		}
	}
	pr(ans);	

}

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

int main(){
	string s;
	cin >> s;
	map<char, int> mp;
	rep(i, s.size()){
		mp[s.at(i)]++;
	}

	if(mp.size() == 2 && mp[s.at(0)] == 2) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws Exception {
try {
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
	String input = buf.readLine();
	
	while(true){
		String[] strAry = input.split(" ");
	       int x = Integer.parseInt(strAry[0]);
	       int y = Integer.parseInt(strAry[1]);
		if(x == 0 && y == 0){
			break;
		}
		if(x > y){
		int chg = x;
		x = y;
		y = chg;
		}		
		System.out.println(x + " " + y);
		input =buf.readLine();
	}
} catch (Exception e) {
	// TODO: handle exception
}
		 }
    }

Measured memory_bytes: 27096
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
bool prime(int x){
 for(int i=2;i<x;i++)
  if(x%i==0)
   return false;
 return true;
} 
int main(){
int n;
cin>>n;
for(int i=31;i<=55555;i+=30){
 if(prime(i)){
  if(i!=31) cout<<' ';
  cout<<i;
  n--;
 }
 if(n==0)
 break;
}
 cout<<endl;
system("pause");
return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){
 float d,e,x,y;
 while(cin >> d >> e && d){
  float ans;
  ans = 1e6;
  for(x=0;x<=d;x++){
   y = d-x;
   ans = min(fabs(sqrt(x*x+y*y)-e),ans);
  }
  cout << ans << endl;
 }
 return 0;
}
   


Measured memory_bytes: 3256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> W(N);
    for(int i=0;i<N;i++) cin >> W.at(i);
    int S1=0,S2=0;
    for(int i=0;i<N/2;i++) S1 += W.at(i);
    for(int i=N/2;i<N;i++) S2 += W.at(i);
    int flag=1;
    if(S2>S1){
        int iti=N/2;
        while(flag){
            if((iti<N) && abs((S1+W.at(iti))-(S2-W.at(iti))) < abs(S1 - S2)){
                S1 += W.at(iti);S2 -= W.at(iti);iti++;
            }
            else flag=0;
        }
    }
    else{
        int iti=N/2-1;
        while(flag){
            if((0<=iti) && abs((S1-W.at(iti))-(S2+W.at(iti))) < abs(S1 - S2)){
                S1 -= W.at(iti);S2 += W.at(iti);iti--;
            }
            else flag=0;
        }
    }
    cout << abs(S1-S2) << endl;
    return 0;
}

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

int R, C, Q;
char g[2005][2005];
int p[2005][2005], h[2005][2005], v[2005][2005];

int main() {
	scanf("%d%d%d", &R, &C, &Q);
	for (int i = 0; i < R; i++) scanf("%s", &g[i]);
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			if (g[i][j] == '1') p[i][j]++;
			if (j + 1 < C) {
				if (g[i][j] == '1' && g[i][j + 1] == '1') h[i][j]++;
			}
			if (i + 1 < R) if (g[i][j] == '1' && g[i + 1][j] == '1') v[i][j]++;
		}
	}
	for (int i = 0; i < R; i++) {
		for (int j = 1; j < C; j++) {
			h[i][j] += h[i][j - 1];
			p[i][j] += p[i][j - 1];
			v[i][j] += v[i][j - 1];
		}
	}
	for (int i = 1; i < R; i++) {
		for (int j = 0; j < C; j++) {
			h[i][j] += h[i - 1][j];
			p[i][j] += p[i - 1][j];
			v[i][j] += v[i - 1][j];
		}
	}
	while (Q--) {
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		a--;
		b--;
		c--;
		d--;
		int ans = p[c][d] - ((a == 0) ? 0 : p[a - 1][d]) - ((b == 0) ? 0 : p[c][b - 1]) + ((a == 0 || b == 0) ? 0 : p[a - 1][b - 1]);
		ans -= ((d == 0) ? 0 : h[c][d - 1]) - ((a == 0 || d == 0) ? 0 : h[a - 1][d - 1]) - ((b == 0) ? 0 : h[c][b - 1]) + ((a == 0 || b == 0) ? 0 : h[a - 1][b - 1]);
		ans -= ((c == 0) ? 0 : v[c - 1][d]) - ((a == 0) ? 0 : v[a - 1][d]) - ((b == 0 || c == 0) ? 0 : v[c - 1][b - 1]) + ((a == 0 || b == 0) ? 0 : v[a - 1][b - 1]);
		printf("%d\n", ans);
	}
}


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

vector<int>E[10001];
string s[10001];

int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		int k; cin >> k >> s[i + 1];
		E[k].push_back(i + 1);
	}
	stack<P>que;
	que.push(P(0, -1));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (~p.second) {
			rep(i, p.second)cout << '.';
			cout << s[p.first] << endl;
		}
		for (int j = E[p.first].size() - 1; j >= 0; j--)
			que.push(P(E[p.first][j], p.second + 1));
	}
}

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

using namespace std;
typedef long long ll;
const int INF = numeric_limits<int>::max() / 2;

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

  string s;cin>>s;
  int len=s.length();
  for(int i=0;i<len;i++){
      if(s[i]==',') cout<<" ";
      else cout<<s[i];
  }
  cout<<endl;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(void){
  
  int N;
  cin >> N;
  
  int h[N];
  for (int i = 0; i<N; i++){
    cin >> h[i];
  }
  
  int cnt, i_max;
  cnt = 0;
  i_max = 0;
  for (int i = 0; i<N-1; i++){
    if (h[i] >= h[i+1]) {
    cnt = cnt + 1;
    i_max = max(cnt, i_max);
    }else{
    cnt = 0;
    }
  } 
  
  cout << i_max << endl;
  
  return 0; 
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//template end

typedef pair<int,int> P;

int n,a[200010];
bool check(int x){
   vector<P> str;
   str.push_back({0,a[0]}); ll sum=a[0];
   rep(i,1,n){
      if(a[i-1]<a[i]){
         if(a[i]-a[i-1])str.push_back({0,a[i]-a[i-1]});
         sum=a[i]; continue;
      }
      while(1){
         P p=str.back(); str.pop_back();
         sum-=p.second;
         if(sum<a[i]){
            p.second=a[i]-sum;
            sum=a[i]; str.push_back(p);
            break;
         }
      }
      int save=0;
      while(1){
         P p=str.back(); str.pop_back();
         if(p.first==x-1)save+=p.second;
         else{
            p.second--; if(p.second)str.push_back(p);
            str.push_back({p.first+1,1});
            if(save)str.push_back({0,save}); break;
         }
         if(save==sum)return false;
      }
   } return true;
}

int main(){
   scanf("%d",&n); rep(i,0,n)scanf("%d",&a[i]);
   //ifstream in("input.txt"); in>>n; rep(i,0,n)in>>a[i];
   int lb=0,rb=1e6;
   while(rb-lb>1){
      int mid=(lb+rb)/2;
      if(check(mid))rb=mid; else lb=mid;
   }
   printf("%d\n",rb);
   return 0;
}


Measured memory_bytes: 4692
from collections import defaultdict
import heapq
import sys
input = sys.stdin.readline


n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]

sushi.sort(key=lambda x: x[1])
kinds = defaultdict(int)
eaten = []
ans = 0
for i in range(k):
    neta, point = sushi.pop()
    kinds[neta] += 1
    ans += point
    heapq.heappush(eaten, [point, neta])

num_of_kinds = len(kinds.keys())
ans += num_of_kinds ** 2
candidate = ans

for i in range(k):
    point, neta = heapq.heappop(eaten)
    if kinds[neta] == 1:
        continue
    kinds[neta] -= 1

    while sushi:
        new_neta, new_point = sushi.pop()
        if kinds[new_neta] >= 1:
            continue
        else:
            break
    else:
        break
    kinds[new_neta] += 1
    num_of_kinds += 1
    delta = new_point - point + (2*num_of_kinds - 1)
    candidate += delta
    ans = max(ans, candidate)

print(ans)

Measured memory_bytes: 33804
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
bool test = 0;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

int M, N;
char a[105][105];

signed main(void) {
	int i, j, k, l;
	cin >> M >> N;
	rep(i, M) {
		cin >> a[i];
	}
	int cnt = 0;
	REP(i, 1, M) {
		rep(j, N) {
			if (a[i][j] != '-') continue;
			if (j - 1 > -1) {
				if (a[i][j - 1] != '-') continue;
			}
			if (j + 1 < N) {
				if (a[i][j + 1] != '-') continue;
			}

			int dx, dy;
			REP(dy, -1, 2) REP(dx, -1, 2) {
				int ny = i + dy;
				int nx = j + dx;
				if (ny < 0 || M <= ny) continue;
				if (nx < 0 || N <= nx) continue;

				if (a[ny][nx] == 'x') goto next;
			}
			cnt++;
		next:;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3104
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort(reverse=True)
f.sort(reverse=False)

def isok(mid):
    total = 0
    for i in range(n):
        if a[i] * f[i] <= mid:
            continue
        total += a[i] - mid // f[i]
    return total <= k

ng = -1
ok = a[0] * f[-1] + 1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if isok(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Measured memory_bytes: 119500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

string dp[100000];

string smax(string a, string b){
    if(a.size() > b.size()){
        return a;
    }else if(a.size() < b.size()){
        return b;
    }else{
        rep(i, 0, a.size()){
            if(a[i] > b[i]){
                return a;
            }else if(a[i] < b[i]){
                return b;
            }
        }
    }
    return a;
}

int main(){
    ll N, M;
    cin >> N >> M;
    VL A(M);

    ll c[10] = {0,2,5,5,4,5,6,3,7,6};
    rep(i, 0, M) cin >> A[i];
    
    rep(i, 0, 100000){
        dp[i] = "-";
    }

    dp[0] = "";
    rep(i, 0, N+1){
        if(dp[i] == "-") continue;
        for(auto a : A){
            if(dp[i+c[a]] == "-") dp[i+c[a]] = dp[i] + (char)(a + '0');
            else dp[i+c[a]] = smax(dp[i+c[a]], dp[i] + (char)(a + '0'));
        }
    }

    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 48128
import Control.Applicative
import Data.List

main = do
  [x,y] <- map read . words <$> getLine
  ordNum [x,y]

ordNum [x,y] = do
  if [x,y] == [0,0]
     then return()
     else do
       putStrLn $ unwords $ map show $ (sort :: [Int] -> [Int]) [x,y]
       [x2,y2] <- map read . words <$> getLine
       ordNum [x2,y2]

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

#define filein freopen ("in.txt", "r", stdin)
#define fileout freopen ("out.txt", "w", stdout)
#define dbg(x) cerr << #x << ": " << x << endl

using namespace std;
typedef long long ll;

const int maxn = 100005;

ll a[maxn], b[maxn];

int main(){
    ll n;
    scanf ("%lld", &n);
    for (ll i = 1; i <= n + 1; i++)
        scanf ("%lld", &a[i]);
    for (ll i = 1; i <= n; i++)
        scanf ("%lld", &b[i]);
    ll ans = 0;
    for (ll i = 1; i <= n; i++){
        ll m = min (a[i], b[i]);
        ans += m;
        a[i] -= m; b[i] -= m;
        m = min (a[i + 1], b[i]);
        ans += m;
        a[i + 1] -= m; b[i] -= m;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
#define MAX 1e9
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<ll,P> event;
#define MOD 1000000007

int main(){
  ll N;
  cin>>N;
  map<ll,ll> mp;
  rep(i,100001){mp[i]=0ll;}
  rep(i,N){
    ll t;
    cin>>t;
    mp[t]++;
  }
  ll Q;
  cin>>Q;
  ll ans=0ll;
  for(auto k: mp){
    ll x=k.first,y=k.second;
    ans=ans+x*y;
  }
  rep(i,Q){
    ll b,c,p;
    cin>>b>>c;
    p=mp[b];
    mp[b]=0ll;
    mp[c]+=p;
    ans-=p*b;
    ans+=p*c;
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 9852
import sys
n = int(input())
a_li = list(map(int,input().split()))
b_li = list(map(int,input().split()))

if sum(a_li)<sum(b_li):
    print(-1)
    sys.exit()

amari_li = []
tarinai_li = []

for  a,b in zip(a_li,b_li):
    if a >= b:
        amari_li.append(a-b)
    else:
        tarinai_li.append(b-a)

t = sum(tarinai_li)

#print(amari_li,tarinai_li)

if len(tarinai_li) == 0:
    print(0)
    sys.exit()

amari_li.sort(reverse=True)
count = 0
for a in amari_li:
    t -= a
    count += 1
    if t <= 0:
        break
print(count+len(tarinai_li))

Measured memory_bytes: 18356
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

#define INF (1000000000)

int g[400][400];

// gの初期化
void init() {
	for (int i = 0; i < 400; ++i)
		for (int j = 0; j < 400; ++j)
			g[i][j] = INF;
}

void WarshallFloyd() {
	for (int k = 0; k < 400; k++) {
		for (int i = 0; i < 400; i++) {
			for (int j = 0; j < 400; j++) {
				if (g[i][k] == INF || g[k][j] == INF) continue;
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
			}
		}
	}
}

signed main() {
	int h, w; cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; ++i)
		cin >> s[i];
	// gを構築
	init();
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (s[i][j] == '#') continue;
			int now = w * i + j;
			// 上
			if (i > 0 && s[i - 1][j] != '#') {
				int up = now - w;
				g[now][up] = 1;
			}
			// 下
			if (i < h - 1 && s[i + 1][j] != '#') {
				int down = now + w;
				g[now][down] = 1;
			}
			// 右
			if (j < w - 1 && s[i][j + 1] != '#') {
				int right = now + 1;
				g[now][right] = 1;
			}
			// 左
			if (j > 0 && s[i][j - 1] != '#') {
				int left = now - 1;
				g[now][left] = 1;
			}
		}
	}
	// WF
	WarshallFloyd();
	// 答えを求める
	int res = 0;
	for (int i = 0; i < 400; ++i)
		for (int j = 0; j < 400; ++j)
			if (i != j && g[i][j] < INF)
				res = max(res, g[i][j]);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

vector<vector<pii>> graph;
vector<int> ans(100001);

void dfs(int v, int prev, int skip)
{
    int color = 1;
    for(int i = 0; i < graph[v].size(); i++)
    {
        int next = graph[v][i].first;
        if(next == prev) continue;
        if(color == skip) color++;
        ans[graph[v][i].second] = color;
        dfs(next, v, color);
        color++;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    int k = 0;
    for(int i = 0; i < n; i++)
    {
        vector<pii> blank;
        graph.push_back(blank);
    }
    for(int i = 0; i < n - 1; i++)
    {
        int a, b; cin >> a >> b;
        a--;
        b--;
        graph[a].push_back({b, i});
        graph[b].push_back({a, i});
        k = max({k, (int)graph[a].size(), (int)graph[b].size()});
    }
    cout << k << endl;
    dfs(0, -1, -1);
    for(int i = 0; i < n - 1; i++) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 8564
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

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

    if(H ==1 or W==1){
        cout << 1 << endl;
        return 0;
    }
    ll a;
    a = (2*W)/2;
    if(H%2 == 0){
        cout << a * (H/2) << endl;
    }
    else{
        if(W%2==0){
            cout << a * (H/2) + W/2 << endl;
        }
        else{
            cout << a * (H/2) + (W/2 +1) << endl;
        }
    }


}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec A(N);
    REP(i,0,N) cin >> A[i];

    ll sum = 0, m = A[0];
    REP(i,1,N) {
        if(m > A[i]) sum += m - A[i];
        else m = MAX(m,A[i]);
    }
    PR(sum);

    return 0;
}

/*



*/

Measured memory_bytes: 4832
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  int N, ans = 0; cin >> N;
  string S; cin >> S;

  vector< vector<int> > cnt(26);
  for(int i = 0; i < S.length(); i++){
    cnt[S[i] - 'a'].push_back(i);
  }

  for(int i = 0; i < 26; i++){
    int cnt_size = cnt[i].size();
    int left;

    for(int j = 0; j < cnt_size; j++){
      left = cnt[i][j];

      for(int k = cnt_size - 1, right = cnt[i][k]; k > j ; k--, right = cnt[i][k]){
        if(N - right <= ans || right - left <= ans) continue; //ansが更新されないところは枝刈り

        int t = 0;
        for(int m = 0; left + m < right; m++){
          if(S[left+m] == S[right+m]) t++;
          else break;
        }
        if(t > ans) ans = t;
      }

    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#define taskname ""

#include <iostream>
#include <algorithm>

using namespace std;
#define long long long

const int N = 2e5 + 10;

int n, h[N], a[N];
long f[N];

#define mid ((l + r) >> 1)
#define lc (id << 1)
#define rc (lc + 1)

struct segmentTree
{
    long tree[N << 2];
    void update(int id, int l, int r, int x, long w)
    {
        if (x < l || r < x) return;
        if (l == r) {tree[id] = w; return;}
        update(lc, l, mid, x, w), update(rc, mid + 1, r, x, w);
        tree[id] = max(tree[lc], tree[rc]);
    }

    long get(int id, int l, int r, int x, int y)
    {
        if (y < l || r < x) return 0;
        if (x <= l && r <= y) return tree[id];
        return max(get(lc, l, mid, x, y), get(rc, mid + 1, r, x, y));
    }
} seg;

int main()
{
//    freopen(taskname".INP", "r", stdin);
//    freopen(taskname".OUT", "w", stdout);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> h[i];
    for (int i = 1; i <= n; ++i) cin >> a[i];

    for (int i = 1; i <= n; ++i) {
        long maxVal = seg.get(1, 1, n, 0, h[i] - 1);
        f[i] = maxVal + a[i];
        seg.update(1, 1, n, h[i], f[i]);
    }
    cout << seg.tree[1];

    return 0;
}


Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A[10002];
int N;
cin>>N;
for(int i=0;i<N;i++){
        cin>>A[i];

}
int mx=A[0];
int mn=A[0];
for(int i=0;i<N;i++){
        if(A[i]>mx)mx=A[i];
        if(A[i]<mn)mn=A[i];
}
cout<<mx-mn;
return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
#define f first
#define s second

using namespace std;

const int maxn = (int)(1e5)+2;
const int inf = (int)(1e9)+7;

int n;
ll a[1111];

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

	ll lcm = a[1];
	for (int i = 2; i <= n; i++) {
	 	lcm = lcm/__gcd(lcm,a[i])*a[i];
	}
	cout << lcm;

	return 0;
}

Measured memory_bytes: 256
n = int(input())

a = input().split()

a = [int(x) for x in a]


for i,x in enumerate(a):
    if i != len(a)-1:
        print(x, end=" ")
    else:
        print(x, end="")
print()

for i in range(1, len(a)):
    v = a[i]
    j = i-1

    while j>= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1

    a[j+1] = v

    for i,x in enumerate(a):
        if i != len(a)-1:
            print(x, end=" ")
        else:
            print(x, end="")
    print()


Measured memory_bytes: 5976
#include <iostream>
#include <set>
#include <vector>

using namespace std;

typedef pair<int, int> P;

int main() {
	int m;
	while (cin >> m) {
		if (m == 0) {
			break;
		}
		vector<P> data(m);
		cin >> data[0].first >> data[0].second;
		for (int i = 1; i < m; i++) {
			cin >> data[i].first >> data[i].second;
			data[i].first -= data[0].first;
			data[i].second -= data[0].second;
		}
		int n;
		cin >> n;
		set<P> star;
		P p;
		for (int i = 0; i < n; i++) {
			cin >> p.first >> p.second;
			star.insert(p);
		}
		set<P>::iterator it = star.begin();
		for (int i = 0; i < star.size(); i++) {
			bool hantei = true;
			for (int j = 1; j < data.size(); j++) {
				if (star.find(P((*it).first+data[j].first, (*it).second+data[j].second)) != star.end()) {
				} else {
					hantei = false;
					break;
				}
			}
			if (hantei) {
				cout << (*it).first-data[0].first << ' ' << (*it).second-data[0].second << endl;
				break;
			}
			it++;
		}
	} 
	return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>
#include <math.h>

using namespace std;


int calcMax(int a, int b) {
	int tmp;
	if (a > b) {
		while (b != 0) {
			tmp = b;
			b = a % b;
			a = tmp;
		}
		return a;
	}
	else {
		while (a != 0) {
			tmp = a;
			a = b % a;
			b = tmp;
		}
		return b;
	}
}

int calcMin(int a, int b) {
	int max_common = calcMax(a, b);
	return (a / max_common)*b;
}


int main() {
	int a, b;
	while (scanf("%d %d", &a, &b) != EOF) {
		printf("%d %d\n", calcMax(a, b), calcMin(a, b));
	}

	return 0;
}


Measured memory_bytes: 2628
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;

long long int N,M;
int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>M;
    M--;
    if(M==0){cout<<0<<endl;return 0;}
    cout<<(M-1)/(N-1)+1<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

int partition(int A[], int n, int p, int r){
  int x, i, j, t;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ ){
    if ( A[j] <= x ){
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i+1]; A[i+1] = A[r]; A[r] = t;
  return i+1;
}

main(){
  int A[MAX], n, i, q;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
  q = partition(A, n, 0, n-1);

  for ( i = 0; i < n; i++ ) {
    if ( i ) printf(" ");
    if ( i == q ) printf("[");
    printf("%d", A[i]);
    if ( i == q ) printf("]");
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>

int main (void)

{

int a,b,c,d;

scanf("%d %d %d",&a,&b,&c);

if(a>b){

 d=a;

 a=b;

 b=d;

}

if(b>c){

 d=b;

 b=c;

 c=d;

}

if(a>b){

 d=a;

 a=b;

 b=d;

}



printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 596
import java.util.Comparator;
import java.util.Scanner;
import java.util.Arrays;

/* static int java.util.Arrays.binarySearch(int[] a, int key); */


public class Main {
    Scanner sc = new Scanner(System.in);
    int n;
    public void run(){
        solve();
    }
    public void solve(){
        int a[] = new int[3];
        a[0] = sc.nextInt();
        a[1] = sc.nextInt();
        a[2] = sc.nextInt();

        Arrays.sort(a);

        int ans = 0;
        for(int i = 0; i < 2; i++){
            ans += a[i+1] - a[i];
        }
        System.out.println(ans);
    }

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

    static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }
    static class Edge{
        int to, cost;
        public Edge(int a, int b){
            this.to = a;
            this.cost = b;
        }
    }
    class MyComparator implements Comparator {
        @Override
        public int compare (Object arg0, Object arg1) {
            int x = ((Pair)arg0).first;
            int y = ((Pair)arg1).first;

            if (x < y) {
                return 1;
            } else if (x > y) {
                return -1;
            } else{
                return 0;
            }
        }
    }
    static class UnionFind{
        int par[];
        int rank[];

        //n要素で初期化
        public UnionFind(int maxn){
            par = new int[maxn];
            rank = new int[maxn];

            for(int i = 0; i < maxn; i++){
                par[i] = i;
                rank[i] = 0;
            }
        }

        //木の根を求める
        int find(int x){
            if(par[x] == x){
                return x;
            }
            else {
                return par[x] = find(par[x]);
            }
        }

        // xとyの属する集合を併合
        void unite (int x, int y){
            x = find(x);
            y = find(y);
            if(x == y){
                return;
            }

            if(rank[x] < rank[y]){
                par[x] = y;
            }
            else{
                par[y] = x;
                if(rank[x] == rank[y]) rank[x]++;
            }
        }

        // xとyが同じ集合に属するか否か
        boolean same(int x, int y){
            return find(x) == find(y);
        }
    }

}

Measured memory_bytes: 23636
n = int(input())
a_array = map(int, input().split())
point_array = [[0, 0] for _ in range(n)]
for i, a in enumerate(a_array):
    if 0 <= i - a < n:
        point_array[i - a][1] += 1
    if 0 <= i + a < n:
        point_array[i + a][0] += 1
ans = 0
for bp, ap in point_array:
    ans += bp * ap
print(ans)


Measured memory_bytes: 41620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
#define all(x) x.begin(),x.end()
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));
    vector<int> count(n);
    rep(i,n) count[i] = c.end() - (upper_bound(all(c),b[i]));
    ll sum = 0;
    ll ans = 0;
    int index = 0;
    rep(i,n) sum += count[i];
    int pre = 0;
    rep(i,n) {
        index = upper_bound(all(b),a[i]) - b.begin();
        if (index == pre) ans += sum;
        else {
            for (int j = pre; j < index; j++) sum -= count[j];
            ans += sum;
            pre = index;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
	char S[5];
	scanf ("%s", &S);
	
	((S[0] == S[1] || S[1] == S[2] || S[0] == S[2]) && (S[0] != S[1] || S[1] != S[2]) || S[0] != S[2]) ? 
        puts ("Yes") : puts ("No");
	
	return 0;
}

Measured memory_bytes: 3164
# coding: utf-8
import math
N = int(input())
sta_info = []
for i in range(N-1):
    l = list(map(int,input().split()))
    sta_info.append(l)

for i in range(N-1):
    start = i
    t = 0
    ans = 0
    for j in range(i,N-1):
        c, s, f = sta_info[j][0], sta_info[j][1], sta_info[j][2]
        #print('到着時 ' + str(t))
        if t <= s:
            t = s
            #print('!!!')
        else:
            n = math.ceil((t - s) / f)
            t += s + n * f - t
        #print('発車時 ' + str(t))
        t += c
        
    print(t)
print(0)


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

int main(){
    int n;
    cin >> n;
    int y = n/1.08;
    for (int i=-1;i <= 1; i ++){
        int k = (y+i) * 1.08;
        if (k == n){
            cout << y+i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
pn = []
pn = [int(x) for x in input().split()]
 
miss = 0
ok = True
for i in range(0,n):
    if i != pn[i]-1:
        if miss == 0:
            miss = pn[i]-1
        else:
            if miss != i:
                ok = False
                break
 
if ok:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>k(m);
    vector< vector<int> > s(m, vector<int>(10));
    vector<int>a(n);
    vector<int>p(m);
    rep(i,m){
        cin>>k[i];
        rep(j,k[i])cin>>s[i][j];
    }
rep(i,m)cin>>p[i];
int ans=0;

for(int bit=0;bit<(1<<n);++bit){
    for(int i=0;i<n;i++){
        if(bit&(1<<i)){
            a[i]=1;
        }
    }
bool x=true;
rep(i,m){
    int count=0;
    rep(j,k[i]){
        if(a[s[i][j]-1]==1)count++;
    }
if(count%2!=p[i]){x=false;break;}
}
if(x==true)ans++;
rep(i,n)a[i]=0;
}

cout<<ans;
return 0;

}


Measured memory_bytes: 3184
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main()
{
	short *A,*B;
	int c[VMAX+1];
	int n,i,j;
	scanf("%d",&n);
	A=(short*)malloc(sizeof(short)*(n+1));
	B=(short*)malloc(sizeof(short)*(n+1));
	for(i=0;i<=VMAX;i++)
	{
		c[i]=0;		
	}
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i+1]);
		c[A[i+1]]++;
	}	
	for(i=1;i<=VMAX;i++)
	{
		c[i]+=c[i-1];
	}
	for(j=1;j<=n;j++)
	{
		B[c[A[j]]]=A[j];
		c[A[j]]--;
	}
	for(i=1;i<=n;i++)
	{
		if(i>1)
			printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	return 0;
} 


Measured memory_bytes: 10584
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b) { return a>b?a:b;}
ll min(ll a,ll b) { return a<b?a:b;}
void solve()
{   int a[5];
    fi(i,0,5)
        cin>>a[i];
    fi(i,0,5)
    {
        if(a[i]==0)
            {cout<<(i+1);return;}
    }
}
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    
    
        solve();

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
    #endif
    return 0;
}


Measured memory_bytes: 3552
//#include <bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	long long int n;
	long long int a[10001] = {};
	long long int count = 0;
	long long int point = 0;

	cin >> n;
	FOR(i, 1, n) {
		point = 0;
		cin >> a[i];
		while (1) {
			if (a[i] % 2 == 0) {
				point++;
				a[i] /= 2;
			}
			else {
				break;
			}
		}
		count += point;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        int n = ReadInt();
        int d = ReadInt();
        int c = 0;
        for (int i = 0; i < n; i++)
        {
            int x = ReadInt();
            int y = ReadInt();
            if ((long)x * x + (long)y * y <= (long)d * d) c++;
        }
        Console.WriteLine(c);
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
}


Measured memory_bytes: 41260
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  vector <int> A(4);
  int num = 0;
  vector<char> hugou(3);
  cin >> N;
  for(int i = 0; i < 4; i++){
    A.at(i) = N % 10;
    N /=10;
  }
  reverse(A.begin(),A.end());
  for(int i = 0; i < (1 << 3); i++){
  	bitset<3> ope(i);
    
    if(ope.test(0)){
      num = A.at(0) + A.at(1);
      hugou.at(0) = '+';
    }
    else{
      num = A.at(0) - A.at(1);
      hugou.at(0) = '-';
    }
    if(ope.test(1)){
      num += A.at(2);
      hugou.at(1) = '+';
    }
    else{
      num -= A.at(2);
      hugou.at(1) = '-';
    }
    if(ope.test(2)){
      num += A.at(3);
      hugou.at(2) = '+';
    }
    else{
      num -= A.at(3);
      hugou.at(2) = '-';
    }
    if(num == 7){
      cout << A.at(0) << hugou.at(0) 
           << A.at(1) << hugou.at(1)
           << A.at(2) << hugou.at(2)
           << A.at(3) << "=7" << endl;
      break;
    }
    num = 0;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int D, N, T[200], A[200], B[200], C[200];
int dp[200][101];

int main() {
  cin >> D >> N;
  for(int i = 0; i < D; i++) cin >> T[i];
  for(int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i];

  fill_n(*dp, 200 * 101, -1);
  for(int i = 0; i < N; i++) {
    if(B[i] >= T[0] && T[0] >= A[i]) dp[0][C[i]] = 0;
  }
  for(int i = 1; i < D; i++) {
    for(int j = 0; j <= 100; j++) {
      if(~dp[i - 1][j]) {
        for(int k = 0; k < N; k++) {
          if(B[k] >= T[i] && T[i] >= A[k]) {
            dp[i][C[k]] = max(dp[i][C[k]], dp[i - 1][j] + max(j - C[k], C[k] - j)); 
          }
        }
      }
    }
  }
  cout << *max_element(dp[0], dp[200]) << endl;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<vector<P>> v(n);
    rep(i,n){
        int a;
        cin >> a;
        rep(j,a){
            int b,c;
            cin >> b >> c;
            v[i].push_back(P(b-1,c));
        }
    }
    int ans = 0;
    rep(i,(1<<n)){
        int cnt = 0;
        int fl = true;
        rep(j,n){
            if((1<<j)&i){
                cnt++;
                for(auto p:v[j]){
                    if(((i>>p.first)&1)^p.second){
                        fl=false;
                    }
                }
            }
        }
        if(fl){
            ans = max(ans,cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  string s ;
  cin >> s ;
  if(s=="SUN")
    cout << 7 << endl ;
  if(s=="MON")
    cout << 6 << endl ;
  if(s=="TUE")
    cout << 5 << endl ;
  if(s=="WED")
    cout << 4 << endl ;
  if(s=="THU")
    cout << 3 << endl ;
  if(s=="FRI")
    cout << 2 << endl ;
  if(s=="SAT")
    cout << 1 << endl ;
  
}

Measured memory_bytes: 764