akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

int main()
{
    unsigned long long c = 0;
    int n; std::cin >> n;
    std::vector<int> h(n);
    int m = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
        m = std::max(m, h[i]);
    }

    for (int i = 1; i <= m; i++) {
        bool b = false;
        for (int j = 0; j < n; j++) {
            if (h[j] >= i) {
                b = true;
            } else {
                if (b) {
                    c++;
                }
                b = false;
            }
        }
        if (b) {
            c++;
        }
    }

    std::cout << c << std::endl;
    return 0;
}


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

int main(){
	int n;
	long double t[100][8];
	long double ab, cd;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 8; j++){
			cin >> t[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		ab = (t[i][1]-t[i][3])*(t[i][4]-t[i][6]);
		cd = (t[i][5]-t[i][7])*(t[i][0]-t[i][2]);
		if(t[i][0] == t[i][2]){
			if(t[i][4] == t[i][6]){
				cout << "YES" << endl;
			}
			else{
				cout << "NO" << endl;
			}
		}
		else if(t[i][1] == t[i][3]){
			if(t[i][5] == t[i][7]){
				cout << "YES" << endl;
			}
			else{
				cout << "NO" << endl;
			}
		}
		else if(ab == cd){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 1244
#include <cstdio>
#include <vector>
#include <algorithm>

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

  std::vector<int> s(1e5+3);
  for (int i=0; i<N; ++i) {
    int a;
    scanf("%d", &a);
    ++s[a];
    ++s[a+1];
    ++s[a+2];
  }

  printf("%d\n", *std::max_element(s.begin(), s.end()));
  return 0;
}


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

long double func(int i,int j,int k, int m, int n, int a, int b, int c, vector<vector<vector<long double> > > &A)
{
	
	if(i+2*j+3*k > m)
	{
	return 0;
}
if(i>a+b+c)
return 0;
	if(j>b+c)
	{
	return 0;
	}
	if(k>c)
	{
	return 0;
	}
	if(A[i][j][k]!=-1)
	return A[i][j][k];
	else {
	long double t= (func(i+1,j,k,m,n,a,b,c,A)*(i+1))/(i+1+j+k);
	if(i!=0)t+=(func(i-1,j+1,k,m,n,a,b,c,A)*(j+1))/(i+j+k);
	if(j!=0)t+=(func(i,j-1,k+1,m,n,a,b,c,A)*(k+1))/(i+j+k);
	//cout<<i<<"^"<<j<<"^"<<k;
	//cout<<"@"<<t<<endl;
	A[i][j][k]=t;
	return t;
	}
}
int main()
{
	int n;
	cin>>n;
	int a=0,b=0,c=0;
	for(int i=0;i<n;i++)
	{
		int t;
		cin>>t;
		if(t==1)a++;
		else if(t==2)b++;
		else if(t==3)c++;
	}
	int m=a+2*b+3*c;
	//cout<<a<<b<<c<<m<<endl;
	int tot=a+b+c;
	vector<vector<vector<long double> > > A(tot+1, vector<vector<long double> > (b+c+1,(vector<long double> (c+1,-1))));
	//cout<<"#";
	A[a][b][c]=1;
	//cout<<"&";
	A[0][0][0]=func(0,0,0,m,n,a,b,c,A);
	//cout<<"*";
	long double ans[m+1]={0};
	for(int i=0;i<=a+b+c;i++)
	{
		for(int j=0;j<=b+c;j++)
		{
			for(int k=0;k<=c;k++)
			{
	//			if(A[i][j][k]!=-1)cout<<i<<j<<k<<A[i][j][k]<<"%";
				if(i+j+k==0)continue;
				if(i+2*j+3*k>m)continue;
				ans[i+2*j+3*k]+=(A[i][j][k]*n)/(i+j+k);
			}
		}
	}
	//cout<<A[3][0][0]<<"!";
	long double an=0;
	for(int i=1;i<=m;i++)
	{
	//	cout<<ans[i]<<" ";
	an+=ans[i];
	}
	cout<<setprecision(19)<<an;
	return 0;
}


Measured memory_bytes: 431488
//shara's here
#include <bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
int main(){
	int n,m,c;
    cin>>n>>m>>c;
    int b[m]; int a[n][m]; int mysum=0;
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		mysum=0;
		for(int j=0;j<m;j++){
			mysum+=a[i][j]*b[j];
		}
		if(mysum+c>0)ans++;
	}
	cout<<ans;






return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// ==================================================
using i64 = int64_t; using u64 = uint64_t;
#define rep(i,a,b) for(i64 i=(i64)(a),i_max=(i64)(b);i<i_max;i++)
#define repn(i,n) rep(i,0,n)
#define din(t, ...) t __VA_ARGS__;_din(__VA_ARGS__)
#define stlv(t,n) vector<t> n
#define stls(t,n) set<t> n
void _din() {} void dout() { cout << endl; }
template <typename T, typename ... Args> inline void _din(T& head, Args& ... rest) { cin >> head; _din(rest...); }
template <typename T, typename ... Args> inline void dout(T head, Args ... rest) { cout << head; if (sizeof...(rest)) cout << ' '; dout(rest...); }
template <typename T>inline void vsortg(vector<T>& v) { sort(v.begin(), v.end(), greater<T>()); }
template <typename T>inline void vsortl(vector<T>& v) { sort(v.begin(), v.end(), less<T>()); }
template <typename T> inline T nmax(T f1, T f2) { return max(f1, f2); }
template <typename T, typename ... Args> inline T nmax(T first, Args ... rest) { return nmax(first, nmax(rest...)); }
template <typename T> inline T nmin(T f1, T f2) { return min(f1, f2); }
template <typename T, typename ... Args> inline T nmin(T first, Args ... rest) { return nmin(first, nmin(rest...)); }

int main()
{
	map<char, char> m = { {'A','T'},{'T','A'},{'C','G'},{'G','C'} };
	din(string, s);
	dout(m[s[0]]);
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
module Main (main) where

import Control.Monad
-- import Control.Monad.Trans.State
import Data.ByteString (ByteString)
-- import qualified Data.ByteString.Unsafe as B
import qualified Data.ByteString.Char8 as C8
import Data.Bool
-- import Data.Bits
-- import Data.Char
-- import Data.List
import Data.Maybe

main :: IO ()
main = do
  [h, w] <- readInts
  xs <- replicateM h readStrings
  let line = replicate (w+2) '#'
  putStrLn line
  mapM_ putStrLn $ solve w $ concat xs 
  putStrLn line

solve :: Int -> [String] -> [String]
solve w = map wrap
  where
    wrap s = concat ["#", s, "#"]

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readStrings :: IO [String]
readStrings = map C8.unpack . C8.words <$> C8.getLine

-- readPair :: IO (Int, Int)
-- readPair = head . unfoldr readT <$> C8.getLine
--   where
--     readT = runStateT $
--       (,) <$> StateT (C8.readInt . C8.dropWhile isSpace)
--           <*> StateT (C8.readInt . B.unsafeTail)

-- readDate :: IO [Int]
-- readDate = map (fst . fromJust . C8.readInt) . concatMap (C8.split '/') . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | ByteString ByteString
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)       = bool "No" "Yes"  b
  show (YESNO b)       = bool "NO" "YES"  b
  show (AB b)          = bool "B"  "A"    b
  show (Number i)      = show i
  show (String s)      = s
  show (ByteString bs) = C8.unpack bs
  show (Compare o)     = ordering "<" "=" ">" o
  show (Compare2 o)    = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

-- | k 番目の文字に関数 f を適用する
indexMapBS :: Int -> (Char -> Char) -> ByteString -> ByteString
indexMapBS k f s = C8.concat [s1, C8.singleton (f c), s3]
  where
    (s1, s2) = C8.splitAt (k-1) s
    c = C8.head s2
    s3 = C8.tail s2

Measured memory_bytes: 1020
N,K = map(int, input().split())
H = list(map(int, input().split()))

dp = [0 for _ in range(N)]

for i in range(N):
    if i == 0:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + abs(H[i]-H[i-1])
        for k in range(2,min(K,i)+1):
            dp[i] = min(dp[i-k] + abs(H[i]-H[i-k]),dp[i])

print(dp[N-1])


Measured memory_bytes: 56544
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
        int cnt = 0;

	for(int i = a; i <= b; i++ ){
		if(c % i == 0){
			cnt += 1;

			
		}
		
	}
	System.out.println(cnt);
  }
	


}

Measured memory_bytes: 26216
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int X[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K; cin >> K;

    cout << X[K-1] << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
import sys
import itertools

def main():
    N, M, Q = map(int, input().split())
    ABCD = [[int(_) for _ in input().split()] for i in range(Q)]
    value_range = list(range(1, M+1))
    seq_list = list(itertools.combinations_with_replacement(value_range, N))

    max_score = 0
    for i_seq in seq_list:
        score = 0
        for a, b, c, d in ABCD:
            if (i_seq[b-1] - i_seq[a-1]) == c:
                score += d

        max_score = max(max_score, score)

    print(max_score)
    return

if __name__ == '__main__':
    main()
    sys.exit(0)

Measured memory_bytes: 84592
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e18;
const ll inf=1e18;
const long double eps=1e-8;
const double pi=acos(-1);
#define __int128 ll
int main(){
    TB

    ll aa,bb,cc;
    cin>>aa>>bb>>cc;
    __int128 a=aa,b=bb,c=cc;
    __int128 z=a*b;
    __int128 y=(c-a-b);
    ll k=y;
    if(k<=(ll)(-1e5)){
        cout<<"No\n";
        return 0;
    }
    y=y*y;
    z=z*4;
    //deg(z)deg(y)
    if(y>z){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

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

    if (n < 10) {
        cout << r + (10 - n) * 100 << endl;
    } else {
        cout << r << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	int n;
	
	while(cin >> n && n){
		int v = 1000 - n;
		int ret = 0;
		
		ret += v / 500;
		v -= (v / 500) * 500;
		
		ret += v / 100;
		v -= (v / 100) * 100;
		
		ret += v / 50;
		v -= (v / 50) * 50;
		
		ret += v / 10;
		v -= (v / 10) * 10;
		
		ret += v / 5;
		v -= (v / 5) * 5;
		
		ret += v;
		cout << ret << endl;
	}
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	int r, d, x;cin >> r >> d >> x;

	REP(i, 10){
		x = r * x - d;
		cout << x << endl;
	}

	return 0;
}


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

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  throw invalid_argument("ctoi argument is not between '0' and '9'.");
}

int main() {
  long long A; // <= 10^15
  string B; // < 10
  cin >> A >> B;

  long long B100 = ctoi(B.at(0)) * 100 + ctoi(B.at(2)) * 10 + ctoi(B.at(3)) * 1;
  cout << A * B100 / 100 << endl;
  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        long[] r = new long[n];
        long[] c = new long[n];
        for (int i = 0; i < n; i++) {
            r[i] = Long.parseLong(scan.next());
            c[i] = Long.parseLong(scan.next());
        }
        scan.close();

        long[][] dp = new long[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i != j) {
                    dp[i][j] = Long.MAX_VALUE;
                }
            }
        }
        for (int i = 0; i < n - 1; i++) {
            dp[i][i + 1] = r[i] * c[i] * c[i + 1];
        }

        for (int i = 2; i < n; i++) {
            for (int j = 0; j < n - i; j++) {
                for (int k = j; k < j + i; k++) {
                    dp[j][j + i] = Math.min(dp[j][j + i], dp[j][k] + dp[k + 1][j + i] + r[j] * c[k] * c[j + i]);
                }
            }
        }

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

}


Measured memory_bytes: 26376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n;
    while(cin >> n)
    {
        ll sum = 0;
        for(int i = 1;i <= n;i++)
        sum += i;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;

int main() {
    string S,T,U;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    cin >> U;
    if(S == U){
        A = A-1;
    }
    else if(T == U){
        B = B-1;
    }
    cout << A <<" "<< B << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
ls = []
for i in range(n):
    x,l = map(int,input().split())
    ls.append([x-l,l+x])
    
ls = sorted(ls, key=lambda item: item[1])
ans = n

for i in range(1,n):
    if ls[i][0] < ls[i-1][1]:
      ls[i][1] = ls[i-1][1]
      ans -=1
        
print(ans)

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<int> B(N);
    for (int i = 0; i < N; i++) cin >> B[i];
    vector<int> C(N);
    for (int i = 0; i < N - 1; i++) cin >> C[i];

    int ans = B[A[0] - 1];
    for (int i = 1; i < N; i++) {
        int prev_food = A[i - 1];
        int food = A[i];
        ans += B[food - 1];
        if (A[i - 1] == A[i] - 1) {
            ans += C[prev_food - 1];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>

using namespace std;

int main(int argc, char *argv[])
{
	int N, L;
	int a[205];

	cin >> N >> L;
	int s1 = 0;
	for (int i = 0; i < N; i++) {
		a[i] = L + (i + 1) - 1;
		s1 += a[i];
	}
	int ans = 0, t = INT_MAX;
	for (int i = 0; i < N; i++) {
		int s2 = 0;
		for (int j = 0; j < N; j++) {
			if (i != j) {
				s2 += a[j];
			} 
		}
		int b = abs(s1 - s2);
		if (b < t) {
			t = b;
			ans = s2;
		}
	}

	cout << ans << "\n";
	return 0;
}

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

#define ll long long
const int N=2e5+9;

vector<int>adj[N];
int n,m;
bool vis[N];
void dfs(int u){
    vis[u]=1;
    for(auto v:adj[u]){
        if(vis[v]==1) continue;
        dfs(v);
    }
}

int main(){

    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            dfs(i);
            ans++;
        }
    }
    cout<<max(0LL,ans-1)<<endl;

}








Measured memory_bytes: 11976
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	x -= a;
	x %= b;
	cout << x << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    int X, t;
    cin >> X>> t;
    cout << max(X - t, 0);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>

using namespace std;

int main(void) {

	int N, K;

	cin >> N >> K;
	string S;

	cin >> S;

	if (S[K - 1] == 'A') { S[K-1] = 'a'; }
	else if (S[K - 1] == 'B') { S[K - 1] = 'b'; }
	else if (S[K - 1] == 'C') { S[K - 1] = 'c'; }

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

int main(){
	
	int n;
	
	while(true){
		
		cin >> n;
		if(n == 0){
			break;
		}
		
		int ans = 1000000;
		
		for(int i = 0; i <= 100; i++){
			for(int j = 0; j <= 1000; j++){
				if(i * i * i + j * j > n){
					break;
				}
				ans = min(ans, i + j + n - i * i * i - j * j);
			}
		}
		
		cout << ans << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <array>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>

using namespace std;

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

#define inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

int main(void) {
	string w; cin >> w;
	array<int, 'z'+1> cnt = {};
	for(char c: w){
		cnt[c]++;
	}
	for(auto x:cnt){
		if(x%2 != 0) 
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <vector>
using namespace std;

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

int main(void){
    int h, w;
    char field[55][55];
    cin >> h >> w;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> field[i][j]; 
        }
    }
    int dx[8] = {1, 1, 0, -1, -1, -1, 0,1};
    int dy[8] = {0, 1, 1, 1, 0, -1,-1,-1};
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(field[i][j] == '.'){
                int cnt = 0;
                for(int k=0; k<8; k++){
                    int nx = j + dx[k], ny = i + dy[k];
                    if(nx >= 0 && nx < w && ny >= 0 && ny < h && field[ny][nx] == '#'){
                        cnt++;
                    }
                }
                cout << cnt;
            }else{
                cout << "#";
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  vector<ll> x(N, 0);
  vector<ll> y(N, 0);
  vector<ll> z(N, 0);
  REP(i, N){
    cin >> x[i] >> y[i] >> z[i];
  }
  vector<ll> xyz(N, 0);
  ll ans = 0;
  for(ll i = -1; i <= 1; i += 2){
    for(ll j = -1; j <= 1; j += 2){
      for(ll k = -1; k <= 1; k += 2){
        ll res = 0;
        REP(l, N){
          xyz[l] = i*x[l] + j*y[l] + k*z[l];
        }
        sort(xyz.begin(), xyz.end(), greater<ll>());
        REP(l, M){
          res += xyz[l];
        }
        ans = max(ans, res);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int k,s;
  cin >> k >> s;

  int cnt = 0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      if(0 <= s-x-y && s-x-y <= k){
        cnt++;
      }
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod=1e9+7;
ll power(ll n,ll p){
    ll ans=1;
    while(p){
        if(p&1)ans=(ans*n)%mod;
        p>>=1;
        n=(n*n)%mod;
    }
    return ans;
}
ll ncr(ll n,ll r){
    ll num=1,dem=1;
    for(ll i=n;i>n-r;i--)num*=i,num%=mod;
    for(ll i=1;i<=r;i++)dem*=i,dem%=mod;
    dem = power(dem,mod-2);
    return (num*dem)%mod;
}
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n,a,b;cin>>n>>a>>b;
    ll ans = power(2,n) - 1 + mod;
    ans%=mod;

    ans = ans - ncr(n,a) ;
    ans+=mod;
    ans%=mod;

    ans = ans - ncr(n,b);
    ans+=mod;
    ans%=mod;

    cout<<ans;
}




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

using namespace std;

int main(){
  int N;
  cin >> N;
  
  vector<long> B(N-1);
  long sum = 0;
  bool flag = true;
  
  for(int i = 0; i < N-1; i++){
    cin >> B.at(i);
  }
  
  for(int i = 0; i < N-1; i++){
    if(i == 0) {
      sum += B.at(i);
      if(N > 2){
        if(B.at(i) > B.at(i+1)){
          sum += B.at(i+1);
        } else{
          sum += B.at(i);
        }
      }else{
        sum += B.at(i);
      }
    }
    else if(i == N-2) sum += B.at(i);
    else{
      if(B.at(i) > B.at(i+1)){
        sum += B.at(i+1);
        flag = true;
      } else if(B.at(i-1) == B.at(i)){
        sum += B.at(i);
        flag = false;
      } else {
      //else if(B.at(i) < B.at(i+1)){
        sum += B.at(i);
        flag = true;
      }
    }
  }
  
  cout << sum;
  
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  set<string> sset;
  string s, prev;
  while (n--) {
    cin >> s;
    if (prev.empty()) {
      sset.insert(s);
      prev = s;
    } else {
      if (prev[prev.size()-1] != s[0] or sset.count(s) > 0) {
        cout << "No\n";
        return 0;
      }
      sset.insert(s);
      prev = s;
    }
  }
  
  cout << "Yes\n";
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int INF = (1 << 30)-1;

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

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

  vector<int> maxA(n+1, -INF), maxAR(n+1, -INF);
  maxA[0] = 0;
  maxAR[n] = 0;
  // maxA : 1 ...
  for(int i = 1; i < n; i++) {
    maxA[i] = max(maxA[i-1], a[i-1]);
  }
  // maxAR : n-1 ...
  for(int i = n-1; i >= 0; i--) {
    maxAR[i] = max(maxAR[i+1], a[i]);
  }

  rep(i, n) {
    cout << max(maxA[i], maxAR[i+1]) << '\n';
  }
  return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
  int N,M;
  cin>>N>>M;
  vector<int> A(N);
  rep(i,N) {
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  vector<vector<int>> B(M, vector<int>(2));
  rep(i,M) {    
    int a,b;
    cin >> a>>b;
    B.at(i).at(0)=b;
    B.at(i).at(1)=a;  
  }
  sort(B.begin(),B.end());
  reverse(B.begin(),B.end());

  int j=0;
  rep(i,N){
    if(B.at(j).at(1)==0){
      j++;
    }
    if(j==M){
      break;
    }
    else if(A.at(i)<B.at(j).at(0)){
      A.at(i)=B.at(j).at(0);
      B.at(j).at(1)--;
    }
    
  }
    
  
  long ans=0;
  rep(i,N){
    ans+=A.at(i);
  }
  
  cout<<ans<<endl;
}



Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct Kruskal{

  struct UnionFind{
    int n;
    vector<int> r,p;
    UnionFind(){}
    UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
    int find(int x){
      return (x==p[x]?x:p[x]=find(p[x]));
    }
    bool same(int x,int y){
      return find(x)==find(y);
    }
    void unite(int x,int y){
      x=find(x);y=find(y);
      if(x==y) return;
      if(r[x]<r[y]) swap(x,y);
      r[x]+=r[y];
      p[y]=x;
    }
  };
  
  struct edge{
    int from,to,cost,used;
    edge(){}
    edge(int from,int to,int cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  int n;
  vector<edge> edges;

  Kruskal(){}
  Kruskal(int sz):n(sz){}
  
  void add_edge(int u,int v,int c){
    edges.emplace_back(u,v,c);
  }

  void input(int m,int offset=0){
    int a,b,c;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      add_edge(a+offset,b+offset,c);
    }
  }
  
  int build(){
    sort(edges.begin(),edges.end());
    UnionFind uf(n+1);
    int res=0;
    for(auto &e:edges){
      if(!uf.same(e.from,e.to)){
	res+=e.cost;
	uf.unite(e.from,e.to);
	e.used=1;
      }
    }
    return res;
  }
};
//END CUT HERE
int main(){
  int V,E;
  cin>>V>>E;
  Kruskal kruskal(V);
  kruskal.input(E);
  cout<<kruskal.build()<<endl;
  return 0;
}

/*
  verified on 2018/01/11
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A&lang=jp
*/



Measured memory_bytes: 4920
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int H,W,h,w;
    scanf("%d%d%d%d",&H,&W,&h,&w);
    int ans=(H-h)*(W-w);
    ans=max(ans,0);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string a, b;
    cin >> a >> b;
    int r = 0;
    
    for( int i = 0; i < a.size(); ++i ) {
        r = r * 10 + a[i] - '0';

    }
    for( int i = 0; i < b.size(); ++i ) {
        r = r * 10 + b[i] - '0';

    }

    bool flg = false;
    int c = 1;
    while( r >= c * c ) {
        if( r == c * c ) flg = true;
        ++c;

    }
    if( flg ) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int main(){
    int n; cin>>n;
    int X, Y, Z;
    cin>>X;
    vector<int> x(X);
    for(int i=0; i<X; i++) cin>>x[i];
    cin>>Y;
    vector<int> y(Y);
    for(int i=0; i<Y; i++) cin>>y[i];
    cin>>Z;
    vector<int> z(Z);
    for(int i=0; i<Z; i++) cin>>z[i];

    set<int> s;

    for(int i=0; i<Z; i++){
        s.insert(z[i]);
    }

    for(int i=0; i<X; i++){
        s.erase(x[i]);
    }

    for(int i=0; i<Y; i++){
        for(int j=0; j<Z; j++){
            if(y[i] == z[j]){
                s.insert(y[i]);
                break;
            }
        }
    }

    cout << s.size() << endl;
}


Measured memory_bytes: 3084
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,a,b,c;
  char s[LIMIT1];
  char t[LIMIT1];
  
  scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
  if(a+b>=k) result = min(a,k);
  else result = a-(k-a-b);
  printf("%lld",result);
  
  return 0;
}



Measured memory_bytes: 1728
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    int A[2][n];
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<n;j++)
            cin>>A[i][j];
    }
    int dp[2][105];
    dp[0][0] = A[0][0];
    dp[1][0] = A[0][0] + A[1][0];
    for(int j = 1; j < n; j++)
        dp[0][j] = dp[0][j-1] + A[0][j]; 
    for(int j = 1; j < n; j++)
    {
        dp[1][j] = max(dp[0][j], dp[1][j-1]) + A[1][j];
    }
    cout << dp[1][n-1] << endl;
    return 0 ; 
}

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

using namespace std;

using ll = long long;

struct _IN {
    _IN() {
        ios::sync_with_stdio(0);
        cin.tie(0);
    }
    template <typename T>
    operator T() const {
        T x;
        cin >> x;
        return x;
    }
    template <typename Container>
    void operator()(Container& c) {
        for (auto& x : c)
            cin >> x;
    }
} IN;

int main() {
    string T = IN;
    for (auto c : T) {
        if (c == '?')
            cout << 'D';
        else
            cout << c;
    }
    cout << endl;
}


Measured memory_bytes: 3744
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
using namespace std;

//const int mod=1000000007;
const int mod=998244353;



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int t,n,m,k,q,x,a,b,c,d;
    string s;
    cin>>s;
    if (s[2]==s[3]&&s[4]==s[5]) {
        cout<<"Yes\n";
    }
    else
        cout<<"No\n";
    return 0;
    
}
    


Measured memory_bytes: 256
N = int(input())  #スペース抜きの複数行,１文字ずつ
 
A = []
for i in range(1,N+1):
  if i % 3 == 0:
    A.append(0)
  elif i % 5 == 0:
    A.append(0)
  else:
    A.append(i)

print(sum(A))

Measured memory_bytes: 33860
object Main extends App {
  var get = readInt
  var list = readLine.split(" ").map(_.toInt)
  var sum = 0
  for(i <-0 to get-3){
    if(list(i+1)>list(i) && list(i+1)<list(i+2))
        sum = sum + 1
    if(list(i+1)<list(i) && list(i+1)>list(i+2))
       sum = sum + 1
  }
  println(sum)
}

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

def main():
    N, K, Q = map(int, input().split())

    t = [Q] * N

    for i in range(Q):
        t[int(input())-1] -= 1
    
    for i in range(N):
        if K - t[i] <= 0:
            print("No")
        else:
            print("Yes")

if __name__ == "__main__":
    main()

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

using namespace std;

#define endl "\n"
typedef long long int ll;

inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}

//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;

ll INF = 1e10;
ll MOD = 1e9+7;

int n;
bool a[22][22];
bool women[22];

int done[(1<<22)];

int base = 0;
ll pairs(int now){
    if(now == n) return 1;
    if(done[base] >= 0) return done[base];
    ll ans = 0;
    for(int j=0;j<n;++j){
        if(a[now][j] && !women[j]){
            women[j] = 1;
            base += 1<<j;
            ans += pairs(now+1);
            women[j] = 0;
            base -= 1<<j;
            if(ans >= MOD) ans-=MOD;
        }
    }
    done[base] = ans;
    //dbg(now); dbg(ans); dbgA(women, n); cerr<<endl;
    return ans;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("debug.txt", "w", stderr);
    #endif
    fastio();
    cin>>n;
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j){
            int x;
            cin>>x;
            a[i][j] = x==1;
        }
    memset(done, -1, sizeof(done));
    cout<<pairs(0);
    return 0;
}


Measured memory_bytes: 20020
H, W = map(int,input().split())
a = [list(input()) for i in range(H)]
ans1 = []

for i in range(H):
    sharp_cnt = a[i].count("#")
    if sharp_cnt != 0:
        ans1.append(a[i])

slicer = []
for j in range(W):
    sharp_cnt = 0
    for i in range(len(ans1)):
        if ans1[i][j] == "#":
            sharp_cnt +=1
    if sharp_cnt == 0:
        slicer.append(j)

del_cnt = 0
for i in slicer:
    i = i - del_cnt
    for j in ans1:
        del j[i]
    del_cnt += 1

for i in ans1:
    print(*i, sep = "")

Measured memory_bytes: 4596
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int t=1000;
    int res = t - n;
    if(res>0)
    {
        printf("%d\n",res);
    }
    else
    {
        for(;res<0;)
        {
            t = t + 1000;
            res = t-n;
        }
        printf("%d\n",res);
    }
}


Measured memory_bytes: 1736
n=int(input())
cost = [[] for _ in range(n)]
for _ in range(n-1):
    a, b, c = (int(x) for x in input().split())
    cost[a-1].append([b-1, c])
    cost[b-1].append([a-1, c])

dp = [0]*n

move = [0]
check = [-1]*n
check[0] = 0

while len(move):
    v = move.pop(0)
    for i, j in cost[v]:
        if check[i] == -1:
            dp[i] = dp[v] + j
            check[i] = 1
            move.append(i)
for i in dp:
    print(i%2)

Measured memory_bytes: 84256
#include <iostream>
#include <string>
#define llint long long
#define mod 1000000007

using namespace std;

int n, m, k;
string s;
llint dp[200005], dif[200005];
llint dp2[200005][2];

llint calc()
{
	int N = (n-1)/2;
	k = min(k, N);
	
	dif[0] = 1, dif[1] = mod-1;
	llint sum = 0;
	for(int i = 0; i <= N; i++){
		sum += dif[i], sum %= mod;
		dp[i] = sum;
		dif[i+1] += dp[i], dif[i+1] %= mod;
		dif[i+k+2] += mod - dp[i], dif[i+k+2] %= mod;
	}
	
	llint ret = 0;
	for(int i = 0; i <= k; i++){
		ret += (i+1)*2 * dp[N-i] % mod;
		ret %= mod;
	}
	return ret;
}

llint calc2()
{
	llint ret = 0;
	
	dp2[1][0] = 1;
	for(int i = 1; i < n; i++){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < 2; k++){
				if(j == 1 && k == 1) continue;
				dp2[i+1][k] += dp2[i][j], dp2[i+1][k] %= mod;
			}
		}
	}
	ret += dp2[n][0] + dp2[n][1], ret %= mod;
	
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 2; j++){
			dp2[i][j] = 0;
		}
	}
	dp2[1][1] = 1;
	for(int i = 1; i < n; i++){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < 2; k++){
				if(j == 1 && k == 1) continue;
				dp2[i+1][k] += dp2[i][j], dp2[i+1][k] %= mod;
			}
		}
	}
	ret += dp2[n][0], ret %= mod;
	
	return ret;
}

int main(void)
{
	cin >> n >> m;
	cin >> s;
	
	if(s[0] == 'B'){
		for(int i = 0; i < m; i++){
			if(s[i] == 'R') s[i] = 'B';
			else s[i] = 'R';
		}
	}
	
	bool diff = false;
	for(int i = 1; i < m; i++){
		if(s[i] != s[i-1]) diff = true;
	}
	if(!diff){
		cout << calc2() << endl;
		return 0;
	}
	if(n % 2){
		cout << 0 << endl;
		return 0;
	}
	
	k = n+1;
	int cnt = 0; bool flag = true;
	for(int i = 0; i < m; i++){
		if(s[i] == 'R') cnt++;
		else{
			if(cnt % 2) k = min(k, cnt);
			if(flag) k = min(k, cnt+1), flag = false;
			cnt = 0;
		}
	}
	k = (k-1)/2;
	
	cout << calc() << endl;
	
	return 0;
}

Measured memory_bytes: 4612
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (200'005)
#define MOD (1000000000l + 7l)
#define OO (1050000000)
#define OOL (1100000000000000000)

//global
ll a[N];

int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	ll n,l;
	cin >> n >> l;
	rep(i,0,n){
		cin >> a[i];
	}
	int pos = -1;
	rep(i,0,n-1){
		if(a[i]+a[i+1] >= l){
			pos = i;
			break;
		}
	}
	if(pos == -1) return cout << "Impossible\n",0;
	cout << "Possible\n";
	rep(ew,0,pos){
		cout << ew+1 << endl;
	}
	for (int i = n-2; i >= pos+1; --i){
		cout << i+1 << endl;
	}
	cout << pos+1;
	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	string n;
	cin >> n;

	rep(i, n.length()){
		if(n[i] == '7'){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    int X;
    cin >>N;
    cin >>X;
    int L[N];
    for(int i=0;i<N;i++)
        cin>>L[i];
    int D[N+2];
    D[0]=0;
    int x=0;
    while(D[x]<=X&&x<N+1){
        x++;
        D[x]=D[x-1]+L[x-1];
    }
    cout<<x;
}

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

struct edge{
    int to,id;
    edge(int to,int id):to(to),id(id){}
};

struct data{
    int pos,day,state;
    data(int pos,int day,int state)
        :pos(pos),day(day),state(state){}
};
const int INF=1001001001;
int N,M,E,S,T,R;
vector<edge>G[100];
int event[100];
int dist[100][101][1<<4];
int main(){
    cin>>N>>M>>E>>S>>T>>R;
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        G[a].push_back(edge(b,-1));
        G[b].push_back(edge(a,-1));
    }

    memset(event,-1,sizeof(event));
    for(int i=0;i<E;i++){
        int a,b,c;
        cin>>a>>b>>c;
        G[a].push_back(edge(b,i));
        G[b].push_back(edge(a,i));
        event[c]=i;
    }

    queue<data>que;
    fill_n(**dist,100*101*(1<<4),INF);
    que.push(data(S,0,(~event[S])?(1<<event[S]):0));
    dist[S][0][(~event[S])?(1<<event[S]):0]=0;


    while(que.size()){
        data d=que.front();que.pop();

        if(d.day<R){
            for(int i=0;i<G[d.pos].size();i++){
                edge &e=G[d.pos][i];
                if((~e.id)&&(d.state>>e.id&1)==0)continue;
                int nstate=d.state;
                if(~event[e.to])nstate|=1<<event[e.to];
                if(dist[e.to][d.day+1][nstate]<=dist[d.pos][d.day][d.state]+1)continue;
                dist[e.to][d.day+1][nstate]=dist[d.pos][d.day][d.state]+1;
                que.push(data(e.to,d.day+1,nstate));
            }
        }
        if(dist[S][0][d.state]>dist[d.pos][d.day][d.state]+1){
            dist[S][0][d.state]=dist[d.pos][d.day][d.state]+1;
            que.push(data(S,0,d.state));
        }
    }
    int mi=INF;
    for(int i=0;i<=R;i++){
        for(int j=0;j<(1<<E);j++){
            mi=min(mi,dist[T][i][j]);
        }
    }
    if(mi==INF)cout<<-1<<endl;
    else cout<<mi<<endl;
    return 0;
}

Measured memory_bytes: 1976
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF int(1e9+7)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

//int re[51][1000000];

ll sol(ll n, ll x) {
	if(x == 0) return 0;
	if(n == 0) return 1;
	//if(x < 1000000 && re[n][x]) return re[n][x];
	ll len = (1LL << (n + 2)) - 3;
	ll llen = (len-3) / 2, res;
	x--;
	if(x <= llen) {
		res = sol(n-1, x);
	} else {
		res = 1LL + sol(n-1, x - llen - 1) + (1LL << n) - 1;
	}
	//if(x < 1000000)
	//	re[n][x] = res;
	return res;
}

int main()
{
	IO_OP;
	
	ll n, x;
	cin >> n >> x;
	cout << sol(n, x) << endl;
	
}



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

 
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	int n;
	
	cin >> n;
	
	int a[n+5], sum = 0, mn = 1e8, sum2 = 0;
	for(int i = 0; i < n; i++) {cin >> a[i]; sum += a[i];}
	
	for(int i = 0; i < n-1; i++){
		sum2 += a[i];
		
		mn = min(mn, abs((sum-sum2)-sum2));
	}
	
	cout << mn << "\n";
	
	return 0;
}


Measured memory_bytes: 256