akhauriyash/Code-Regression huggingface dataset:
// Problem : F - path pass i
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int n, c[maxN], sz[maxN], prv[maxN], parent[maxN];
ll ans[maxN];
vi graph[maxN];
int odj[maxN];
bool first[maxN];

void DFS(int u, int par) {
	for(auto x: graph[u]) {
		if (x != par) {
			parent[x] = u;
			DFS(x, u);
			sz[u] += sz[x];
		}
	}
	sz[u]++;
}

ll calc(vector<ll>& vec) {
	ll sum = 0;
	ll tmp = 0;
	for (auto x: vec) sum += x;
	for (auto x: vec) {
		sum -= x;
		tmp += x * sum;
		sum += x;
	}
	tmp /= 2;
	tmp += sum;
	tmp++;
	return tmp;
}

void DFS2(int u, int par) {
	//cout << u << endl;
	vector<ll> vec;
	vec.clear();
	bool f = false;
	for (auto x: graph[u]) {
		if (x != par) {
			vec.pb(sz[x]);
		}
	}
	int lala = odj[c[u]];
	if (prv[c[u]] == 0) {
		vec.push_back(n - sz[u] - odj[c[u]]);
		lala = odj[c[u]];
	} else {
		vec.push_back(sz[prv[c[u]]] - sz[u] - odj[c[u]]);
	}
	ll tmp = calc(vec);
	//cout << u << " " << tmp << endl;
	ans[c[u]] += tmp;
	for (auto x: graph[u]) {
		if (x != par) {
			int k = prv[c[u]];
			prv[c[u]] = x;
			odj[c[u]] = 0;
			DFS2(x, u);
			prv[c[u]] = k;
		}
	}
	odj[c[u]] = lala;
	odj[c[u]] += sz[u];
}

// sprawdz MODULO!
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	RI(i, n) cin >> c[i];
	REP(_, n - 1) {
		int a, b;
		cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	DFS(1, -1);
	RI(i, n) {
		prv[i] = 0;	
	}
	DFS2(1, -1);
	RI(i, n) cout << ans[i] << "\n";
	return 0;
}
 


Measured memory_bytes: 73108
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

void solve() {
	int n;
	cin>>n;
	int ans = 0;
	for(int i = 0; i<n; ++i) {
		int c;
		cin>>c;
		if(c%2 && (i+1)%2) {
			ans++;
		}
	}
	cout<<ans<<endl;
}	

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


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin>>n;
  vector<pair<int,int>>v(n);
  for(int i=0;i<n;i++)
      cin>>v[i].first>>v[i].second;
  int cnt=0;
  for(int i=0;i<n-2;i++)
  {
     if(cnt==3)
      break;
    
   else if(v[i].first==v[i].second && v[i+1].first==v[i+1].second && v[i+2].first==v[i+2].second) {cnt=3;break;}
    
    else cnt=0;
  }
  
 if(cnt==3){cout<<"Yes"<<endl;}
 else {cout<<"No"<<endl;}
  return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
int main(void){
    int a, b;
    -1000 <= a, b <= 1000;
    scanf("%d %d",&a, &b);
    if(a < b)
        printf("a < b\n");
    else if(a > b)
        printf("a > b\n");
    else if(a == b)
        printf("a == b\n");
    return 0;
}



Measured memory_bytes: 2104
s = int(input())
a = [s]

while(1):
   if (a[-1] % 2 == 0):
      fn = int(a[-1] / 2)
   else:
      fn = 3 * a[-1] + 1

   if(fn in a):
      print(len(a) + 1)
      break
   else:
      a.append(fn)


Measured memory_bytes: 2940
#include<stdio.h>

#define max 100
#define a 0
#define b 1
#define c 2

int inf=(1<<21);
int n;
int m[max][max];

int P(){
int u, min, i, v, sum=0;
int d[max], p[max], ch[max];
for(i=0 ; i<n ; i++){
  d[i]=inf;
  p[i]=-1;
  ch[i]=a;
  }
  d[0]=0;
  while(1){
    min=inf;
    u=-1;
    for(i=0 ; i<n ; i++){
      if(min>d[i] && ch[i]!=c){
        u=i;
        min=d[i];
      }
    }
    if(u==-1)break;
    ch[u]=c;
    for(v=0 ; v<n ; v++){
      if(ch[v]!=c && m[u][v]!=inf){
        if(d[v]>m[u][v]){
        d[v]=m[u][v];
        p[v]=u;
        ch[v]=b;
        }
      }
    }
  }
  for(i=0 ; i<n ; i++){
    if(p[i]!=-1)sum+=m[i][p[i]];
  }
  return sum;
}

int main(){
int i, j, num;
scanf("%d",&n);
for(i=0 ; i<n ; i++){
  for(j=0 ; j<n ; j++){
    scanf("%d", &num);
    if(num==-1)m[i][j]=inf;
    else m[i][j]=num;
    }
  }
  printf("%d\n",P());
  return 0;
}



Measured memory_bytes: 2112
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 200100
using namespace std;
int   main()
{
	int a[maxn],n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	double d=a[0];
	for(int i=0;i<n;i++)
		d=(d+a[i]*1.0)/2;
	printf("%.5lf\n",d);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define pb push_back 
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define sc(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
ll sum[200005];
ll a[200005];
ll b[200005];
int main(int argc, char** argv) {
	ll n,m,k;
	cin>>n>>m>>k;
	rep(i,1,n)sl(a[i]);
	rep(i,1,m)sl(b[i]);
	rep(i,1,n)
	{
		sum[i]=sum[i-1]+a[i];
	}
	ll now=0,kk=0;
	rep(i,0,m)
	{
		now+=b[i];
		if(now>k)break;
		ll l=0,r=n,ans=0;
		while(l<=r)
		{
			ll mid=(l+r)>>1;
			if(now+sum[mid]<=k)
			{
				l=mid+1;
				ans=mid;
			}
			else r=mid-1;
		}
		kk=max(ans+i,kk);
	}
	cout<<kk;
	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <map>

using namespace std;

int main(){
	int num_of_information;
	cin >> num_of_information;

	map<int, int> information;
	int A, B, min_B, min_key;
	for (int i = 0; i < num_of_information; i++) {
		cin >> A >> B;
		information[A] = B;
	}
	min_B = information.begin()->second;
	min_key = information.begin()->first;
	for (auto itr = information.begin(); itr != information.end(); itr++) {
		if (min_B > itr->second) {
			min_B = itr->second;
			min_key = itr->first;
		}
	}
	cout << min_B + min_key << endl;
	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

    string s; std::cin >> s;
    rep(i, 3) std::cout << s[i];
    std::cout << "\n";
}


Measured memory_bytes: 3608
#include<stdio.h>

int main(void) {
	int N,i, L[10],max=0,sum=0;
	scanf("%d\n", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &L[i]);
		if (max < L[i]) max = L[i];
		sum += L[i];
	}
	if (sum > 2 * max) printf("Yes");
	else printf("No");

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main() {
	set<char> s;
	copy_n(istream_iterator<char>(cin), 3, inserter(s, s.end()));
	cout << (s.size() == 2 ? "Yes" : "No") << endl;
	return 0;
}


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

int main(){
  int N,c=0;
  cin >> N;
  
  for(int i=100;i>=1;i/=10){
    if(int(N/i)==7){
      c=1;
      break;
    }
    N=N%i;
  }
  if(c==0)  
    cout << "No"<<endl;
  else
    cout << "Yes"<<endl;

}


Measured memory_bytes: 3528
n = int(input())
A= list(map(int, input().split()))

mod = int(1e9+7)
def powermod(p,n,mod):
    #if n==0: return 1
    if n==1:
        return p%mod
    if n%2:
        return powermod(p,n//2,mod)**2 * p %mod
    else:
        return powermod(p,n//2,mod)**2 %mod


memo={}
for i, a in enumerate(A):
  if a in memo:
    L = memo[a]
    C = i - memo[a] -1
    R = len(A) - i-1
    break
  else:
    memo[a] = i
    
#print(L,C,R)
_LR = [0]*(n+3)
_LCR = [0] * (n+3) # _LCR[k] = (L+C+R)C(k)
_k = [0] * (n+3)
_LR[0] = _LCR[0] = _k[0] = 1

LR = [0]*(n+2) #LR[k] = (L+R)C(k)
LR[0] = 1
#LDR = [0]*(n+2)
#LDDR = [0]*(n+2)

LCR = [0] * (n+2) # LCR[k] = _LCR[k] - LR[k]
#LDCR = [0] * (n+2) #最後に*2を忘れないこと
#LDCDR = [0] * (n+2)

for k in range(1,n+2):
  _LR[k] = (_LR[k-1] * (L+R+1-k)) %mod
  _LCR[k] = (_LCR[k-1] * (L+C+R+1-k))% mod
  _k[k] = (_k[k-1] * powermod(k, mod-2, mod)) %mod
  
  LR[k] = (_LR[k] * _k[k])%mod
#  LDR[k] = LR[k-1]
#  LDDR[k] = LDR[k-1]
  
  LCR[k] = (_LCR[k] * _k[k])%mod - LR[k]
#  LDCR[k] = LCR[k-1]
#  LDCDR[k] = LDCR[k-1]
  #print(LR, LCR)
  print((LR[k] + LR[k-1] + LR[k-2] + LCR[k] + 2*LCR[k-1] + LCR[k-2])%mod)
  
#print(LR)
#print(LDR)
#print(LDDR)
#print(_LCR)
#print(LCR)
#print(LDCR)
#print(LDCDR)

Measured memory_bytes: 31368
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector< vector<int> > dp(3001,vector<int>(3001,-1));
string s,t;
int calc(int m,int n){
	if(m<=0 || n<=0)
	return 0;
	if(dp[m][n]!=-1)
	return dp[m][n];
	else{
		if(s[m-1]==t[n-1])
		dp[m][n]=calc(m-1,n-1)+1;
		else{
			dp[m][n]=max(calc(m-1,n),calc(m,n-1));
		}
	}
	return dp[m][n];
}
int main(){
	cin>>s>>t;
	calc(s.length(),t.length());
	int i=s.length(),j=t.length();
	string f;
	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			f+=s[i-1];
			i--;j--;
		}
		else{
			if(dp[i-1][j]>dp[i][j-1])
			i--;
			else
			j--;
		}
	}
	for(int i=f.length()-1;i>=0;i--)
	cout<<f[i];
	return 0;
}

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

int main(){
    ll n;
    cin >> n;
    int m = sqrt(n);
    int a = 0;
    for(int i = m;i>0;i--){
        if(n%i==0){
            a = i;
            break;
        }
    }
    cout << (a-1)+(n/a)-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, b, e) for (int i = (int)(b); i <= (int)(e); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long i64;
typedef unsigned long long u64;
typedef long double ld;
typedef long long ll;

const int maxn = 100500;
int a[maxn], d[maxn];

void uin(int &x, int y) {
    x = min(x, y);
}

int main() {
#ifdef LOCAL
    freopen("d.in", "r", stdin);
#endif

    int n;
    cin >> n;
    forn(i, n) cin >> a[i], --a[i], d[i] = maxn*2;
    d[n] = maxn*2;
    d[0] = 0;
    forn(i, n) {
        if (a[i] != i) uin(d[i+1], d[i]);
        if (i+1 < n && a[i] != i+1 && a[i+1] != i) uin(d[i+2], d[i]+1);
        if (i+2 < n) {
            if (a[i] != i+2 && a[i+1] != i && a[i+2] != i+1)
                uin(d[i+3], d[i]+2);
            if (a[i] != i && a[i+1] != i+2 && a[i+2] != i)
                uin(d[i+3], d[i]+2);
        }
    }
    cout << d[n] << endl;


#ifdef LOCAL
    cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
#endif
    return 0;
}


Measured memory_bytes: 1024
# 部分文字列のうち、acgtのみからなるものの最大長
# 先頭から探索して、acgtなら長さを+1する
ans = 0
length = 0
s = input()
for i in s:
  if i in ["A","C","G","T"]:
    length += 1
    ans = max(ans,length)
  else:
    length = 0
print(ans)

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

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> pq;
  rep(i, n) {
    int a;
    cin >> a;
    pq.push(a);
  }

  rep(i, m) {
    int x = pq.top();
    x /= 2;
    pq.pop();
    pq.push(x);
  }

  ll ans = 0;
  while (!pq.empty()) {
    ans += pq.top();
    pq.pop();
  }

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


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

const int N = 2e5 + 10;

int k , n , a[N] , Max;

int main(){
	scanf("%d %d" , &k , &n);
	for(int i = 1; i <= n; i++)
		scanf("%d" , &a[i]);
	for(int i = 2; i <= n; i++)
		Max = max(Max , a[i] - a[i - 1]);
	Max = max(Max , a[1] + k - a[n]);
	printf("%d" , k - Max);
	return 0;
} 

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

int main()
{
	int n, m, ans = 0;
	cin>>n>>m;
	vector<long long int>high(n);//展望台の高さ
	vector<int>count(n);//道をカウントする用;
	vector<vector<int>>road(2, vector<int>(m));//つなぐ道
	
	for(int i=0;i<n;i++)
		cin>>high[i];
	
	for(int i=0;i<m;i++){
		cin>>road[0][i];
		count[road[0][i]-1]++;
		cin>>road[1][i];
		count[road[1][i]-1]++;
	}
		
	for(int i=0;i<m;i++){
		if(high[road[0][i]-1] > high[road[1][i]-1]) count[road[0][i]-1]--;
		else if(high[road[0][i]-1] < high[road[1][i]-1]) count[road[1][i]-1]--;
	}
	
	for(int i=0;i<n;i++)//countが0になっている　=　つながっている道の先のどの展望台よりも高いか、道がない展望台
		if(count[i] == 0) ans++;
		
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5640
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	std::string t;
	std::cin >> t;
	std::string s;
	bool ok = false;
	REP(i, 0, 5){
		s += "hi";
		if(s==t) ok = true;
	}
	puts(ok? "Yes":"No");
	return 0;
}



Measured memory_bytes: 256
<?php
$N = trim(fgets(STDIN));

for ($i = 0; $i <= $N - 1; $i++) {
    $c[] = trim(fgets(STDIN));
}
$d = $c;

sort($d);

$fc = array_flip($c);
$fd = array_flip($d);

$sum = 0;
foreach($fc as $k => $v){
    if($v % 2 != $fd[$k] % 2){
        $sum++;
    };
}

echo ceil($sum / 2);

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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

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

    int n, m, x;
    cin >> n >> m >> x;
    vector<int> A(m);
    REP(i, m) cin >> A[i];

    int idx = lower_bound(A.begin(), A.end(), x) - A.begin();
    cout << min(idx, m - idx) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(ll i = 0; i < n; ++i)
#define rep1(i,n) for(ll i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
int main()
{
  ll N; cin >> N;
  ll M = 3500;
  rep1(i,M) {
    rep1(j,M) {
      ll x = 4*i*j - N*i - N*j;
      if(x <= 0) continue;
      if(N*i*j % x == 0) {
	cout << i << " ";
	cout << j << " ";
	cout << N*i*j / x << "\n";
	return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  int n,m;
  cin>>n>>m;
  
  vector<int> k(m);
  vector<vector<int>> s(m,vector<int>(0));  
  rep(i,m){
    cin>>k[i];
    rep(j,k[i]){
      int x;
      cin >> x;
      s[i].pb(x-1);
    }
  }

  vector<int> p(m);
  rep(i,m){
  cin >> p[i];
  }
  
  int ans = 0;
  rep(i,(1<<n)){
    bool memo = true;
    rep(j,m) {
      int cnt = 0;
        rep(l,k[j]){
          if(i & (1<<s[j][l])) cnt++;
        }
      if(cnt%2!=p[j]) memo=false;
    }
    if(memo) ans++;
  }
 
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

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

const ll MXLL = 1e18;

int n, w;
vector<ll> dp;
vector<pll> arr;

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

   cin >> n >> w;
   arr = vector<pll>(n, {MXLL, MXLL});
   dp = vector<ll>(w+1, 0);
   for(size_t i=0;i<n;i++)
      cin >> arr[i].fi >> arr[i].se;

   dp[0] = 0;
   for(auto&& p : arr) {
      for(int i=w;i>=0;i--) {
         if(i+p.fi <= w)
            dp[i+p.fi]=max(dp[i+p.fi], dp[i] + p.se);
      }
   }

   cout << *max_element(dp.begin(), dp.end());
   return 0;
}




Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;
  if (N == 3 || N == 5 || N == 7) {
    COUT("YES");
  } else {
    COUT("NO");
  }
  return 0;
}

Measured memory_bytes: 256
#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 rt (a); return (a); 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(n / 2);
	x %= mod;
	x *= x;
	x %= mod;
	if (n % 2 == 1)x *= 10;
	x %= mod;
	return x;
}

int main(){
	int n;
	cin >> n;
	int sum = 0;
	hei(int) A;
	rep(i, 1, n + 1) {
		sum += i;
		A.push_back(i);
		if (sum >= n)break;
	}
	rep(i, 0, A.size()) {
		if (sum - n != A[i])cout << A[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

ll gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) { //にぶたんgreater
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

vector<ll> Divisor(ll x) { // 約数列挙
	vector<ll> result;
	ll i=1LL;
	for( ; i*i<x; i++) {
		if(x%i) continue;
		result.push_back(i);
		result.push_back(x/i);
	}
	if(i*i==x&&x%i==0)
		result.push_back(i);
	
	sort(result.begin(),result.end());
	return result;
}

vector<llpair> PrimeFact(ll x) { // 素因数分解 {素因数,指数}
	vector<llpair> result;
	ll ex=0LL;
	if(x%2==0) {
		while(x%2==0) {
			x/=2;
			ex++;
		}
		result.push_back({2,ex});
	}

	for(ll i=3LL; i*i<=x; i+=2) {
		if(x%i) continue;

		ex=0LL;
		while(x%i==0) {
			x/=i;
			ex++;
		}
		result.push_back({i,ex});
	}

	if(x!=1) result.push_back({x,1});

	return result;
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}


int main() {
	string S; cin>>S;
	int N=S.length();

	vector<int> v;
	int ser=1;
	if(S[0]=='S') v.push_back(0);
	
	for(int i=1; i<N; i++) {
		if(S[i]==S[i-1]) ser++;
		else {
			v.push_back(ser);
			ser=1;
		}
	}
	v.push_back(ser);
	if(v.size()%2) v.push_back(0);

	while(v.size()!=2) {
		if(v[2]-v[1]>0) {
			v[0]+=v[2]-v[1];
		}
		else {
			v[3]+=v[1]-v[2];
		}
		v.erase(v.begin()+1,v.begin()+3);
	}

	cout<<v[0]+v[1]<<endl;
}


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

using namespace std;
typedef long long ll;

int main() {
  ll x;
  cin >> x;
  vector<ll> tmp;
  for (int i = -1000; i <= 1000; ++i) {
    tmp.push_back(pow(i, 5));
  }
  for (int i = 0; i < 2000; ++i) {
    int idx = lower_bound(tmp.begin(), tmp.end(), tmp[i] + x) - tmp.begin();
    if (tmp[idx] == tmp[i] + x) {
      cout << 1000 - i << " " << 1000 - idx<< '\n';
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 4132
#include<iostream>
using namespace std;
int main()
{
  int m1,m2,d1,d2;
  cin >> m1 >> d1;
  cin >> m2 >> d2;
  if(d2==1)
    cout << "1" << endl;
  else
    cout << "0" << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

template <typename A, typename B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream &operator<<(ostream &out, const array<T, N> &a) {
  out << "[";
  bool first = true;
  for (auto &v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
  out << "[";
  bool first = true;
  for (auto &v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T, class Cmp>
ostream &operator<<(ostream &out, const set<T, Cmp> &a) {
  out << "{";
  bool first = true;
  for (auto &v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) {
  out << "{";
  bool first = true;
  for (auto &p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) cerr << "@" << __LINE__ << " -> "; __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 
#endif
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
#define ll long long
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#pragma endregion

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int &x: v) cin >> x;
  map<int, int> even, odd;
  for (int i = 0; i < n; i++) {
    if (i & 1) {
      odd[v[i]]++;
    } else even[v[i]]++;
  }
  trace(n, v);
  vector<pair<int, int>> o, e;
  for (auto [a, occ] : even) e.push_back({occ, a});
  for (auto [a, occ] : odd) o.push_back({occ, a});
  sort(all(o), greater<pair<int, int>>());
  sort(all(e), greater<pair<int, int>>());
  int ans = n;
  trace(o);
  trace(e);
  if (e[0].second != o[0].second) {
    ans -= e[0].first + o[0].first;
  } else {
    int a1 = e[0].first, a2 = (sz(e) > 1 ? e[1].first : 0);
    int a3 = o[0].first, a4 = (sz(o) > 1 ? o[1].first : 0);
    trace(a1, a2, a3, a4);
    trace(n - a1 - a4, n - a2 - a3);
    ans = min(n - a1 - a4, n - a2 - a3);
  }
  cout << ans << endl;
}

Measured memory_bytes: 9244
n,k=map(int,input().split())
#print(n,k)
ans=0
if k==0:
    ans=n**2
else:
    for i in range(k+1,n+1):
        a,b=n//i,n%i
        if b<k:
            ans+=a*(i-k)
        else:
            ans+=a*(i-k)+(b-k+1)
print(ans)

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back

bool isOkashi(int suu, int &x) {
  if(suu <= x) {
    x -= suu;
    return true;
  }
  return false;
}

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

  int n, x;
  cin >> n >> x;
  vector<int> vec;
  rep(i, n) {
    int a;
    cin >> a;
    vec.pb(a);
  }

  sort(ALL(vec));
  int count1 = 0;
  rep(i, n-1) {
    if(isOkashi(vec[i], x)) count1++;
  }
  if(vec.back() == x) count1++;

  reverse(ALL(vec));
  int count2 = 0;
  rep(i, n-1) {
    if(isOkashi(vec[i], x)) count2++;
  }
  if(vec.back() == x) count2++;

  cout << max(count1, count2) << endl;
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using uint1024_t = mp::uint1024_t;
using namespace std;


int main() {
	int n, k;
	cin >> n >> k;
	deque<int>a;
	vector<int>mod(k);
	if (k == 1) {
		cout << (ll)n*n*n << endl;
	}
	else {
		FOR(i, 1, n + 1) {
			if (i * 2 % k == 0) {
				mod[i%k]++;
			}
		}

		ll count = 0;
		if (k % 2 == 0) {
			count += (ll)mod[0] * mod[0] * mod[0];
			count += (ll)mod[k/2] * mod[k/2] * mod[k/2];
			FOR(i, 1, k - i) {
				count += mod[i] * mod[k - i];

			}

		}
		else {
			count +=(ll) mod[0] * mod[0] * mod[0];
			FOR(i, 1, k-i) {
				count += mod[i] * mod[k - i];
			}
		}
		cout << count << endl;
	}
}


Measured memory_bytes: 1024
using System;
using System.Text;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var o = Console.ReadLine().ToCharArray();
            var e = Console.ReadLine().ToCharArray();
            var l = o.Length > e.Length ? o.Length : e.Length;

            var sb = new StringBuilder();
            for(var i = 0; i < l; i++){
                if(i < o.Length){
                    sb.Append(o[i]);
                }
                if(i < e.Length){
                    sb.Append(e[i]);
                }
            }

            Console.WriteLine(sb.ToString());
        }
    }
}


Measured memory_bytes: 13140
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

const M: usize = 1_000_000_007;

fn abs(x: i32) -> i32 {
    if x < 0 {
        -x
    } else {
        x
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut xs: Vec<i32> = vec![];
    xs.push(0);
    for _ in 0..n { xs.push(sc.cin()); }
    xs.push(0);

    let mut sum = 0;
    {
        let mut x = 0;
        for i in 1..(n+2) {
            sum += abs(xs[i] - x);
            x = xs[i];
        }
    }

    for i in 1..(n+1) {
        let ans = sum - abs(xs[i-1] - xs[i]) - abs(xs[i+1] - xs[i]) + abs(xs[i+1] - xs[i-1]);
        put!(ans);
    }
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int A,B,K; cin >> A >> B >> K;
    REP(i,K){
        if(i%2 == 0){
            B += A/2;
            A /= 2;
        }
        else{
            A += B/2;
            B /= 2;
        }
    }
    cout << A << " " << B << en;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define MAX_V 10000
#define INF 1000000001
typedef pair<int,int> P;
 
struct edge { int to,cap,cost,rev; };
 
int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];
 
void init_edge(){
  for(int i=0;i<V;i++)G[i].clear();
}
 
void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,(int)G[to].size()});
  G[to].push_back((edge){from,0,-cost,(int)G[from].size()-1});
}
 
int min_cost_flow(int s,int t,int f){
  int res = 0;
  fill(h,h+V,0);
  while(f>0){
 
    priority_queue< P, vector<P>, greater<P> >  que;
    fill( dist, dist+V , INF );
    dist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      int v = p.second;
      if(dist[v]<p.first)continue;
      for(int i=0;i<(int)G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap>0&&dist[e.to] > dist[v]+e.cost+h[v]-h[e.to]){
          dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
          prevv[e.to]=v;
          preve[e.to]=i;
          que.push(P(dist[e.to],e.to));
        }
      }
    }
 
    if(dist[t]==INF){
      return -1;
    }
    for(int v=0;v<V;v++)h[v]+=dist[v];
 
    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}
 
int main(){
  int E,F,a,b,c,d;
  cin>>V>>E>>F;
  while(E--){
    cin>>a>>b>>c>>d;
    add_edge(a,b,c,d);
  }
  cout<<min_cost_flow(0,V-1,F)<<endl;
  return 0;
}

Measured memory_bytes: 3440
//  main.cpp
//  solve
//
//  Created by Ahmed on 11/16/16.
//  Copyright Â© 2016 Abdellah. All rights reserved.
//


#include<set>
#include<map>
#include <unordered_map>
#include <unordered_set>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <strings.h>




#define f first
#define s second
#define pb push_back
#define sz(a) (int)(a).size()
#define lp(i,a,n) for(int (i)=(a);(i)<=(int)(n);(i)++)
#define lpd(i,n,a) for(int (i)=(n);(i)>=(a);--(i))
#define mp make_pair
#define clr(a,b) memset(a,b,sizeof a)
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define eps 1e-6
#define infi 1000000002
#define infll 4000000000000000005ll
#define MX 1000000
#define X real()
#define Y imag()
#define polar(r,t) ((r)* exp(point(0,(t))))
#define length(a) hypot( (a).X , (a).Y )
#define angle(a) atan2( (a).Y , (a).X )
#define vec(a,b) ( (b) - (a) )
#define dot(a,b) (conj(a)*(b)).X
#define cross(a,b) (conj(a)*(b)).Y
#define lengthsqr(a) dot(a,a)
#define reflect(V,M) (conj((V)/(M)) * (M))
#define normalize(a)   ((a)/length(a))
#define ccw(a,b,c)   cross(vec(a,b) , vec(a,c)) > -eps
#define cosRule(a,b,c) (acos(((a)*(a)+(b)*(b)-(c)*(c))/(2*(a)*(b))))
#define cosDot(a,b) (acos(dot(a,b)/length(a)/length(b)))
#define EQ(a,b) (fabs((a) - (b)) <= eps) /* equal to */
#define NE(a,b) (fabs((a) - (b)) > eps)  /* not equal to */
#define LT(a,b) ((a) < (b) - eps)        /* less than */
#define GT(a,b) ((a) > (b) + eps)        /* greater than */
#define LE(a,b) ((a) <= (b) + eps)       /* less than or equal to */
#define GE(a,b) ((a) >= (b) - eps)       /* greater than or equal to */
#define mod1 100050001
#define mod2 100030001
#define base1 37
#define base2 31
#define que priority_queue<pair<int,int>, vector<pair<int,int>> , greater<pair<int,int> > >
#define rotate(v,t) ((v)*exp(point(0,t)))
#define rotateabout(v,t,a) (rotate(vec(a,v),t)+(a))
#define PI atan(1)*4


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef complex<long double> point;
//typedef pair<point, point> line;
typedef pair<double , point> Circle;






//const int N = 2005;




int main(){
    
    ll x,y;
    cin>>x>>y;
    
    if(x%y == 0) return printf("-1\n"),0;
    
    cout<<x*(y-1)<<endl;
    
    return 0;
}

/*
 
 5 4
 1 2
 2 3
 3 4
 3 5
 
 */
//freopen("output.txt","w",stdout);
//freopen("input.txt","r",stdin);
//ios::sync_with_stdio(0);cin.tie(0);


Measured memory_bytes: 256
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    S = []
    for _ in range(N):
        a, b = map(int, input().split())
        S.append([a, b])

    S = sorted(S, key=lambda x: x[0])
    ans = 0
    for s in S:
        if s[1] >= M:
            ans += s[0] * M
            break
        else:
            ans += s[0] * s[1]
            M -= s[1]

    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
using namespace std;

bool is_valid(string s) {
    for (auto c : { '3', '5', '7' }) {
        if (find(s.begin(), s.end(), c) == s.end()) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    string s = to_string(n);
    queue<string> st;
    for (auto str : { "3" ,"5", "7" })
        st.push(str);
    int ans = 0;
    while (1) {
        string front = st.front();
        st.pop();
        ll t;
        sscanf(front.c_str(), "%lld", &t);
        if (t > n)
            break;
        if (is_valid(front))
            ans++;
        for (auto c : { '3', '5', '7' }) {
            st.push(front + c);
        }
    }
    cout << ans;
    return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

    ll n, k; std::cin >> n >> k;
    vi a(n); rep(i, n) std::cin >> a[i], a[i]--;
    vi visited(n);
    ll cur = 0, cnt = 0;
    while (visited[cur] < 1) {
        visited[cur]++;
        cur = a[cur];
        cnt++;
        if (k == cnt) {
            std::cout << cur+1 << "\n";
            return 0;
        }
    }
    k -= cnt;
    cnt = 0;
    while (visited[cur] < 2) {
        visited[cur]++;
        cur = a[cur];
        cnt++;
    }
    k = k % cnt;
    rep(i, k) {
        cur = a[cur];
    }
    std::cout << cur+1 << "\n";
}


Measured memory_bytes: 4784
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

def modfact(n):
    fact=[1]*(n+1)
    invfact=[1]*(n+1)
    for i in range(1,n+1):
        fact[i]=i*fact[i-1]%MOD
    invfact[n]=pow(fact[n],MOD-2,MOD)
    for i in range(n-1,-1,-1):
        invfact[i]=invfact[i+1]*(i+1)%MOD
    return fact,invfact

def resolve():
    x,y=map(int,input().split())
    if((x+y)%3):
        print(0)
        return

    z=(x+y)//3
    if(x-z<0 or y-z<0):
        print(0)
        return
    
    fact,invfact=modfact(z)
    print(fact[z]*invfact[x-z]%MOD*invfact[y-z]%MOD)
resolve()

Measured memory_bytes: 49136
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
using LP = pair<ll,ll>;
using P = pair<ll,int>;
ll inf = 1e18;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h) cin >> g[i];
    vector<bool> check_h(h,false), check_w(w,false);
    rep(i, h) {
        bool flag = true;
        rep(j, w){
            if(g[i][j] == '#') {
                flag = false;
                break;
            }
        }
        if (flag) check_h[i] = flag; 
    }
    rep(i, w) {
        bool flag =true;
        rep(j, h){
            if(g[j][i] == '#') {
                flag = false;
                break;
            }
        }
        if (flag) check_w[i] = flag; 
    }
    rep(i, h){
        if (check_h[i]) continue;
        rep(j, w){
            if (check_w[j]) continue;
            cout << g[i][j];

        }
        cout << endl;
    }


}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}

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

    ll N; cin >>N;
    vector<ll> B(N);
    rep(i, N) {
        int A;
        cin >> A;
        B[i] = A - (i + 1);
    }
    sort(all(B));

    ll b = N % 2 ? B[N/2] : (B[N/2-1] + B[N/2]) / 2;

    ll ans = 0;
    rep(i, N) {
        ans += abs(B[i] - b);
    }

    cout << ans << endl;
}


Measured memory_bytes: 1920
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    ans = []
    for i in range(len(s)):
        if s[i] == "B":
            if len(ans) != 0:
                ans.pop()
        else:
            ans.append(s[i])
    print("".join(ans))


if __name__ == '__main__':
    slove()


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

const int LIMIT = 200000;
int n, m, t[LIMIT];
map<int, int> mpd, mpt;
string ans = "YES";

int main() {
    cin >> n;
    rep(i, n) {
        cin >> m; mpd[m]++;
    }
    cin >> m;
    rep(i, m) {
        cin >> t[i]; mpt[t[i]]++;
    }
    
    rep(i, m) {
        if (mpd[t[i]] < mpt[t[i]]) ans = "NO";
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 19712