akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// #define cerr if(false)cerr
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb emplace_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
#define minel(a) *min_element(all(a))
#define maxel(a) *max_element(all(a))
#define pq(t) priority_queue<t, vector <t>, greater <t>>
#define pqd(t) priority_queue<t>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))      // Used to iterate over the types

const ll mod = 1e9 + 7;
const ll mx = 1e18;
const ll inf = 1e7;

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// For printing variables and their respective values

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}

template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

auto mods() { return 0; }

template<typename T, typename... Args>
auto mods(T a, Args... args) { return (a + mods(args...) + mod) % mod; }

auto modp() { return 1; }

template<typename T, typename... Args>
auto modp(T a, Args... args) { return ( a * modp(args...) )% mod; }
// ! inputs should be positive and less than `mod`.

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// !Taking `int` input

template<typename T>
T nxt(){
    T x;
    cin >> x;
    return x;
}

//  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

inline void solve()
{
   int n = nxt<int>();
   string s;
   cin >> s;
   cout << count(s.begin(), s.begin() + count(all(s), 'R'), 'W') << endl;
}

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

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3704
H,W=map(int,input().split())
A=[]
for _ in range(H):
    a=input()
    A.append(a)
mod=10**9+7

dp=[[0 for i in range(0,W)] for j in range(0,H)]

dp[0][0]=1
for i in range(0,H):
    for j in range(0,W):
        if i!=0 or j!=0:
            if A[i][j]==".":
                ans=0
                if i!=0:
                    ans+=dp[i-1][j]
                if j!=0:
                    ans+=dp[i][j-1]

                dp[i][j]=ans%mod


print(dp[H-1][W-1])

Measured memory_bytes: 55388
def solve():
	if C<D:
		cnt = 0
		for i in range(A, D):
			if S[i:i+1]=='#':
				cnt += 1
				if cnt>=2:
					print('No')
					return
			else:
				cnt = 0
		print('Yes')
		return

	if C<B:
		cnt = 0
		for i in range(A, C):
			if S[i:i+1]=='#':
				cnt += 1
				if cnt>=2:
					print('No')
					return
			else:
				cnt = 0
		cnt = 0
		for i in range(B, D):
			if S[i:i+1]=='#':
				cnt += 1
				if cnt>=2:
					print('No')
					return
			else:
				cnt = 0
		print('Yes')
		return

	cnt = 0
	for i in range(A, C):
		if S[i:i+1]=='#':
			cnt += 1
			if cnt>=2:
				print('No')
				return
		else:
			cnt = 0
	cnt = 0
	for i in range(B-2, D+1):
		if S[i:i+1]=='.':
			cnt += 1
			if cnt>=3:
				print('Yes')
				return
		else:
			cnt = 0
	print('No')
	return

N, A, B, C, D = map(int, input().split())
S = input()
solve()

Measured memory_bytes: 40688
#include <bits/stdc++.h>
using namespace std;
string s;
bool flag;
int main(){
    cin>>s;
    for(int i = 0; i < s.size()-1; i++){
        if(s[i]=='A' and s[i+1] == 'C')flag = true;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
n , w = map(int,raw_input().split())

weights = []
values = []

for i in range(n):
	val,wei = map(int,raw_input().split())
	values.append(val)
	weights.append(wei)

dp = [[-1 for i in range(w+1)] for i in range(n+1)]

dp[0][0] = 0

for i in range(n):
	for j in range(w+1):
		if j >= weights[i] and dp[i][j-weights[i]] != -1 :
			dp[i+1][j] = max(dp[i][j-weights[i]] + values[i], dp[i][j])
		else :
			dp[i+1][j] = dp[i][j]

print max(dp[n])


Measured memory_bytes: 19552
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int itemstoread = 2;
    int inp[itemstoread];
    int i;
    
    // read in K, N
    bool isSpace = false;
    for (i = 0; i < itemstoread; ++i) {
        if (!isSpace) {
            cin >> inp[i --];
        }
        isSpace = !isSpace;
    }

    // read in Ai 
    isSpace = false;
    itemstoread = inp[1];
    vector<int> dist;
        for (i = 0; i < itemstoread; ++i) {
        if (!isSpace) {
            int item;
            cin >> item;
            dist.push_back(item);
            -- i;
        }
        isSpace = !isSpace;
    }
    
    // reverse sort the array 
    sort( begin(dist), end(dist), greater<int>() );
    
    unsigned long long minim = -1;
    int offset = 0;
    for (i = 0; i < inp[1]; ++ i) {
        int distance = dist[offset] - dist[offset + inp[1] - 1];
        minim = (distance < minim) ? distance : minim;
        // dont pop off front, use offset instead
        dist.push_back(dist[offset] - inp[0]);
        offset ++;
    }
    
    cout << minim << endl;
    return 0;
}

Measured memory_bytes: 2420
sx,sy,tx,ty=map(int,input().split())
dx=tx-sx
dy=ty-sy
outp="R"*dx+"U"*dy+"L"*dx+"D"*dy+"D"+"R"*(dx+1)+"U"*(dy+1)+"L"+"U"+"L"*(dx+1)+"D"*(dy+1)+"R"
print(outp)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int dis[2][N];
vector<int> g[N];

void bfs(int be, int id) {
  queue<int> q;
  q.push(be);
  dis[id][be] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (!dis[id][v]) {
        dis[id][v] = dis[id][u] + 1;
        q.push(v);
      }
    }
  }
}

int main() {
  int n, x, y, u, v, res = 0;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  bfs(x, 0);
  bfs(y, 1);
  for (int i = 1; i <= n; i++) {
    if (dis[0][i] < dis[1][i]) res = max(res, dis[1][i] - 2);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 9964
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1;
    int dy = y2 - y1;

    swap(dx, dy);
    dx = -dx;
    int x3 = x2 + dx;
    int y3 = y2 + dy;
    cout << x3 << ' ' << y3 << ' ';

    swap(dx, dy);
    dx = -dx;
    int x4 = x3 + dx;
    int y4 = y3 + dy;
    cout << x4 << ' ' << y4 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
  long long x, y;
  scanf("%lld%lld", &x, &y);
  
  long ans = 1;
  while (x <= y)
  {
    x <<= 1;
    if (x <= y) ++ans;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	for (int N; cin >> N;) {
		vector<int> a(N, -1); rep(i, 1, N) { cin >> a[i]; a[i]--; }
		vector<int> d(N, 0);
		rep(i, 1, N)d[a[i]]++;
		dumpc(d);
		vector<int> b = d;
		using State = tuple<int, int, int, int>;
		priority_queue<State> pq;
		rep(i, 1, N) {
			if (d[i] != 0)continue;
			pq.emplace(-d[i], -d[a[i]], a[i], i);
		}
		vector<int> flag(N, false);
		while (pq.size()) {
			int cd, nd, ni, ci;
			tie(cd, nd, ni, ci) = pq.top(); pq.pop();
			cd = -cd;
			nd = -nd;
			dump(cd)dump(ni + 1)dumpl(ci + 1);
			if (flag[ci])continue;
			flag[ci] = true;
			chmax(d[ni], b[ni] + cd);
			b[ni]--;
			dumpc(b);
			dumpc(d);
			if (a[ni] == -1) {
				continue;
			}
			if (b[ni] != 0)continue;
			pq.emplace(-d[ni], -d[a[ni]], a[ni], ni);

			//int cd, nd, bd, ni, ci;
			//tie(cd, nd, ni, ci) = pq.top(); pq.pop();
			//cd = -cd;
			//dump(cd)dump(ni + 1)dumpl(ci + 1);
			//if (flag[ci])continue;
			//flag[ci] = true;
			//chmax(d[ni], b[ni] + cd);
			//b[ni]--;
			//dumpc(b);
			//dumpc(d);
			//if (a[ni] == -1) {
			//	chmax(ans, nd);
			//	continue;
			//}
			//pq.emplace(-d[ni], -d[a[ni]], a[ni], ni);
		}
		cout << d[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 6768
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n, x, m = map(int,input().split())
    sum_lis = [-1] * m #余りが最初にiのときの和
    a_lis_i = [-1] * m #余りが最初にiのときのindex
    a = x
    sum_a = a
    sum_lis[a] = sum_a
    a_lis_i[a] = 0
    for i in range(1, n):
        a = pow(a, 2, m)
        sum_a += a
        if sum_lis[a] != -1: #2週目
            loop_i = i - a_lis_i[a] #1循環の個数
            loop_sum = sum_a - sum_lis[a] #1循環の和
            loop_cunt = (n - 1 - i)//loop_i #i+1以降の循環個数
            sum_a += loop_sum*loop_cunt #ループ分まとめて足す
            i += loop_i*loop_cunt
            for j in range(i + 1, n):
                a = pow(a, 2, m)
                sum_a += a             
            print(sum_a)
            sys.exit()
        sum_lis[a] = sum_a
        a_lis_i[a] = i
    print(sum_a)

if __name__=='__main__':
    main()

Measured memory_bytes: 13960
#include "bits/stdc++.h"
using namespace std;
#define INF (1LL<<60)
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl
#define SP << " " << 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#define MSB(x) (63-__builtin_clzll(x))
#define pcnt(x) (__builtin_popcountll(x))
#define parity(i,j) (i&(1LL<<j))
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
int n,m,k,z = 0;
vec a,b;
 
// mid以下がk個以上ある？
bool check(int mid){
  int sum = 0;
  if(mid >= 0){
    sum += z*(z-1)/2 + z*(n+m) + n*m;
    int r = n-1;
    REP(l,n){
      while(r >= 0 && a[l]*a[r] > mid) r--;
      sum += max(0LL,r-l);
    }
    r = m-1;
    REP(l,m){
      while(r >= 0 && b[l]*b[r] > mid) r--;
      sum += max(0LL,r-l);
    }
  }
  else{
    REP(i,n){
      sum += m-(lower_bound(b.begin(),b.end(),(-mid+a[i]-1)/a[i])-b.begin());
    }
  }
  return sum >= k;
}
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
 
  cin >> n >> k;
 
  REP(_,n){
    int x;
    cin >> x;
    if(x>0) a.emplace_back(x);
    else if(x == 0) z++;
    else b.emplace_back(-x);
  }
 
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  n = a.size(); m = b.size();
 
  int ng = -INF, ok = INF;
  while (abs(ng-ok)>1) {
    int mid = ng+(ok-ng)/2;
    (check(mid)?ok:ng) = mid;
  }
 
  cout << ok << endl;
 
  return 0;
}

Measured memory_bytes: 2420
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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;
}
const int MOD = 1000000007;

int main() {
    string S;
    cin>>S;
    int l = S.size();
    int res = 0;
    rep(i, 0, l / 2) {
        if(S[i] != S[l - i - 1]) {
            res++;
        }
    }
    cout << res << endl;
}

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

typedef long long ll;

int main(){
    string s;
    cin>>s;
    ll n=s.size();
    ll k;
    ll ans=0;
    rep(i,n){
        if(s[i]=='>') k++;
        else break;
    }
    ans+=k*(k+1)/2;
    ll l=0,m=0;
    rept(i,k,n){
        if(s[i]=='<'&&m==0){
            l++;
            continue;
        }
        else if(s[i]=='>'){
            m++;
            continue;
        }
       // std::cout<<l<<" "<<m<<endl;
        if(l<m) swap(l,m);
        ans+=l*(l+1)/2+m*(m-1)/2;
        m=0;l=1;
    }
    if(l<m) swap(l,m);
    ans+=l*(l+1)/2+m*(m-1)/2;
    std::cout<<ans<<endl;


    return 0;

}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define ll long long int
#define mx 1007
double arr[mx];

#define pi acos(-1)
using namespace std;


int main()
{
    ll t,item,temp,a,m,x,y,z;
    ll x1,x2,y1,y2;

    vector<ll>v;
    string s1,s2,s3;
    stack<string>ba;
    stack<string>fo;
    vector<ll>v1;
    vector<ll>v2;
    map<ll,ll>mp1;
    map<ll,ll>mp2;



    ll r,g,b;
    ll n;
    char c;
  cin>>n>>a;
  for(int i=0;i<n;i++)
  {
      cin>>item;
      v.push_back(item);
  }
  sort(v.begin(),v.end());
  ll ans=0;
  for(int i=0;i<a;i++)
    ans+=v[i];
  cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 3604
num = (int)(input())
ans = 0
for i in range(1, num + 1):
  #print((num // i) * (i * 2 + ((num // i) - 1) * i) // 2)
  ans += (num // i) * (i * 2 + ((num // i) - 1) * i) // 2
print(ans)

Measured memory_bytes: 9168
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    ss=readline().rstrip()
    j=len(ss)
    ans=0
    if j==1:
        print(0)
        return
    for i in range(len(ss)):
        if ss[i]=="W":
            j-=1
            if j >= 0:
                while ss[j]!="R":
                    j-=1
                    if j < 0:
                        break
            if j > i:
                ans+=1
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 16340
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define lli long long int
#define d double
#define mod 1000000007
#define mx 100001
using namespace std;
int main() {
	FIO;
	int n,k;
	cin>>n>>k;
	vector<int> vec(n);
	unordered_map<int,bool> mp;
	for(int i=0;i<n;i++){
		cin>>vec[i];
		mp[vec[i]]=true;
	}
	sort(vec.begin(),vec.end());
	vector<char> dp(k+1);//dp[i]->winner with exactly i numbers of stones....
	for(int i=0;i<vec[0];i++) dp[i]='S';
	for(int i=0;i<n;i++){
		dp[vec[i]]='F';
		for(int j=vec[i]+1;j<vec[i+1];j++){
			int flag=0;
			for(int k=0;k<=i;k++){
				if(dp[j-vec[k]]=='S'){
					flag=1;
					break;
				}
			}
			if(flag) dp[j]='F';
			else dp[j]='S';
		}
	}
	for(int i=vec[n-1]+1;i<=k;i++){
		int flag=0;
		for(int j=0;j<n;j++){
			if(dp[i-vec[j]]=='S'){
				flag=1;
				break;
			}
		}
		if(flag) dp[i]='F';
		else dp[i]='S';
	}
	if(dp[k]=='F') cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 384
N = int(input()) # 数字を変数に格納

result = 0
list = [[0]*9 for i in range(9)]

for i in range(1,N+1):
    if i < 10:
        list[i-1][i-1] += 1
    else:
        long = len(str(i))
        first = int(i / (10**(long-1)))
        last = i % 10
        if first != 0 and last != 0:
            list[first-1][last-1] += 1
            

for i in range(9):
    for j in range(i,9):
        if i == j:
            tmp = list[i][j]
            result += tmp * tmp
        else:
            result += list[i][j] * list[j][i] * 2

print(result)

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

#define oo ll(1e14)
#define maxn 5003

using namespace std;
typedef long long ll;

int n;

int a[maxn];

ll dp[maxn][maxn][2];
int sz[maxn];

vector < int > g[maxn];

void dfs(int u, int du) {
  if (a[u] >= 0)
    dp[u][1][1] = 1;
  dp[u][1][0] = a[u];
  sz[u] = 1;

  for (auto v : g[u]) {
    if (v == du) continue;

    dfs(v, u);
    sz[u] += sz[v];

    for (int j = sz[u]; j > 0; --j) {
      bool flag = 0;
      ll mi = oo;

      for (int k = max(1, j - sz[u] + sz[v]); k <= j && k <= sz[v]; ++k) {
        flag |= (dp[u][j - k + 1][1] & dp[v][k][1]);
        mi = min(mi, dp[u][j - k + 1][0] + dp[v][k][0]);

        if (dp[v][k][0] < 0 || dp[v][k][1]) {
          mi = min(mi, dp[u][j - k][0]);
          flag |= dp[u][j - k][1];
        }
      }

      dp[u][j][1] = flag;
      dp[u][j][0] = mi;
    }
  }

  return;
}

int main(){
  ios_base::sync_with_stdio(0);

  cin >> n;

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

  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;

    g[u].push_back(v);
    g[v].push_back(u);
  }

  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= n; ++j) {
      dp[i][j][0] = oo;
      dp[i][j][1] = 0;
    }

  dfs(1, 1);

  for (int j = 1; j <= n; ++j)
    if (dp[1][j][0] < 0 || dp[1][j][1]) {
      cout << j - 1;
      break;
    }
  return 0;

}


Measured memory_bytes: 391936
#include<iostream>
#include<cmath>

using namespace std;

int n;
int h[100000];
int mn[100000];
int main() {
    cin >> n;
    int sm = 0;
    for (int i = 0; i < n; ++i) {
        sm += h[i];
        cin >> h[i];
        mn[i] = sm;
    }
    mn[0] = 0;
    mn[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; ++i) {
        mn[i] = min(mn[i - 1] + abs(h[i] - h[i - 1]), mn[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << mn[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N, M;
        cin >> N >> M;
        vector<vector<int>> s(M);
        vector<int> p(M);

        rep(i, 0, M) {
            int k;
            cin >> k;
            rep(j, 0, k) {
                int tmp;
                cin >> tmp;
                tmp--;
                s[i].push_back(tmp);
            }
        }
        rep(i, 0, M) {
            cin >> p[i];
        }

        int ans = 0;
        for (int bit = 0; bit < 1 << N; ++bit) {
            vector<int> A;
            for (int i = 0; i < N; ++i) {
                if (bit >> i & 1) {
                    A.push_back(i);
                }
            }
            int cnt = 0;
            for (int i = 0; i < M; ++i) {
                vector<int> B = s[i];
                sort(all(A));
                sort(all(B));
                int i1 = 0;
                int i2 = 0;
                int c = 0;
                while (i1 < A.size() && i2 < B.size()) {
                    if (A[i1] == B[i2]) {
                        c++;
                        i1++;
                        i2++;
                    } else if (A[i1] < B[i2]) {
                        i1++;
                    } else {
                        i2++;
                    }
                }
                if (c % 2 == p[i]) {
                    cnt++;
                }
            }
            if (cnt == M) {
                ans++;
            }
        }
        cout << ans << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def func(i, k):
    count = 0
    while i < k:
        i *= 2
        count += 1
    return count


def main():
    n, k = Input()
    ans = 0
    for i in range(1, n+1):
        ans += 1/n * (1/2 ** func(i, k))
    print(ans)


main()

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N;
    cin>>N;
    vi P(N), pos(N);
    REP(i, 0, N){
        int p ;
        cin >> p;
        P[i] = p;
        p--;
        pos[p] = i;
    }
    int max = 0, count = 0, max_len = 0;
    REP(i, 0, N + 1){
        if(pos[i] > max && i != N){
            max = pos[i];
            count++;
        }else{
            max = pos[i];
            max_len = std::max(count, max_len);
            count = 1;
        }
    }
    cout << N - max_len << endl;
}

Measured memory_bytes: 1792
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int N;
  cin >> N;
  string a;
  cin >> a;

  int MAX = 0; 
  REP(i,N-1){
    int flag = 0;
    int cnt = 0;
    FOR(k,97,123){
      flag = 0;
      REP(j,i+1){
        if(a.at(j) == k){
          flag = 1;
          break;
        }
      }
      FOR(j,i+1,N){
        if(a.at(j) == k && flag == 1){
          cnt++;
          break;
        }
      }
    }
    MAX = max(MAX,cnt);
  }
  cout << MAX << endl;
}

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

int main(){
  int n;
  cin>>n;
  
  vector<int> li;
  rep(i,1,10){
    rep(j,1,10){li.emplace_back(i*j);}
  }

  rep(i,0,81){
    if(n==li[i]){cout<<"Yes"<<endl;break;}
    if(i==80){cout<<"No"<<endl;break;}
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
    int a;
    cin>>a;
    set<int > s1,c;
    set<int > s2;
    while (a--)
    {
        int t;
        cin>>t;
        s1.insert(t);
    }
    cin>>a;
    while (a--)
    {
        int t;
        cin>>t;
        s2.insert(t);
    }

    set_intersection(s1.cbegin(),s1.end(),s2.begin(),s2.end(),inserter(c,c.begin()));

    auto it=c.begin();
    auto its=c.end();
    for (auto i = it; i !=its ; ++i)
    {
        cout<<*i<<endl;
    }

}


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

using namespace std;
using ll = long long;

ll dfs(string S, int i, ll sum) {
  if (i == 0) {
    return sum + stoll(S);
  }

  ll ret = dfs(S, i - 1, sum);
  ret += dfs(S.substr(S.length() - i), i - 1, stoll(S.substr(0, S.length() - i)) + sum);
  return ret;
}

int main() {
  string S;
  cin >> S;
  cout << dfs(S, S.length() - 1, 0) << endl;

  return 0;
}


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

typedef long long LL;

int main()
{
    ios::sync_with_stdio(false);
    LL N;
    /***
    4/N = 1/h+1/n+1/w
    4/N = (nw+hw+hn)/hnw
    4*hnw = N*(nw+hw+hn)
    4*hnw = N*nw + N*hw + N*nh
    4*hnw-N*nw-N*hw = N*nh
    w(4*hn-N*n-N*h) = N*nh
    **/
    cin >> N;
    for(LL h = 1; h <= 3500; ++h)
    {
        for(LL n = 1; n <= 3500; ++n)
        {
            LL temp = 4*h*n-N*n-N*h;
            if(temp > 0 && N*n*h%temp == 0)
            {
                cout << h << " " << n << " " << N*n*h/temp << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

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

const ll INF = (1LL<<60);

int main(){

    string s; cin >> s;

    cout << (s=="ABC" ? "ARC" : "ABC") << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 100050;
int N, K;
long long a[MAX_N];

long long ac[MAX_N], seg[MAX_N];
long long ideal_until[MAX_N], ideal_from[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N >> K;

    for (int i = 1; i <= N; i++) {
        std::cin >> a[i];
    }

    ac[0] = 0;
    ideal_until[0] = 0;

    for (int i = 1; i <= N; i++) {
        ac[i] = ac[i-1] + a[i];
        ideal_until[i] = ideal_until[i-1] + std::max(a[i], (long long)0);
    }

    for (int i = 1; i <= N - K + 1; i++) {
        seg[i] = ac[i + K - 1] - ac[i - 1];
    }

    ideal_from[N+1] = 0;
    for (int i = N; 1 <= i; i--) {
        ideal_from[i] = ideal_from[i+1] + std::max(a[i], (long long)0);
    }

    long long ret = 0;

    for (int i = 1; i <= N - K + 1; i++) {
        ret = std::max(ret, std::max(seg[i], (long long)0) + ideal_until[i-1] + ideal_from[i + K]);
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll a, b, c, d, e;
    cin>>a>>b>>c>>d>>e;
    if(a == 0){
        cout<<1<<endl;
    }else if(b == 0){
        cout<<2<<endl;
    }else if(c == 0){
        cout<<3<<endl;
    }else if(d == 0){
        cout<<4<<endl;
    }else{
        cout<<5<<endl;
    }
}

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

using namespace std;

int main()
{
	int n;
	vector<long long int> a;
	vector<long long int> b;

	cin >> n;

	long long int wk;

	for (int i = 0; i < n + 1; i++) {
		cin >> wk;
		a.push_back(wk);
	}


	for (int i = 0; i < n; i++) {
		cin >> wk;
		b.push_back(wk);
	}


	long long int score = 0;

	for (int i = 0; i < n; i++) {
		wk = b[i];

		if (a[i] >= b[i]) {
			a[i] -= wk;
			score += wk;
		}
		else {
			wk -= a[i];

			score += a[i];
			a[i] = 0;

			if (a[i + 1] >= wk) {
				a[i + 1] -= wk;
				score += wk;
			}
			else {


				score += a[i + 1];
				a[i + 1] = 0;

			}



		}





	}
	
	cout << score << endl;







}


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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define m_p make_pair

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n,m,ans=1;
  cin >> n >> m;
  if(abs(n-m)>=2) ans = 0;
  else if(abs(n-m)<=1){
    REP(i,1,n+1){
      ans *= i;
      ans %= MOD;
    }
    REP(i,1,m+1){
      ans *= i;
      ans %= MOD;
    }
    if(abs(n-m)==0){
      ans *= 2;
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}

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

vector<vector<ll>> matrix_prod(vector<vector<ll>>& a, vector<vector<ll>>& b, ll mod) {
    int n = a.size();
    vector<vector<ll>> res(n, vector<ll>(n));
    for ( int i = 0; i < n; i++ ) {
        for ( int j = 0; j < n; j++ ) {
            for ( int k = 0; k < n; k++ ) {
                res[i][j] += a[i][k] * b[k][j];
                res[i][j] %= mod;
            }
        }
    }
    return res;
}

vector<vector<ll>> matrix_pow(vector<vector<ll>>& m, ll d, ll mod) {
    int n = m.size();
    vector<vector<ll>> res(n, vector<ll>(n));
    vector<vector<ll>> tmp(m);
    for ( int i = 0; i < n; i++ ) res[i][i] = 1;
    while ( d ) {
        if ( d % 2 == 1 ) {
            res = matrix_prod( res, tmp, mod );
        }
        tmp = matrix_prod( tmp, tmp, mod );
        d /= 2;
    }
    return res;
}

vector<ll> matrix_vec_prod(vector<vector<ll>>& a, vector<ll>& vec, ll mod) {
    int n = vec.size();
    vector<ll> res(n);
    for ( int i = 0; i < n; i++ ) {
        for ( int j = 0; j < n; j++ ) {
            res[i] += a[i][j] * vec[j];
            res[i] %= mod;
        }
    }
    return res;
}

int main() {
    ll L, A, B, M;
    cin >> L >> A >> B >> M;
    
    ll DMAX = 20;
    // d桁以下のsの件数
    vector<ll> cnt(DMAX);
    ll p10 = 1;
    for ( int i = 1; i < DMAX; i++ ) {
        p10 *= 10;
        if ( p10 <= A ) continue;
        cnt[i] = min( (p10 - A + B - 1) / B, L);
    }

    vector<ll> v{0, A % M, B % M};
    int n = 3;
    vector<vector<ll>> tmp(n, vector<ll>(n));
    for ( int i = 0; i < n; i++ ) tmp[i][i] = 1;
    p10 = 1;
    for ( int i = 1; i < DMAX; i++ ) {
        p10 *= 10;
        p10 %= M;
        ll cd = cnt[i] - cnt[i-1];
        if ( cd == 0 ) continue;
        vector<vector<ll>> T{
            {p10, 1, 0},
            {0, 1, 1},
            {0, 0 ,1}
        };
        auto Td = matrix_pow(T, cd, M);
        tmp = matrix_prod(Td, tmp, M);
    }
    auto r = matrix_vec_prod(tmp, v, M);

    ll ans = r[0];
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>
using namespace std;
int sx, sy, tx, ty;
int main()
{
    int n;
    int a[110000] = {};
    int tmp;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        a[tmp]++;
    }
    if (n % 2 == 0)
    {
        for (int i = 1; i < n; i += 2)
            if (a[i] != 2)
            {
                cout << 0 << endl;
                return 0;
            }
    }
    else
    {
        if (a[0] != 1)
        {
            cout << 0 << endl;
            return 0;
        }
        else
            for (int i = 2; i < n; i += 2)
                if (a[i] != 2)
                {
                    cout << 0 << endl;
                    return 0;
                }
    }
    long long an = 1;
    for (int i = 0; i < n / 2; i++)
    {
        an *= 2;
        an %= (long long)1e9 + 7;
    }
    cout << an << endl;
}

Measured memory_bytes: 640
#include"iostream"
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<list>
#include<map>
#include<string>
#include<algorithm> 
#include <queue> 
#include <sstream>
#include <fstream>
#include<cmath>
#define INF 100000000000
#define LL long long
using namespace std;
map<LL, LL> m;
long long N, M, K,Q, ans, A[100001], B[100001], ss[100001],a[100000], b[100000];

string s;

LL gcd(LL x, LL y) {
	if (x < y) {
		LL c = x;
		x = y;
		y = c;
	}
	if (y == 0)return x;
	if (x%y == 0) {
		return y;
	}
	else {
		return gcd(y, x%y);
	}
}
int main() {
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			if (s[i] == '0')N++;
			else M++;
		}
		else {
			if (s[i] == '1')N++;
			else M++;
		}
	}

	cout << min(s.size()-N, s.size() - M) << endl;
	
	
	return 0;
}

Measured memory_bytes: 512
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
#include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)   (x).begin(),(x).end()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define mp       make_pair
#define eb       emplace_back
typedef pair<LL, LL> P;
typedef pair<P, P> PP;

int a, b, c, d, e, f;

bool calc(int i, int j) {
	bool isok = false;
	for (int l = 0; l * a <= j; l++) {
		if ((j - l * a) % b == 0) {
			isok = true;
			break;
		}
	}
	if (!isok) {
		return false;
	}
	isok = false;
	for (int l = 0; l * c <= i; l++) {
		if ((i - l * c) % d == 0) {
			isok = true;
			break;
		}
	}
	return isok;
}

int main() {
	cin >> a >> b >> c >> d >> e >> f;
	double cc = -1;
	int cci = -1, ccj = -1;
	for (int j = a; j <= f / 100; j++) {
		for (int i = 0; i <= e * j; i++)
			if (calc(i, j) && i + j * 100 <= f) {
				if (cc < 1.0 * i / j)
					cc = 1.0 * i / j, cci = i, ccj = j;
			}
	}
	cout << (cci + ccj * 100) << " " << cci << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int cnt=0;
    for(int i=0;i<=N/R;i++){
        for(int j=0;j<=N/G;j++){
            int num = N - i*R - j*G;
            if(num<0){
                break;
            }
            else{
                if(num%B==0){
                    cnt++;
                }
            }
        }
    }
    cout << cnt<< endl;
}

Measured memory_bytes: 3636
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define inf 2147483647
#define eps 1e-9
using namespace std;
typedef long long ll;
const double PI=acos(-1);
struct node{
	int x,y;
	friend bool operator <(node a,node b){
		return a.x==b.x?a.y<b.y:a.x<b.x;
	}
}p[200001];
int n,sx,sy,tx,ty,_x,_y,top=0,tot=0,s[200001];
double ans;
bool ok1=false,ok2=false;
int main(){
	scanf("%d%d%d%d%d",&sx,&sy,&tx,&ty,&n);
	if(sx>tx){
		sx=-sx;
		tx=-tx;
		ok1=true;
	}
	if(sy>ty){
		sy=-sy;
		ty=-ty;
		ok2=true;
	}
	for(int i=1;i<=n;i++){
		scanf("%d%d",&_x,&_y);
		_x*=ok1?-1:1;
		_y*=ok2?-1:1;
		if(_x>=sx&&_x<=tx&&_y>=sy&&_y<=ty){
			p[++top].x=_x;
			p[top].y=_y;
		}
	}
	sort(p+1,p+top+1);
	for(int i=1;i<=top;i++){
		if(!tot||p[i].y>s[tot]){
			s[++tot]=p[i].y;
		}else{
			int nw=lower_bound(s+1,s+tot+1,p[i].y)-s;
			s[nw]=p[i].y;
		}
	}
	ans=(double)(tx-sx+ty-sy)*100.0-(double)tot*(20.0-PI*5.0)+((tot==min(tx-sx+1,ty-sy+1))?PI*5.0:0);
	printf("%.11lf",ans);
	return 0;
}

Measured memory_bytes: 2560
# coding: utf-8
# Your code here!
n,W = [int(i) for i in input().split()]
wv = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行
V=10**5
MAX=10**12
dp = [MAX]*(V+1)
dp[0]=0
newdp = [MAX]*(V+1)
for i in range(n):
    w, v = wv[i]
    newdp = dp[:]
    for j in range(V+1):
        if j+v <= V:
            newdp[j+v] = min(dp[j] + w, newdp[j+v])
    newdp, dp = dp, newdp
#    print(dp)

print(max([i for i,c in enumerate(dp) if c <= W]))


#print(dp)



Measured memory_bytes: 68172
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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 (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N,K,Q;
int A[100010];
int main()
{
   cout << fixed << setprecision(10);
   cin >> N >> K >> Q;
   int a;
   REP(i, Q) {
      cin >> a;
      A[a]++;
   }
   REP(i, N) {
      if (K - (Q - A[i + 1]) <= 0) cout << "No" << endl;
      else cout << "Yes" << endl;
   }
   return 0;
}



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

typedef long long int ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define sz(a) (int)(a).size()
const int lt=100005;
ll mod=1000000007;

void printv(vector <ll> a){
	for(int i=0;i<a.size();i++)
		cout << a[i] << " ";
	cout << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,x,t;
	cin >> n >> x >> t;
	if(n%x==0)
		cout << (n/x)*t << endl;
	else
		cout << ((n/x)+1)*t << endl;
	return 0;
}

Measured memory_bytes: 3640
import math


def main():
    K = int(input())

    N = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

    print(N[K-1])
    return 0


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
from fractions import gcd
def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    x, y = map(int ,input().split())
    ans = abs(abs(x) - abs(y))
    if x >= 0:
        if y > x:
            pass
        elif 0 < y < x:
            ans += 2
        else:
            ans += 1
    else:
        if y < x:
            ans += 2
        elif x < y <= 0:
            pass
        else:
            ans += 1
    print(ans)
main()

Measured memory_bytes: 5076
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
typedef long long lint;
const int N=1005;
int n,val[N];
bool use[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	std::vector <int> step;
	n=nxi();
	{
		lint v[2]={0};
		bool all_neg=1;
		int xpos=1;
		for(int i=1; i<=n; ++i){
			val[i]=nxi();
			if(val[i]>0) v[i&1]+=val[i];
			all_neg&=val[i]<0;
			if(val[xpos]<val[i]) xpos=i;
		}
		bool p=v[1]>v[0];
		printf("%lld\n",all_neg?(lint)val[xpos]:v[p]);
		for(int i=1; i<=n; ++i){
			use[i]=(i&1)==p&&val[i]>=0;
		}
		if(all_neg) use[xpos]=1;
	}
	while(n>1){
		int x=n;
		for(; x&&(use[x]||(x!=1&&x!=n&&use[x-1]!=use[x+1])); --x);
		assert(x);
		step.push_back(x);
		if(x==1||x==n){
			n-=1;
			for(int i=x; i<=n; ++i) use[i]=use[i+1];
		}
		else{
			n-=2;
			for(int i=x; i<=n; ++i) use[i]=use[i+2];
		}
	}
	printf("%d\n",(int)step.size());
	for(std::vector <int> ::iterator it=step.begin(); it!=step.end(); ++it){
		printf("%d\n",*it);
	}
	return 0;
}


Measured memory_bytes: 256
/*
 * omg.cpp
 *
 *  Created on: 2019/06/03
 *      Author: J01003
 */
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a>12){
		cout<<b<<endl;
	}else if(a>5){
		cout<<b/2<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << ""; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	string s;
	vector<ll> v;

	cin >> s;

	REP(i, s.size()) {
		if (s[i] == '0') {
			v.push_back(0);
		}
		else if (s[i] == '1') {
			v.push_back(1);
		}
		else if (s[i] == 'B' && v.empty() == false) {
			v.pop_back();
		}
	}
	
	cout << v << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <sstream>
using namespace std;
#define rep(i,n) for (int i=0; i<n; i++)
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    vector<int> c(n-1);
    rep(i,n-1) cin >> c[i];
    rep(i,n) a[i]--;
    int ans = 0;
    rep(i,n){
        ans += b[a[i]];

    }

    rep(i,n-1){
        if (a[i]+1 == a[i+1]){
            ans += c[a[i]];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

char s[3][10];

int main(void) {
	// your code goes here
	scanf("%s %s %s",s[0],s[1],s[2]);
	
	int tmp = 'A'-'a';
	printf("%c%c%c",s[0][0]+tmp,s[1][0]+tmp,s[2][0]+tmp);
	return 0;
}


Measured memory_bytes: 128
S = input()

mae = int(S[0]+S[1])
ato = int(S[2]+S[3])

if 0 < mae and mae < 13 and 0 < ato and ato < 13:
    print('AMBIGUOUS')
elif mae == 0 or mae > 12:
    if 0 < ato and ato < 13:
        print('YYMM')
    else:
        print('NA')
elif ato == 0 or ato > 12:
    if 0 < mae and mae < 13:
        print('MMYY')
    else:
        print('NA')

Measured memory_bytes: 3064
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
N, M= map(int,input().split())
UF=UnionFind(N)
for i in range(M):
  A, B=map(int,input().split())
  A=A-1
  B=B-1
  UF.union(A,B)
print(UF.group_count()-1)

Measured memory_bytes: 78664
fun main(args: Array<String>) {
    val s = readLine()!!
    val k = readLine()!!.toInt()
    val n = s.length

    fun combination(a: Int, b: Int): Long {
        if (a < b) return 0
        var r = 1L
        for (i in 0 until b) {
            r *= (a - i)
        }
        for (i in 1..b) {
            r /= i
        }
        return r
    }

    fun pow9(p: Int): Long {
        var r = 1L
        repeat(p) { r *= 9 }
        return r
    }

    var ans = 0L
    fun dfs(i: Int, r : Int) {
        if (r == 0) {
            ans++
            return
        }
        if (i >= n) return

        val d = s[i] - '0'
        for (x in 0..d) {
            if (x == d) {
                if (d > 0) dfs(i + 1, r - 1)
                else dfs(i + 1, r)
            } else {
                if (x > 0) {
                    ans += combination(n - i - 1, r - 1) * pow9(r - 1)
                } else {
                    ans += combination(n - i - 1, r) * pow9(r)
                }
            }
        }
    }
    dfs(0, k)
    println(ans)
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

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

const long long INF = 1LL << 60;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int s; cin>>s;
  
  if (s>=30) {
    cout<<"Yes";
  } else {
    cout<<"No";
  }
  
  return 0;
}

Measured memory_bytes: 3636
def main():

    N,M=map(int,input().split())
    #undivList=[map(int,(input().split())) for _ in range(N)]
    undivList=[]
    for _ in range(M):
        l=map(int,input().split())
        undivList +=l
    atmax=max(undivList[0::2])
    atmin=min(undivList[1::2])
    
    if atmax>atmin:
        print(0)
    else:
        print(abs(atmax-atmin)+1)



if __name__== "__main__":
    main() 

Measured memory_bytes: 11800