akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
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; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    vi p(n);
    rp(i,n) cin >> p.at(i);
    int ctr=0;
    repi(i,1,n-1){
        if(p[i-1]<p[i]&&p[i]<p[i+1]||p[i-1]>p[i]&&p[i]>p[i+1]) ctr++;
    }
    print(ctr);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3584
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/****@author: Sayed Sohan, CSE 13th batch(2016), MBSTU*****/
/**********************************************************/

#include <bits/stdc++.h>
using namespace std;
//              Typedefs
typedef long long               ll;
typedef unsigned long long      ull;

//              Templates
template<class T>               using min_heap = \
                                priority_queue<T, \
                                std::vector<T>, std::greater<T>>;

//              Basic-Defs
#define PB                      push_back
#define MP                      make_pair
#define SP                      " "
#define NL                      "\n"
#define all(v)                  v.begin(), v.end()

//              DEBUG--SECTION
#define DE                      cout<<"HERE\n";
#define DE1(x)                  cout<<x<<"###\n";
#define DE2(x,y)                cout<<x<<"####"<<y<<"\n";
#define Pause                   system("pause");

//              Functions
#define clr(arr,value)          memset(arr,value,sizeof(arr))
#define __FAST_IO               ios_base::sync_with_stdio(0);\
                                cin.tie(0);cout.tie(0);
#define NUM1(x)                 __builtin_popcount(x)
#define LCM(x,y)                (x*y)/__gcd(x,y)

//              Sizes--Math     0123456789
#define MOD                     1000000007   //1e9+7 
#define MAX                     100050      
#define INF                     1e18
#define PI                      acos(-1)
#define eps                     1e-6

//** your code goes from here


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    
    ll i,j,k,n,m,T; //basic variables
    cin>>n>>m;

    for(i=0;i<=n;i++){
    	if(i*4 + (n-i)*2==m){
    		cout<<"Yes"<<NL;
    		return 0;
    	}
    }
    cout<<"No"<<NL;


    /// Don't forget to set array size....
    return 0;
}




Measured memory_bytes: 3684
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   N : Integer;
   K : Integer;
begin
   Get (N);
   Get (K);
   if K = 1 then
      Put_Line ("0");
   else
      Put_Line (Integer'Image (N-K));
   end if;
end Solve;

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n;
 cin>>n;
 vector<int> h(n);
 for(int i=0;i<n;i++) cin>>h[i];
 vector<int> dp(n);
 dp[n-1]=0;
 if(n>=2) dp[n-2]=abs(h[n-1]-h[n-2]);
 for(int i=n-3;i>=0;i--){
  dp[i]=min(abs(h[i+1]-h[i])+dp[i+1],abs(h[i+2]-h[i])+dp[i+2]);
 }
 cout<<dp[0]<<endl;
 return 0;
}

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

using namespace std;


using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int X, Y;
  cin >> X >> Y;
  int ret = 0;
  if(X == 3) ret += 100000;
  else if(X == 2) ret += 200000;
  else if(X == 1) ret += 300000;
  swap(X, Y);
  if(X == 3) ret += 100000;
  else if(X == 2) ret += 200000;
  else if(X == 1) ret += 300000;
  if(X == 1 && Y == 1) ret += 400000;

  cout << ret << endl;
}






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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

class UnionFind {
  private:
    std::vector<int> par;
    std::vector<int> sizes;
    std::vector<int> rank;
    int group;

  public:
    UnionFind(int n) : par(n), sizes(n, 1), rank(n, 0), group(n) {
      for(int i = 0; i < n; ++i) par[i] = i;
    }

    int find(int x) {
      if(x == par[x]) return x;
      return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
      x = find(x);
      y = find(y);

      if(x == y) return;

      if(rank[x] < rank[y]) std::swap(x, y);
      par[y] = x;
      sizes[x] += sizes[y];
      if(rank[x] == rank[y]) rank[x]++;
      group--;
    }

    bool same(int x, int y) {
      return find(x) == find(y);
    }

    int size(int x) {
      return sizes[find(x)];
    }

    int groupSize() {
      return group;
    }
};

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

  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, 0, m) {
    int x, y, z;
    cin >> x >> y >> z;
    x--; y--;
    uf.unite(x, y);
  }
  cout << uf.groupSize() << endl;
}

Measured memory_bytes: 1408
import math
from itertools import combinations
from functools import reduce


def gcd_3(*numbers):
    return reduce(math.gcd, numbers)


K = int(input())
ans = 0
for abc in combinations(range(1, K+1), 3):
    ans += gcd_3(*abc) * 6

for a, b in combinations(range(1, K+1), 2):
    ans += math.gcd(a, b) * 6

for aaa in range(1, K+1):
    ans += aaa

print(ans)

Measured memory_bytes: 9636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vs grid(H);
    rep(i, H) cin >> grid[i];
    int num = 0;
    rep(i, H) {
        rep(j, W) {
            if (grid[i][j] == '#') num++;
        }
    }
    int ans = 0;
    for (int bit_h = 0; bit_h < (1 << H); bit_h++) {
        vs g_tmp = grid;
        int num1 = 0;
        rep(i, H) {
            if ((bit_h >> i) & 1) {
                rep(j, W) {
                    if (g_tmp[i][j] == '#') num1++;
                    g_tmp[i][j] = 'R';
                }
            }
        }
        for (int bit_w = 0; bit_w < (1 << W); bit_w++) {
            int num2 = 0;
            rep(j, W) {
                if ((bit_w >> j) & 1) {
                    rep(i, H) {
                        if (g_tmp[i][j] == '#') num2++;
                    }
                }
            }
            if (num - num1 - num2 == K) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define NB 100001
int abs(int a) {
	if(a<0) return -a;
	return a;
}

ll tab[2][NB];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll cur_max = 0;
	ll n,w;
	cin>>n>>w;
	ll cpos = 1;
	ll weight, price;
	for(int i = 0; i < n; ++i) {
		cin>>weight>>price;
		for(int j = 0; j < weight; ++j) tab[cpos^1][j] = tab[cpos][j];
		for(int j = weight; j <= w; ++j) {
			tab[cpos^1][j] = max(tab[cpos][j], tab[cpos][j - weight] + price);
			cur_max = max(cur_max, tab[cpos^1][j]);
		}
		cpos^=1;
	}
	cout<<cur_max<<endl;
	return 0;
}


Measured memory_bytes: 5072
N, K = map(int, input().split())
a = list(map(int, input().split()))

rireki = [0] * (2 * 10 ** 5 + 1)
flag = [[] for _ in range(2 * 10 ** 5 + 1)]
rireki[0] = 1
flag[1].append(0)
count = 0
roop_start = 0
roop_count = 0
while True:
    count += 1
    rireki[count] = a[rireki[count - 1] - 1]
    flag[rireki[count]].append(count)
    if len(flag[rireki[count]]) == 2:
        roop_start = flag[rireki[count]][0]
        roop_count = flag[rireki[count]][1] - flag[rireki[count]][0]
        break
    if count == K:
        break
if roop_count != 0:
    print(rireki[(K - roop_start) % roop_count + roop_start])
else:
    print(rireki[K])


Measured memory_bytes: 117232
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
   int n,k;
   cin>>n>>k;
 vector<double>v;
 for(int i=0;i<n;i++)
 {
     double x;
     cin>>x;
     double  val =  (x+1)*0.5;
     v.push_back(val);
 }
 deque<double>d;
 double  ans = 0,sum=0;
 for(int i=0;i<k;i++)
 {
     sum+=v[i];
     d.push_back(v[i]);
 }
 ans = sum;
 int ind = k;
 while(ind<n)
 {
    sum-=d.front();
    d.pop_front();
    d.push_back(v[ind]);
    sum+=v[ind];
    ans = max(ans,sum);
    ind++;
  }
  cout<<fixed<<showpoint;
  cout<<setprecision(8)<<ans<<endl;

}


Measured memory_bytes: 3440
#include<bits/stdc++.h>
   using namespace std;
   int main()
   {
   ios::sync_with_stdio(0);
   cin.tie(0);
   long long  n;
   cin>>n;
   string res="";
   char x[26]={'z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'};
   while(n>0)
   {
      res+=x[n%26];
     if(n%26==0)
     n--;
     
     n/=26;
      
   }
   reverse(res.begin(),res.end());
   cout<<res;
   
   return 0;
   }

Measured memory_bytes: 3652
package main

import (
        "fmt"
)

func solution(n int) int {
        sum := 0
        for i := 1; i <= n; i++ {
                for j := 1; j <= n; j++ {
                        for k := 1; k <= n; k++ {
                                sum += threeGcd(i, j, k)
                        }
                }
        }
        return sum
}

func main() {
        var k int
        fmt.Scan(&k)
        fmt.Println(solution(k))
}

func threeGcd(a, b, c int) int {
        return gcd(gcd(a, b), c)
}
func gcd(a, b int) int {
        for b != 0 {
                r := a % b
                a = b
                b = r
        }
        return a
}

Measured memory_bytes: 1776
n = int(input())
list_m = [[0] * n for i in range(n)]
for i in range(n):
	a,b, *args = map(int,input().split())
	for num in args:
		list_m[a-1][num-1] = 1
for i in range(n):
	for j in range(n):
		list_m[i][j] = str(list_m[i][j])
for row in list_m:
	print(" ".join(row))


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

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

int a[26];
char c[100];
int n;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	while(cin>>n,n) {
		rep(i,26)a[i]=0;
		int k=0, t=0, s=0;
		
		rep(i, n)cin>>c[i];
		rep(i, n) {
			k++;
			a[c[i]-'A']++;
			if(t<a[c[i]-'A']) {
				t = a[c[i]-'A'];
			}else {
				if(s<a[c[i]-'A']) {
					s = a[c[i]-'A'];
				}
			}
			if(t>n-k+s)break;
		}
		if(k==n) {
			bool f=true,g=true;
			int u=0;
			rep(i, 26) {
				if(t==a[i]) {
					if(f) {
						f=false;
						u=i;
					}else {
						g=false;
						cout<<"TIE"<<endl;
						break;
					}
				}
			}
			if(g)cout<<(char)('A'+u)<<' '<<k<<endl;;
		}else {
			rep(i, 26) {
				if(t==a[i]) {
					cout<<(char)('A'+i)<<' '<<k<<endl;
					break;
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 3144
S = list(input())
a = 0
sum_A = 0

if S[0] == 'A':
    a = 1

for i in range(1, len(S)-1):
    if S[i] == 'A':
        a += 1 
    elif S[i] == 'B' and S[i + 1] == 'C':
        sum_A += a
    elif S[i] == 'C' and S[i - 1] == 'B':
        continue
    else:
        a = 0

print(sum_A)

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

#define int long long

int32_t main(){
	int n ;
	string s ;
	cin >> n >> s ;
	int count = 0 ;
	for(int i = 0 ; i <= n - 3 ; i++){
		string k = "" ;
		for(int j = i ; j < i+3 ; j++){
			k += s[j] ;
		}
		if(k == "ABC") count++ ;
	}
	cout <<  count ;
	return 0 ;
}



Measured memory_bytes: 256
#include<stdio.h>
#define ll long long
const ll mod=1e9+7;
const int N=1e5+9;
ll vis[N],a[N];
int main()
{
    int t,n,x;
    scanf("%d%d",&t,&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        vis[x]=1;
    }
    a[0]=1;
    if(!vis[1]) a[1]=1;
    for(int i=2;i<=t;i++)
    {
        if(vis[i]) continue;
        a[i]=(a[i-1]+a[i-2])%mod;
//        printf("%lld  a[i],  %d  i\n",a[i],i);
    }
    printf("%lld\n",a[t]);
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int in(){int x; scanf("%d",&x); return x;}
static const int MAX = 10000;


int main(){
  int N = in(), p[MAX], count = 0;
  rep(i, N) p[i] = in();
  sort(p, p+N);

  count += p[N-1]/2;
  rep(i, N-1){
    count += p[i];
  }
  cout << count << endl;
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int M;
inline void solve(){
  IN(M);
  OUT(48-M);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = []
aa = 0
bb = 0
b = []
flag = 0
for i in range(N):
    aa += A[i]
    a.append(aa)
for i in range(M):
    bb += B[i]
    b.append(bb)
MAX = 0
for i in range(N):
    t = a[i]
    if t > K:
        break
    else:
        tt = K-t
        index = bisect_left(b,tt)
    if index == M:
        MAX = max(MAX,i+1+M)
    elif b[index] == tt:
        MAX = max(MAX,i+1+1+index)
    else:
        MAX = max(MAX,i+1+index)
for i in range(M):
    t = b[i]
    if t > K:
        break
    else:
        tt = K-t
        index = bisect_left(a,tt)
    if index == N:
        MAX = max(MAX,i+1+N)
    elif a[index] == tt:
        MAX = max(MAX,i+1+1+index)
    else:
        MAX = max(MAX,i+1+index)



print(MAX)

Measured memory_bytes: 50412
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

int a[5];
signed main(){
  int n;cin >> n;
  rep(i,5)cin >> a[i];
  int mn = *min_element(a, a+5);
  cout << ((n+mn-1)/mn)-1+5 << endl;
  return 0;
}






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

int main() {
    int n;
    cin >> n;
    vector<string> a, b, ab, c;
    int count = 0;
    rep(i,n) {
        string s;
        cin >> s;
        int pos = s.find("AB");
        while (pos != string::npos) {
            count++;
            if (pos+2 < s.size()) pos = s.find("AB", pos+2);
            else break;
        }
        if(s.at(0) == 'B' && s.at(s.size()-1) == 'A') ab.push_back(s);
        else if (s.at(0) == 'B') b.push_back(s);
        else if (s.at(s.size() - 1) == 'A') a.push_back(s);
        else c.push_back(s);
    }
    int minab = min(a.size(), b.size());
    int maxab = max(a.size(), b.size());
    count += minab;
    if(0 < ab.size() && 0 == maxab) count += ab.size() - 1;
    else count += ab.size();
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3876
import java.util.*;
import java.util.stream.*;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int target = sc.nextInt();
        List<Integer> products = new ArrayList<>(Arrays.asList(100, 101, 102, 103, 104, 105));
        List<Integer> p = IntStream.rangeClosed(0, target).map(e -> e == 0 ? e : -1).boxed().collect(Collectors.toList());
        for (int product : products) {
            for (int j = 0; j <= target; j++) {
                if (p.get(j) >= 0) p.set(j, 1000000);
                else if (j < product || p.get(j - product) <= 0) p.set(j, -1);
                else p.set(j, p.get(j - product) - 1);
            }
        }

        System.out.println(p.get(target) >= 0 ? 1 : 0);
    }
}


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

int main(){
	// sengen
	int n;
	string s,t,u;
	// nyuryoku
	cin >> n >> s >> t;
	u = s[0];
	u = u + t[0];
	// keisan
	for(int i=1;i<n;i++){
		u = u + s[i] + t[i];
	}
	cout << u;
	// syutsuryoku
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<string.h>
struct data{
	int x;
	int y;
};
int map[401][401];
struct data d[201];
int main(){
	int n,i,j,k;
	int s,t;
	int x_max=0,x_min=0,y_max=0,y_min=0;
	while(1){
		for(i=0;i<401;i++)for(j=0;j<401;j++)map[i][j]='.';
		for(i=0;i<201;i++){d[i].x=0;d[i].y=0;}
		x_max=0,x_min=0,y_max=0,y_min=0;
		scanf("%d",&n);
		if(!n)break;
		if(n==1)printf("1 1\n");
		else{
			d[0].x=0;
			d[0].y=0;
			map[200][200]='*';
			for(i=1;i<n;i++){
				scanf("%d %d",&s,&t);
				if(!(t%2)){
					if(t==0)d[i].x=-1;
					else d[i].x=1;
				}
				else{
					if(t==1)d[i].y=-1;
					else d[i].y=1;
				}
				d[i].x+=d[s].x;
				d[i].y+=d[s].y;
				if(x_max<d[i].x)x_max=d[i].x;
				if(x_min>d[i].x)x_min=d[i].x;
				if(y_max<d[i].y)y_max=d[i].y;
				if(y_min>d[i].y)y_min=d[i].y;
				map[d[i].y+200][d[i].x+200]='*';
			}
			printf("%d %d\n",x_max-x_min+1,y_max-y_min+1);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, K;
  cin >> N >> K;
  string s;
  cin >> s;

  if(s[K-1] == 'A') s[K-1] = 'a';
  if(s[K-1] == 'B') s[K-1] = 'b';
  if(s[K-1] == 'C') s[K-1] = 'c';

  cout << s << endl;
  
  return 0;
}


Measured memory_bytes: 256
from itertools import * 
*x,=map(int,input().split())
K=int(input())
c = combinations_with_replacement(range(3), K)
a=x.copy()
ans=0
for i in c:
    a=x.copy()
    for j in i:
        a[j] = a[j] * 2
        if a[0] < a[1] and a[1] < a[2]: 
            ans=1
if ans==1: 
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  
  int five_c = 0;
  int seven_c = 0;

  rep(i, 3)
    if(A[i] == 5)
      five_c++;
    else if(A[i] == 7)
      seven_c++;

  if(five_c == 2 && seven_c == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
while true
    limit, n_t, n_p, n_r = gets.chomp.split.map(&:to_i)
    break if [limit, n_t, n_p, n_r] == [0, 0, 0, 0]
    result = Array.new(n_t){[0, 0, nil, Hash.new(0)]}
    1.upto(n_t){|team| result[team - 1][2] = team}
    n_r.times{
        time, team, problem, judge = gets.chomp.split.map(&:to_i)
        if judge == 0
            result[team - 1][0] += 1
            result[team - 1][1] += (time + 20 * result[team - 1][3][problem])
        else
            result[team - 1][3][problem] += 1
        end
    }
    result.sort_by!{|n_solved, total, team, n_mis| [-n_solved, total, -team]}
    prev = nil
    result.each{|team|
        if prev
            if prev[0] == team[0] && prev[1] == team[1]
                print "="
            else
                print ","
            end
        end
        print team[2]
        prev = team
    }
    puts
end


Measured memory_bytes: 7088
use std::io::*;

fn read() -> Vec<char> {
    let s = stdin();
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<Vec<char>>();
	b
}

fn main() {
	let c1 = read();
	let c2 = read();

	let s1 = c1[0] == c2[2];
	let s2 = c1[1] == c2[1];
	let s3 = c1[2] == c2[0];

	if s1 && s2 && s3 {
		println!("YES");
	} else {
		println!("NO");
	}
}


Measured memory_bytes: 4352
def honestcount(i):
    return bin(i).count("1")

def is_honest(i,j):
    return (i>>j)%2 == 1

N = int(input())

A = [0] * N
shogens=[]

for i in range(N):
    a = int(input())
    shogen=[]
    for j in range(a):
        x,y = map(int, input().split())
        shogen.append((x-1,y))
    shogens.append(shogen)
# print(shogens)

count=0
for i in range(1<<N):
    is_ok =True
    for j in range(N):
        if not is_honest(i,j):
            continue
        for x,y in shogens[j]:
            if y!=is_honest(i,x):
                is_ok=False
                break
    if is_ok:
        count=max(count,honestcount(i))
print(count)


Measured memory_bytes: 3064
import collections

N = int(input())
D = list(map(int, input().split()))
D_set = set(D)
M = int(input())
T = list(map(int, input().split()))

D_count = collections.Counter(D)
T_count = collections.Counter(T)
flag = 0
for key, value in T_count.items():
    if key not in D_set:
        flag = 1
        print("NO")
        break
    else:
        if D_count[key] < value:
            flag = 1
            print("NO")
            break


# flag = 0
# for t in T:
#     try:
#         D.remove(t)
#     except ValueError:
#         flag = 1
#         print("NO")
#         break
if flag == 0:
    print("YES")

Measured memory_bytes: 127568
#include <stdio.h>
#define N 100000

int partition(int *A,int p,int r){
	int x,i,j,tmp;

	x = A[r];
	i = p - 1;

	for(j=p; j<r; j++){
	  if(A[j] <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
		}
	}
	tmp = A[r];
	A[r] = A[i+1];
	A[i+1] = tmp;

	return i+1;
}

int main(){
  int x,n,i,A[N];

  scanf("%d",&n);

	for(i=0; i<n; i++){
	  scanf("%d",&A[i]);
	}

	x = partition(A,0,n-1);

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

  printf("\n");

  return 0;
}


Measured memory_bytes: 2100
import heapq
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x:x[0])
ans=0
q=[]
heapq.heapify(q)
e=0
for i in range(1,m+1):
  while e<n and ab[e][0]==i:
    heapq.heappush(q,-ab[e][1])
    e+=1
  if len(q)>0: 
    ans-=heapq.heappop(q)
print(ans)

Measured memory_bytes: 31924
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt(), b = sc.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            String str = String.valueOf(i);
            long tempSum = 0;
            for (int j = 0; j < str.length(); j++) {
                tempSum += Integer.parseInt(String.valueOf(str.charAt(j)));
            }
            if (tempSum >= a && tempSum <= b) {
                sum += i;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 24276
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;

bool is_edge(int x, int y, int r, int c)
{
  return (x == 0 || x == r || y == 0 || y == c);
}

int key(int x, int y, int r, int c)
{
  if (y == 0) return x;
  if (x == r) return r + y;
  if (y == c) return r + c + (r - x);
  return r + c + r + (c - y);
}

struct Point {
  int key, id, flag;
  Point(int k, int i, bool f):key(k),id(i),flag(f){};
  bool operator<(const Point& p) const {
    return key < p.key;
  };
};

int main(int argc, char *argv[])
{
  int r, c, n;
  scanf("%d%d%d", &r, &c, &n);

  vector<Point> pts;
  pts.reserve(n);
  for (int i = 0; i < n; ++i) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    if (is_edge(x1,y1,r,c) && is_edge(x2,y2,r,c)) {
      int k1 = key(x1,y1,r,c);
      int k2 = key(x2,y2,r,c);
      pts.push_back(Point(min(k1,k2),i,true));
      pts.push_back(Point(max(k1,k2),i,false));
    }
  }

  sort(pts.begin(), pts.end());

  stack<int> st;
  for (vector<Point>::iterator pt = pts.begin(); pt != pts.end(); ++pt) {
    if (pt->flag) {
      st.push(pt->id);
    } else {
      if (st.top() != pt->id) {
        puts("NO");
        return 0;
      }
      st.pop();
    }
  }
  puts("YES");
  return 0;
}


Measured memory_bytes: 3584
import sys
sys.setrecursionlimit(10**9)

H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]
MOD = 10 ** 9 + 7
count = [0]
dp = [[-1] * W for _ in range(H)]

def dfs(x, y):
  ret = 0
  for nx, ny in ((1,0), (0,1)):
    nx += x
    ny += y
    if nx >= W or ny >= H:
      continue

    if nx == W-1 and ny == H-1:
      ret += 1
    elif dp[ny][nx] > -1:
      ret += dp[ny][nx]
    elif field[ny][nx] == ".":
      ret += dfs(nx, ny)
  dp[y][x] = ret % MOD
  return ret

dfs(0,0)
print(dp[0][0])


Measured memory_bytes: 167816
a,b,c=input().split()
a,c=int(a),int(c)
while b!='?':
    if b=='+':
        print(a+c)
    elif b=='-':
        print(a-c)
    elif b=='*':
        print(a*c)
    elif b=='/':
        print(a//c)
    a,b,c=input().split()
    a,c=int(a),int(c)


Measured memory_bytes: 5596
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

bool[10^^5+1] PS;

void prime_init()
{
    PS[] = true;
    PS[0] = false;
    PS[1] = false;
    foreach (i; 2..10^^5+1) {
        if (PS[i]) {
            auto x = i*2;
            while (x <= 10^^5) {
                PS[x] = false;
                x += i;
            }
        }
    }
}

void main()
{
    prime_init();
    auto qs = new int[](10^^5+1);
    foreach (i; 2..10^^5+1) if (PS[i] && PS[(i+1)/2]) qs[i] = 1;
    foreach (i; 0..10^^5) qs[i+1] += qs[i];

    auto Q = readln.chomp.to!int;
    foreach (_; 0..Q) {
        auto lr = readln.split.to!(int[]);
        writeln(qs[lr[1]] - qs[lr[0]-1]);
    }
}

Measured memory_bytes: 4092
N,K = (int(x) for x in input().split())
R,S,P = (int(x) for x in input().split())
T = input()

SCORE = {
    'r': R,
    's': S,
    'p': P
}

hands = [None]*N
ans = 0

for i in range(N):
    if T[i] == 'r':
        win = 'p'
    elif T[i] == 's':
        win = 'r'
    else:
        win = 's'
    
    if i < K:
        hands[i] = win
        ans += SCORE[win]
    else:
        if hands[i-K] == win:
            hands[i] = None
        else:
            hands[i] = win
            ans += SCORE[win]
            
            
print(ans)    

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

vector<int64_t> fct, inv;
void finit(int cmx, ll mod =MD){
	fct.resize(cmx+20); inv.resize(cmx+20);
	fct[0] = fct[1] = inv[1] = inv[cmx] = 1;
	for(int i=2;i<cmx+3;i++) fct[i] = fct[i-1] * i % mod;
	for(ll x=fct[cmx], n=mod-2; n > 0; n >>=1, x = x*x %mod)
		if(n & 1) inv[cmx] = inv[cmx] * x %mod;
	for(int i=cmx;i>=1;i--) inv[i-1] = inv[i] * i % mod;
}
ll nPk(ll n, ll k, ll mod =MD) {
	if(k > n || n <0 || k <0) return 0;
	ll ret =fct[n] * inv[n-k] % mod;
	return ret;
}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	vector<VL> r(n);
	finit(k+1000);
	rep(i, n-1){
		int a, b; cin >>a >>b;
		r[a-1].push_back(b-1);
		r[b-1].push_back(a-1);
	}
	VL dst(n);
	dst[0] = nPk(k, sz(r[0]) +1);
	
	auto dfs =[&](auto dfs, int c, int p =-1)->void{
		dbg(c, p);
		for(auto v: r[c]) if(v != p ){
			dst[v] = nPk(k-2, sz(r[v]) -1);
			dfs(dfs, v, c);
		}
	};
	
	dfs(dfs, 0);
	ll ans = 1LL;
	for(auto z: dst) (ans *= z) %=MD;
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 10240
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n, m := io.NextInt(), io.NextInt()
	h := io.NextInts(n)
	g := make([][]int, n)
	for i := 0; i < m; i++ {
		from, to := io.NextInt()-1, io.NextInt()-1
		g[from] = append(g[from], to)
		g[to] = append(g[to], from)
	}
	ans := solve(h, g)
	io.Println(ans)
}

func solve(h []int, g [][]int) (ans int) {
	for i := range g {
		isGood := true
		for j := range g[i] {
			from, to := i, g[i][j]
			if h[from] <= h[to] {
				isGood = false
				break
			}
		}
		if isGood {
			ans++
		}
	}
	return ans
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextInts returns n integers from stdin
func (io *Io) NextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = io.NextInt()
	}
	return ret
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 17244
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A = 0, B = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  for (int j = 0; j < N; j++) {
    if (j % 2 == 0) {
      A += a.at(j);
    }
    else {
      B += a.at(j);
    }
  }
  cout << A - B << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define MOD 1000000007
int main(){
  int N,ans=0,B;
  cin>>N;
  vector<int> A(N),C(N-1);
  rep(i,N) cin>>A.at(i);
  rep(i,N){cin>>B;
           ans+=B;
           }
  rep(i,N-1) cin>>C.at(i);
  rep(i,N-1){if(A.at(i)+1==A.at(i+1))
               ans+=C.at(A.at(i)-1);
             }
  cout<<ans<<endl;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
#define MAX 10000005
#define mod 1000000007
#define sp fixed<<setprecision(12)
using namespace std;
/*
vector<int> primes;
ll sumprime[MAX];
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    for(int i=0;i<MAX;i++){
        if(!is_prime[i]){
            sumprime[i]=sumprime[i-1]+i;
        }else{
            sumprime[i]=sumprime[i-1];
        }
    }
}
*/


using namespace std;
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;
    //sieve();
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n][3];
        int dp[n][3];
        for(int i=0;i<n;i++){
            for(int j=0;j<3;j++){
                cin>>a[i][j];
            }
        }
        dp[0][0]=a[0][0];
        dp[0][1]=a[0][1];
        dp[0][2]=a[0][2];
        for(int i=1;i<n;i++){
            dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
        }
        cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});

    }
    
    
    
    
    
    return 0;
    
}

Measured memory_bytes: 5932
n = int(input())
s = input()
peak = [0]
x = 0
for i in range(n):
  if s[i] == "I":
    x += 1
    peak.append(x)
    
  elif s[i]=="D":
    x -= 1
    peak.append(x)

peak.sort()
print(peak[-1])
  

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
  cin >> n;
  int acm=0,square=0,temp;
  rep(i,n){
    cin >> temp;
    acm+=temp;
    square+=temp*temp;
  }
  cout << (acm*acm-square)/2 << endl;

}


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

using namespace std;

#define INF 1000000007
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define maxn 15

signed main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> s(M);
    rep(i, M)
    {
        int k;
        cin >> k;
        s[i].resize(k);
        rep(j, k)
        {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<int> p(M);
    rep(i, M)
    {
        cin >> p[i];
    }
    int ans = 0;
    rep(i, (1 << N))
    {
        bool check = true;
        rep(j, M)
        {
            int c = 0;
            for (auto S : s[j])
            {
                if ((i >> S) & 1)
                {
                    c++;
                }
            }
            if (c % 2 != p[j])
            {
                check = false;
            }
        }
        if (check)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

    int K;
    int N;
    int n[200000];
    int distance = 0;
    int result;
    int i;
    // input 
    scanf("%d %d", &K, &N);

    for (i = 0; i < N; i++) {
        scanf("%d", &n[i]);
    }
    // 途中
    for (i = 1; i < N; i++) {
        if (n[i] - n[i - 1] > distance) {
            distance = n[i] - n[i - 1];
        }
    }

    // 最後の家と最初の家の間
    if (n[0] + (K - n[N - 1]) > distance) {
        distance = n[0] + (K - n[N - 1]);
    }

    result = K - distance;

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

    return 0;
}

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

signed main(void)
{
	int n, m;
	cin >> n >> m;
	vector<int> graph[n];
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	queue<int> que;
	vector<int> label(n, -1);
	que.push(0);
	while(!que.empty())
	{
		int now = que.front();
		que.pop();
		for(int i = 0; i < graph[now].size(); i++)
		{
			if (label[graph[now][i]] != -1) continue; 
			label[graph[now][i]] = now + 1;
			que.push(graph[now][i]);
		}
	}
	for(int i = 1; i < n; i++)
	{
		if (label[i] == -1)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	for(int i = 1; i < n; i++)
	{
		cout << label[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 10152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e3+5;
map<char,int>mp;
int main()
{
    string a;
    cin>>a;
    for(int i=0;i<3;i++)
    {
        mp[a[i]]++;
    }
    if(mp['A']&&mp['B'])
        cout<<"Yes"<<'\n';
    else
        cout<<"No"<<'\n';
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main { 
public static void main(String args[]) { 
Scanner sc = new Scanner(System.in);
long n=sc.nextLong(); 
int x=0;
int y=0;
int z=0;
while(n>=3600){
n=n-3600;
x=x+1;
}
while(n>=60){
n=n-60;
y=y+1;
}
z=(int)n;
System.out.print(x);
System.out.print(":");
System.out.print(y);
System.out.print(":");
System.out.println(z); } }


Measured memory_bytes: 26248
a=gets.to_i
b=gets.to_i
c=gets.to_i
x=gets.to_i
cnt=0

(0..a).each do |a|
  (0..b).each do |b|
    (0..c).each do |c|
      if a*500+b*100+c*50==x
        cnt += 1
      end
    end
  end
end
puts cnt

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n;
    char C1,C2;
    string s;
    long double ans,x[50];
    cin >> n;

    for(i=0;i<n;i++){
        cin >> x[i];
    }

    sort(x,x+n);
    
    ans = x[0];

    for(i=1;i<n;i++){
        ans = (ans+x[i])/2;
    }

    cout << ans;

    return 0;
}



Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as C
import Data.Int
import Data.List
import Data.Maybe
import qualified Data.Vector.Unboxed as V

main = C.interact $ C.pack . show . sol . V.tail . V.unfoldr (C.readInt . C.dropWhile (<'0'))

sol v = if 0 `V.elem` v then 0 else fromMaybe (-1) $ V.foldM' f (1 :: Int64) v

f x a  = if toInteger x*toInteger a > 10^18 then Nothing else Just (x*fromIntegral a)

Measured memory_bytes: 10196
#include <bits/stdc++.h>
typedef long long L;
using namespace std;
 
#define N 100005
map<L,L> path[N];
L par[N],dep[N],siz[N],hev[N],cst[N],add[N],pos[N],hl_par[N],bit[N],
k,n,q,a,b,c,cnt;
void dfs(L a){
    siz[a]=1;
    for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){
        L d=I->first;
        if(d==par[a]) continue;
        par[d]=a;
        dep[d]=dep[a]+1;
        cst[d]=I->second;
        dfs(d);
        siz[a]+=siz[d];
        if(!hev[a] || siz[hev[a]]<siz[d])
            hev[a]=d;
    }
}
   
L edgecost(L a){
    L ret=add[a]+add[par[a]]+cst[a];
    return ret%k ? ret : 0;
}
   
L sum(L i){
    L ret=0;
    while(i){
        ret+=bit[i];
        i-=i&-i;
    }
    return ret;
}
void S(L i, L x){
    x-=sum(i+1)-sum(i);
    i++;
    while(i<N){
        bit[i]+=x;
        i+=i&-i;
    }
}
   
L cost(L a, L b){
    L p=hl_par[a], q=hl_par[b];
    if(p==q) return abs(sum(pos[a])-sum(pos[b]));
    if(dep[p]<dep[q]){
        swap(p, q);
        swap(a, b);
    }
    return sum(pos[a]) - sum(pos[p])
        + edgecost(p) + cost(par[p], b);
}
 
main(){
    cin >> n >> k;
    for(L i=0; i<n-1; i++){
        cin >> a >> b >> c;
        path[a][b]=c;
        path[b][a]=c;
    }
    for(L i=0; i<n; i++) hev[i]=0;
    par[0]=dep[0]=cst[0]=0;
    dfs(0);
   
    for(L i=0; i<n; i++) add[i]=0;
   
    for(L i=0; i<n; i++){
        if(i && hev[par[i]]==i) continue;
        L j=i;
        do{
            pos[j]=cnt++;
            hl_par[j]=i;
        }while(j=hev[j]);
    }
  
    for(L i=0; i<N; i++) bit[i]=0;
    for(L i=0; i<n; i++)
        S(pos[i], edgecost(hev[i]));
    
    cin >> q;
    for(L i=0; i<q; i++){
        string s;
        cin>>s>>a>>b;
        if(s[0]=='a'){
            add[a]+=b;
            S(pos[a], edgecost(hev[a]));
            if(a) S(pos[a]-1, edgecost(a));
        }else{
            cout << cost(a, b) << endl;
        }
    }
}

Measured memory_bytes: 31880
#include <iostream>
#include <algorithm>
using namespace std;
int maxtime(int x) {
	// Maximum consuming time for x-minute order
	return (x + 9) / 10 * 10;
}
int remtime(int x) {
	// Remained time for x-minute order
	return maxtime(x) - x;
}
int main() {
	int A, B, C, D, E;
	cin >> A >> B >> C >> D >> E;
	int sum = maxtime(A) + maxtime(B) + maxtime(C) + maxtime(D) + maxtime(E);
	sum -= max({ remtime(A), remtime(B), remtime(C), remtime(D), remtime(E) });
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3596
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int ans = 0;
        if(a + b <= c*2){
            ans = a*x + b*y;
        }else{
            if(x >= y){
                ans = Math.min(a*(x-y) + 2*c*y, 2*c*x);
            }else{
                ans = Math.min(b*(y-x) + 2*c*x,2*c*y);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21204