akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main() {
	ll N, A; cin >> N >> A;
	while(1) {
		if(N >= 500) N -= 500;
		else break;
	}
	if(N <= A) {
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n,t=map(int,input().split())
    A=list(map(int,input().split()))
    mlist=[0]*n
    mlist[0]=A[0]
    for i in range(1,n):
        if A[i]<mlist[i-1]:
            mlist[i]=A[i]
        else: mlist[i]=mlist[i-1]
    val=[0]*n
    for i in range(n):
        val[i]=A[i]-mlist[i]

    print(val.count(max(val)))

    
resolve()

Measured memory_bytes: 86108
#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <string>
#include <string.h>
#include <limits>
#include <utility>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <cmath>

using namespace std;

namespace
{

}

#if 1
int main()
{
	int n;
	int t, a;

	cin >> n;
	cin >> t >> a;

	vector<int> hs;
	hs.resize(n);

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

	const double da = static_cast<double>(a);

	double diff = std::numeric_limits<double>::max();
	int index = -1;

	for (int i = 0; i < n; i++)
	{
		int h = hs[i];
		double hf = (t * 1.0) - h * 1.0 * 0.006;
		double tempdiff = abs(da - hf);

		if (tempdiff < diff)
		{
			diff = tempdiff;
			index = i;
		}
	}

	cout << index + 1;
}
#endif


Measured memory_bytes: 256
S = list(input())
if S.count(S[0]) == 2:
    if S[0]==S[1]:
        if S[2]==S[3]:
            print('Yes')
        else:
            print('No')
    elif S[0]==S[2]:
        if S[1]==S[3]:
            print('Yes')
        else:
            print('No')
    elif S[0]==S[3]:
        if S[1]==S[2]:
            print('Yes')
        else:
            print('No')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n); for(long long i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n; cin >> n;
  int n_num = n;
  bool r = false;
  rep(i,9){
    if(n%(i+1) == 0){
      n = n/(i+1);
      if(n <= 9){
        r = true;
        break;
      }
      else n = n_num;
    }
  }
  if(r) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

struct edge{ int to,cost; };
const int N = 1e5+10;
vector< edge > G[N];

int prim(){
  typedef pair<int, int> P;
  const int INF = 1 << 30;

  priority_queue<P,vector<P>,greater<P>> que;
  vector<bool> visited(N,false);

  que.push({0,0}); //{距離,頂点}
  int total = 0;

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(visited[v]) continue;
    visited[v] = true;
    total += p.first;
    for(auto e : G[v]){
      if(!visited[e.to]){
        que.push( {e.cost,e.to} );
      }
    }
  }
  return total;
}

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

  int V; cin >> V;
  for(int i = 0; i < V; i++){
    for(int j = 0; j < V; j++){
      int cost; cin >> cost;
      if(cost == -1) continue;
      G[i].push_back({j,cost});
    }
  }
  cout << prim() << endl;

  return 0;
}



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

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N), a(N + 1), B(M), b(M + 1);
  rep(i, N) {
    cin >> A[i];
    a[i + 1] = a[i] + A[i];
  }
  rep(i, M) {
    cin >> B[i];
    b[i + 1] = b[i] + B[i];
  }

  ll ans = 0, j = M;
  rep(i, N + 1) {
    if (a[i] > K) break;
    while (b[j] > K - a[i]) j--;
    ans = max(ans, i + j);
  }
  cout << ans << endl;
  return 0;
}


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

void solve(long long A, long long B)
{
    long long sum = 1;
    long long tap = 0;
    while (sum < B)
    {
        tap++;
        sum += (A - 1);
    }
    cout << tap << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


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

public class Main {

    public static void main(String[] args) {
        System.out.println(process(readAll(System.in)));
    }

    protected static String process(String data) {
        final String[] lines = splitForLines(data);

        final int[] array = split(lines[1]);

        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        long sum = 0;

        for (int i : array) {
            min = Math.min(i, min);
            max = Math.max(i, max);
            sum += i;
        }

        return min + " " + max + " " + sum;
    }

    private static String readAll(InputStream is) {
        InputStreamReader r = null;
        BufferedReader br = null;

        try {
            r = new InputStreamReader(is);
            br = new BufferedReader(r);
            StringBuilder sb = new StringBuilder();
            String s;

            while ((s = br.readLine()) != null) {
                sb.append(s).append('\n');
            }

            return sb.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }
            if (r != null) {
                try {
                    r.close();
                } catch (IOException e) {
                }
            }
        }
    }

    private static int[] split(String s) {
        final String[] s0 = s.split(" ");
        int[] ia = new int[s0.length];

        for (int i = 0; i < s0.length; i++) {
            ia[i] = Integer.parseInt(s0[i]);
        }

        return ia;
    }

    private static String[] splitForLines(String lines) {
        return lines.split("\\n");
    }

}

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

int main(){
    int N;
    cin >> N;
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        int D;
        cin >> D;
        mp[D]++;
    }
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
        int T;
        cin >> T;
        if (mp[T] == 0){
            cout << "NO" << endl;
            return 0;
        }else mp[T]--;
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 9600
import math

def standard_deviation(ls):
    n=len(ls)
    ave=sum(ls)/float(n)
    var=.0
    for x in ls:
        var+=((x-ave)**2)/float(n)
        
    return math.sqrt(var)
    
    

def run():
    
    while True:
    
        n=int(input())
        
        if n==0:
            break
        
        ls=list(map(float,input().split()))
            
        
        var=standard_deviation(ls)
        print(f"{var}")
        

run()


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

int main() {
	string S;
	cin >> S;
	int n=S.size();
	if(S[0]=='0' || S[n-1]=='1'){
		cout << -1 << endl;
		return 0;
	}
	for(int i=0; i<n-2-i; ++i){
		if(S[i]!=S[n-2-i]){
			cout << -1 << endl;
			return 0;
		}
	}
	int now=1;
	for(int i=2; i<=n; ++i){
		cout << now << ' ' << i << endl;
		if(S[i-2]=='1'){
			now=i;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
/*
 * atcoder/abc089/b.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve();
int main() { solve(); return 0; }

#include <set>
void solve() {
  int x, y; cin >> x >> y;
  set<int> S1 { 1, 3, 5, 7, 8, 10, 12 };
  set<int> S2 { 4, 6, 9, 11 };
  set<int> S3 { 2 };
  
  auto f = [&](int x) {
    if (S1.count(x)) return 0;
    if (S2.count(x)) return 1;
    return 2;
  };
  
  vector<string> A { "No", "Yes" };
  cout << A[f(x) == f(y)] << endl;
}


Measured memory_bytes: 3616
N, Y = map(int, input().split())

for a in range(N+1):
    b = (Y - 9000*a - 1000*N) // 4000
    mod = (Y - 9000*a - 1000*N) % 4000
    if 0 <= b <= N - a and mod == 0:
        print("{} {} {}".format(a, b, N-a-b))
        import sys
        sys.exit()

print("-1 -1 -1")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m, k;
	cin>>n>>m;
	vector<int> liked(m, 0);
	for(int i = 0; i < n; ++i){
		cin>>k;
		for(int j = 0; j < k; ++j){
			int a;
			cin>>a;
			liked[a-1]++;
		}
	}
	int res = 0;
	for(int i = 0; i < m; ++i){
		if(liked[i] >= n)res++;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
import * as fs from 'fs'
import {type} from "os";

const input = fs.readFileSync('/dev/stdin', 'utf8');
const args = input.split('\n').map(l => l.split(' '));

const s = args[0][0];
const t = args[1][0];

const flag = induceFromAlphabets(s, t) && induceFromAlphabets(t, s);

const msg = flag ? 'Yes' : 'No';

console.log(msg);

function induceFromAlphabets(s: string, t: string): boolean {
  const m = new Map<string, string>();

  for (let i = 0; i < s.length; i++) {
    const c = m.get(s[i]);
    if (typeof c == 'undefined') {
      m.set(s[i], t[i]);
      continue
    } else if (c !== t[i]) {
      return false
    }
  }

  return true
}


Measured memory_bytes: 7712
import sys, collections

def solve():
    input = sys.stdin.readline
    N = int(input())
    k = 1
    while k <= N:
        if k == N:
            print("No")
            break
        else: k *= 2
    else:
        if N % 2 == 1:
            print("Yes")
            ans = ""
            ans += "1 2\n"
            ans += "2 3\n"
            ans += "3 " + str(N + 1) + "\n"
            ans += str(N + 1) + " " + str(N + 2) + "\n"
            ans += str(N + 2) + " " + str(N + 3) + "\n"
            for i in range(2, N // 2 + 1):
                ans += str(2 * i) + " " + str(2 * i + 1) + "\n"
                ans += str(2*i+1) + " 1\n"
                ans += "1 " + str(N + 2*i) + "\n"
                ans += str(N+2*i) + " " + str(N+2*i+1) + "\n"
            print(ans)
        else:
            print("Yes")
            ans = ""
            ans += "1 2\n"
            ans += "2 3\n"
            ans += "3 " + str(N + 1) + "\n"
            ans += str(N + 1) + " " + str(N + 2) + "\n"
            ans += str(N + 2) + " " + str(N + 3) + "\n"
            for i in range(2, N // 2):
                ans += str(2 * i) + " " + str(2 * i + 1) + "\n"
                ans += str(2*i+1) + " 1\n"
                ans += "1 " + str(N + 2*i) + "\n"
                ans += str(N+2*i) + " " + str(N+2*i+1) + "\n"
            b = N ^ (N - 1)
            ans += str(N) + " " + str(N-1) + "\n"
            if b % 2 == 1:
                ans += str(N + b - 1) + " " + str(2 * N)
            else:
                ans += str(b + 1) + " " + str(2 * N)
            print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9720
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  vector<int> p(n);
  int e=0;
  rep(i,n){
    p[i]=e;
    if(s[i]=='E') e++;
  }

  int w=0;
  for(int i=n-1;i>=0;i--){
    p[i]+=w;
    if(s[i]=='W') w++;
  }

  int ans=0;
  rep(i,n){
    chmax(ans,p[i]);
  }

  cout << n-1-ans << endl;

}

Measured memory_bytes: 1796
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

constexpr int64_t DIV = 1000000007; // 10^9 + 7

using namespace std;

/** 素因数分解
 */
template<typename T>
std::map<T, size_t>
prime_factorize(T n) {
    std::map<T, size_t> res;
    for (T p = 2; p * p <= n; ++p) {
        if (n % p != 0) {
            continue;
        }
        size_t num = 0;
        while (n % p == 0) {
            ++num;
            n /= p;
        }
        res[p] = num;
    }
    if (n != 1) {
        res[n] = 1;
    }
    return res;
}

/** 二項係数計算
    (1 ≦ k ≦ n ≦ 107 程度)
 */
class Combination {
public:
    Combination(int64_t max, int64_t mod) : mod_(mod) {
        fac_.resize(max+1);
        inv_.resize(max+1);
        finv_.resize(max+1);

        fac_[0] = fac_[1] = 1;
        finv_[0] = finv_[1] = 1;
        inv_[1] = 1;
        for (int64_t i = 2; i <= max; i++){
            fac_[i] = fac_[i - 1] * i % mod;
            inv_[i] = mod - inv_[mod%i] * (mod / i) % mod;
            finv_[i] = finv_[i - 1] * inv_[i] % mod;
        }
    }

    int64_t get(int64_t n, int64_t k) const {
        if (n < k) {
            return 0;
        }
        if (n < 0 || k < 0) {
            return 0;
        }
        return fac_[n] * (finv_[k] * finv_[n - k] % mod_) % mod_;
    }

    std::vector<int64_t> fac_;
    std::vector<int64_t> finv_;
    std::vector<int64_t> inv_;

    int64_t mod_;
};


int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    auto fac = prime_factorize(M);

    int64_t ans = 1;
    if (fac.size() > 0) {
        auto a = std::max_element(std::begin(fac), std::end(fac), [](auto l, auto r) {
                return l.second < r.second;
            })->second;
        Combination c(a + N-1 , DIV);

        for (auto f: fac) {
            auto n = f.second;
            ans *= c.get(n + N-1, N-1);
            ans %= DIV;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 2560
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
	return a * b // gcd (a, b)

n = int(input())
A = list(map(int, input().split()))

ans = 1
for a in A:
    ans = lcm(ans, a)
print(ans)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


signed main(void){
    int N,M,V,P,a;
    vector<int> A;
    cin >> N >> M >> V >> P;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    sort(A.begin(),A.end());
    
    
    int L=-1,R=N,mid;
    while((R-L)>1){
        mid=(L+R)/2;
        vector<int> B;REP(i,N){B.push_back(0);}
        for(int i=0;i<=mid;i++){
            B[i]+=M;
        }
        for(int i=mid+1;i<N;i++){
            B[i]+=max(0ll,A[mid]+M-A[i]);
        }
        
        //REP(i,N){cout << B[i] << " ";}cout << endl;
        
        int Bsum=0;
        REP(i,N){Bsum+=B[i];}
        for(int i=N-1;i>=0;i--){
            if(Bsum>=M*V)break;
            Bsum+=M-B[i];
            B[i]=M;
        }
        //REP(i,N){cout << B[i] << " ";}cout << endl;
        int judge=A[mid]+M;
        REP(i,N){B[i]+=A[i];}
        sort(B.begin(),B.end());
        //REP(i,N){cout << B[i] << " ";}cout << endl;
        decltype(B)::iterator it = upper_bound(B.begin(), B.end(), judge);
        it--;
        int loc=(it-B.begin());
        
        //cout << L MM R MM mid MM loc<< endl;
        if(loc>=N-P){
            R=mid;
        }else{
            L=mid;
        }
    }
    cout << N-R << endl;
    return 0;
}



Measured memory_bytes: 2896
N, M=[int(x) for x in input().split()]
shopl = [[int(x) for x in input().split()] for _ in range(N)]
sl =sorted(shopl,key=lambda x:(x[0])) 
cnt = 0
price =0
for i in range(N):
    amt = min(sl[i][1], M - cnt)
    price += sl[i][0] * amt
    cnt +=amt
    if cnt == M:
      break
print(price)


Measured memory_bytes: 23528
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80  
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ll n;
	cin >> n;
	vl heights(n);

	FOR(i, 0, n) {
		cin >> heights[i];
	}

	vl minimums(n, oo);
	minimums[0] = 0;

	FOR(i, 0, n) {
		FOR(j, min(n - 1, i + 1), min(n, i + 3)) {
			minimums[j] = min(minimums[j], minimums[i] + abs(heights[j] - heights[i]));
		}
	}

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


} //cin.tie(0) bei schnellem Wechseln

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

using namespace std;

int main()
{

  int N;
  cin >> N;
  
  vector<int> suji;
  
  for(int i=0;i<N;i++) 
  {
    int buf;
    cin >> buf;
    suji.push_back(buf);
  }
   
  int count = 1;
  int break_count = 0;
  for(auto ite:suji) 
  {
    if(ite==count){
      	count++;
    }else{
    	break_count++;
    }    
  }
  if(count ==1){
  	break_count = -1;
  }
  cout << break_count;
}


Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
//最初に設定する.
const int MAX = 510000; const ll MOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];  void modcinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long modc(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; }
int main( ){
    ll n,m;
    cin>>n>>m;
    ll k;
    cin>>k;
    modcinit();
    ll mod=998244353;
    ll res=0;
    rep(i,0,k+1){
        ll add=(((m*modc(n-1,i)%mod)+mod)%mod*modpow(m-1,n-1-i,mod)%mod+mod)%mod;
        res=((res+add)%mod+mod)%mod;
    }
    cout<<res<<endl;
    return 0;
}




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

int main() {
  int n,sum,ans=1e9;
  cin >> n;
  int x[n];
  for(int i=0;i<n;i++) cin >> x[i];
  for(int p=1;p<101;p++){
    sum = 0;
    for(int i=0;i<n;i++){
      sum += (x[i]-p) * (x[i]-p);
    }
    ans = min(ans,sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[]a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();
		int cnt1 = 0;
		int cnt2 = 0;
		int cnt3 = 0;
		for(int i = 0; i < N; i++){
			if(a[i] % 4 == 0) {
				cnt1++;
			}else if(a[i] % 2 == 0) {
				cnt2++;
			}else {
				cnt3++;
			}
		}
		if(cnt1 >= cnt3 - 1 && cnt2 == 0) {
			System.out.println("Yes");
			System.exit(0);
		}
		if(cnt1 >= cnt3) {
			System.out.println("Yes");
			System.exit(0);
		}
		if(cnt3 == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 50324
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define ull unsigned long long

using namespace std;

int a[105], n, ans = 0;

inline ll in()
{
	ll Req = 0, wX = 0; char ch;
	while (!isdigit(ch)) {wX |= (ch == '-'); ch = getchar();}
	while (isdigit(ch)) {Req = (Req << 3) + (Req << 1) + (ch ^ 48); ch = getchar();}
	return wX ? -Req : Req;
}

inline void out(ll x)
{
	register short Pxn[20], Ry = 0;
	if (x == 0) putchar('0');
	if (x < 0) putchar('-'), x = -x;
	while (x != 0) Pxn[Ry] = x % 10, x /= 10, Ry++;
	for (int i = Ry - 1; i >= 0; i--) putchar(Pxn[i] + '0');
}

int main()
{

	n = in();
	for (int i = 0; i < n - 1; i++) a[i] = in();
	ans = a[0] + a[n - 2];
	for (int i = 0; i < n - 2; i++) ans += min(a[i], a[i + 1]);
	out(ans);

  return 0;

}



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

int n;
vector<int> p, q;

class Problem{
public:
  long long solve(int x, vector<int> & p, vector<int> & q){
    long long u = 0;
    vector<int> r;
    r = p;
    long long a, b;
    a = b = 0;
    sort(r.begin(), r.end());
    do{
      if(p == r){a = u;}
      if(q == r){b = u;}
      u++;
    }while(next_permutation(r.begin(), r.end()));
    return abs(a - b);
  }
};

int main(){
  cin>>n;
  p.resize(n, 0);
  q.resize(n, 0);
  for(int i = 0; i < n; ++i)cin>>p[i];
  for(int i = 0; i < n; ++i)cin>>q[i];
  Problem C;
  cout<<C.solve(n, p, q)<<endl;  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    char c;
    cin >>c;
    
    if (c == 'a' || c == 'e' ||c == 'i' ||c == 'o' ||c == 'u')cout << "vowel" << endl;
    else cout << "consonant" << endl;
    
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		s = s.substring(0, s.length() - 1);
		if (s.length() % 2 != 0)
			s = s.substring(0, s.length() - 1);
		while (!s.substring(0, s.length() / 2).equals(s.substring(s.length() / 2 , s.length())))
			s = s.substring(0, s.length() - 2);
		System.out.println(s.length());
	}
}

Measured memory_bytes: 23764
#include <stdio.h>

int main(void)
{
	int N, a[100000][2] = {}, ans = 0, tmp = 0, i;
	scanf("%d", &N);
	for (i = 0; i < N; ++i) scanf("%d", &a[i][0]);
	for (i = 0; a[i][0] != 2; ++ans) {
		if (a[i][1] == 1) {
			tmp = 1;
			break;
		}
		a[i][1] = 1;
		i = a[i][0] - 1;
	}
	if (tmp == 0) printf("%d", ans + 1);
	else puts("-1");
	return 0;
}

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

long long n,ans,cc[100005],tmp[100005];
int m,a[100005],b[100005],parent[100005];

int find(int x){
	if(parent[x]==-1) return x;
	return parent[x] = find(parent[x]);
}



int main(){
//	memset(parent,-1,sizeof parent);
	scanf("%lld%d",&n,&m);
	for(int i =0;i<=n;i++){
		parent[i] = -1;
		cc[i] = 1;
	}
	for(int i =0;i<m;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	ans = n*(n-1)/2;
	for(int i =m-1;i>=0;i--){
		tmp[i] = ans;
		int aa = find(a[i]);
		int bb = find(b[i]);
		
		if(aa!=bb){
			ans-=cc[aa]*cc[bb];
			cc[aa] += cc[bb];
			parent[bb] = aa; 	
		} 
	}
	for(int i =0;i<m;i++){
		printf("%lld\n",tmp[i]);
	}
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  map<int,int> mp;
  REP(i, N){
    cin >> A[i];
    mp[A[i]]++;
  }
  if(N%2==0){
    int flag=0;
    for(int i=1;i<=(N/2)*2-1;i=i+2){
      if(mp[i]!=2){
        flag=1;
      }
    }
    if(flag==1){
      cout << 0 << endl;
    }else{
      mint ans=1;
      REP(i,N/2){
        ans*=2;
      }
      cout << ans << endl;
    }
  }else{
    int flag=0;
    for(int i=2;i<=(N/2)*2;i=i+2){
      if(mp[i]!=2){
        flag=1;
      }
    }
    if(mp[0]!=1){
      flag=1;
    }
    if(flag==1){
      cout << 0 << endl;
    }else{
      mint ans=1;
      REP(i,N/2){
        ans*=2;
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 4480
sc = input().split()
n = int(sc[0])
m = int(sc[1])
a = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
    sc = input().split()
    for j in range(m):
        a[i][j] = int(sc[j])
b = [0] * m
for i in range(m):
    b[i] = int(input())
for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j] * b[j]
    print(c)


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

int main(){
  string S;
  cin >> S;
  bool ans = false;
  if(S[0] == S[1] && S[1] == S[2]) ans = true;
  if(S[1] == S[2] && S[2] == S[3]) ans = true;
  
  cout << ( ans ? "Yes" : "No" ) << endl;
  
}

Measured memory_bytes: 256
package main

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

type dice struct {
	t int64
	e int64
	w int64
	s int64
	n int64
	b int64
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	d := make([]*dice, n)
	for i := int64(0); i < n; i++ {
		d[i] = &dice{
			t: nextInt(sc),
			s: nextInt(sc),
			e: nextInt(sc),
			w: nextInt(sc),
			n: nextInt(sc),
			b: nextInt(sc),
		}
	}

	for i := int64(0); i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			if d[i].same(d[j]) {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

func (d *dice) same(d2 *dice) bool {
	d2.setTopAndSouth(d.t, d.s)
	return d.t == d2.t && d.b == d2.b && d.n == d2.n &&
		d.e == d2.e && d.s == d2.s && d.w == d2.w
}

func (d *dice) setTopAndSouth(t, s int64) {
	d.setTop(t)
	switch s {
	case d.e:
		d.pitchL()
	case d.n:
		d.pitchR()
		d.pitchR()
	case d.w:
		d.pitchR()
	}
}

func (d *dice) setTop(t int64) {
	switch t {
	case d.s:
		d.rollN()
	case d.n:
		d.rollS()
	case d.e:
		d.rollW()
	case d.w:
		d.rollE()
	case d.b:
		d.rollN()
		d.rollN()
	}
}

func (d *dice) rollS() {
	oldB := d.b
	d.b = d.s
	d.s = d.t
	d.t = d.n
	d.n = oldB
}

func (d *dice) rollN() {
	oldB := d.b
	d.b = d.n
	d.n = d.t
	d.t = d.s
	d.s = oldB
}

func (d *dice) rollE() {
	oldB := d.b
	d.b = d.e
	d.e = d.t
	d.t = d.w
	d.w = oldB
}

func (d *dice) rollW() {
	oldB := d.b
	d.b = d.w
	d.w = d.t
	d.t = d.e
	d.e = oldB
}

func (d *dice) pitchR() {
	oldN := d.n
	d.n = d.e
	d.e = d.s
	d.s = d.w
	d.w = oldN
}

func (d *dice) pitchL() {
	oldN := d.n
	d.n = d.w
	d.w = d.s
	d.s = d.e
	d.e = oldN
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



Measured memory_bytes: 1116
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
string s;
int a[30];

int main(){
  cin >> s;
  string ans = "yes";
  REP(i,s.size()){
    if(a[s[i]-'a'] ==0) a[s[i]-'a']++;
    else ans = "no";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll Q,Bs=0;
  cin>>Q;
  
  // Eは小さいものを降順 Fは大きいものを昇順
  priority_queue<ll> E;
  priority_queue<ll,vector<ll>,greater<ll>> F;
  ll Es=0,Fs=0;
  
  REP(q,Q){
    ll X,A,B;
    cin>>X;
    if(X==1){
      cin>>A>>B;
      Bs+=B;
      if(E.size()>F.size()){
        ll P=E.top();
        if(A>=P){
          F.push(A);
          Fs+=A;
        }
        else{
          E.pop();
          Es-=P;
          E.push(A);
          Es+=A;
          F.push(P);
          Fs+=P;
        }
      }
      else{
        if(E.empty()){
          E.push(A);
          Es+=A;
        }
        else{
          ll P=F.top();
          if(A<=P){
            E.push(A);
            Es+=A;
          }
          else{
            F.pop();
            Fs-=P;
            F.push(A);
            Fs+=A;
            E.push(P);
            Es+=P;
          }
        }
      }
    }
    else{
      ll W=E.top();
      ll ans=(W*(int)E.size()-Es)+(Fs-W*(int)F.size())+Bs;
      cout<<W<<" "<<ans<<endl;
    }
  }
  return 0;
}

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

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(int[]);
    auto BS = readln.split.to!(int[]);
    foreach (i; 1..N) {
        AS[i] += AS[i-1];
        BS[i] += BS[i-1];
    }
    int r;
    foreach (i; 0..N) {
        r = max(r, AS[i] + BS[N-1] - (i == 0 ? 0 : BS[i-1]));
    }
    writeln(r);
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<int,int> P;

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

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

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

long long dp[100010][4]={};
int main(){
    string S;
    cin >> S;
    int N=S.size();

    for(int i=N; i>=0; i--){
        for(int j=3; j>=0; j--){
            if(i==N){
                dp[i][j]=(j==3 ? 1:0);
            }else{
                dp[i][j]=dp[i+1][j]*(S[i]=='?' ? 3LL : 1LL);
                if(j<3 && (S[i]=='?' || S[i]=="ABC"[j])){
                    dp[i][j]+=dp[i+1][j+1];
                }
                dp[i][j]%=MOD;
            }
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}



Measured memory_bytes: 3584
#include<cstdio>
#include<cstring>
#define maxn 105
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
int n,m,sumr[maxn][maxn],sumc[maxn][maxn],ex,ey,ans;
short dp[maxn][maxn][maxn][maxn];
char s[maxn][maxn];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			sumr[i][j]=sumr[i][j-1];
			sumc[i][j]=sumc[i-1][j];
			if(s[i][j]=='E') ex=i,ey=j;
			if(s[i][j]=='o') sumr[i][j]++,sumc[i][j]++;
		}
	int L=ey-1,R=m-ey,U=ex-1,D=n-ex;
	memset(dp,-1,sizeof(dp));
	dp[0][0][0][0]=0;
	for(int l=0;l<=L;l++)
		for(int r=0;r<=R;r++)
			for(int u=0;u<=U;u++)
				for(int d=0;d<=D;d++)
				{
					int tmp=dp[l][r][u][d];
					if(tmp==-1) continue;
					ans=max(tmp,ans);
					int up=max(ex-u,d+1),dn=min(ex+d,n-u),le=max(ey-l,r+1),ri=min(ey+r,m-l);
					if(up>dn||le>ri) continue;
					if(u<U-d) dp[l][r][u+1][d]=max(dp[l][r][u+1][d],tmp+sumr[ex-u-1][ri]-sumr[ex-u-1][le-1]);
					if(d<D-u) dp[l][r][u][d+1]=max(dp[l][r][u][d+1],tmp+sumr[ex+d+1][ri]-sumr[ex+d+1][le-1]);
					if(r<R-l) dp[l][r+1][u][d]=max(dp[l][r+1][u][d],tmp+sumc[dn][ey+r+1]-sumc[up-1][ey+r+1]);
					if(l<L-r) dp[l+1][r][u][d]=max(dp[l+1][r][u][d],tmp+sumc[dn][ey-l-1]-sumc[up-1][ey-l-1]);
				}
	printf("%d\n",ans);
}

Measured memory_bytes: 237696
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))
a=[bin(j)[2:].zfill(n) for j in range(2**n)]
ans=0
for jj in range(2**n):
  b=0
  for i in range(m):
    num=0
    for ii in range(1,s[i][0]+1):
      num+=int(a[jj][s[i][ii]-1])
    if num%2!=p[i]:
      b+=1
  if b==0:
    ans+=1
print(ans)

Measured memory_bytes: 3188
using System;
using System.Linq;

namespace B.Maximum_Difference
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Ai = Console.ReadLine().Split().Select(int.Parse);

            Console.WriteLine(Math.Abs(Ai.Max() - Ai.Min()));
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int a, b;
  cin >> a >> b;
  int d = a/b;
  int r = a%b;
  double f = (double)a/b;
  printf("%d %d %.10f\n", d,r,f);
  return 0;
}


Measured memory_bytes: 3232
#include<iostream>
#include<string>
using namespace std;
long long n,a[200010];
const int mod=1000000007;
int main()
{
	int n;
	cin>>n;
	long long s=0,sum=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=1;i<=n;i++)
	{
		sum-=a[i];
		s=(((a[i]%mod)*(sum%mod)%mod)+s)%mod;
	}
	cout<<s<<endl;
	return 0;		
}

Measured memory_bytes: 5152
import itertools
n=int(input())
p=tuple(map(int, input().split()))
q=tuple(map(int, input().split()))

per=itertools.permutations(range(1, n+1), n)
for i, v in enumerate(per):
    if(p==v): pi=i
    if(q==v): qi=i

print(abs(pi-qi))


Measured memory_bytes: 9160
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{
    int n,i,j;
    long long tt = 0;
    long long sum=0,a[100001],dis;
    cin >> n;
    for (i=1;i<=n;i++)
    {
        cin >> a[i];
        sum += a[i];
        tt += i;
    }

    if ( sum%tt!=0)
    {
      cout << "NO";
      return 0;
    }

    sum = sum / tt;
    long long fr;
    for (i=1;i<n;i++)
    {
        dis = a[i+1] - a[i];
        if (sum<dis)
        {
          cout << "NO";
          return 0 ;
        }
        if ((sum-dis)%n!=0)
        {
            cout << "NO";
            return 0;
        }
        fr+= (sum-dis)/n;

    }

    if (fr=sum)
        cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	 public static void main(String[] args) throws IOException {
	        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	        String input = br.readLine();
	        int n = Integer.valueOf(input);
	        while(n > 0 && (input = br.readLine()) != null) {
	            String[] s = input.split(" ");
	            int[] edges = {
	                (int) Math.pow(Integer.valueOf(s[0]), 2),
	                (int) Math.pow(Integer.valueOf(s[1]), 2),
	                (int) Math.pow(Integer.valueOf(s[2]), 2),
	            };            
	            Arrays.sort(edges);
	            System.out.println(((edges[0]+edges[1])==edges[2]) ? "YES" : "NO");
	            n--;
	        }
	    }
}

Measured memory_bytes: 10000
#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 <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, d,t,s, ok=1;
	cin >>d >>t >>s;
	
	if(d > t*s) ok=0;
	puts(ok?"Yes":"No");
	return 0;
}



Measured memory_bytes: 3672
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]

if A == B and C ==D and A != C:
  print("Yes")
elif A == C and B ==D and A != B:
  print("Yes")
elif A == D and B == C and A != B:
  print("Yes")
else:
  print("No")
  

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

int main()
{
  int height[10];
  
  for(int i = 0 ; i < 10 ; i++)
    {
      cin >> height[i];
    }

  for(int i = 0 ; i < 10 ; i++)
    {
      for(int j = i + 1 ; j < 10 ; j++)
	{
	  if(height[i] < height[j])
	    {
	      int dumy = height[i];
	      height[i] = height[j];
	      height[j] = dumy;
	    }
	}
    }
  for(int i = 0 ; i < 3 ; i++)
    {
      cout << height[i] << endl;
    }
  return 0;
}

Measured memory_bytes: 0