akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int h = hw[0];
        int w = hw[1];
        string[] map = Enumerable.Repeat(0, h).Select(_ => Console.ReadLine()).ToArray();
        UnionFind uf = new UnionFind(h * w);
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w - 1; j++)
            {
                if (map[i][j] != map[i][j + 1]) uf.Unite(i * w + j, i * w + j + 1);
            }
        }
        for (int i = 0; i < h - 1; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (map[i][j] != map[i + 1][j]) uf.Unite(i * w + j, (i + 1) * w + j);
            }
        }

        var groups = uf.GetGroupes;
        long res = 0;
        foreach (var group in groups)
        {
            long c1 = 0;
            long c2 = 0;
            foreach (var elem in group)
            {
                
                int bh = elem / w;
                int bw = elem % w;
                if ((bh % 2 + bw % 2) % 2 == 0) c1++;
                else c2++;
            }
            c1.WriteLog();
            c2.WriteLog();
            res += c1 * c2;
        }
        res.WriteLine();
    }
}


class UnionFind
{
    int[] data;
    public UnionFind(int count)
    {
        data = Enumerable.Range(0, count).ToArray();
    }
    public void Unite(int x, int y)
    {
        int xp = Parent(x);
        int yp = Parent(y);
        if (xp != yp)
        {
            data[yp] = xp;
        }
    }
    public bool IsSameGroup(int x, int y) => Parent(x) == Parent(y);
    public int[] AllParents() => data.Where((x, y) => x == y).ToArray();
    public IEnumerable<IEnumerable<int>> GetGroupes => data.Select((x, y) => new Tuple<int, int>(Parent(x), y)).GroupBy(x => x.Item1).Select(x => x.Select(y => y.Item2));
    public int Parent(int x)
    {
        form(x);
        return data[x];
    }
    private void form(int x)
    {
        while (data[x] != data[data[x]])
        {
            data[x] = data[data[x]];
        }
    }
}

static class Writer
{
    public static void WriteLine<T>(this T item) => Console.WriteLine(item);

    public static void WriteLog<T>(this T item) => Debug.WriteLine(item);
}


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

int main(){
    int N; cin >> N;
    string S, T; cin >> S >> T;

    string ans;
    for (int i = 0; i < S.size(); i++)
    {
        ans += S[i];
        ans += T[i];
    }
    cout << ans << endl;   
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            cout << i << "x" << j << "=" << i * j << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3016
#include <stdio.h>

int main()
{
  int i,j,flag,tmp=0,k=0;
  int N,A[100];

  scanf("%d",&N);
  for(i=0;i<N;i++)
    {
      scanf("%d",&A[i]);
    }
  flag=1;
  while(1)
    {
      flag=0;
      for(j=N-1;j>0;j--)
	{
	  if(A[j]<A[j-1])
	    {
	      tmp=A[j-1];
	      A[j-1]=A[j];
	      A[j]=tmp;
	      k++;
	      flag=1;
	     }
	}
      if(flag==0) break;
    }
  for(i=0;i<N;i++)
    {
      if(i>0)printf(" ");
      printf("%d",A[i]);
    }
  printf("\n%d\n",k);
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
int main(){
	int n;
	std::vector<int> shot(0);
	int a=1;
	std::vector<int> yeah(0);
	while(true){
		yeah.resize(a);
		std::cin>>n;
		if(n==0){
			break;
		}
		for(int i=1;i<=n/4;i++){
			shot.resize(i);
			std::cin>>shot[i-1];
			yeah[a-1]+=shot[i-1];
		}
		a++;
	}
	for(int i=0;i<a-1;i++){
		std::cout<<yeah[i]<<std::endl;
	}
}

Measured memory_bytes: 1220
N = int(input())
S = input()

# "("*L + S + ")"*R
L,R = 0,0
# 余っている "(" の個数 
rem = 0

for s in S:
    # ")"
    if s==")":
        if rem==0:
            L += 1
        else:
            R -= 1
            rem -= 1
    # "("
    else:
        R += 1
        rem += 1

print("("*L + S + ")"*R) 

Measured memory_bytes: 3060
/*
* Created by: WeirdBugsButOkay
*/

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second

using namespace std;

void solve()
{
    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;
}

int main()
{
    int q = 1;
    //scanf("%d", &q);
    for(int i = 1; i <= q; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll ksm(int a,int b)
{
	ll ans =1;
	while(b)
	{
		if(b&1) ans=(ll)ans*a%mod;
		b/=2;
		a=(ll)a*a%mod;
	}
	return ans%mod;
}
int main()
{
	int n,k,s[5000];
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&s[i]);
	}
	int h[5000],sum[5000];
	memset(h,0,sizeof h);
	memset(sum,0,sizeof sum);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<i;j++)
			if(s[i]>s[j])
				sum[i]++;
		for(int j=i+1;j<n;j++)
			if(s[i]>s[j])
				h[i]++;
		sum[i]+=h[i];
	//	cout<<sum[i]<<' '<<h[i]<<endl;
	}
	ll ans=0;
	ll res=ksm(2,mod-2);
//	cout<<res<<endl;
	//cout<<(ll)k*(k-1)/2%mod<<endl; 
	for(int i=0;i<n;i++)
	{
		ans=(ans%mod+(ll)h[i]*k%mod)%mod;
		ans=(ans%mod+((((ll)k*(k-1))%mod*res)%mod*sum[i])%mod)%mod;
	}
	cout<<ans%mod;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

class Main {

    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);
        while (true) {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            boolean findAble = false;

            if (n + m == 0) break;

            int[] ns = new int[n];
            int[] ms = new int[m];

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

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

            int sumN = IntStream.of(ns).sum();
            int sumM = IntStream.of(ms).sum();

            OUT:
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (sumN - ns[i] + ms[j]  == sumM - ms[j] + ns[i] ) {
                        System.out.println(ns[i] + " " + ms[j]);
                        findAble = true;
                        break OUT;
                    }
                }
            }
            if (!findAble) {
                System.out.println("-1");
            }

        }
    }
}



Measured memory_bytes: 33128
n, m = map(int, input().split())
switch = [[] for i in range(n)]
for j in range(m):
    a = [(int(i) - 1) for i in input().split()]
    for aa in a[1:]:
        switch[aa].append(j)
p = [int(i) for i in input().split()]
ans = 0
for i in range(2 ** n):
    calc = [0 for _ in range(m)]
    k = bin(i)[2:]
    k = (n - len(k)) * ["0"] + list(k)
    for j, kk in enumerate(k):
        if kk == "1":
            for s in switch[j]:
                if calc[s] == 0:
                    calc[s] = 1
                else:                    
                    calc[s] = 0
    if calc == p:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
	for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+(ch^'0');
	return x*f;
}
int n;
int a[202];
int Ans;
int main(){
	n=read();
	for(register int i=1;i<=2*n;++i)
		a[i]=read();
	sort(a+1,a+2*n+1);
	for(register int i=1;i<=2*n;i+=2)
		Ans+=a[i];
	cout<<Ans<<endl;
	return 0;
}

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

int main() {
    int W, H, N;
    cin >> W >> H >> N;

    int minx = 0, maxx = W, miny = 0, maxy = H;
    for (int i = 0; i < N; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            minx = max(minx, x);
        } else if (a == 2) {
            maxx = min(maxx, x);
        } else if (a == 3) {
            miny = max(miny, y);
        } else if (a == 4) {
            maxy = min(maxy, y);
        }
    }

    if (minx <= maxx && miny <= maxy) {
        cout << (maxx - minx) * (maxy - miny) << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
int main()
{
	int s;
	while (cin >> s) {
		int a = 0;
		for (int i = 0; i < 10; i++) {
			for (int k = 0; k < 10; k++) {
				for (int j = 0; j < 10; j++) {
					for (int l = 0; l < 10; l++) {
						if (i + k + j + l == s) { a++; }
					}
				}
			}
		}cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 2976
#include <cstdio>
int N;
int h[100005];
int main() {
    scanf("%d",&N);
    h[0] = 0;
    bool flag = true;
    for (int i = 1; i <= N; i++) {
        scanf("%d",&h[i]);
        if (!flag)
            continue;
        if (h[i] >= h[i-1] + 1)
            h[i]--;
        if (h[i] < h[i-1])
            flag = false;
    }
    if (flag)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

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

	int N=in(),M=in();
	auto H=vecin(N);
	vector<int> A(N,0);
	ConnectNodeInfo connect(N);
	REP(i,M){
		int a=in()-1,b=in()-1;
		connect.AddNonDirectionalConnection(a,b,1);
	}
	
	int sum=0;
	REP(i,N){
		bool exist =true;
		for(auto& x:connect[i]){
			if(H[i]<=H[x.first]){
				exist = false;
				break;
			}
		}
		if(exist) sum++;
	}
	out(sum);
	return 0;
}


Measured memory_bytes: 11644
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,i,j,cc=0;
    ll ara[5];
    for(i=0;i<5;i++)cin>>ara[i];
    pair<ll,ll>v[10];
    for(i=0;i<5;i++){
        ll x=ara[i]%10;
        if(x != 0)
        v[i]=make_pair(10-x,ara[i]);
        else{
            v[i]=make_pair(0,ara[i]);
        }
    }
    sort(v,v+5);
    for(i=0;i<5;i++){
       // cout<<v[i].first<<spc<<v[i].second<<endl;
        if(i+1 != 5){
            cc+=v[i].first;
            cc+=v[i].second;
        }
        else{
            cc+=v[i].second;
        }
    }
    cout<<cc<<endl;
return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <utility>
using namespace std;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
const lli inf = 1e18;

int main(){
	int a,p;
	cin >> a >> p;
	cout << (3*a +p)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<cstring>

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s=="abc" || s=="acb" || s=="bac" || s=="bca" || s== "cab" || s=="cba")cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  if (K > (N - 1) * (N - 2) / 2) {
    cout << -1 << endl;
    return 0;
  }
  int x = (N - 1) * (N - 2) / 2 - K;
  cout << N - 1 + x << endl;
  for (int i = 2; i <= N; ++i) {
    cout << 1 << " " << i << endl;
  }
  for (int i = 2; i <= N; ++i) {
    for (int j = i + 1; j <= N; ++j) {
      if (x == 0) return 0;
      cout << i << " " << j << endl;
      --x;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e12+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
int main(void){
	int i,n,m,ki=0;cin>>n>>m;
	if(n==1){cout<<1<<endl<<1<<endl<<1<<endl;RE;}
	vector<int>A(m);
	for(i=0;i<m;i++){cin>>A[i];}
	for(i=0;i<m;i++){
		if(A[i]%2==1){
			if(ki==0){swap(A[0],A[i]);ki++;}
			else {swap(A[m-1],A[i]);}
			
		}
	}
	ki=0;
	for(i=0;i<m;i++){ki+=A[i]%2;}
	if(ki>=3){cout<<"Impossible"<<endl;RE;}
	for(i=0;i<m;i++){cout<<A[i]<<" ";}
	cout<<endl;
	if(m==1){cout<<2<<endl<<n-1<<" "<<1<<endl;RE;}
	if(A[0]!=1){cout<<m<<endl;}else{cout<<m-1<<endl;}
	for(i=0;i<m;i++){
		if(i==0&&A[i]==1){}
		else if(i==0){cout<<A[i]-1<<" ";}
		else if(i==m-1){cout<<A[i]+1<<" ";}
		else{cout<<A[i]<<" ";}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll MOD=998244353;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




struct UnionFind{
    vector<int> data;

    UnionFind(int sz){
        data.assign(sz, -1);
    }

    int find(int k){
        if(data[k] < 0) return k;
        return data[k] = find(data[k]);
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int k){
        return -data[find(k)];
    }

};

int main(){
    int n;cin >> n;
    vector<pair<P,int>> v(n);
    for (int i = 0; i < n; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        v[i] = mp(mp(x, y),i);
    }
    sort(ALL(v));
    priority_queue<P ,vector<P>, greater<P>> pq;
    UnionFind uf(n);
    for (int i = 0; i < n; i++) {
        int id = v[i].sc;
        bool f = false;
        P p;
        if(not pq.empty()) p = pq.top();
        while(not pq.empty() and pq.top().fs < v[i].fs.sc){
            auto pp = pq.top(); pq.pop();
            uf.unite(pp.sc, id);
            f = true;
        }
        if(f){
            pq.push(p);
        }
        else{
            pq.push(mp(v[i].fs.sc, v[i].sc));
        }
    }
    for (int i = 0; i < n; i++) {
        cout << uf.size(i) << endl;
    }
    return 0;
}



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

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

int main() {
  ll n;
  cin >> n;
  vector<P> a(n);
  rep(i, n) cin >> a[i].first >> a[i].second;
  vector<ll> v(n);
  rep (i, n) v[i] = i;
  double sum=0;
  ll count = 0;
  do {
    count++;
    rep(i, v.size()-1) {
      sum += sqrt(pow(a[v[i]].first-a[v[i+1]].first, 2) + pow(a[v[i]].second-a[v[i+1]].second, 2));
    }
  } while(next_permutation(v.begin(), v.end()));//順列全探索
  // next_permutation : 順列を昇順
  // prev_permutation : 順列を降順
  printf("%.6f", sum/count);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderBeginnerContest
{
    public class Program
    {
        public static long[] iro;
        public static long over;

        public static void Main(string[] args)
        {
            // 064-C
            var N = long.Parse(Console.ReadLine());

            var line = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

            iro = new long[] { 0, 0, 0, 0, 0, 0, 0, 0 };
            over = 0;

            foreach (var item in line)
            {
                Rate(item);
            }

            long max = 0;
            long min = 0;

            foreach (var item in iro)
            {
                if (item != 0) min++;
            }
            max = min + over;
            min = min == 0 ? 1 : min;
            //if (max > 8) max = 8;

            Console.WriteLine($"{min} {max}");

        }

        public static void Rate(long n)
        {
            if(1 <= n && n<= 399)
            {
                iro[0]++;
            }
            else if (400 <= n && n <= 799)
            {
                iro[1]++;

            }
            else if (800 <= n && n <= 1199)
            {
                iro[2]++;

            }
            else if (1200 <= n && n <= 1599)
            {
                iro[3]++;

            }
            else if (1600 <= n && n <= 1999)
            {
                iro[4]++;

            }
            else if (2000 <= n && n <= 2399)
            {
                iro[5]++;

            }
            else if (2400 <= n && n <= 2799)
            {
                iro[6]++;

            }
            else if (2800 <= n && n <= 3199)
            {
                iro[7]++;

            }
            else if (3200 <= n && n <= 4800)
            {
                over++;
            }
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;

int main()
{
    int n,m,i,x;
    long long s;
    cin>>n>>m;s=n;
    for(i=1;i<=m;i++)
    {
        cin>>x;
        s-=x;
    }
    if(s<0)
        cout<<"-1";
    else
        cout<<s;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cassert>
#include <cctype>
#include <string>
#include <algorithm>
using namespace std;

string s, s2;
size_t cur;

string change_string(const string &s, int i, int j, int k){
  int size = s.size();
  string s1;
  for(int l = 0; l < size; l++){
    if(s[l] == 'P'){
      s1.push_back(char('0' + i));
    }else if(s[l] == 'Q'){
      s1.push_back(char('0' + j));
    }else if(s[l] == 'R'){
      s1.push_back(char('0' + k));
    }else{
      s1.push_back(s[l]);
    }
  }
  return s1;
}

int formula(){
  if(isdigit(s2[cur])){
    return s2[cur++] - '0';
  }else if(s2[cur] == '-'){
    cur++;
    assert(cur < s2.size());
    return 2 - formula();
  }else{
    assert(s2[cur] == '(');
    cur++;
    int a = formula();
    char op = s2[cur++];
    assert(cur < s2.size());
    int b = formula();
    cur++;
    if(op == '+'){
      return max(a, b);
    }else{
      return min(a, b);
    }
  }
}
    

int main(){
  while(cin >> s && s != "."){
    int count = 0;
    for(int i = 0; i <= 2; i++){
      for(int j = 0; j <= 2; j++){
	for(int k = 0; k <= 2; k++){
	  cur = 0;
	  s2 = change_string(s, i, j, k);
	  if(formula() == 2) count++;
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}

    

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;

void solveEquation(const vector<double>& a, vector<double>& x)
{
    class Func{
    public:
        static double f(const vector<double>& a, double x){
            double y = 0.0;
            for(int i=a.size()-1; i>=0; --i){
                y *= x;
                y += a[i];
            }
            return y;
        }
        static double findZero(const vector<double>& a, double x1, double x2){
            double y1 = f(a, x1);
            double y2 = f(a, x2);
            while(x1 < x2 - EPS){
                double x = (x1 + x2) / 2;
                double y = f(a, x);
                if((y1 < y2) ^ (y > 0))
                    x1 = x;
                else
                    x2 = x;
            }
            return (x1 + x2) / 2;
        }
    };

    x.clear();
    int n = a.size();
    if(n == 2){
        x.push_back(- a[0] / a[1]);
        return;
    }

    vector<double> b(n-1), x2; // 導関数の係数、極値点のx座標
    for(int i=0; i<n-1; ++i)
        b[i] = a[i+1] * (i+1);
    solveEquation(b, x2);
    
    const double LIMIT = 1.0e10;
    x2.insert(x2.begin(), -LIMIT);
    x2.push_back(LIMIT);

    for(unsigned i=0; i<x2.size()-1; ++i){
        double y1 = Func::f(a, x2[i]);
        double y2 = Func::f(a, x2[i+1]);
        if(abs(y1) < EPS){
            x.push_back(x2[i]);
        }else if(abs(y2) < EPS){
            x.push_back(x2[i+1]);
        }else if((y1 < 0) ^ (y2 < 0)){
            x.push_back(Func::findZero(a, x2[i], x2[i+1]));
        }
    }
}

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

    while(--n >= 0){
        vector<double> a(4);
        for(int i=0; i<4; ++i)
            cin >> a[3-i];

        vector<double> x;
        solveEquation(a, x);

        vector<int> ret(2, 0);
        for(unsigned i=0; i<x.size(); ++i){
            if(x[i] > EPS)
                ++ ret[0];
            else if(x[i] < -EPS)
                ++ ret[1];
        }
        cout << ret[0] << ' ' << ret[1] << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
const int N=1000050;
int go[N][26],root,tsz,w[N];
void Add(string s){
	if(!root)root=++tsz;
	int now=root;
	for(char c:s){
		if(!go[now][c-'a'])go[now][c-'a']=++tsz;
		now=go[now][c-'a'];
	}
	w[now]++;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;cin>>n;
	vector<string> v(n);
	for(auto&s:v)cin>>s;
	vector<int> idx;
	for(int i=0;i<n;i++)idx.pb(i);
	sort(idx.begin(),idx.end(),[&](int i,int j){return v[i].size()<v[j].size();});
	int ans=0;
	for(int j:idx){
		string s=v[j];
		vector<int> cnt(26,0);
		for(char c:s)cnt[c-'a']++;
		int now=root;
		for(int i=(int)s.size()-1;i>=0;i--){
			for(int z=0;z<26;z++){
				if(cnt[z])ans+=w[go[now][z]];
			}
			cnt[s[i]-'a']--;
			now=go[now][s[i]-'a'];
		}
		reverse(s.begin(),s.end());
		Add(s);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 109164
import java.awt.*;

import java.util.*;
public class Main
{


    public static void main (String[] args)
    {

       Scanner c = new Scanner(System.in);
        int n = c.nextInt();
        int k = c.nextInt();
        int [] cost = new int[n];
        int[] dp = new int[n];
        for(int i = 0; i<n; i++){
            dp[i] = Integer.MAX_VALUE;
            cost[i] = c.nextInt();
        }
        dp[0] = 0;
        for(int i = 0; i<n; i++){
            for(int j = 1; j<=k; j++) {
                if (i >= j) {
                    dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(cost[i] - cost[i - j]));
                }

            }
        }


        System.out.println(dp[n-1]);
    }

}


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

int main(){
  vector<char> N(4);
  for(int i=0; i<4; i++)
    cin >>N.at(i);
  if(N.at(0)==N.at(1)&&N.at(1)==N.at(2))
    cout <<"Yes" <<endl;
  else if(N.at(1)==N.at(2)&&N.at(2)==N.at(3))
    cout <<"Yes" <<endl;
  else
    cout <<"No" <<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

using i64 = int64_t;
using vi = vector<int>;

string s1,s2;
int n,m;

int a1[4048][26],a2[4048][26];

bool f(int len){
    set<vector<int>> st;

    for(int i=0;i<n;i++){
        // see s[i,i+len-1]
        if(i+len-1>=n) break;
        vector<int> tmp(26);
        rep(j,26) tmp[j] = a1[i+len][j] - a1[i][j];
        st.insert(tmp);
    }

    for(int i=0;i<m;i++){
        // see s2[i,i+len-1]
        if(i+len-1>=m) break;
        vector<int> tmp(26);
        rep(j,26) tmp[j] = a2[i+len][j] - a2[i][j];
        if(st.count(tmp)) return true;
    }
    return false;
}

int main() {
    cin >> s1 >> s2;
    n = s1.size();
    m = s2.size();

    for(int i=0;i<n;i++){
        for(int j=0;j<26;j++){
            if(s1[i]-'a' == j) a1[i+1][j] = a1[i][j] + 1;
            else a1[i+1][j] = a1[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<26;j++){
            if(s2[i]-'a' == j) a2[i+1][j] = a2[i][j] + 1;
            else a2[i+1][j] = a2[i][j];
        }
    }

    for(int len = min(n,m);len>=0;len--){
        if(f(len)){
            cout << len << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 4680
N, W = [int(x) for x in input().split()]
VW = [[int(x) for x in input().split()] for _ in range(N)]


dp = [0] * (W + 1)

for i in range(1, W + 1):
    tmp = 0
    for v, w in VW:
        if i < w:
            continue
        tmp = max(tmp, dp[i - w] + v)

    dp[i] = tmp

print(dp[W])





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

int main() {
  int s,w;
  cin>>s>>w;

  if(s<=w){cout<<"unsafe"<<endl;}
  else{cout<<"safe"<<endl;}
  
  return 0;
}


Measured memory_bytes: 3644
N = int(input())
a = list(map(int, input().split()))
a.sort()

minus_flag = 1
max_value = a[N - 1]
min_value = a[0]
ans = []

while a[minus_flag] <=  0 and minus_flag < N - 1:
    ans.append(str(max_value) + " " + str(a[minus_flag]))
    max_value = max_value - a[minus_flag]
    minus_flag += 1

plus_flag = minus_flag

while  plus_flag < N - 1:
    ans.append(str(min_value) + " " + str(a[plus_flag]))
    min_value = min_value - a[plus_flag]
    plus_flag += 1

print(max_value - min_value)
for i in range(len(ans)):
    print(ans[i])
print(str(max_value)  + " " + str(min_value))




Measured memory_bytes: 16592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, M, V, P;
ll ans;
vector<ll> A;
ll sum[105000];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> V >> P;
    A.resize(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    for(int i = 1; i <= N; i++) {
        sum[i] = sum[i-1] + A[i-1];
        //cerr << i << " " << sum[i] << endl;
    }
    /*
    for(int i = N - 1; i >= V; i--) {
        if(A[i] + M >= A[P-1]) ans++;
    }
    */
    ll ans = P;
    cerr << ans << endl;
    cerr << sum[N-P] << endl;
    for(ll i = N - P - 1; i >= 0; i--) {
        ll val = A[i] + M;
        if(val < A[N-P]) continue;
        /*
        auto itr = lower_bound(A.begin(), A.end(), val + 1);
        int index = distance(A.begin(), itr);
        if(index + P <= N) continue;
        */
        ll num = V - P;
        chmax(num, 0LL);
        //ll rest = (index + 1) * val - sum[index];
        //ll rest = (N - P) * val - sum[N - P + 1] + A[i];
        //cerr << i << " " << val << " " << index << " " << sum[index] << " " << rest << endl;
        ll rest = i * M;
        rest += (N - P - i) * val;
        rest -= sum[N-P+1] - sum[i+1];
        //cerr << i << " " << val << " " << num << " " << rest << endl;
        if(rest >= num * M) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int N;
    string S;
    cin >> N >> S;
    vector<int> sumR(N+1);
    for(int i=0; i<N; i++) sumR[i+1] = sumR[i] + (S[i] == 'R');
    int ans = 1e9;
    for(int i=0; i<=N; i++){
        int res = max(i-sumR[i], sumR[N]-sumR[i]);
        ans = min(ans, res);
    }
    cout << ans << endl;
    return 0;
}


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

int power(int n){
  long long sum = 1;
  for(int i = 1;i <= n;i++){
     sum = sum * i % 1000000007;
  }
  return sum;
}
int main(){
  int n;
  cin >> n;
  cout << power(n) << endl;
}


Measured memory_bytes: 3620
#include<cctype>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<cstdio>
#include<queue>
#include<ctime>
#define pprint(x) print(x),putchar(' ')
#define fprint(x) print(x),putchar('\n')
using namespace std;
//#define getchar() (SS == TT && (TT = (SS = BB) + fread(BB,1,1 << 15,stdin),TT == SS) ? EOF : *SS++)
char BB[1 << 15],*SS = BB,*TT = BB;
inline long long read()
{
	long long x = 0;int f = 1;
	char ch = getchar();
	for(;!isdigit(ch);ch = getchar())
		if(ch == '-')
			f = -1;
	for(;isdigit(ch);ch = getchar())
		x = x * 10 + (ch ^ 48);
	return x * f;
}
inline void print(long long x)
{
	if(x < 0)
	{
		putchar('-');
		x = -x;
	}
	char ch = x % 10 + '0';
	if(x > 9)
		print(x / 10);
	putchar(ch);
}
const int N = 200;
const long long INF = 1e15;
struct edge
{
	int to,nxt;
	long long cap;
}e[N * N << 1];
int head[N],cnt = 1;
void add(int u,int v,long long w)
{
	e[++cnt].to = v,e[cnt].cap = w,e[cnt].nxt = head[u];
	head[u] = cnt;
}
void add_edge(int u,int v,long long w)
{
	add(u,v,w),add(v,u,0);
}

int n,a[N];
int S,T;
long long sum,ans;
int dis[N];

bool BFS()
{
	memset(dis,-1,sizeof(dis));
	queue<int> q;
	while(!q.empty())
		q.pop();
	q.push(S),dis[S] = 0;
	while(!q.empty())
	{
		int u = q.front();q.pop();
		for(int i = head[u];i;i = e[i].nxt)
		{
			int v = e[i].to;
			if(!(~dis[v]) && e[i].cap > 0)
				dis[v] = dis[u] + 1,q.push(v);
		}
	}
	return ~dis[T];
}
long long DFS(int u,long long exp)
{
	if(u == T)
		return exp;
	long long flow = 0,tmp = 0;
	for(int i = head[u];i;i = e[i].nxt)
	{
		int v = e[i].to;
		if(dis[v] == dis[u] + 1 && e[i].cap > 0)
		{
			tmp = DFS(v,min(e[i].cap,exp));
			exp -= tmp;
			flow += tmp;
			e[i].cap -= tmp;
			e[i ^ 1].cap += tmp;
			if(!exp)
				break;
		}
	}
	return flow;
}
long long Dinic()
{
	long long maxflow = 0;
	while(BFS())
		maxflow += DFS(S,INF);
	return maxflow;
}

int main()
{
	n = read();
	for(int i = 1;i <= n;i++)
	{
		a[i] = -read();
		if(a[i] > 0)
			sum += a[i];
	}
	for(int i = 1;i <= n;i++)
		for(int j = 2;i * j <= n;j++)
			add_edge(i,i * j,INF);

	S = n + 1,T = n + 2;
	for(int i = 1;i <= n;i++)
		if(a[i] > 0)
			add_edge(S,i,a[i]);
		else
			add_edge(i,T,-a[i]);

	ans = sum - Dinic();
	for(int i = 1;i <= n;i++)
		ans -= a[i];
	fprint(ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
long long x[N],d[N],z=INT_MAX,e,t;
int main()
{
	int n;
	scanf("%d%lld%lld",&n,&e,&t);
	for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
	for(int i=1,j=0;i<=n;i++)
	{
		while((x[i]-x[j+1])*2>t){z=min(z,d[j]-x[j+1]*2);j++;} 
		d[i]=min(z+x[i]*2,d[j]+t);
	}
	printf("%lld\n",d[n]+e);
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int num, k;
        cin >> num >> k;
        vector<int> G(n, 0);
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            G[v-1] = 1;
        }
        cout << G[0];
        for (int j = 1; j < n; j++) {
            cout << " " << G[j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#define T 1001
#define M 1000000007
#define E e[x][i]
#define S e[x].size()
using namespace std;
typedef long long ll;
ll func(int);
int N,s,t;
string n[T];
vector<int> e[T];
 
main(){
  cin>>N;
  for(int i=0;i<N;i++) cin>>n[i];
  for(int i=0;i<N-1;i++) cin>>s>>t,e[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
}

ll func(int x){
  ll res=0;
  if(!S){
    if(n[x]=="E") return 1;
    return 2;
  }
  if(n[x][0]=='E'){
    res++;
    for(int i=0;i<S;i++) res*=func(E);
    if(n[x]=="E?") res++;
  }
  else if(n[x][0]=='A'){
    for(int i=0;i<S;i++) res+=func(E);
    if(n[x]=="A?") res++;
  }else{
    res++;
    for(int i=0;i<S;i++) res*=(1+func(E));
    if(n[x]=="R") res--;
  }
  return res%M;
}

Measured memory_bytes: 1356
a=input()
a=a.split(' ')
A,B=int(a[0]),int(a[1])
flag=1
for i in range(1,1001):
    if (int(i*0.08)==A and int(i*0.1)==B):
        flag=0
        print(i)
        break;
if flag:
    print(-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

long long M  = 1e9+7;

int calc(int a, int b, int x){
    int ans = ((a*x)/b) - a*((x/b));
    return ans;
} 
signed main(){
    fast;
    int a,b,n; cin >> a >> b >> n;
    int l = 0 , r = n;
    int ans = 0;
    int val = 0;
    cout << calc(a,b,min(b-1,n))  << endl;
    // while(l<=r){
    //     cout << calc(a,b,l) << endl;
    //     l++;
    // }
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>

using namespace std;

const int MaxN = 1e5;
typedef long long LL;
typedef unsigned long long ULL;

LL n,x,ans,sum;
LL a[MaxN + 5];
int main(){
	ans = 0;
	sum = 0;
	cin >> n >> x;
	for(int i  = 1;i <= n;i++){
		cin >> a[i];
	}
	sort(a+1,a+1+n);
	for(int i = 1;i <= n;i++){
		x -= a[i];
		if(x >= 0 && i != n){
			ans++;
		}
		else if(i == n && x != 0){
			break;
		}
		else if(x < 0){
			break;
		}
		else if(i == n && x==0){
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int x,y,i,c,t;
    bool f=false;
    cin>>x>>y;
    for(i=0;i<=x;i++)
    {
        c=i*2;
        t=(x-i)*4;
        if(c+t==y)
        {
            f=true;
            break;
        }
    }
    if(f)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
void solve()
{
	ll a,b;
	cin>>a>>b;
	cout<<a*b;
}
int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

constexpr int si = 600;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    vvec<int> g(N);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vec<int> col(N,1),ans(Q,0);
    int K = (Q+si-1)/si;
    vvec<int> T(K),V(K);
    for(int i=0;i<Q;i++){
        int t,v;
        cin >> t >> v;
        v--;
        int k = i/si;
        T[k].push_back(t);
        V[k].push_back(v);
    }
    
    auto solve = [&](int k,vec<int>& T,vec<int>& V){
        int n = T.size();
        vec<int> check(N,0);
        for(int i=0;i<n;i++) check[V[i]] = 1;
        vvec<int> tree(N);
        vec<int> val = col;
        vec<int> vis(N,-1);
        
        auto comp = [&](auto& self,int cur,int par,int s)->void{
            if(s!=cur){
                val[s] += val[cur];
                val[cur] = 0;
            }
            for(auto& e:g[cur]) if(e!=par && !check[e] && col[e]) self(self,e,cur,s);
        };

        for(int i=0;i<N;i++) if(!check[i] && col[i] && val[i]) comp(comp,i,-1,i);

        vec<int> need(N,0);
        for(int i=0;i<N;i++) need[i] = (check[i] || val[i]);

        auto dfs = [&](auto& self,int cur,int par,int s,vec<int>& v)->void{
            vis[cur] = s;
            for(auto& e:g[cur]) if(e!=par){
                if(need[e]) v.push_back(e);
                else if(col[e]) self(self,e,cur,s,v);
            }
        };

        for(int i=0;i<N;i++) if(!check[i] && val[i]){
            vec<int> v;
            dfs(dfs,i,-1,i,v);
            if(v.size()==1){
                val[v[0]] += val[i];
                val[i] = 0;
                need[i] = false;
            }else{
                for(auto& x:v) tree[i].push_back(x);
            }
        }

        for(int i=0;i<N;i++) if(check[i]){
            for(auto& e:g[i]){
                if(check[e]) tree[i].push_back(e);
                else if(need[vis[e]]) tree[i].push_back(vis[e]);
            }
        }

        auto dfs2 = [&](auto& self,int cur,int par,int q)->void{
            ans[q] += val[cur];
            for(auto& e:tree[cur]) if(e!=par && col[e]) self(self,e,cur,q);
        };

        for(int i=0;i<n;i++){
            if(T[i]==1){
                col[V[i]] ^= 1;
                val[V[i]] += (col[V[i]]? 1:-1);
            }else dfs2(dfs2,V[i],-1,k*si+i);
        }
    };

    for(int k=0;k<K;k++) solve(k,T[k],V[k]);

    for(int i=0;i<Q;i++) if(ans[i]) cout << ans[i] << "\n";
}


Measured memory_bytes: 14432
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char B[1 << 15], *S = B, *T = B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 100010
const char word1[5] = {'d', 'r', 'e', 'a', 'm'};
const char word2[5] = {'e', 'r', 'a', 's', 'e'};
char s[maxn];
int main()
{
//	setfile();
	scanf("%s", s); R int len = strlen(s);
	for (R int pos = 0; pos < len; )
	{
//		printf("%c\n", s[pos] );
		if (s[pos] == 'd')
		{
			R bool flag = 1;
			for (R int i = 0; i < 5 && flag; ++i)
				if (s[pos + i] != word1[i])
					flag = 0;
			if (!flag) {puts("NO"); return 0;}
			if (s[pos + 5] == 'e' && s[pos + 6] == 'r')
			{
				if (s[pos + 7] == 'a') pos += 5;
				else pos += 7;
			}
			else pos += 5;
		}
		else if (s[pos] == 'e')
		{
			R bool flag = 1;
			for (R int i = 0; i < 5 && flag; ++i)
				if (s[pos + i] != word2[i])
					flag = 0;
			if (!flag) {puts("NO"); return 0;}
			if (s[pos + 5] == 'r') pos += 6;
			else pos += 5;
		}
		else {puts("NO"); return 0;}
	}
	puts("YES");
	return 0;
}


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

void solve(long long A, long long B, long long C, long long X, long long Y)
{
    long long res = 1000000009;

    for (long long k = 0; k <= max(X, Y); k++)
    {
        res = min(res, 2 * C * k + A * max(0LL, X - k) + B * max(0LL, Y - k));
    }

    cout << res << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
#define base 139
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case %lld: ", ++c)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
const ll N=2010;
ll n, x, y, dis[N], vis[N], res[N];
vector<ll>adj[N];
void bfs(ll s, ll f)
{
    queue<ll>q;
    q.push(s);
    vis[s]=f;
    dis[s]=0;
    while(!q.empty())
    {
        ll u=q.front();
        q.pop();
        for(auto v:adj[u])
        {
            if(vis[v]!=f)
            {
                vis[v]=f;
                q.push(v);
                dis[v]=dis[u]+1;
                res[dis[v]]++;
            }
        }
    }
}
int main()
{
    in1(n);
    in2(x,y);
    adj[x].pb(y);
    adj[y].pb(x);
    for(int i=1;i<n;i++)
    {
        adj[i].pb(i+1);
        adj[i+1].pb(i);
    }
    for(int i=1;i<=n;i++)
        bfs(i, i);
    for(int i=1;i<n;i++)
        printf("%lld\n", res[i]/2);

    return 0;
}

/*

*/


Measured memory_bytes: 384
#include <stdio.h>
 #include <string.h>
 char s[101];
 int main(void) {
 scanf("%s", s);
 int res = 0;
 int n = strlen(s);
 for (int i = 0; i < n; i++) {
 if (s[i] != s[n - 1 - i]) res++;
 }
 printf("%d\n", res / 2);
 }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

ll dp[101010][13];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int n = S.size();
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        int c;
        if(S[i] == '?') c = -1;
        else c = S[i] - '0';
        for(int j=0;j<10;j++){
            if(c != -1 && c != j) continue;
            for(int k=0;k<13;k++){
                dp[i+1][(j+k*10)%13] += dp[i][k];
            }
        }
        for(int j=0;j<13;j++) dp[i+1][j] %= MOD;
    }
    cout << dp[n][5] << endl;
}


Measured memory_bytes: 10704
import numpy as np

def dfs(a, c, a_lis, i, total_c):
    global min_c
    if len(a_lis.shape) > 1:
        total_sum = np.sum(a_lis, axis=0)
        for j in range(len(total_sum)):
            if total_sum[j] < x:
                break
            if j == len(total_sum)-1:
                min_c.append(total_c)
    if i >= n:
        return 0
    dfs(a, c, np.vstack((a_lis, a[i])), i+1, total_c + c[i])
    dfs(a, c, a_lis, i+1, total_c)


n,m,x = map(int,input().split())
li = []
c = []
for i in range(n):
    li.append(list(map(int,input().split())))
    c.append(li[i].pop(0))
a = np.array(li)
total_sum = np.sum(a, axis=0)
for i in total_sum:
    if i < x:
        print(-1)
        exit()
min_c = []
dfs(a, c, np.zeros(m), 0, 0)
print(min(min_c))

Measured memory_bytes: 27320
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;

int n;
vector<int> adj[MaxN + 1];

int dfs(int u, int fa)
{
	int w = 0;
	for (int v : adj[u])
		if (v != fa)
			w ^= dfs(v, u) + 1;
	return w;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; ++i)
	{
		int u = getint(), v = getint();
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	cout << (dfs(1, 0) ? "Alice" : "Bob");
	cout << endl;

	return 0;
}

Measured memory_bytes: 10496