akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c, std::vector<long long> d)
{
    for (size_t i = 0; i < N; i++)
    {
        ll checkpoint;
        ll dist = LLONG_MAX;
        for (size_t j = 0; j < M; j++)
        {
            if ((abs(a[i] - c[j]) + abs(b[i] - d[j])) < dist)
            {
                dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                checkpoint = j + 1;
            }
        }

        cout << checkpoint << endl;
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &a[i]);
        scanf("%lld", &b[i]);
    }
    std::vector<long long> c(M);
    std::vector<long long> d(M);
    for (int i = 0; i < M; i++)
    {
        scanf("%lld", &c[i]);
        scanf("%lld", &d[i]);
    }
    solve(N, M, std::move(a), std::move(b), std::move(c), std::move(d));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PAIR pair<double, double>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
#define PI acos(-1)
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int n;
	cin >> n;
	cout << modpow(n, 3) << endl;
	return 0;
}


Measured memory_bytes: 256
def solve(i, j):
    if i == 0:
    	return True
    if j < n and A[0] <= i <= sum(A[j:]):
        x = solve(i-A[j], j+1)
        if x:
        	return x
        y = solve(i, j+1)
        if y:
        	return y

n = input()
A = sorted(map(int, raw_input().split()))
p = input()
m = map(int, raw_input().split())

for k in m:
	if solve(k, 0):
		print "yes"
	else:
		print "no"

Measured memory_bytes: 6448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
str s;
int main(){
    cin>>s;
    if(s=="A"){s="T";}
    else if(s=="C"){s="G";}
    else if(s=="G"){s="C";}
    else if(s=="T"){s="A";}
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll H, W, K; cin >> H >> W >> K; K--;
    ll mod = 1e9+7;
    vvll dp(H+1, vll(W));
    dp[0][0] = 1;
    rep(i, H) {
        rep(j, W) {
            rep(k, 1<<(W-1)) {
                bool ok = true;
                rep(l, W-2) {
                    if (((k >> l) & 1) && ((k >> (l+1)) & 1)) {ok = false; break;}
                }
                if (ok) {
                    if ((j >= 1 && ((k >> (j-1)) & 1))) dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]) % mod;
                    else if ((j <= W-2 && ((k >> j) & 1))) dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod;
                    else dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod;
                }
            }
        }
    }
    cout << dp[H][K] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(void)
{
    int N;
    cin >> N;
    string ans;
    if (N <= 999)
        ans = "ABC";
    else
        ans = "ABD";
    cout << ans;
    return 0;
}


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

ll R, C, dp[1005][1005];
char A[1005][1005];

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

	cin >> R >> C;
	for (ll i = 0; i < R; i++) {
		for (ll j = 0; j < C; j++) {
			cin >> A[i][j];
		}
	}

	for (ll i = 0; i < R; i++) {
		if (A[i][0] == '.') dp[i][0] = 1;
		else break;
	}
	for (ll i = 0; i < C; i++) {
		if (A[0][i] == '.') dp[0][i] = 1;
		else break;
	}

	for (ll i = 1; i < R; i++) {
		for (ll j = 1; j < C; j++) {
			if (A[i][j] == '.') {
				dp[i][j] = dp[i-1][j] + dp[i][j-1];
				dp[i][j] %= 1000000007;
			}
		}
	}

	cout << dp[R-1][C-1] << "\n";

	return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

const int CN = 1e3+3;
const int INF = 0x3f3f3f2f;

int n,m,f[1<<12],c[CN],d[CN];
bool bit[CN];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		memset(bit, 0, sizeof(bit));
		
		int bi; scanf("%d%d",&c[i],&bi);
		while(bi--){
			int x; scanf("%d",&x); bit[x] = true;
		}
		
		for(int j=1;j<=n;j++) (d[i] <<= 1) |= bit[j];
	}
	
	memset(f, 0x3f,sizeof(f));
	f[0] = 0;
	for(int ps = 0; ps < (1<<n); ps++){
		for(int i=1;i<=m;i++){
			int s = ps | d[i];
			f[s] = min(f[s], f[ps] + c[i]);
		}
	}
	
	printf("%d",f[(1 << n) - 1] < INF ? f[(1 << n) - 1] : -1);
} 

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        h: usize,
        w: usize,
        v: [chars; h]
    }
    let d = 1000000007;
    let mut tab: Vec<Vec<usize>> = vec![vec![0; w]; h];
    tab[0][0] = 1;
    for i in 1..w {
        if v[0][i] == '#' {
            break;
        }
        tab[0][i] = tab[0][i - 1];
    }
    for i in 1..h {
        if v[i][0] == '#' {
            break;
        }
        tab[i][0] = tab[i - 1][0];
    }
    for i in 1..h {
        for j in 1..w {
            if v[i][j] == '#' {
                continue;
            }
            tab[i][j] = (tab[i][j - 1] + tab[i - 1][j]) % d;
        }
    }
    println!("{}", tab[h - 1][w - 1]);
}


Measured memory_bytes: 16636
#include <iostream>

using namespace std;

int dict[500];
int f[500][500];

int n, m;

void solve(int a, int depth)
{
    if (depth == 3) return;

    dict[a] = 1;

    for(int i = 0; i < n; ++i) if (f[a][i] == 1) solve(i, depth + 1);
}

int main(void)
{
    while (cin >> n >> m, n && m) {
        dict[0] = 1;

        for(int i = 0; i < m; ++i) {
            int a, b; cin >> a >> b;
            a--; b--;
            f[a][b] = f[b][a] = 1;
        }

        solve(0, 0);

        int ans = 0;

        for(int i = 1; i < n; ++i) {
            if (dict[i]) ans++;
        }

        cout << ans << endl;

        for(int i = 0; i < 500; ++i) {
            dict[i] = 0;
            for(int j = 0; j < 500; ++j) f[i][j] = 0;
        }
    }
}

Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
 
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            if(i*j==n)
            {
                cout<<"Yes\n";
                exit(0);
            }
 
        }
    }
 
 
   cout<<"No\n";
    exit(0);
}

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

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

  int n;
  cin >> n;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

long long f[10000001] = {0};

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

    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            f[j]++;
        }
    }

    long long ans = 0;
    for (long long i = 1; i <= n; i++) {
        ans += (i * f[i]);
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 79852
from collections import Counter

n = int(input())
aaa = list(map(int, input().split()))
cnt = Counter(aaa)
aaa_unique = list(set(aaa))
aaa_unique.sort(reverse=True)

rs = sum(aaa)

ans = 0
for a in aaa_unique:
    rs -= a * cnt[a]
    ans += cnt[a]
    if a > 2 * rs:
        break
print(ans)


Measured memory_bytes: 21180
#include <iostream>
using namespace std;
int main(){
  int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
  cout << x2-(y2-y1) << " " <<  y2-(x1-x2) << " " << x1-(y2-y1) << " " << y1-(x1-x2) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vector<vector<T>> read(int n, int m)
{
	vector<vector<T>> v;
	REP(i,n) { v.push_back(read<T>(m)); }
	return v;
}

template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }
template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

void solve();
int main() { solve(); return 0; }

/// template end ///



void solve()
{
	READ(int, N);
	auto IDs = read<string>(N);

	bool locked = true;
	READ(int, M);
	REP(i, M)
	{
		READ(string, id);
		if (count(ALLOF(IDs), id))
		{
			locked = !locked;
			write( string(locked ? "Closed" : "Opened") + string(" by ") + id);
		}
		else
		{
			write("Unknown " + id);
		}
	}
}

Measured memory_bytes: 1228
h, w, d = gets.split.map(&:to_i)
a = Array.new(h) { gets.split.map(&:to_i) }
q = gets.to_i
l, r = Array.new(q) { gets.split.map(&:to_i) }.transpose
t = Array.new(h * w)

h.times do |i|
  w.times { |j| t[a[i][j]] = [i, j] }
end

cum = [0]
d.times { cum << 0 }

(d + 1).upto(r.max) do |i|
  p_x, p_y = t[i - d]
  n_x, n_y = t[i]
  cum[i] = cum[i - d] + (p_x - n_x).abs + (p_y - n_y).abs
end

l.zip(r).each do |bl, br|
  puts cum[br] - cum[bl]
end

Measured memory_bytes: 32116
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#define rep(i,j,k) for(register int i = j; i <= k; i++) 
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define fi first
#define se second
//#define P pair<ull,ull>
//#define PP pair<int,pair<int,int> >
//#define mp(a,b) make_pair(a,b)
#define ll long long
#define ull unsigned long long
using namespace std;
 
inline int read() { 
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int N = 205, p = 998244353;
ll A[N], B[N]; 
inline int Q(int n) { return 1 + n + n * (n-1) / 2; }
inline int Pow(ll x,int t) { 
	int ret = 1;
	while( t ) { 
		if( t & 1 ) ret = ret * x % p;
		x = x * x % p, t >>= 1;
	} return ret;
}

int main() {
	int n = read();
	rep(i,1,n) A[i] = read(), B[i] = read();
	ll ans = (Pow(2,n) - Q(n) + p) % p; 
	
	rep(i,1,n) { 
		rep(j,i+1,n) { 
			ll X = A[i] - A[j], Y = B[i] - B[j]; int cnt = 2; 
			rep(k,1,n) { 
				if( k == i || k == j ) continue;
				if( X * B[k] - Y * A[k] - B[j] * X + A[j] * Y != 0 ) continue;
				if( k < j ) break;
				cnt++; 
			}
			ans = (ans - Pow(2,cnt) + p) % p;
			ans = (ans + Q(cnt)) % p;
		}
	}
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 256
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))


(princ (if (<= (read) (loop repeat (read) sum (read)))
		 "Yes"
		 "No"))


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

#define mkp make_pair
#define fst first
#define snd second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef set<pll>::iterator spit;
const int MAXN = 100010;

template<typename T> inline T read() {
	T x(0), 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;
}

int n, cnt, ans;
ll p[3000];
bool np[3000];
multiset<ll> m;
set<pll> S;

inline void getprime() {
	for(int i = 2; i < 3000; i++) {
		if(!np[i]) p[++cnt] = i;
		for(int j = 1; j <= cnt && p[j]*i < 3000; j++) {
			np[p[j]*i] = true;
			if(i % p[j] == 0) break;
		}
	}
}

int main() {

	n = read<int>();
	getprime();
	for(int i = 1; i <= n; i++) {
		ll s = 1, r = 1;
		ll x = read<ll>();
		for(int j = 1; x != 1 && j <= cnt; j++) {
			if(x % p[j] == 0) {
				int e = 0;
				while(x % p[j] == 0) {
					x /= p[j];
					e++;
				}
				e %= 3;
				if(e == 1) s *= p[j], r *= p[j]*p[j];
				else if(e == 2) s *= p[j]*p[j], r *= p[j];
			}
		}
		s *= x;
		if(x != 1) {
			ll L = 1, R = 100000;
			while(L < R) {
				ll mid = (L+R+1)>>1;
				if(mid*mid <= x) L = mid;
				else R = mid-1;
			}
			if(L*L != x) r *= x*x;
			else r *= L;
		}
		//printf("%lld %lld\n", s, r);
		S.insert(s>r?mkp(s, r):mkp(r, s));
		m.insert(s);
	}

	for(spit i = S.begin(); i != S.end(); i++) {
		ll val1 = i->fst, val2 = i->snd;
		if(val1 == 1 && val2 == 1) {
			ans++;
			continue;
		}
		ll c1 = m.count(val1), c2 = m.count(val2);
		ans += max(c1, c2);
	}

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int , int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti set <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll ans[k+1]={0};
    for(ll i=0;i<k;i++)
    {
        if(ans[i]==0)
        {
            for(ll j=0;j<n;j++)
            {
                if((i+a[j])<=k)
                {
                    ans[i+a[j]]=1;
                }
            }
        }
    }
    if(ans[k]==1)
        cout<<"First";
    else
        cout<<"Second";
}

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

int main() {
	double L;
	cin >> L;
	L = (L / 3);
	//cout << (L * L * L) << endl;
	printf("%.8f", L * L * L);
}

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

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

    int write;
    int times;
    if (a != b) {
        if (a > b) {
            times = a;
            write = b;
        } else {
            times = b;
            write = a; 
        }
    } else {
        write = a;
        times = a;
    }
    for (int i = 0; i < times; i++){
        cout << write;
    }
    cout << endl;
}

Measured memory_bytes: 384
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [a, b] <- map strToInt . words <$> getLine
    -- 出力
    putStrLn $ if (a + b) >= 10 then "error" else show (a + b)


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define sync ios::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL);

int main(){
  sync;
  int n;
  cin >> n;
  long long a[n],ans=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    a[i]=(a[i]-(i+1));
  }
  sort(a,a+n);
  long long b=(n%2==0)?(a[n/2]+a[n/2-1])/2:a[n/2];
  for(int i=0;i<n;i++){
    ans+=(abs(a[i]-b));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>

const double PI(3.141592653589);

int main()
{
	int a, b, result;
	char op;
	while (std::cin >> a >> op >> b)
	{
		if (op == '?')
		{
			break;
		}
		switch (op)
		{
		case '+':
			result = a + b;
			break;
		case '-':
			result = a - b;
			break;
		case '*':
			result = a * b;
			break;
		case '/':
			result = a / b;
			break;
		default:
			result = 0;
			break;
		}
		std::cout << result << '\n';
	}
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  bool c[8];
  for (int i = 0; i < 8; ++i) {
    c[i] = false;
  }
  int N;
  cin >> N;
  int over = 0;
  for (int i = 0; i < N; ++i) {
    int rate;
    cin >> rate;
    if (rate >= 3200) {
      over++;
    } else {
      c[rate/400] = true;
    }
  }
  int colored = 0;
  for (int i = 0; i < 8; ++i) {
    if (c[i]) {
      colored++;
    }
  }
  int maxi, mini;
  mini = colored > 0 ? colored : 1;
  maxi = colored + over;
  cout << mini << " " << maxi << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define vpii vector<pair<int,int> >
#define X first
#define Y second
#define fr(i,a,n) for(int i=a;i<n;i++)
#define mod 1000000007
#define fi ios_base::sync_with_stdio(false);cin.tie(NULL);

vector< vector<ll> >  v;
vector<ll> dum;
ll n,m,q,ans=0,qq;
void rec(ll i, ll a)
{
    if(i==n)
    {
        ll sum=0;
        for(int k=0;k<qq;k++)
        {
            if(dum[v[k][1]-1] - dum[v[k][0]-1] == v[k][2])
            sum+=v[k][3];
        }
        ans=max(ans,sum);
        return;
    }
    fr(j,a,m+1)
    {
        dum.pb(j);
        rec(i+1,j);
        dum.pop_back();
    }
}


int main()
{
    
    cin>>n>>m>>q;
  // int i=0;
    qq=q;
    vector<ll> vv(4,0);
    while(q--)
    {
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        vv[0]=a;
        vv[1]=b;
        vv[2]=c;
        vv[3]=d;
       
        v.pb(vv);
   // i++;
    }
   
    
    rec(0,1);
    cout<<ans;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long int a[n],sum[n+1]={0},ssum=0,ans=1e10,ar,k;
  sum[0]=0;
  for(int i=0;i<n;i++) {
    cin >> a[i];
    sum[i+1]+=(sum[i]+a[i]);
    ssum+=a[i];
  }
 for(int i=1;i<n;i++){
    ar=ssum-sum[i];
    k=abs(ar-sum[i]);
    ans=min(ans,k);
 }
 cout << ans <<endl;
}


Measured memory_bytes: 3328
#include <iostream>
#define MAX_N 10
#define MAX_S 1001
using namespace std;

int main() {
  long long dp[MAX_N][MAX_S];
  for (int i = 0; i < MAX_N; i++) {
    for (int j = 0; j < MAX_S; j++) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  for (int i = 0; i <= 100; i++) {
    for (int j = 9; j >= 1; j--) {
      for (int k = 0; k <= 1000; k++) {
	if (k - i >= 0) dp[j][k] += dp[j - 1][k - i];
      }
    }
  }

  while (true) {
    int n, s;
    cin >> n >> s;
    if (n == 0 && s == 0) return 0;

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

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define ms(a,v) memset(a,v,sizeof a)
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor a.k.a. OakenSh1eld
 *
 * */
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k; cin>>n>>k;
	vector<bool> dp(k+1, 0);
	vector<int> stones (n);
	for(int i=0; i<n; ++i) cin>>stones[i];
	dp[0] = 0;
	for(int i=1; i<=k; ++i){
		for(int c: stones) if (i>=c) {
			if(!dp[i-c]) dp[i] = 1;
	}	}
	cout<<(dp[k] ? "First" : "Second");
	return 0;
}


Measured memory_bytes: 256
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>

typedef long long llong;
using namespace std;


int main() {
	int n;
	int w[1000];
	int sorted_w[1000];
	bool has_arrived[1000] = { false };
	int pos_save[10010];
	llong sumcost = 0;
	int min_cycle;
	int min_all;
	int origin_pos;
	int move_pos;
	int num_cycle;
	int sum_cycle;
	int plan_inside, plan_outside;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		sorted_w[i] = w[i];
		pos_save[w[i]] = i;
	}
	sort(sorted_w, sorted_w + n);
	min_all = sorted_w[0];


	for (int i = 0; i < n; i++) {
		min_cycle = w[i];
		sum_cycle = w[i];
		origin_pos = i;
		move_pos = pos_save[sorted_w[i]];
		num_cycle = 0;
		while (move_pos != origin_pos&&!has_arrived[i]) {
			num_cycle++;
			min_cycle = min(min_cycle, w[move_pos]);
			sum_cycle += w[move_pos];

			has_arrived[move_pos] = true;
			move_pos = pos_save[sorted_w[move_pos]];
			
		}
		if (num_cycle) {

			plan_inside = num_cycle * min_cycle + sum_cycle - min_cycle;
			plan_outside = 2 * min_all + 2 * min_cycle + min_all * num_cycle + sum_cycle - min_cycle;
			sumcost += min(plan_inside, plan_outside);
		}
		has_arrived[i] = true;
	}
	cout << sumcost << endl;
	return 0;
}



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

const int MAXN = 20;
int arr[1 << MAXN];

main() {
    int n;
    cin >> n;
    multiset<int> s;
    for (int i = 0; i < (1 << n); ++i) {
        cin >> arr[i];
        s.insert(arr[i]);
    }
    auto it = s.end();
    it--;
    vector<int> now;
    now.push_back(*it);
    s.erase(it);
    for (int i = 0; i < n; ++i) {
        vector<int> n2;
        for (auto elem : now) {
            auto it = s.lower_bound(elem);
            if (it == s.begin()) {
                cout << "No";
                return 0;
            }
            it--;
            n2.push_back(*it);
            s.erase(it);
        }
        for (auto elem : n2) {
            now.push_back(elem);
        }
    }
    cout << "Yes";
    return 0;
}


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

int main() {
  int a, b, c;
  int choho = 0;
  int hishi = 0;
  while(scanf("%d,%d,%d", &a, &b, &c) != EOF) {
    if(a == b) hishi++;
    if(a*a + b*b == c*c) choho++;
  }

  cout << choho << endl;
  cout << hishi << endl;
  return 0;
}

Measured memory_bytes: 0
from sys import stdin
 
n = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
print(*A)
for i in range(1, n):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j = j-1
    else:
        A[j+1] = v
        print(*A)


Measured memory_bytes: 5980
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    vector<ll> x;
    x.push_back(a*c);
    x.push_back(a*d);
    x.push_back(b*c);
    x.push_back(b*d);

    if(a < 0 and b > 0){
        x.push_back(0*c);
        x.push_back(0*d);
    }
    if(c < 0 and d > 0){
        x.push_back(0*a);
        x.push_back(0*b);
    }

    sort(x.rbegin(), x.rend());

    ll ans = x[0];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
import sys
input=lambda: sys.stdin.readline().rstrip()
import heapq
n,m,s=map(int,input().split())
s=min(s,2499)
E=[]
for _ in range(m):
  E.append(tuple(map(int,input().split())))
CD=[]
for _ in range(n):
  CD.append(tuple(map(int,input().split())))
nn=n*2500
edge=[[] for i in range(nn)]
for u,v,a,b in E:
  u-=1
  v-=1
  for i in range(a,2500):
    edge[u*2500+i].append(b*10**6+v*2500+i-a)
    edge[v*2500+i].append(b*10**6+u*2500+i-a)
for i in range(n):
  c,d=CD[i]
  for j in range(2500):
    if j+c<2500:
      edge[i*2500+j].append(d*10**6+i*2500+j+c)

def dijkstra_heap(s):
  d=[float("inf")]*nn
  used=[True]*nn
  d[s]=0
  used[s]=False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while edgelist:
    minedge=heapq.heappop(edgelist)
    minedge_cost=minedge//(10**6)
    minedge_v=minedge%(10**6)
    if not used[minedge_v]:
      continue
    d[minedge_v] = minedge_cost
    used[minedge_v] = False
    for e in edge[minedge_v]:
      e_cost=e//(10**6)
      e_v=e%(10**6)
      if used[e_v]:
        heapq.heappush(edgelist,e+minedge_cost*10**6)
  return d
D=dijkstra_heap(s)
for i in range(1,n):
  ans=D[i*2500]
  for j in range(1,2500):
    ans=min(ans,D[i*2500+j])
  print(ans)


Measured memory_bytes: 104348
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int n = scan.nextInt();
        int x = scan.nextInt();
        int[] l = new int[n];
        int[] a = new int[n + 1];
        int b = 0;
        int c = 0;
        for(int i = 0; i < n; i++){
            l[i] = scan.nextInt();
            b += l[i];
            if(b <= x){
                c++;
            }
        }
        System.out.println(c + 1);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>

#define N 36

typedef struct{
  char mark[N];
  int value[N];
}Card;

Card BubbleSort(Card , int);
Card SelectionSort(Card , int);

int main() {
  Card data[3];
  int n, i, j;
  
  scanf("%d", &n);
  
  for (i = 0; i < n; i++) {
    scanf("%*c%c%d", &data[0].mark[i], &data[0].value[i]);
  }

  data[1] = BubbleSort(data[0], n);
  data[2] = SelectionSort(data[0], n);

  for (i = 0; i < n; i++) {
    printf("%c%d", data[1].mark[i], data[1].value[i]);
    if (i == n-1) printf("\n");
    
    else printf(" ");
  }

  printf("Stable\n");

  for (i = 0; i < n; i++) {
    printf("%c%d", data[2].mark[i], data[2].value[i]);
    if (i == n-1) printf("\n");
    
    else printf(" ");
  }

  for (i = 0; i < n; i++) {
    if (data[1].mark[i] != data[2].mark[i]) {
      printf("Not stable\n");
      break;
    }
    else if (i == n-1) printf("Stable\n");
  }


  return 0;
}

Card BubbleSort(Card c, int n) {
  int i, j, tempn;
  char tempc;
  
  for (i = 0; i < n; i++) {
    for (j = n-1; j > i; j--) {
      if (c.value[j] < c.value[j-1]) {
	tempn = c.value[j];
  tempc = c.mark[j];
	c.value[j] = c.value[j-1];
  c.mark[j] = c.mark[j-1];
	c.value[j-1] = tempn;
  c.mark[j-1] = tempc;
      }
    }
  }
  return c;
}


Card SelectionSort(Card c, int n) {
  int i, j, minj, tempn;
  char tempc;
  
  for (i = 0; i < n; i++) {
    minj = i;
    for (j = i; j < n; j++) {
      if (c.value[j] < c.value[minj]) {
	      minj = j;
      }
    }
    if (minj != i) {
      tempn = c.value[i];
      tempc = c.mark[i];
      c.value[i] = c.value[minj];
      c.mark[i] = c.mark[minj];
      c.value[minj] = tempn;
      c.mark[minj] = tempc;
    }
  }
  return c;
}



Measured memory_bytes: 2120
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;

vector <LL> v[405][405];
LL n,m;
LL vis[405],p[405];
LL e[405][405],ans[405][405],a[405][405];

LL dfs(LL u){
	if(!u) return 1;
	for(LL i = 1;i <= n + n;i ++){
		if(e[u][i] <= 0) continue;
		if(vis[i]) continue;
		vis[i] = 1;
		if(dfs(p[i])){
			p[u] = i; p[i] = u;
			return 1;
		}
	}
	return 0;
}

void get_match(LL x){
	memset(p,0,sizeof(p));
	for(LL i = 1;i <= n;i ++){
		memset(vis,0,sizeof(vis));
		dfs(i);
	}
	for(LL i = 1;i <= n;i ++){
		e[i][p[i]] --; e[p[i]][i] --;
		ans[x][i] = v[i][p[i]][v[i][p[i]].size() - 1];
		v[i][p[i]].pop_back();
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= m;j ++){
			cin >> a[i][j];
			e[i][(a[i][j] - 1) / m + 1 + n] ++;
			e[(a[i][j] - 1) / m + 1 + n][i] ++;
			v[i][(a[i][j] - 1) / m + 1 + n].push_back(a[i][j]);
		}
	}
	for(LL i = 1;i <= m;i ++) get_match(i);
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= m;j ++){
			cout << ans[j][i] << (j == m ? '\n' : ' ');
		}
	}
	for(LL i = 1;i <= m;i ++){
		for(LL j = 1;j <= n;j ++){
			for(LL k = 1;k <= n;k ++){
				if(ans[i][j] < ans[i][k]) swap(ans[i][j],ans[i][k]);
			}
		}
	}
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= m;j ++){
			cout << ans[j][i] << (j == m ? '\n' : ' ');
		}
	}
	return 0;
}
//

Measured memory_bytes: 6912
S = str(input())
slist = list(S)
l = len(slist)
a = 0
nlist = []
while a < l-2:
  num = ""
  num += slist[a] + slist[a+1] + slist[a+2]
  num = int(num)
  nlist.append(abs(num-753))
  a+=1
nlist.sort()
print(nlist[0])

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = [int(e) for e in lines[0].split(" ")][0]
    d = [int(e) for e in lines[1].split(" ")]

    return (n, d)


def solve(n, d):

    s = 0
    for i in range(n-1):
        for j in range(i+1, n):
            s = s + d[i]*d[j]

    return s


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
def li():
    return [int(x) for x in input().split()]


N = int(input())
D = [li() for _ in range(N)]

maxzoro = 0
zoro = 0

for i in range(len(D)):
    a, b = D[i][0], D[i][1]
    if a == b:
        zoro += 1
        maxzoro = max(maxzoro, zoro)
    else:
        zoro = 0

print('Yes' if maxzoro >= 3 else 'No')

Measured memory_bytes: 9200
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void reconstruct(vector<int> preorder, vector<int> inorder, vector<int>& postorder) {
    if (preorder.size() == 0) return;
    if (preorder.size() == 1) {
        postorder.push_back(preorder[0]);
        return;
    }

    int root = preorder[0];
    int left = distance(inorder.begin(), find(inorder.begin(), inorder.end(), root));
    reconstruct(vector<int>(preorder.begin() + 1, preorder.begin() + left + 1),
                vector<int>(inorder.begin(), inorder.begin() + left),
                postorder);
    reconstruct(vector<int>(preorder.begin() + left + 1, preorder.end()),
                vector<int>(inorder.begin() + left + 1, inorder.end()),
                postorder);
    postorder.push_back(root);
}

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

    int n;
    cin>>n;
    vector<int> preorder(n), inorder(n), postorder;
    rep(i, n) cin>>preorder[i];
    rep(i, n) cin>>inorder[i];
    reconstruct(preorder, inorder, postorder);
    rep(i, n - 1) cout<<postorder[i]<<" ";
    cout<<postorder[n - 1]<<endl;
}


Measured memory_bytes: 3220
#include <iostream>
#include <stdio.h>
#include <vector>

typedef long long ll;

#define debug(x) cerr << #x << ": " << x << "\n";
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

//fixed << setprecision(8)

using namespace std;

#define ll long long
#define vec vector
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll n,ans=0;
	string s;

	vector<pair<ll, ll>> a(4);

	cin >> a[0].first >> a[0].second >> a[1].first >> a[1].second;

	ll addx = a[1].first - a[0].first;
	ll addy = a[1].second - a[0].second;

	a[2] = { a[1].first - addy,a[1].second + addx };
	a[3] = { a[2].first - addx,a[2].second - addy };

	cout << a[2].first << " " << a[2].second << " " << a[3].first << " " << a[3].second;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;



int main(void)
{
	//変数の宣言
	int a,b,c,d,e,m;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	int dummy;



	//データの読み込み


	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&k);
//	scanf_s("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&k);

/*	for(i=0;i<n;i++){
//		scanf("%d",&s[i]);
		scanf_s("%d",&s[i]);
	}*/

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	



	//	printf("計算部分終了\n");

	//出力
	if(e-a>k){
		printf(":(");
	}else{
		printf("Yay!");
	}


/*	for(i=0;i<b+w;i++){
		printf("%lld %lld\n",black[i],white[i]);
	}*/


	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
char  S,T,U;
int A1,A2,A3;
int total=0;
int main() {
		cin>>S>>T>>U;
		if(S=='1')total+=1;
		if(U=='1')total+=1;
		if(T=='1')total+=1;

		cout<<total<<endl;
		return 0;
}


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

using namespace std;

int main(){
    string s;
    cin >> s;
    int a[2] = {0,0};
    for(int i = 0; i < s.size(); i++){
        if (s[i] == '0') {
            a[0]++;
        }else{
            a[1]++;
        }
    }
    int ans = 2 * min(a[0], a[1]);
    cout << ans << "\n";
}

Measured memory_bytes: 512
#include <stdio.h>
#define ll long long int
#include <queue>
#include <vector>
#include <iostream>
using namespace std;

int main(){
int k,total,i;
total=0;
double hasil;
cin>>k;
for(i=k;i>0;i--){
if(i%2!=0){
total+=1;
}
}
hasil=(double)total/k;
cout<<hasil;
}

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

int dp[1010][1010];

int main(){
  int H, W;
  cin >> H >> W;
  dp[0][0] = 1;
  string field[1010];
  rep(i,H) cin >> field[i];
  
  rep(h,H)rep(w,W){
    if(h+1 < H && field[h+1][w] == '.'){
      dp[h+1][w] += dp[h][w];
      dp[h+1][w] %= MOD;
    }
    if(w+1 < W && field[h][w+1] == '.'){
      dp[h][w+1] += dp[h][w];
      dp[h][w+1] %= MOD;
    }
    if(field[h][w] == '#') dp[h][w] = 0;
  }
  
  cout << dp[H-1][W-1] % MOD << endl;
}

Measured memory_bytes: 5248
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto PI = 3.14159265359;
	auto A = RD;
	auto B = RD;
	auto H = RD;
	auto M = RD;

	auto t = H*60+M;
	double[2] h, m;
	auto a = t % 720;
	auto b = t % 60;
	if (a < 360)
	{
		auto x = sin(PI*(a/360.0))*A;
		auto y = cos(PI*(a/360.0))*A;
		h = [x, y];
	}
	else
	{
		auto x = sin(PI*((a-360)/360.0))*A;
		auto y = cos(PI*((a-360)/360.0))*A;
		h = [-x, -y];
	}
	if (b < 30)
	{
		auto x = sin(PI*(b/30.0))*B;
		auto y = cos(PI*(b/30.0))*B;
		m = [x, y];
	}
	else
	{
		auto x = sin(PI*((b-30)/30.0))*B;
		auto y = cos(PI*((b-30)/30.0))*B;
		m = [-x, -y];
	}

	auto d = [h[0]-m[0], h[1]-m[1]];
	writefln(FMT_F, sqrt(d[0]^^2 + d[1]^^2));
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 3044
($k, $s) = split(/ /, <>);
$cnt = 0;
for ($x = 0; $x <= $k; $x++){
	for ($y = 0; $y <= $k; $y++){
		last if(($s - $x - $y) < 0);
		next if(($s - $x - $y) > $k);
		$cnt++;
	}
}
print "$cnt\n";


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

using ll = long long int;
using P = std::pair<int, int>;

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

constexpr int siz = 6400;

int main()
{
    int h, w;

    std::cin >> h >> w;

    std::vector<std::vector<int>> dat(h + 1, std::vector<int>(w + 1));

    rep(i, h)
    {
        rep(j, w)
        {
            std::cin >> dat[i][j];
        }
    }

    rep(i, h)
    {
        rep(j, w)
        {
            int b;
            std::cin >> b;
            dat[i][j] = std::abs(dat[i][j] - b);
        }
    }

    std::vector<std::vector<std::vector<bool>>> dp(h + 1, std::vector<std::vector<bool>>(w + 1, std::vector<bool>(siz + 1, 0)));

    dp[1][1][dat[1][1]] = 1;

    rep(i, h)
    {
        rep(j, w)
        {
            for (int k = 0; k <= siz; ++k)
            {
                for (int l = -1; l <= 1; l += 2)
                {
                    int z = std::abs(k + l * dat[i][j]);

                    if (z <= siz)
                        dp[i][j][k] = dp[i][j][k] | dp[i - 1][j][z] | dp[i][j - 1][z];
                }
            }
        }
    }

    for (int i = 0; i <= siz; ++i)
    {
        if (dp[h][w][i] > 0)
        {
            std::cout << i << std::endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 8804
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
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; }



int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	int h, w, k; cin >> h >> w >> k;
	
	int table[h][w] = {};
	int table2[h][w] = {};

	char c;
	
	rep(i,h){
		rep(j,w){
			cin >> c;
			table[i][j] = (c == '#');
		}
	}
	
	int ans = 0;
	
	rep(i,(1 << (h+w))){
		int cnt = 0;
		rep(i,h) rep(j,w) table2[i][j] = table[i][j];
		rep(j,(h+w)){ // [0,h): 縦操作, 
			if(i & (1 << j)){
				if(j < h) rep(k,w) table2[j][k] = 0; 
				else rep(k,h) table2[k][j-h] = 0;

			}
		}
		rep(i,h) rep(j,w) if(table2[i][j] == 1) cnt++;
		if(cnt == k) ans++;
		//cout << cnt << endl;
	}
	cout << ans << endl;

	
	
	return 0;
}


Measured memory_bytes: 3636
a = gets.split(" ")
$n = a[0].to_i
$x = a[1].to_i
$m = a[2].to_i

if $n < 10**6 
  ans = 0
  a = $x
  $n.times do |i|
    ans += a 
    a = (a * a) % $m
  end
  puts ans
else
  cycle = [$x]
  cycle_sum = $x
  s1 = Hash.new
  s1[$x] = 0

  element = $x
  $first_in_cycle = 0
  $m.times do |i|
    element = (element * element) % $m 
    if (s1.include?(element))
      $first_in_cycle = s1[element]
      $first_in_cycle.times do |j|
        cycle_sum -= cycle[j]
      end
      break
    end
    cycle.push(element)
    cycle_sum += element
    s1[element] = i+1
  end
  # byebug
  q = ($n - $first_in_cycle) / (cycle.length - $first_in_cycle)
  r = ($n - $first_in_cycle) % (cycle.length - $first_in_cycle)
  ans = q * cycle_sum
  r.times do |i|
    ans += cycle[$first_in_cycle + i]
  end
  $first_in_cycle.times do |i|
    ans += cycle[i]
  end
  puts ans
end


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

using namespace std;
using ll = long long;

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

    int a, b, c;
    cin >> a >> b >> c;

    if(a == b && c != a || b == c && a != b || c == a && b != c) printf("Yes\n");
    else printf("No\n");

    return 0;
}

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N, M;
  int sum = 0;
  cin >> N >> M;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }
  sort(all(A));
  if (A[N-M] < (sum+4*M-1)/(4*M)) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// #include "boost/math/common_factor.hpp" // gcd, lcm
using namespace std;

// #define int long long

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int n;
  int s;
  array<int, 1000000> a;
  // cin >> s;
  vector<int> v;
  cin >> n;

  for (int i = 0; i < n; ++i) {
    int l;
    cin >> l;
    v.push_back(l);
    num = max(num, l);
  }

  int sum = accumulate(v.begin(), v.end(), 0);
  if (2 * num < sum) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define vi vector <int>
#define all(v) v.begin(),v.end()

//ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y,ll M){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	ll n; cin>>n;
	string s; cin>>s;
	ll cc = 0;
	forn(i,n) if(s[i]=='1') cc++;
	ll p1 = cc+1, p2 = cc-1;
	if(p2<0) p2 = p1;
	ll curr1 = 0, curr2 = 0;
	for(int i=n-1;i>=0;i--)
	{
		if(s[i]=='0') continue;
		ll h = n-1-i;
		curr1 += powerm((ll)2,h,p1);
		curr1 %= p1;
		if(p2==0) continue;
		curr2 += powerm((ll)2,h,p2);
		curr2 %= p2;
		//cout<<i<<':'<<curr1<<':'<<curr2<<endl;
	}
	ll pre[n+10];
	pre[0] = 0;
	forn1(i,n)
	{
		ll f = __builtin_popcountll(i);
		pre[i] = pre[i%f] + 1;
	}
	//forn1(i,n) cout<<pre[i]<<' '; cout<<endl;
	//cout<<curr1<<":"<<curr2<<endl;
	forn(i,n)
	{
		if(s[i]=='0')
		{
			ll r = n-1-i;
			ll d = curr1 + powerm((ll)2,r,p1);
			d %= p1;
			cout<<1 + pre[d]<<'\n';
		}
		else
		{
			if(p2==0){ cout<<0<<'\n'; continue; }
			ll r = n-1-i;
			ll d = curr2 - powerm((ll)2,r,p2) + p2;
			d %= p2;
			cout<<1 + pre[d]<<'\n';
		}
		
	}

	return 0;
}


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

int main(){
  int n,m,ans=0;
  cin>>n>>m;
  vector<int> c(m);
  for(int i=0; i<n; i++){
    int k; cin>>k;
    for(int j=0; j<k; j++){
      int a; cin>>a;
      c[a-1]++;
    }
  }
  for(int i=0; i<m; i++) if(c[i]==n) ans++;
  cout<<ans;
}

Measured memory_bytes: 256