akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

struct COODINATE
{
public:
    int x, y, n;
};

vector<string> Gin;
Graph Gout;
queue<COODINATE> Q;

int search(int x, int y, int n, int h, int w){
    if(x<0 || w<=x || y<0 || h<=y || Gout[y][x] != -1){
        return 0;
    }
    if(Gin[y][x] == '#'){
        Gout[y][x] = 0;
        Q.push(COODINATE{x+1, y, n});
        Q.push(COODINATE{x-1, y, n});
        Q.push(COODINATE{x, y+1, n});
        Q.push(COODINATE{x, y-1, n});
        return 0;
    }
    Gout[y][x] = n+1;
    Q.push(COODINATE{x+1, y, n+1});
    Q.push(COODINATE{x-1, y, n+1});
    Q.push(COODINATE{x, y+1, n+1});
    Q.push(COODINATE{x, y-1, n+1});
    return n+1;
}

int main(){
    int h, w;
    cin >> h >> w;
    for(int i=0;i<h;i++){
        string s;
        cin >> s;
        Gin.push_back(s);
    }
    Gout.assign(h, vector<int>(w, -1));
    int ans = 0;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(Gin[i][j] == '#'){
                Q.push(COODINATE{j, i, 0});
            }
        }
    }
    
    while(!Q.empty()){
        COODINATE coodinate = Q.front();
        Q.pop();
        int num = search(coodinate.x, coodinate.y, coodinate.n, h, w);
        if(ans < num){
            ans = num;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 53576
#include<cstdio>

int main(){
    long long n;
    scanf("%lld",&n);
    if(n%2 || n==0) printf("0\n");
    else{
        long long ans = 0;
        n /= 2ll;
        while(n){
            ans += (n/5ll);
            n /= 5ll;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[1<<26];
int main()
{
    string s;
    cin>>s;
    int x=0;
    for(int i=0;i<(1<<26);i++)dp[i]=1e9;
    dp[0]=0;
    int ans=1e9;
    for(int i=0;i<s.size();i++)
	{
        ans=1e9;
        x^=1<<(s[i]-'a');
        ans=min(ans,dp[x]+1);
        for(int j=0;j<26;j++)ans=min(ans,dp[x^(1<<j)]+1);
        dp[x]=min(dp[x],ans);
    }
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++) 
#define loop(i, s, n) for(int i = s; i < n; i++) 

using namespace std;

int n;

int a, b;

int main() {
    cin >> a >> b;

    int ma = max(a, b);
    int mi = min(a,b);

    rep(i,ma){
        cout << mi;
    }
    cout << endl;

    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int count=0;
  rep(i,3){
    if(S.at(i)=='R'){
      count++;
    }
  }
  if(S=="RSR"){
    count=1;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
	int main()
	{
  
		int N,M,tmp,tmp2;
		tmp = tmp2 = 0;
		cin >> N >> M ;
		int a[M];
  
		for (int i = 0 ; i < M ;i++){
			cin >> a[i];
			tmp += a[i];
          
		}
		
		tmp2 = N - tmp; //N 日数　tmp2　必要日数
		if(tmp2 > -1){
          	cout << tmp2;
        }else{
			cout << "-1";
        }
          
    }

    
    

Measured memory_bytes: 3672
#include<stdio.h>
#include<vector>
using namespace std;
vector<int> e[100000];
int par[18][100000];
int index[200000];
int fapr[100000];
int lapr[100000];
int bit[200000];
int bit_n;
int n;
void add(int i,int x){
	while(i<bit_n){
		bit[i]+=x;
		i+=i&-i;
	}
}
int sum(int i){
	int s=0;
	while(i>0){
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}
int dfs(int v,int k){
	index[k]=v;
	fapr[v]=k++;
	for(int i=0;i<e[v].size();i++){
		k=dfs(e[v][i],k);
		index[k++]=v;
	}
	lapr[v]=k-1;
	return k;
}
int main(){
	while(1){
	int q;
	int i,j;
	scanf("%d %d",&n,&q);
	if(n==0)return 0;
	for(i=0;i<n;i++)for(j=0;1<<j<n;j++)par[j][i]=-1;
	for(i=0;i<n;i++)e[i].clear();
	for(i=1;i<n;i++){
		scanf("%d",&par[0][i]);
		par[0][i]--;
		e[par[0][i]].push_back(i);
	}
	for(i=1;1<<i<n;i++){
		for(j=0;j<n;j++){
			if(par[i-1][j]==-1)continue;
			par[i][j]=par[i-1][par[i-1][j]];
		}
	}
	int m=i-1;
	dfs(0,1);
	bit_n=n*2;
	for(i=0;i<bit_n;i++)bit[i]=0;
	add(1,1);
	long long ans=0;
	for(i=0;i<q;i++){
		char t;int v;
		scanf(" %c %d",&t,&v);
		v--;
		if(t=='M'){
			add(fapr[v],1);
			add(lapr[v]+1,-1);
		}else{
			int k=sum(fapr[v]);
			for(j=m;j>=0;j--){
				if(par[j][v]==-1)continue;
				int s=sum(fapr[par[j][v]]);
				if(s==k){
					v=par[j][v];
				}
			}
			ans+=v+1;
		}
	}
	printf("%lld\n",ans);
	}
}

Measured memory_bytes: 21140
import sys
sys.setrecursionlimit(500000)

N,K = map(int,input().split())
T = [[]*N for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)
visited = [0]*N
ans = 1
def bfs(i,bb,b):
    global ans
    visited[i] = 1
    ans = (ans*(K-bb-b))%(10**9+7)
    cnt = 0
    for j in T[i]:
        if visited[j] == 1:
            continue
        bfs(j,b+cnt,1)
        cnt += 1
bfs(0,0,0)
print(ans)




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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll N, K; cin >> N >> K;
	vll arr (N); 
	F0R(i, N) cin >> arr[i];
	F0R(i, N) --arr[i];

	vll time (N, -1);

	ll pos = 0;
	ll t = 0;

	while (K > 0) {
		if (time[pos] != -1) break;
		time[pos] = t;

		pos = arr[pos];
		t++;
		--K;
	}
	// print(pos, K);
	ll cycle_length = t - time[pos];
	K %= cycle_length;
	F0R(i, K) {
		pos = arr[pos];
	}
	print(pos+1);
}

Measured memory_bytes: 6368
n = int(input())
t = 0
x = 0
y = 0
for i in range(n):
    t_in,x_in,y_in = map(int,input().split())
    diff_t = t_in - t
    diff_x = abs(x_in-x)
    diff_y = abs(y_in-y)
    sum_xy = diff_x + diff_y
    if diff_t < sum_xy:
        print('No')
        exit()
    else:
        if diff_t%2 != sum_xy%2:
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 3060
#include <stdio.h>
int main(){

int i,j,H,W;

while(1){
scanf("%d %d",&H,&W);
if(H==0&&W==0)break;
for(i=0; i<H; i++){
for(j=0; j<W; j++){
printf("#");
}
printf("\n");
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 2032
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n;
vector< long long > arr( 410 ), pref( 410, 0 );
long long dp[ 410 ][ 410 ];

long long solve( int l, int r )
{
	if( l == r )
	{
		return 0;
	}
	if( dp[ l ][ r ] != -1 )
	{
		return dp[ l ][ r ];
	}
	dp[ l ][ r ] = 1e18;
	for( int i = l; i <= r - 1; ++i )
	{
		dp[ l ][ r ] = min( dp[ l ][ r ], solve( l, i ) + solve( i + 1, r ) + pref[ r ] - pref[ l - 1 ] );
	}
	return dp[ l ][ r ];
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> n;
	for( int i = 1; i <= n; ++i )
	{
		cin >> arr[ i ];
		pref[ i ] += pref[ i - 1 ] + arr[ i ];		
	}
	memset( dp, -1, sizeof( dp ) );
	cout << solve( 1, n ) << "\n";
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
const int INF = 1001001001;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) {//最大公約数
    if(a<b){
        ll tmp = a;
        a = b;
        b = tmp; 
    }
    if (b==0) return a;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {//最小公倍数
    return a * b / gcd(a, b);
}

int main() {
    int x,y,z; cin >> x >> y >> z;

    cout << z <<endl;
    cout << x << endl;
    cout << y << endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define task "atcoder"
#define rep(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define per(i,b,a) for(int i=(b),_a=(a);i>=_a;--i)
#define BIT(x, i) (((x) >> (i)) & 1)
#define lb lower_bound
#define ub upper_bound
#define lla(v) (v).begin(),(v).end()
#define zs(v) int((v).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
const ll mod=1000000007; /// 998244353
const int base=311;
const int N=1e5+5;

ll fact[2*N];

ll pw(ll n, ll k)
{
    if(k==1) return n;
    if(k==0) return 1;
    ll t=pw(n,k/2);
    if(k&1) return t*t%mod*n%mod;
    else return t*t%mod;
}
ll C(ll n, ll k)
{
    ll ans=fact[n-k]*fact[k]%mod;
    ans=pw(ans,mod-2);
    return (ans*fact[n]%mod);
}
void solved()
{
    fact[0]=1;
    rep(i,1,200000) fact[i]=fact[i-1]*i%mod;
    int n,m,a,b;
    cin>>n>>m>>a>>b;
    ll ans=0;
    for(int i=b+1;i<=m;++i)
    {
        ll ways=C(n-a+i-2,n-a-1);
//        cout<<ways<<endl;
//        cout<<n-a+i<<' '<<n-a<<' '<<i<<endl;
        ll tam=C(a+m-i+1-2,a-1);
        ans=(ans+ways*tam%mod)%mod;
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    solved();
}










Measured memory_bytes: 5212
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin >> n >> k;

	double prob_win = 0.0;
	for (int i = 1; i <= n; ++i) {
		if (i < k) {
			double curr = 1.0 / n;
			int p = i;
			while (p < k) {
				curr *= 0.5;
				p <<= 1;
			}

			prob_win += curr;
		} else {
			prob_win += 1.0 / n;
		}
	}

	cout << setprecision(12) << prob_win << "\n";

	return 0;

}

Measured memory_bytes: 256
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
int n,p[2005],v[2005],ind[2005],leaf[2005],used[2005];
vector<int>opr;
int deg[2005],sz[2005];
vector<int>g[2005];
int belong[2005],dep[2005];
bool ins[2005];
void dfs1(int x){
	sz[x]=(leaf[x]?1:0);
	for(auto to:g[x]){
		if(!used[to]){
			dep[to]=dep[x]+1;dfs1(to);
			sz[x]+=sz[to];
		}
	}
}
void dfs2(int x){
	if(leaf[x])belong[x]=x;
	for(auto to:g[x]){
		if(!used[to]){
			dfs2(to);
			if(leaf[x])belong[x]=belong[to];
		}
	}
}
void rotate(int x){
	opr.push_back(x);
	vector<int>vec;vec.push_back(x);
	while(x){
		x=p[x];vec.push_back(x);
	}
	reverse(vec.begin(),vec.end());
	int tmp=v[0];
	for(int i=0;i+1<vec.size();i++)v[vec[i]]=v[vec[i+1]];
	v[vec.back()]=tmp;
	for(int i=0;i<vec.size();i++)ind[v[vec[i]]]=vec[i];
}
void insert(int x){
	int pos=belong[x];
	while(ins[pos]&&v[pos]>x&&pos)pos=p[pos];
	rotate(pos);
	while(ins[pos])pos=p[pos];ins[pos]=1;
}
void erase_leaf(){
	memset(deg,0,sizeof deg);
	memset(leaf,0,sizeof leaf);
	for(int i=1;i<n;i++){
		if(!used[i])deg[p[i]]++;
	}
	for(int i=0;i<n;i++){
		if(!used[i])if(deg[i]==0){
			leaf[i]=1;
		}
	}
	dfs1(0);
	for(int i=0;i<n;i++)if(!used[i]&&sz[i]==1)leaf[i]=1;
	dfs2(0);
	set<int>wanted;
	for(int i=0;i<n;i++)if(leaf[i])wanted.insert(i);
	for(auto x:wanted)used[x]=1;
	while(1){
		while(wanted.count(v[0])&&v[0]){wanted.erase(v[0]);insert(v[0]);}
		bool all_ok=true;
		for(int i=0;i<n;i++)if(leaf[i])all_ok&=(v[i]==i);
		if(all_ok)break;
		pair<int,int>deep(-1,-1);
		for(auto i:wanted){
			deep=max(deep,make_pair(dep[ind[i]],ind[i]));
		}
		rotate(deep.second);
	}
}
int main(){
//	freopen("data.txt","r",stdin);
	cin>>n;
	for(int i=1;i<n;i++)cin>>p[i],g[p[i]].push_back(i);
	for(int i=0;i<n;i++)cin>>v[i],ind[v[i]]=i;
	while(1){
		if(*min_element(used,used+n)==1)break;
		erase_leaf();
	}
	if(opr.size()>25000)assert(0);
	#ifndef LOCAL
		cout<<opr.size()<<endl;
		for(auto x:opr)cout<<x<<endl;
	#else
		for(int i=0;i<n;i++)if(v[i]!=i)cerr<<i<<" "<<v[i]<<endl;
	#endif
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
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; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

map<int,int> m;
void yakusu(int k) {
    REP(i,2,k+1) {
        while(k%i==0) {
            k /= i;
            m[i]++; 
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    REP(i,2,n+1) {
        yakusu(i);
    }
    int n74 = 0, n24 = 0, n14 = 0, n4 = 0, n2 = 0;
    for(auto val : m) {
        if(val.second>=2) n2++;
        if(val.second>=4) n4++;
        if(val.second>=14) n14++;
        if(val.second>=24) n24++;
        if(val.second>=74) n74++;
    }

    cout << n4*(n4-1)/2*(n2-2)+n24*(n2-1)+n14*(n4-1)+n74 << endl;


    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
s = input().split()
N = int(s[0])
K = int(s[1])
s = input().split()
s = [int(i) for i in s]

dic = {}
for i in range(N): 
    if s[i] in dic : 
        dic[s[i]] += 1
    else :
        dic[s[i]] = 1

L = len(dic)
if K >= L : 
    print(0)
else :
    okikae = L - K
    x = sorted(dic.items(), key=lambda x: x[1])
    rst = 0
    for i in range(okikae) : 
        rst += x[i][1]
    print(rst)

Measured memory_bytes: 39932
def solve(N):
    for h in range(1, 3501):
        for n in range(1, 3501):
            d = 4*h*n - N*h - N*n
            if d <= 0: continue
            w = N*h*n / d
            if w == int(w):
                print(h, n, int(w))
                return

N = int(input())

solve(N)


Measured memory_bytes: 3060
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(),m=scan.nextInt(),a[]=new int[50],b[]=new int[50],c[]=new int[50],d[]=new int[50],t1,t2=0,i,j;
		for(i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=scan.nextInt();
		}
		for(i=0;i<m;i++) {
			c[i]=scan.nextInt();
			d[i]=scan.nextInt();
		}
		scan.close();
		for(i=0;i<n;i++) {
			t1=Integer.MAX_VALUE;
			for(j=0;j<m;j++) {
				if(t1>Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j])) {
					t1=Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]);
					t2=j;
				}
			}
			System.out.println(t2+1);
		}
	}
}

Measured memory_bytes: 21712
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

template<typename W, typename V>
struct dijkstra_result {
	std::vector<W> distance; // 距離
	std::vector<V> prev; // 「前」の頂点
};

/**
 * ダイクストラ法で、ある頂点から到達可能な頂点までの距離と最短経路を求める
 * 
 * @tparam G グラフを表す型。
 *           グラフ g で頂点 u から v への重み w の辺があることを g[u][v] = w で表す。無向グラフなら g[u][v] = g[v][u] にしておく
 *           G は map<V, map<V, W>> や vector<vector<pair<V, W>>> などが可能
 * @tparam V 頂点番号の型。普通は int にすると思う
 * @tparam W 重みの型。 G から求まるので指定しなくてよい
 */
template<typename G, typename V, typename W = typename std::remove_reference<decltype(std::declval<G>()[0][0])>::type>
dijkstra_result<W, V> dijkstra(/*const*/ G& graph, V start, V num)
{
	using PQT = std::pair<W, V>;

	std::vector<W> distance;
	std::vector<V> prev;
	std::deque<bool> done; // 既に確定している頂点かどうか（覚えておかなくても計算できるが無駄がある）
	std::priority_queue<PQT, std::vector<PQT>, std::greater<PQT>> q;

	distance.resize(num);
	prev.resize(num);
	done.resize(num);

	for (V i = 0; i < num; ++i) {
		distance[i] = std::numeric_limits<W>::max();
	}
	distance[start] = 0;
	q.push({0, start});

	while (!q.empty()) {
		const auto& du = q.top();
		const auto dist = du.first;
		const auto u = du.second;
		q.pop();
#if 0
		// これを書いても正しい結果になるが、かえって遅くなるようだ？
		if (done[u]) {
			continue;
		}
#endif
		done[u] = true;
		const auto& edges = graph[u];
		for (const auto& vw : edges) {
			const auto v = vw.first;
			const auto w = vw.second;
			if (!done[v]) {
				long updated = dist + w;
				if (distance[v] > updated) {
					distance[v] = updated;
					prev[v] = u;
					q.push({updated, v});
				}
			}
		}
	}

	return {distance, prev};
}

int main()
{
	// ABC126D

	long N;
	std::unordered_map<long, std::unordered_map<long, long> > E; // src -> {dst -> weight}

	std::cin >> N;
	for (int i = 0; i < N-1; ++i) {
		long u, v;
		long w;
		std::cin >> u >> v >> w;
		--u;
		--v;
		E[u][v] = w;
		E[v][u] = w;
	}

	auto dij_res = dijkstra(E, 0L, N);
	auto& D = dij_res.distance;

	for (long i = 0; i < N; ++i) {
		std::cout << (D[i] % 2) << "\n";
	}
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

const int MAXN = 500;
int table[MAXN][MAXN], used[MAXN][MAXN], a[MAXN], n, sum[MAXN][MAXN];

int get(int l, int r) {
    if (used[l][r]) {
        return table[l][r];
    }
    used[l][r] = 1;
    if (l == r) {
        table[l][r] = 0;
        return table[l][r];
    }
    for (int i = l;i <= r - 1;i++) {
        chkmin(table[l][r], sum[l][i] + sum[i + 1][r] + get(l, i) + get(i + 1, r));
    }
    return table[l][r];
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    for (int i = 0;i < MAXN;i++) {
        for (int j = 0;j < MAXN;j++) {
            used[i][j] = 0;
            table[i][j] = 1e18;
        }
    }
    cin >> n;
    for (int i = 0;i < n;i++) {
        cin >> a[i];
    }

    for (int i = 0;i < n;i++) {
        for (int j = i;j < n;j++) {
            sum[i][j] = 0;
            for (int k = i;k <= j;k++) {
                sum[i][j] += a[k];
            }
        }
    }

    cout << get(0, n - 1);

    return 0;
}


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

#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

void solve()
{
  int n,k;
    cin >> n >> k;
    
  int a[n];
    f(i,n) cin >> a[i];
    
  vector<bool> dp(k+1,0);
    
  dp[0] = 0;
    
  for(int i=1;i<=k;i++)
  {
    f(j,n) if(i-a[j] >= 0)
             dp[i]=dp[i]|(dp[i-a[j]]^1);
  }
    
  if(dp[k]) cout <<"First\n";
  else cout <<"Second\n";
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] prices = new int[n];
    int ans = 0;
    for (int i = 0; i < n; i++) {
      prices[i] = sc.nextInt();
    }
    Arrays.sort(prices);
    for (int j = 0; j < k; j++) {
      ans += prices[j];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 38564
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[3];
        arr[0] = Integer.parseInt(sc.next());
        arr[1] = Integer.parseInt(sc.next());
        arr[2] = Integer.parseInt(sc.next());
        
        Arrays.sort(arr);
        for(int i = 0; i < arr.length/2; i++){
            int bef = 0;
            int aft = 0;
            bef = arr[i];
            aft = arr[arr.length-1-i];
            arr[i] = aft;
            arr[arr.length-1-i] = bef;
            
        }
        int sum = 0;
        for(int i = 0; i < arr.length-1; i++){
            sum += Math.abs(arr[arr.length-1-i] - arr[arr.length-1-i-1]);
        }
        System.out.println(sum);
    }
}

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

int dp[505050];

int main() {
        int n; 
        scanf("%d", &n);
        string s; 
        cin >> s;
        s = "0" + s + "0";
        for (int i = 1; i < s.size() - 1; i ++) {
                dp[i + 1] = max(dp[i + 1], dp[i]);
                if (s[i - 1] == '1' && s[i] == '0' && s[i + 1] == '1') {
                        int prev = i - 1, next = i + 1;
                        while (true) {
                                if (s[prev] == '0') break;
                                dp[i + 1] = max(dp[i + 1], dp[prev - 1] + (i - prev));
                                prev --;
                        }
                        while (true) {
                                if (s[next] == '0') break;
                                dp[next] = max(dp[next], dp[i - 2] + (next - i));
                                next ++;
                        }
                }
        }
        printf("%d\n", dp[s.size() - 1]);
        return 0;
}


Measured memory_bytes: 2840
//
// Created by 李青坪 on 2018/10/20.
//

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int pos;
vector<int > pre, in, back;

void reconstruction(int left, int right){
    if (left >= right) return;
    int root = pre[pos++];
    int index = find(in.begin(), in.end(), root) - in.begin();
    reconstruction(left, index);
    reconstruction(index+1, right);
    back.push_back(root);
}

int main(){
    int n;
    scanf("%d", &n);
    int num;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &num);
        pre.push_back(num);
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d", &num);
        in.push_back(num);
    }
    pos = 0;
    reconstruction(0, in.size());
    for (int j = 0; j < back.size(); ++j) {
        if (j) printf(" ");
        printf("%d", back[j]);
    }
    printf("\n");
}

/*
5
1 2 3 4 5
3 2 4 1 5
 */


Measured memory_bytes: 2832
#include<iostream>  
#include<cstdio>
#include<stdio.h>
#include<cstring>  
#include<cstdio>  
#include<climits>  
#include<cmath> 
#include<vector>
#include <bitset>
#include<algorithm>  
#include <queue>
#include<map>
using namespace std;
long long int n, m, sum;
int main()
{
	cin >> n >> m;
	if (n * 2 <= m) printf("%lld\n", n + (m - 2 * n) / 4);
	else printf("%lld\n", m / 2);
}

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

namespace ConsoleApp15
{
    class Class394
    {
        static void Main()
        {
            var abk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = abk[0], b = abk[1], k = abk[2];

            int count = 0;
            for (int i = Math.Min(a,b); i >= 1; i--)
            {
                if (a % i == 0 && b % i == 0)
                    count++;

                if (count == k)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 28264
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {

		FastScanner sc = new FastScanner();
		char n[] = sc.next().toCharArray();

		boolean result = true;
		for (int i = 0; i < n.length; i++) {
			if (n[i] == (((i + 1) % 2 == 0) ? 'R' : 'L')) {
				System.out.println("No");
				return;
			}
		}

		System.out.println("Yes");
	}
}

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: 21332
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100010];
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n, greater<int>());
    for(int i = 1; i <= n; ++i){
        if(i + 1 > a[i + 1]){
            int p = 0;
            while(a[p + i + 1] == i) ++p;
            if(p & 1 || (a[i] - i) & 1) printf("First");
            else printf("Second");
            break;
        }
    }
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] s = new int[n];
		int[] t = new int[n];
		for(int i = 0 ; i < n ; i++) {
			s[i] = sc.nextInt();
			t[i] = sc.nextInt();
		}
		long a = 1, b = 1;
		for(int i = 0 ; i < n ; i++) {
			long x = Math.max(a / s[i], b / t[i]);
			for(long j = x ;; j++) {
				if(a <= s[i] * j && b <= t[i] * j) {
					a = s[i] * j;
					b = t[i] * j;
					break;
				}
			}
		}
		System.out.println(a + b);
	}
}


Measured memory_bytes: 23504
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int n,a,b,c,x;
	int y;
	int frame;

	while(1){
		cin>>n>>a>>b>>c>>x;
		if(n+a+b+c+x==0) break;

		frame=0;

		for(int i1=0;i1<n;i1++){
			cin>>y;
			if(x==y && i1==0) continue;
			while(1){
				x=(a*x+b)%c;
				frame++;
				if(x==y) break;
				if(frame>10000) break;
			}
		}

		if(frame>10000) cout<<-1<<endl;
		else cout<<frame<<endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int> h(n+1,0);
    for(int i=1;i<=n;i++) cin >> h[i];
    vector<int> v[n+1];
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int res=0;
    for(int i=1;i<=n;i++)
    {
        bool ok=1;
        for(int to:v[i]) if(h[to]>=h[i]) ok=0;
        res+=ok;
    }
    cout << res << endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    long long ans = 0;
    rep(i, N) {
        auto iter1 = lower_bound(A.begin(), A.end(), B[i]);
        auto iter2 = upper_bound(C.begin(), C.end(), B[i]);
        long long x = distance(A.begin(), iter1);
        long long y = distance(iter2, C.end());
        ans += x * y;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
e=enumerate
n,a=open(0)
n=int(n)
d=[0]+[1e18]*n
for j,(a,i)in e(sorted((-int(a),i)for i,a in e(a.split()))):d=[min(t+a*abs(~i-j+k+n),d[k-1]+a*abs(~i+k))for k,t in e(d)]
print(-min(d))

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

#define INF 1e9

long long solve(long long i,vector <vector <long long> >& in,long long w,vector <vector <long long> >& dp){
	if(dp[i][w]>=0) return dp[i][w];
	int n=in.size();
	if(i==n){dp[i][w]=0; return 0;}
	if(w==0){dp[i][w]=0; return 0;}
	long long  m=0;
	m=max(m,solve(i+1,in,w,dp));
	if(w-in[i][0]>=0) m=max(m,in[i][1]+solve(i+1,in,w-in[i][0],dp));
	dp[i][w]=m;
	return m;
	}
int main(){
	long long n,w;
	cin>>n>>w;
	vector <vector <long long> > in (n,vector <long long> (2,0));
	for(int i=0;i<n;i++) cin>>in[i][0]>>in[i][1];
	vector <vector <long long> > dp (n+1,vector <long long> (w+1,-1));
	cout<<solve(0,in,w,dp)<<"\n";
	return 0;
}



Measured memory_bytes: 80256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include<stdio.h>
using namespace std;
int main(){
    while (1){
        int h, w;
        cin >> h >> w ;
        if (h == 0 && w == 0){

            break;
        } else{
            int i, j;
            for(i = 0; i < h; i++){
                for(j = 0; j < w; j++){

                    cout << "#" ;
                    if (j == w-1){
                        cout << "\n";
                    }
                } 
            }
            cout << "\n";
        }
    }
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> W(N);
  for(auto& w : W){
    cin >> w;
  }
  
  int total = 0;
  for(auto& w : W){
    total += w;
  }
  
  int ans = total;
  int sum = 0;
  for(auto& w : W){
    sum += w;
    ans = min(ans, abs(total - sum - sum));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        long a,b,i,j;
		while(true){
        a = sc.nextInt();
        b = sc.nextInt();
            if(a==0&&b==0)break;
            
		for(i=0;i<a;i++){
            for(j=0;j<b;j++){
                if(i==0||i==a-1||j==0||j==b-1)System.out.print("#");
                else System.out.print(".");
        } 
         System.out.println();
      }
            System.out.println();
    }
  }
}


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

using namespace std;
const long long  N=2e5+10,big=1e18,mod=1e9+7;
const double pi=acos(-1);

long long n,m,k,mini=N,maxi;
pair<long long,long long > a[N];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i].second>>a[i].first;

    sort(a,a+n);
    long long t=0;
    for(int i=0;i<n;i++)
    {
        if(t+a[i].second>a[i].first)
            return cout<<"No" , 0;
        t+=a[i].second;
    }
    cout<<"Yes";


}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		//データの読み込み準備
		Scanner sc = new Scanner(System.in);
		
		//データ格納用配列
		int numbers[] = new int[3];
				
		//データの格納
		numbers[0] = sc.nextInt();
		numbers[1] = sc.nextInt();
		numbers[2] = sc.nextInt();
		
		//バブルソート
		for(int i = 0; i < 2; i++){
			for(int j = 0; j < 2 - i;j++){
				if(numbers[j] > numbers[j+1]){
					int temp = numbers[j];
					numbers[j] = numbers[j + 1];
					numbers[j + 1] = temp;
				}
			}
		}
		
		//結果の出力
		System.out.println(numbers[0] + " " + numbers[1] + " " + numbers[2]);
	}
}


Measured memory_bytes: 26220
### constant

MAX_H = 20

### main

loop do
  w, d = gets.split.map(&:to_i)
  break if (w | d) == 0

  hxs = gets.split.map(&:to_i)
  hys = gets.split.map(&:to_i)

  hxcs = (MAX_H + 1).times.map{0}
  hycs = (MAX_H + 1).times.map{0}

  hxs.each{|h| hxcs[h] += 1}
  hys.each{|h| hycs[h] += 1}

  count = 0
  for h in (1..MAX_H)
    count += ((hxcs[h] > hycs[h]) ? hxcs[h] : hycs[h]) * h
  end
  p count
end

Measured memory_bytes: 6132
import math
 
N,M = map(int,input().split())
 
ans = 1
for i in range(1,int(math.sqrt(M))+1+1):
  if M % i != 0:#約数ではないとき
    continue
  B = int(M / i)#intとらないと，N = 1 , M = 100 のとき　ans = 100.0になってエラー？
  
  if (i * N <= M):
    ans = max(ans,i)
  if (B * N <= M):
    ans = max(ans,B)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long n,k,ans;
inline long long read()
{
   long long sum=0,x=1;
   char ch=getchar();
   while (ch<'0'||ch>'9')
   {
       if (ch=='-')
	     x=-1;
	   ch=getchar();
   }
   while (ch>='0'&&ch<='9')
   {
   	   sum=sum*10+ch-'0';
	   ch=getchar();
   }
   return sum*x;
}
inline void write(long long x)
{
    if (x<0)
	{
        putchar('-');
        x=-x;
    }
    if (x>9)
      write(x/10);
    putchar(x%10+'0');
    return;
}
int main()
{
    n=read();k=read();
    if (k==0)
      write(n*n);else
    {
    	for (register int i=k+1;i<=n;++i)
        {
            ans=ans+(i-k)*(n/i);
            if (n%i-k>=0)
              ans=ans+1+n%i-k;
        }
	    write(ans);
	}
    return 0;
}

Measured memory_bytes: 3556
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	static String reverce(String str) {
		String strr="";
		for(int i=str.length()-1;i>=0;i--) {
			strr+=str.charAt(i);
		}
		return strr;
	}
	public static void main(String[] args) {
		String str=scan.next();
		str=str.substring(4,10);
		System.out.println("2018"+str);
	}
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
int s[13][13];

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> k(M),p(M);
  for(int i=0;i<M;i++){
    cin >> k[i];
    for(int j=0;j<k[i];j++)cin >> s[i][j];
  }
  for(int i=0;i<M;i++)cin >> p[i];
  int ans=0;
  for(int bit=0;bit<(1<<N);bit++){
    vector<int> q(N+10);
    for(int i=0;i<N;i++){
      if(bit & (1<<i))q[i]=1;
      else q[i]=0;
    }
    bool qw=true;
    for(int i=0;i<M;i++){
      int sum=0;
      for(int j=0;j<k[i];j++){if(q[s[i][j]-1])sum++;}
      if(sum%2!=p[i]){qw=false; break;}
    }
    if(qw)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;

map<int, int> primeFactorization(int n){
    map<int, int> ret;
    for(int i = 2; i * i <= n; i++){
        while(n % i == 0){
        ret[i]++;
        n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }

    map<int, int> primes;
    for(auto x : a){
        auto tmp = primeFactorization(x);
        for(auto y : tmp){
            primes[y.first]++;
        }
    }

    string ans = "pairwise coprime";
    bool flag1 = false;
    for(auto x : primes){
        if(x.second == n){
            ans = "not coprime";
            break;
        }
        if(x.second != 1){
            ans = "setwise coprime";
        }
    }

    cout << ans << endl;
    return 0;
}


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

 int main(){
     int N,A = 0;
     cin >> N;
    for(int i = 0;i < N+1; i++){
        A += i;
        }
     cout << A << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		dPA();

	}

	private static void dPA() {
		Scanner scanner = null;
		int numFlog = 0;

		try {
			scanner = new Scanner(System.in);
			numFlog = scanner.nextInt();
			int[] heightArray = new int[numFlog];

			for (int i = 0; i < numFlog; i++) {
				heightArray[i] = scanner.nextInt();
			}

			int[] koufukuArray = new int[numFlog];
			for (int i = 0; i < heightArray.length; i++) {
				if (i != 0 && i != 1) {
					int val1 = Math.abs(heightArray[i] - heightArray[i - 1]);
					int val2 = Math.abs(heightArray[i] - heightArray[i - 2]);
					koufukuArray[i] = Math.min(koufukuArray[i - 1] + val1, koufukuArray[i - 2] + val2);
				} else if (i == 0) {
					koufukuArray[i] = 0;
				} else if (i == 1) {
					koufukuArray[i] = koufukuArray[i - 1] + Math.abs(heightArray[i] - heightArray[i - 1]);
				}

			}
			System.out.println(koufukuArray[koufukuArray.length - 1]);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 50848
#include<bits/stdc++.h>
#define sc scanf
using namespace std;
const int N=3e5+5;
const int mod=1e9+7;
typedef unsigned long long ull;
typedef long long ll;
template <typename it>int o(it a){cout<<a<<endl;return 0;}
int n,m;
int s[N],t[N];
ll dp[2005][2005]={0};
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>s[i];
    for(int i=1;i<=m;i++)cin>>t[i];
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    if(s[i]==t[j])dp[i][j]=(dp[i-1][j]+dp[i][j-1]+1)%mod;
    else dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mod)%mod;
    o((dp[n][m]+1)%mod);
}


Measured memory_bytes: 33024
#include<cstdio>
using namespace std;
int n, s, l, r, last;
long long ans, x[100001], p[100001];
int main()
{
    scanf("%d%d", &n, &s);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%lld%lld", &x[i], &p[i]);
    }
    l = 1;
    r = n;
    while (l <= r)
    {
        if (s <= x[l])
        {
            ans += x[r] - s;
            break;
        }
        if (s >= x[r])
        {
            ans += s - x[l];
            break;
        }
        ans += x[r] - x[l];
        if (p[l] >= p[r]) 
        {
			while (l < r && p[l] >= p[r])
            {
				p[l] += p[r];
                r--;
            }
		} 
        else 
			while (l < r && p[l] < p[r])
            {
				p[r] += p[l];
                l++;
            }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cctype>
#include <queue>
#include <vector>

using namespace std;

typedef struct nametime
{
	string name;
	int time;
};

int main() {

	queue<int> round;
	queue<string> stround;
	string name,copyname;
	int n, q, time, no, elapsed = 0;
	cin >> n >> q;

	vector<nametime> str(n);

	for (int i = 0; i < n; i++) {
		cin >> str[i].name;
		cin >> str[i].time;
		round.push(str[i].time);
		stround.push(str[i].name);
	}

	while (1) {
		if (round.empty()) 
		{
			break;
		}
		if (round.front() > q) {
			no = round.front() - q;
			copyname = stround.front();
			round.pop();
			round.push(no);
			stround.pop();
			stround.push(copyname);
			elapsed += q;
		}
		else {
			elapsed += round.front();
			round.pop();
			cout << stround.front() << ' ' << elapsed << endl;
			stround.pop();
		}
			
	}

	return 0;
}

Measured memory_bytes: 4968
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    K=int(input())
    A,B=map(int,input().split())
    f=False
    for i in range(1000):
        if A<=i*K<=B:
            f=True
    if f:
        print('OK')
    else:
        print('NG')

if __name__ == '__main__':
    main()


Measured memory_bytes: 61812
// AOJ_C++.cpp : アプリケーションのエントリ ポイントを定義します。
//
#include <iostream>
#include <iomanip>
#include <string>

void Output(int a, int b) {
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < b; ++j) {
			std::cout << "#";
		}
		std::cout << "\n";
	}
	std::cout << "\n";
}

int main()
{
	int arr[1000][2];
	for (int i = 0; true; ++i) {
		int a, b;
		std::cin >> a >> b;
		if (a == 0 && b == 0) {
			for (int j = 0; j < i; j++) {
				Output(arr[j][0], arr[j][1]);
			}
			break;
		}
		arr[i][0] = a;
		arr[i][1] = b;
	}

	
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    vector <int> v;
    for  (int i=0;i<5;++i){
        int x;
        cin>>x;
        v.push_back(x);
    }
    auto ptr = find(v.begin(),v.end(),0);
    cout << ptr - v.begin() + 1 << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<long long>A(N+1);
  vector<long long>B(N);
  for (int i = 0; i < N + 1; i++){
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++){
    cin >> B.at(i);
  }
  long long c = 0;
  for (int i = 0; i < B.size(); i++){
    if(B[i] >= A[i]){
      c += A[i];
      B[i] = B[i] - A[i];
      A[i] = 0;
      if (B[i] >= A[i+1]){
        c += A[i+1];
        B[i] = B[i] - A[i+1];
        A[i + 1] = 0;
      }else{
        c += B[i];
        A[i + 1] = A[i+1] - B[i];
        B[i] = 0;
      }
    }else{
      c += B[i];
      A[i] = A[i] - B[i];
      B[i] = 0;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
N = int(input())
abc = [[0,0,0]]+[list(map(int,input().split())) for _ in range(N)]
dp = [[0,0,0] for _ in range(N+1)]

for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if j == k:continue
            #print('i={},j={},k={}'.format(i,j,k))
            #print(dp[i][j],abc[i][j],abc[i-1][k])
            dp[i][j] = max(dp[i][j],abc[i][j]+dp[i-1][k])
print(max(dp[-1]))

Measured memory_bytes: 47172