akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
struct info {int a[MAXN]; };
int n; ll m;
info inv(info a) {
	info res;
	for (int i = 1; i <= n; i++)
		res.a[a.a[i]] = i;
	return res;
}
info unit() {
	info res;
	for (int i = 1; i <= n; i++)
		res.a[i] = i;
	return res;
}
info operator * (info a, info b) {
	info res;
	for (int i = 1; i <= n; i++)
		res.a[i] = b.a[a.a[i]];
	return res;
}
info p, q, r;
info power(info a, ll x) {
	if (x == 0) return unit();
	if (x < 0) return power(inv(a), -x);
	info tmp = power(a, x / 2);
	if (x % 2 == 0) return tmp * tmp;
	else return tmp * tmp * a;
}
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++)
		read(p.a[i]);
	for (int i = 1; i <= n; i++)
		read(q.a[i]);
	while (m % 6 != 1) {
		info r = inv(p) * q;
		p = q, q = r, m--;
	}
	r = power(inv(q) * p * q * inv(p), m / 6) * power(p, m / 6 + 1);
	info res = r * p * inv(r);
	for (int i = 1; i <= n; i++)
		printf("%d ", res.a[i]);
	return 0;
}

Measured memory_bytes: 103168
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

bool check(vi a){
    int is[] = {19, 7, 8, 18};
    int at[] = {19, 7, 0, 19};
    rep(i,a.size()-3){
        bool c = true;
        rep(j,4)if(a[i+j] != is[j])c = false;
        if(c) return true;
    }
    rep(i,a.size()-3){
        bool c = true;
        rep(j,4)if(a[i+j] != at[j])c = false;
        if(c) return true;
    }
    return false;
}

signed main(void) {
    int num;
    cin >> num;
    string s;
    getline(cin,s);
    while(num--){
        getline(cin,s);
        int n = s.size();
        vi v(n,INF);
        rep(i,n)if(s[i] != ' '){
            v[i] = s[i] - 'a';
        }
        rep(a,26)if(gcd(a,26) == 1)rep(b,26){
            vi t = v;
            rep(i,n)if(t[i] < INF){
                t[i] = (a*t[i]+b) % 26;
            }
            if(check(t)){
                string ans = "";
                rep(i,n){
                    if(t[i] == INF)ans += " ";
                    else ans += t[i]+'a';
                }
                cout << ans << endl;
                a = b = INF;
            }
        }
    }
}



Measured memory_bytes: 3112
#include<iostream>
#include<cstring>
#include<map>
#define N 200005
typedef long long ll;
using namespace std;
ll a[N],sum[N],n,K,res=0,mini;
map<ll,ll> s;
int main(){
	memset(a,0,sizeof(a));
	memset(sum,0,sizeof(sum));
	s.clear();
	scanf("%lld%lld",&n,&K);
	for (int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		//a[i]%=K;
		//sum[i]=(sum[i-1]+a[i])%K;
		sum[i]=sum[i-1]+a[i];
	}
	for (int i=1;i<=n;i++)
		sum[i]=(sum[i]+K-i%K)%K;
	mini=min(n,K-1);
	/*
	map<int,int>::iterator iter;
	for (iter=s.begin();iter!=s.end();iter++)
		res+=(iter->second)*((iter->second)-1)/2;
	cout<<res<<endl;
    */
	for (int i=0;i<=mini;i++){
        res+=s[sum[i]];
        s[sum[i]]++;
    }
    for (int i=mini+1;i<=n;i++){
        s[sum[i-K]]--;
        res+=s[sum[i]];
        s[sum[i]]++;
    }
	printf("%lld",res);
	return 0;
} 

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int INF = (int)100100100;

int main() {
  int N;
  cin >> N;
  int sum=0;
  int a[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
    sum+=a[i];
  }
  int mi=1000000;
  int ans=0;
  for(int i=0;i<N;i++){
    if(abs(N*a[i]-sum)<mi){
      mi=abs(N*a[i]-sum);
      ans=i;
    }
  }
  cout << ans;
}

/*



 */



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long a, b, c, k;
    cin>> a>> b>> c>> k;
    if(k%2 == 0) {
        cout<<a - b<<endl;
    }
    else {
        cout<<b - a<<endl;
    }
    return 0;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ConfigData = Console.ReadLine().Trim().Split(' ');

            int HowManyWays = int.Parse(ConfigData[0]);
            int LimitTime = int.Parse(ConfigData[1]);

            Way[] way = new Way[HowManyWays];

            for(int i = 0; i < HowManyWays; i++)
            {
                string[] data = Console.ReadLine().Trim().Split(' ');

                int cost = int.Parse(data[0]);
                int time = int.Parse(data[1]);

                way[i] = new Way(cost, time);
            }

            var searchMostShortTime = way.Where(item => item.time <= LimitTime);

            if(searchMostShortTime.Count() != 0)
            {
                var searchMostCheepCost = searchMostShortTime.OrderBy(x => x.cost).FirstOrDefault();
                //var result = searchMostCheepCost.id;
                Console.WriteLine(searchMostCheepCost.cost);
            }
            else
            {
                Console.WriteLine("TLE");
            }
        }   
    }

    class Way
    {
        //public int id;
        public int cost;
        public int time;

        public Way(int cost, int time)
        {
            //this.id = id;
            this.cost = cost;
            this.time = time;
        }
    }
}

Measured memory_bytes: 11476
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String[] s = S.split("/");
		int y = Integer.parseInt(s[0]);
		int m = 0;
		if(s[1].charAt(0) == '0') {
			m = Integer.parseInt(s[1].substring(1, 2));
		}else {
			m = Integer.parseInt(s[1]);
		}
		int d = 0;
		if(s[2].charAt(0) == '0') {
			d = Integer.parseInt(s[2].substring(1, 2));
		}else {
			d = Integer.parseInt(s[2]);
		}
		if(m <= 4) {
			System.out.println("Heisei");
		}else {
			System.out.println("TBD");
		}
	}
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a[100010];
int dp[100010];

int main(){
	cin >> n;
	REP(i,0,n) cin >> a[i]; REP(i,0,n) dp[i]=INF;
	REP(i,0,n) *lower_bound(dp,dp+n,a[i])=a[i];
	cout << lower_bound(dp,dp+n,INF)-dp << endl;
	return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var NX = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var N = NX[0];
            var X = NX[1];
            var L = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            int[] D = new int[N+1];
            int count = 1;
            D[0] = 0;

            for (int i = 1; i < N+1; i++)
            {
                D[i] = D[i - 1] + L[i-1];

                if (D[i] <= X)
                {
                    count++;
                }
            }

            Console.WriteLine(count);





        }
    }
}


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

using namespace std;

int n, m;
vector<int> g[222222];

int dist[222222];

typedef pair<int, int> ii; // dist, who

const int MAX = 0x3f3f3f3f;
void dijkstra()
{
    fill(dist, dist + 222222, MAX);

    priority_queue<ii, vector<ii>, greater<ii>> pq;
    dist[1] = 0;
    pq.push(ii(0, 1));

    while (pq.empty() == false) {
        ii cur = pq.top();
        pq.pop();

        int u = cur.second;
        int d = cur.first;

        if (d > dist[u])
            continue;

        for (auto v : g[u]) {
            if (dist[v] > d + 1) {
                dist[v] = d + 1;
                pq.push(ii(dist[v], v));
            }
        }
    }

    // for (int i = 0; i <= n; i++)
    //     printf("%d%c", dist[i], i == n ? '\n' : ' ');
}

int main()
{
    scanf("%d %d", &n, &m);

    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);

        g[a].push_back(b);
        g[b].push_back(a);
    }

    dijkstra();

    printf("%s\n", dist[n] == 2 ? "POSSIBLE" : "IMPOSSIBLE");

    return 0;
}

Measured memory_bytes: 14448
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    """
    末尾だけが重要，dp[i][j]でi枚目まで見て末尾がj，O(NK)
    Nが小さければ問題ない，jの部分は(N/j)の切り捨てでまとめられる．
    前半部分は1~sqrt(N)で，各組1こずつ．後半はN/i (i<=sqrt(N))
    
    """
    N,K=MI()
    M=int(N**0.5)
    cnt=[]
    
    i=1
    while i<=N:
        if i<=M:
            cnt.append(1)
            i+=1
        else:
            temp=int(N/i)
            cnt.append(int(N/temp-i+1))
            i=int(N/temp +1)
            
    N2=len(cnt)
            

    
    dp=[[0]*N2 for _ in range(K)]
    #dp[i][j]はi個見て，最後尾がグループL[j]に属す場合の数
    #j番目のグループはMーj番目までのグループと組める
    
    for j in range(N2):
        dp[0][j]=cnt[j]
        
    for i in range(K-1):
        S=[0]*(N2+1)
        for j in range(N2):
            S[j+1]=(S[j]+dp[i][j])%mod
        
        for j in range(N2):
            dp[i+1][j]=(S[N2-j]*cnt[j])%mod
            
    ans=0
    for j in range(N2):
        ans=(ans+dp[-1][j])%mod
        
    print(ans)


    
    

main()


Measured memory_bytes: 173156
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
//priority_queue< int,vector<int>,greater<int> >
struct edge { int to; llint a, b; };

int main() {
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--;
	t--;
	whei(edge) G(n);
	rep(i, 0, m) {
		int u, v;
		llint a, b;
		cin >> v >> u >> a >> b;
		v--;
		u--;
		G[v].push_back(edge{ u,a,b});
		G[u].push_back(edge{ v,a,b});
	}
	hei(llint) dA(n, INF);
	dA[s] = 0;
	priority_queue<Pint, vector<Pint>, greater<Pint>> que; //総cost,頂点
	que.push(Pint(0,s));
	while (!que.empty()) {
		Pint p = que.top(); que.pop();
		llint cost = p.first;
		int v = p.second;
		for (edge x : G[v]) {
			if (dA[x.to] > cost + x.a) {
				dA[x.to] = cost + x.a;
				que.push(Pint(dA[x.to], x.to));
			}
		}
	}
	hei(llint) dB(n, INF);
	dB[t] = 0;
	que.push(Pint(0, t));
	while (!que.empty()) {
		Pint p = que.top(); que.pop();
		llint cost = p.first;
		int v = p.second;
		for (auto x : G[v]) {
			if (dB[x.to] > cost + x.b) {
				dB[x.to] = cost + x.b;
				que.push(Pint(dB[x.to], x.to));
			}
		}
	}
	hei(Pint) sum(n);
	rep(i, 0, n) {
		sum[i].first = dA[i] + dB[i];
		sum[i].second = i;
	}
	sort(sum.begin(), sum.end());
	hei(llint)ans(n, -1);
	rep(i, 0, n) {
		for (int j = sum[i].second; j >= 0; j--) {
			if (ans[j] != -1)break;
			ans[j] = sum[i].first;
		}
	}
	rep(i, 0, n) {
		ans[i] = 1000000000000000 - ans[i];
		cout << ans[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 16280
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let mut n: usize = itr.next().unwrap().parse().unwrap();
    // 3桁では
    // 1 ~ 26
    let mut ans = Vec::new();
    while n > 0 {
        n -= 1;
        ans.push(n % 26);
        n /= 26;
    }
    ans.reverse();
    let mut out = Vec::new();
    for i in 0..ans.len() {
        write!(out, "{}", (ans[i] as u8 + 97) as char).ok();
    }
    writeln!(out, "").ok();
    stdout().write_all(&out).unwrap();
}


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

using namespace std;

using ll = long long;

int main(){
    ll n, k;
    cin >> n >> k;
    ll arr[n];
    for(ll i = 0; i < n; ++i){
        cin >> arr[i];
    }
    sort(arr, arr + n);
    ll ans = INT_MAX;
    for(ll i = 0; i <= n - k; ++i){
        ans = min(abs(arr[i] - arr[i + k - 1]), ans);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
import sys
input=sys.stdin.readline
from collections import defaultdict
from heapq import heappush,heappop
from itertools import accumulate
N,m,s,t=map(int,input().split())
en=defaultdict(set)
sneek=defaultdict(set)
for i in range(m):
    u,v,a,b=map(int,input().split())
    en[u]|={(a,v)}
    en[v]|={(a,u)}
    sneek[u]|={(b,v)}
    sneek[v]|={(b,u)}
inf=float('inf')
def makedist(first,branch):
    dist=[inf]*(N+1)
    dist[first]=0
    check=[(0,first)]
    while len(check)>0:
        d,now=heappop(check)
        if dist[now]<d:
            continue
        for lenth,nex in branch[now]:
            if d+lenth<dist[nex]:
                dist[nex]=d+lenth
                heappush(check,(d+lenth,nex))
    return dist
disten=makedist(s,en)
distsneek=makedist(t,sneek)
ans=list(accumulate([y+s for y,s in zip(disten,distsneek)][::-1],min))
big=10**15
for i in range(N-1,-1,-1):
    print(big-ans[i])
#https://atcoder.jp/contests/soundhound2018-summer-qual/submissions/4993088

Measured memory_bytes: 115616
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;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 dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_D&lang=jp

int n;
int A[1000005];
int cnt;
vector<int> G;

static void insertion(int g) {
    for (int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;
        while( j>=0 && A[j] > v) {
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}

static void shellsort() {
    int h = 1;
    while(true) {
        if (h>n) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    for (int i = G.size()-1; i >= 0; i--) {
        insertion(G[i]);
    }
}

int main() {
    cin >> n;
    REP(i, n) cin >> A[i];
    shellsort();
    cout << G.size() << "\n";
    reverse(G.begin(), G.end());
    arrdump((int)G.size(), G.data());
    cout << cnt << "\n";
    REP(i, n) cout << A[i] << "\n";
    return 0;
}



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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  int max = -K;

  int ans=-K;
  if(A>=K){
    ans = K;
  }else if(B>=(K-A)){
    ans = A;
  } else {
    ans = A-(K-A-B);
  }

  cout << ans << endl;

  // for(int x=0;x<=A;x++){
  //   for(int y=0;y<=B;y++){
  //     int z = K-x-y;
  //     if(z<0 || z > C) continue;
  //     int sum = x-z;
  //     if(sum > max){
  //       max = sum;
  //     }
  //   }
  // }
  // cout << max << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  ll ans = 0;
  rrep(i, n) {
    if((i == 0 && A[i] != 0) || (i && A[i]-1 > A[i-1])) {
      cout << -1 << endk;
      return 0;
    }
    if(i && A[i]-1 == A[i-1]) ans++;
    else ans += A[i];
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 4752
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    
    su_set = set()
    for _ in range(K):
        d = int(rl())
        ai = list(map(int, rl().split()))
        for aij in ai:
            su_set.add(aij)
    
    print(N - len(su_set))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9204
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int d = sc.nextInt();
        int dist = 2 * d + 1;
        int ans = (n + dist - 1) / dist;
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21076
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE UndecidableInstances #-}

module Main where

import Control.Category hiding (id, (.))
import Control.Exception (assert)
import Control.Monad
import Control.Monad.ST
import Control.Monad.State.Strict
import qualified Data.ByteString.Char8 as BS
import Data.List as List
import Data.Maybe
import Data.Set as Set
import qualified Data.Vector.Unboxing as U
import qualified Data.Vector.Unboxing.Mutable as UM
import Debug.Trace
import GHC.Generics

readInt = fst . fromJust . BS.readInt

readIntList = Prelude.map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

range begin end = [begin .. (end - 1)]

partitionIdx vec pred =
  assert (U.length vec >= 0) $
    if pred (vec U.! 0) == False
      then 0
      else loop 0 (U.length vec)
  where
    loop begin end =
      if end == begin + 1
        then end
        else
          let !mid = (begin + end) `div` 2
           in if pred (vec U.! mid) then loop mid end else loop begin mid

-- data Point = Pt {-# UNPACK #-} Int {-# UNPACK #-} Int
--   deriving (Generic)
--   deriving (U.Unboxable) via U.Generics Point

-- ptX :: Point -> Int
-- ptX (Pt x y) = x

-- ptY :: Point -> Int
-- ptY (Pt x y) = y

main :: IO ()
main = do
  [n, a, b] <- getIntList
  xs <- fmap U.fromList getIntList
  let ans = runST $ do
        dp <- UM.replicate n (0 :: Int)
        forM_ (range 1 n) $ \i -> do
          prev <- UM.read dp (i - 1)
          let add = min walk tel
                where
                  dist = xs U.! i - xs U.! (i -1)
                  walk = dist * a
                  tel = b
          UM.write dp i (prev + add)
        U.freeze dp
  print $ ans U.! (n - 1)

Measured memory_bytes: 10124
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>

#define rep(i,n,m) for(int i=n;i<(int)(m);i++)

using namespace std;

int main() {
	long long a, b, c,mmax,d;
	cin >> a >> b >> c;
	mmax = max(a, max(b, c));
	d = a + b + c - mmax;
	if (mmax - d == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input=input.split("\n");
  const A=['Sunny','Cloudy','Rainy','Sunny'];
  for(var i=0;i<3;i++){
    if(A[i]===input[0]){
      console.log(A[i+1]);
      return;
    }
  }
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


Measured memory_bytes: 29600
(function() {
  var isInRange, isNum, reader;

  isNum = function(n) {
    return n.match(/(-|)\d{1,3}/);
  };

  isInRange = function(start, end) {
    return function(n) {
      return n >= start && n <= end;
    };
  };

  reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
  });

  reader.on('line', function(line) {
    var H, W, r, sp, whr, x, xy, y;
    sp = line.split(/\s/);
    W = isNum(sp[0]) ? parseInt(sp[0], 10) : void 0;
    H = isNum(sp[1]) ? parseInt(sp[1], 10) : void 0;
    x = isNum(sp[2]) ? parseInt(sp[2], 10) : void 0;
    y = isNum(sp[2]) ? parseInt(sp[3], 10) : void 0;
    r = isNum(sp[2]) ? parseInt(sp[4], 10) : void 0;
    whr = isInRange(0, 100);
    xy = isInRange(-100, 100);
    if (whr(W) && whr(H) && whr(r) && xy(x) && xy(y)) {
      if (x + r > W || x - r < 0 || y + r > H || y - r < 0) {
        return console.log("No");
      } else {
        return console.log("Yes");
      }
    }
  });

}).call(this);

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

// 入力
int n, W;
int weight[110], value[110];

// DPテーブル
int dp[110][10010] = {0};

int main() {
    cin >> n >> W;
    for (int i = 0; i < n; ++i) cin >> value[i] >> weight[i];


    // DPループ
    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= W; ++w) {
        if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
        else dp[i+1][w] = dp[i][w];
        }
    }

    cout << dp[n][W] << endl;
}


Measured memory_bytes: 7020
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
const ll INF = 10e9;
ll MOD=1000000007;

int main(){
  int n; cin>>n;
  vector<int>A(n), B(n);
  rep(i,n) cin>>A[i]>>B[i];
  int ma = -1;
  int num = -1;
  rep (i,n){
    if (ma<A[i]){
      ma = A[i];
      num = i;
    }
  }
  cout << A[num]+B[num] << endl;
}

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

using namespace std;

const unsigned long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

int cnt[15];
vector<int> times = {0};

int helper(int hour){

    if(hour == 13){

        int low = 30;

        //cout << "__________________________\n";

        for(int i = 0; i < times.size(); ++i){
            //cout << times[i] << " ";
            for(int j = i + 1; j < times.size(); ++j){
                int d = abs(times[i] - times[j]);
                low = min(low, min(d, 24 - d));
            }
        }

        //cout << endl << low << endl;

        return low;

    }

    if(cnt[hour] == 0) return helper(hour + 1);


    for(int i = 0; i < cnt[hour]; ++i)
        times.push_back(i % 2 == 0 ? 24 - hour : hour);

    int best = helper(hour + 1);

    for(int i = 0; i < cnt[hour]; ++i)
        times.pop_back();
    for(int i = 0; i < cnt[hour]; ++i)
        times.push_back(i % 2 == 1 ? 24 - hour : hour);


    best = max(best, helper(hour + 1));

    for(int i = 0; i < cnt[hour]; ++i)
        times.pop_back();

    return best;

}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n; cin >> n;

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

    cout << helper(0);

    return 0;

}


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

using namespace std;
char s[1005];
map<char,bool> mp;
int main()
{
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++) mp[s[i]]=true;
	if(mp['S']==mp['N']&&mp['E']==mp['W']) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=105;
int n,tn,a[N],ans[N];
int main()
{
	RI i,j; for (scanf("%d",&n),i=1;i<=n;++i) scanf("%d",&a[i]);
	tn=n; while (n)
	{
		int pos=0; for (i=n;i;--i) if (a[i]==i) { pos=i; break; }
		if (!pos) return puts("-1"),0; ans[n]=pos;
		for (i=pos;i<n;++i) a[i]=a[i+1]; --n;
	}
	for (i=1;i<=tn;++i) printf("%d\n",ans[i]); return 0;
}

Measured memory_bytes: 1708
s = "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"
ss = list(s.split(", "))

k = int(input())

print(ss[k - 1])


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  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;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    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 COM(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;
}

// べき乗
ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i,N) {
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  ll ok=1e9+1,ng=0,now;
  while (ok-ng>1) {
    ll cnt=0;
    now = (ok+ng)/2;
    // for (ll i=1;i<1e9;i++) {
    //   if (upper_bound(A.begin(),A.end(),now*i)==A.end()) break;
    //   cnt += i*(upper_bound(A.begin(),A.end(),now*(i+1)) - upper_bound(A.begin(),A.end(),now*i));

    // }
    rep(i,N) cnt += (A[i]-1)/now;
    if (cnt>K) {
      ng=now;
      // cout << now << ' ' << cnt << ';' << "ng" << endl;
    }
    else {
      ok = now;
      // cout << now << ' ' << cnt << ';' << "ok" << endl;
    }
  }
  cout << ok << endl;
}


Measured memory_bytes: 4736
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define for1(i, n) for (int i = 1; i <= n; ++i)
#define for0(i, n) for (int i = 0; i < n; ++i)
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()

#define next qwerty1
#define left qwerty2
#define right qwerty3
#define y1 qwerty4
#define y0 qwerty5

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;







int main() {
	int k, p;
	scanf("%d %d", &k, &p);
	for (int i = p - (k - 1); i <= p + (k - 1); ++i) 
		printf("%d ", i);
	puts("");
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll H, W;
    cin >> H >> W;

    // １つ目が今の値、２つ目が開始地点
    map<ll, ll> M;
    // 今のポジションごとにどのくらい動いているか
    multiset<ll> vals;

    // スタート地点から流れたのものがどこに行き着くのか
    REP(i, W){
        M[i] = i;
        vals.insert(0);
    }

    REP(i, H){
        ll l, r;
        cin >> l >> r;
        l--;
        
        auto it = M.lower_bound(l);
        ll mr = -1;
        // 今の値が線分の中に入っているもので最も小さいものからスタート
        while(it != M.end() && it->first <= r){
            mr = max(mr, it->second);
            ll x = it->first - it->second;
            vals.erase(vals.find(x));
            M.erase(it++);
        }
        // 更新があり、範囲内のときは
        if(mr != -1 && r < W){
            vals.insert(r-mr);
            M[r] = mr;
        }
        ll ans = -1;
        if(vals.size() > 0){
            ans = *vals.begin() + (i+1);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 25476
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <bitset>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int dp[110][10];
int H, W, K;
bool correct(int bit) {
    rep(i, W - 2) {
        if((bit & (1 << i)) && bit & (1 << (i + 1))) {
            return false;
        }
    }
    return true;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> H >> W >> K;
    dp[0][0] = 1;
    rep(i, H) {
        rep(bit, (1 << (W - 1))) {
            if(!correct(bit)) continue;
            //cout << bitset<8>(bit) << endl;
            rep(j, W) {
                if(j + 1 < W && bit & (1 << j)) {
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
                    dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod;
                    j++;
                } else {
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
                }
            }
        }
    }
    cout << dp[H][K - 1] << endl;


    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
int main(void){
    double ans3;
    int a,b,i,ans1,ans2;
    
    scanf("%d %d", &a, &b);
    ans1 = a / b;
    ans2 = a % b;
    ans3 = (double) a / b;
    
    printf("%d %d %lf", ans1,ans2,ans3);  
}


Measured memory_bytes: 2104
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
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; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));


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


    vector<double> p;
    while(true){
        int N;
        cin >> N;
        if(N == 0) break;
        vector<int> P(N);
        for(int i =0 ; i < N; i++) cin >> P[i];
        double sum = 0;
        for(int p : P) sum+=p;
        double ave = sum / N;
        double ans = 0;
        for(int p : P){
            ans += (p - ave) * (p - ave);
        }
        ans /= N;
        p.push_back(sqrt(ans));
    }
    for(double a : p) cout << a << endl;
}



Measured memory_bytes: 3312
# -*- coding:utf-8 -*-

def solve():
    L = input()
    MOD = 10**9+7
    n = len(L)
    dp = [[0 for j in range(2)] for i in range(n+1)]
    dp[0][0] = 1

    for i, D in enumerate(L):
        # Da + Db = 0
        if D == "0":
            dp[i+1][0] = dp[i][0]
            dp[i+1][1] = dp[i][1]
        else:
            dp[i+1][1] = (dp[i][0] + dp[i][1]) % MOD

        # Da + Db = 1
        if D == "0":
            dp[i+1][1] += (dp[i][1]*2 % MOD)
            dp[i+1][1] %= MOD
        else:
            dp[i+1][0] += dp[i][0]*2 % MOD
            dp[i+1][1] += dp[i][1]*2 % MOD
            dp[i+1][0] %= MOD
            dp[i+1][1] %= MOD

    ans = (dp[n][0] + dp[n][1]) % MOD
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 21168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i >= (b); --i)
#define all(x) x.begin(), x.end()
#define pb  push_back
#define mb  make_pair
#define fi  first
#define se  second
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
const ll mod = 1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}



void solve()
{
    int n;
    cin >> n;
    int arr[n+1];
    rep(i,0,n+1)
        arr[i] = 0;
    int t;
    rep(i,0,n-1)
    {
        cin >> t;
        arr[t]++;
    }
    rep(i,1,n+1)
        cout << arr[i]<<"\n";
}

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

	solve();
	return 0;
}


Measured memory_bytes: 4396
import numpy as np

(N, M) = map(int, raw_input().split())
cakes = [map(int, raw_input().split()) for i in xrange(N)]
cakes_p = np.array(sorted(cakes, key=lambda x: sum(x))[::-1])
cakes_nx = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[0])[::-1])
cakes_ny = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[1])[::-1])
cakes_nz = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[2])[::-1])
cakes_list = [cakes_p, cakes_nx, cakes_ny, cakes_nz, cakes_p[::-1], cakes_nx[::-1], cakes_ny[::-1], cakes_nz[::-1]]
value = max([sum(map(abs,sum(cake[:M]))) for cake in cakes_list]) if M != 0 else 0

print value

Measured memory_bytes: 19308
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

int main(){
    int N, x;
    cin >> N >> x;
    // i + 1, i, i - 1, i + 2
    // i + 1, i, i - 1, i - 2;
    vector<int> as(2 * N - 1, -1);
    as[N - 1] = x;
    as[N] = x - 1;
    if( 1 >= x || x >= 2 * N - 1){
        cout << "No" << endl;
        return 0;

    }

    if(N == 2){
        as = {x - 1, x , x + 1};
        cout << "Yes" << endl;
        rep(i, as.size()){
            cout << as[i] << endl;
        }
        return 0;
    }


    vector<bool> exst(2 * N, false);


    if(x + 2 > 2 * N - 1){
        as[N + 1] = x - 2;
        as[N - 2] = x + 1;
    }else{
        as[N + 1] = x + 2;
        as[N - 2] = x + 1;
    }

    int index = 1;
    cout << "Yes" << endl;
    rep(i, as.size()){
        if(as[i] != -1){
            exst[as[i]] = true;
        }
    }
    rep(i, as.size()){
        if(as[i] == -1){
            while(exst[index]){
                index ++;
            }
            as[i] = index;
            exst[as[i]] = true;
        }
        cout << as[i] << endl;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2304
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
  int a, b, R;
  while(cin >> a >> b >> R, a||b){
    vector<long long int> A_x(a), A_y(a);
    for(int i = 0; i < a; ++i) cin >> A_x[i] >> A_y[i];
    vector< vector<long long int> > M(100010);
    for(int i = 0; i < b; ++i){
      long long int x, y;
      cin >> x >> y;
      M[x].push_back(y);
    }
    for(auto &x : M) sort(x.begin(), x.end());
    long long int ans = 0;
    for(int i = 0; i < a; ++i){
      long long int x = A_x[i], y = A_y[i];
      for(long long int j = max(0LL, x - 4*R); j <= min(100000LL, x + 4*R); ++j){
        long long int d = floor(sqrt(16*R*R - (x - j)*(x - j)) + 1e-8);
        ans += upper_bound(M[j].begin(), M[j].end(), y + d) - lower_bound(M[j].begin(), M[j].end(), y - d);
      }
    }
    cout << ans << endl;
  }
  return 0;
}



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

int k[11];
int p[11];
int s[11][11];

int total = 0;
vector<array<int, 11>> v;
array<int, 11> ar;

int dfs(int* S, int I, int n) {
    if(I >= n) {
        //cout << "test" << endl;
        for(int i = 0; i <= 11; i++) {
            ar[i] = S[i];
        }
        v.push_back(ar);
        return 1;
    } else {
        S[I] = 0;
        dfs(S,I+1,n);
        S[I] = 1;
        dfs(S,I+1,n);
        return 1;
    }

}

int main() {
    int n, m;
    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        cin >> k[i];
        for(int j = 0; j < k[i]; j++) {
            int tmp;
            cin >> tmp;
            s[i][tmp -1] = 1;
        }
    }
    for(int i = 0; i < m; i++) {
        cin >> p[i];
    }

    int S[11];
    S[0] = 0;
    dfs(S,1,n);
    S[0] = 1;
    dfs(S,1,n);
    
    int ret = 0;
    for(int i = 0; i < (int)v.size(); i++) {
        total = 0;
        //cout << v[i][0] << v[i][1] << v[i][2] << v[i][3] << v[i][4] << endl;
        for(int j = 0; j < m; j++) {
            int on = 0;
            for(int k = 0; k < n; k++) {
                //cout << "test" <<  v[i][k] << " " << s[j][k] << endl;
                if(v[i][k] == 1 && s[j][k]) {
                    on++;
                }
            }
            //cout << on << "p " << p[j] << endl;
            if(on % 2 == p[j]) {
                //cout << "on" << endl;
                total++;
            }
        }
        if(total == m) {
            //cout << "ret+" << total << endl;
            ret++;
        }
    }

    cout << ret << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mp make_pair
#define xx first
#define yy second
using namespace std;
typedef long long ll;
const int N = 100010;
const ll mod = 998244353;
int a[N],b[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    ll ans = a[n]-a[1];
    b[1]=a[1];b[2]=a[n];
    int i,j;
    i=2;j=n-1;
    int st=1;
    while(i<=j)
    {
        if(abs(a[j]-b[1])>=abs(a[i]-b[2]))
        {
            ans+=abs(a[j]-b[1]);
            b[1] = a[j--];

        }
        else
        {
            ans+=abs(a[i]-b[2]);
            b[2] = a[i++];
        }
        sort(b+1,b+3);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    int n, m;
    cin >> n >> m;
    pll a[n];
    REP(i,n)cin >> a[i].FI >> a[i].SE;
    sort(a, a + n);
    ll hon=0,val=0;
    REP(i, n)
    {
        hon += a[i].SE;
        if (hon >= m){
            hon -= a[i].SE;
            val += a[i].FI * (m - hon);
            break;
        }
        val += a[i].FI * a[i].SE;
    }
    cout << val << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
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 N;
    string S1,S2;
    cin>>N>>S1>>S2;
    ll ans=3;
    ll mod=1e9+7;
    //
    bool p=false;
    if(S1[0]==S1[1]) p=true;
    if(p) ans*=2;
    rep(i,N-1){
        if(p&&i==0) continue;
        if(S1[i+1]==S2[i+1]){ //次のタイルが1x2
            if(S1[i]==S2[i]){ //現在のタイルが1x2
                ans*=2;
            }else{ //現在のタイルが2x1
                ans*=1;
            }
        }else{ //次のタイルが2x1
            if(S1[i]==S2[i]){
                ans*=2;
            }else{
                ans*=3;
            }
            i++;
        }
        ans%=mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}
int main(){
int n;
scanf("%d",&n);
call(n);
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


const ll MOD = 1e9+7;

signed main(){
    ll a,b;
    cin >> a >> b; 
    a = max(a-1,0LL);
    switch(a%4){
        case 1:
            a = 1;
            break;
        case 2:
            a++;
            break;
        case 3:
            a = 0;
            break;
    }
    switch(b%4){
        case 1:
            b = 1;
            break;
        case 2:
            b++;
            break;
        case 3:
            b = 0;
            break;
    }

    cout << (a ^ b) << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;


class Solution{

public:
    long long ways(vector<int>& nums, int A){

        int n = nums.size();
        vector<vector<vector<long long>>> dp(n, vector<vector<long long>>(n + 1, vector<long long>(n * A + 1, -1)));

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

        long long res = 0;
        for(int i = 1; i <= n; i ++)
            res += solve(nums, 0, i, i * A, dp);
        return res;
    }

private:
    long long solve(const vector<int>& nums, int index, int left, int N,
                    vector<vector<vector<long long>>>& dp){

        if(index == nums.size())
            return N == 0 && left == 0 ? 1 : 0;
        if(left == 0) return N == 0 ? 1 : 0;
        if(dp[index][left][N] != -1) return dp[index][left][N];

        if(nums[index] > N) return 0;

        long long res = solve(nums, index + 1, left, N, dp);
        if(nums[index] <= N && left) res += solve(nums, index + 1, left - 1, N - nums[index], dp);
        return dp[index][left][N] = res;
    }
};

int main() {

//    vector<int> nums1 = {7, 9, 8, 9};
//    cout << Solution().ways(nums1, 8) << endl;
//    // 5
//
//    vector<int> nums2 = {6, 6, 9};
//    cout << Solution().ways(nums2, 8) << endl;
//    // 0
//
//    vector<int> nums3 = {3, 6, 2, 8, 7, 6, 5, 9};
//    cout << Solution().ways(nums3, 5) << endl;
//    // 19
//
//    vector<int> nums4(33, 3);
//    cout << Solution().ways(nums4, 3) << endl;
//    // 8589934591

    int N, A;
    scanf("%d%d", &N, &A);

    vector<int> nums(N);
    for(int i = 0; i < N; i ++) scanf("%d", &nums[i]);
    printf("%lld\n", Solution().ways(nums, A));

    return 0;
}


Measured memory_bytes: 53924