akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>

using namespace std;

#define sqr(x) x * x
#define all(x) x.begin(), x.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
typedef long long ll;

struct act {
	int a, b, c;
};

void solve() {
	int n;
	cin >> n;
	vector<act> acts(n);
	for (int i = 0; i < n; ++i)
		cin >> acts[i].a >> acts[i].b >> acts[i].c;
	vector<vector<int>> d(n, vector<int>(3));
	d[0][0] = acts[0].a, d[0][1] = acts[0].b, d[0][2] = acts[0].c;
	for (int i = 1; i < n; ++i) {
		d[i][0] = max(d[i - 1][1] + acts[i].a, d[i - 1][2] + acts[i].a);
		d[i][1] = max(d[i - 1][0] + acts[i].b, d[i - 1][2] + acts[i].b);
		d[i][2] = max(d[i - 1][0] + acts[i].c, d[i - 1][1] + acts[i].c);
	}
	cout << max(d.back()[0], max(d.back()[1], d.back()[2]));
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 6912
int a[100009];
int s[100009];
int
main()
{
  int i;
  int ai;
  int n,m;
  scanf("%d %d", &n, &m);
  for (i=0; i<m; i++) {
    scanf("%d", &a[i]);
  }

  ai = 0;
  s[0] = 1;
  if (a[ai] == 1) {
    s[1] = 0;
    ai ++;
  } else {
    s[1] = 1;
  }
  for (i=1; i<n; i++) {
    if (a[ai] == i) {
      s[i] = 0;
      s[i+1] = s[i-1];
      ai++;
    } else {
      s[i+1] = (s[i-1] + s[i]) % 1000000007;
    }
  }

  /*
  for (i=0; i<n+1; i++) {
    printf("%d\n", s[i]);
  }
  */
  printf("%d\n", s[n]);
  
}





Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
	IOS;
	int a,b;
	cin>>a>>b;
	for(int i=0;i<max(a,b);i++){
		cout<<min(a,b);
	}
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j;
  int res1=0,res2=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    j=i;
    res1=0;
    while(j!=0){
      j=j/10;
      res1++;
    }
    if((res1)%2==1)res2++;
  }
  printf("%d",res2);
  return 0;
}


Measured memory_bytes: 128
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n; cin>>n;
    vector<ll> v;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0)
        {
            ll cnt=0;
            while(n%i==0) n=n/i, cnt++;
            v.push_back(cnt);
        }
    }
    if(n!=1) v.push_back(1);
    ll ans=0;
    for(int i=0;i<v.size();i++){
        ll val=1;
        ll j=2;
        while(1)
        {
           if(val+j>v[i]) break;
           val+=j;
           j++;
        }
        ans+=(j-1);
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3656
# input
O = input()
E = input()

password = [0 for _ in range(len(O) + len(E))]

for i in range(len(O)):
    password[2 * i] = O[i]

for i in range(len(E)):
    password[2 * i + 1] = E[i]

password_str = ''.join(password)
print(password_str)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define K 10001

int main(){
  int *a, *b, c[K];
  int n, i;

  scanf("%d", &n);
  a = (int *)malloc(sizeof(int) * n);
  if( a == NULL ){
    printf("An error has occurred.\n");
    return -1;
  }
  b = (int *)malloc(sizeof(int) * n);
  if( a == NULL ){
    printf("An error has occurred.\n");
    return -1;
  }
  for(i = 0; i < n; i++) scanf("%d", &a[i]);

  for(i = 0; i < K; i++) c[i] = 0;

  for(i = 0; i < n; i++) c[ a[i] ]++;

  for(i = 1; i < K; i++) c[i] = c[i] + c[i - 1];

  for(i = n - 1; i > -1; i--){
    b[ c[ a[i] ] - 1] = a[i];
    c[ a[i] ]--;
  }

  for(i = 0; i < n - 1; i++) printf("%d ", b[i]); 
  printf("%d\n", b[n - 1]);

  free(a);
  free(b);

  return 0;
}

Measured memory_bytes: 16120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const string yes = "Yes";
const string no = "No";

int main()
{
  ll n; cin >> n;
  ll m; cin >> m;
  vector<ll> a(n);
  ll sum = 0;
  for (int i=0; i<n; i++){
    cin >> a[i];
    sum += a[i];
  }
  ll t = (sum + (4*m) -1)/(4*m);

  ll cnt = 0;
  rep(i, n) {
    if (a[i] >= t) cnt++;
  }
  if (cnt < m) cout << no << endl;
  else cout << yes << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    ll N,M;
    cin>>N>>M;
    if(M<=N){
        cout<<M/2<<endl;
    }else{
        ll ans=0;
        if(M>=2*N){
            M-=2*N;
            ans+=N;
            M/=4;
            ans+=M;
            cout<<ans<<endl;
        }else{
            cout<<M/2<<endl;
        }
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

map<ll, ll> prime_factorization(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while(n >= a*a){
    if(n % a == 0){
      ans[a]++;
      n /= a;
    }else{
      a++;
    }
  }
  ans[n]++;

  return ans;
}

int main(){
  int n;
  cin >> n;
  map<ll, ll> pr;
  for(int i = 1; i <= n; i++){
    auto add = prime_factorization(i);
    for(auto p : add){
      pr[p.first] += p.second;
    }
  }
  mint ans = 1;
  for(auto p : pr){
    // cerr << p.first << " " << p.second << endl;
    if(p.first == 1) continue;
    ans *= (p.second+1);
  }
  cout << ans.x << endl;
  return 0;
}

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

int e;
char a,b,c,d;

int main(){
    e=0;
	cin>>a>>b>>c>>d;
	if(a==43){
	    e++;
	}
	else if(a==45){
	    e--;
	}
	if(b==43){
	    e++;
	}
	else if(b==45){
	    e--;
	}
	if(c==43){
	    e++;
	}
	else if(c==45){
	    e--;
	}
	if(d==43){
	    e++;
	}
	else if(d==45){
	    e--;
	}
	cout<<e<<endl;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */
int main(){
    map<string, int> m;
    ii(n);
    rep(i, n){
        string s; cin >> s;
        m[s]++;
    }
    vector<string> res; int M = 0;
    for(auto& p : m){
        M = max(M, p.se);
    }
    for(auto& p : m){
        if(p.se == M) res.push_back(p.fi);
    }
    sort(all(res));
    rep(i, res.size()){
        out(res[i]);
    }
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=1;(i)<=(n);(i)++)
using namespace std;
int main() {
  double N, M; cin >> N >> M;
   double p=0;
  cout << fixed << setprecision(20);
  rep(i,N) {
     double temp = 1.0/N;
    int now = i;
    while (now < M){
      now *= 2;
      temp /= 2;
    }
    p += temp;
  }
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
const ll INF = 1e10;

bool ok(ll x,vector<ll>& H, ll& a, ll& b, ll& n) { 
    ll cnt = 0;
    for (ll i = 0; i < n; i ++) {
        if (H[i] - b * x > 0) {
            cnt += (H[i] - b * x + a - 1)/a;
        }
    }
    return cnt <= x;
}

int main() {
    ll n,a,b; cin >> n >> a >> b;
    a -= b;

    vector<ll> H(n);
    for (ll i = 0; i < n; i ++) cin >>H[i];

    ll l = -1;
    ll r = 1e10;
    while (r - l > 1) {
        ll mid = (r + l)/2;
        if (ok(mid,H,a,b,n)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}

Measured memory_bytes: 1024
(defmacro read-to-list ()
  `(read-from-string
    (concatenate 'string "(" (read-line) ")")))

(defun solve (s &optional (res 0) (prev #\0))
  (if (null s)
      res
      (if (char-equal (first s)
                      prev)
          (solve (rest s) res (first s))
          (solve (rest s) (1+ res) (first s)))))


(defun main ()
  (let ((n (read))
        (s (concatenate 'list (read-line))))
    (format t "~a~%" (solve s))))


(main)


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

long e2[111111] = { 1 }, e3[111111] = { 1 }, c[111111];
int main() {
	string L;
	cin >> L;
	int p = 1e9 + 7;
	for (int i = 0; i < L.length(); i++) {
		e2[i + 1] = e2[i] * 2 % p, e3[i + 1] = e3[i] * 3 % p;
		c[i + 1] = c[i];
		if (L[i] == '1') c[i + 1]++;
	}
	long d = e2[c[L.length()]];
	for (int i = L.length(); i--;)
		if (L[i] == '1')
			(d += e2[c[i]] * e3[L.length() - i - 1]) %= p;
	cout << d << endl;
	return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli,lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mp  make_pair
#define ss  second
#define ff  first
#define all(x) sort(x.begin(),x.end())
#define BLACK 0
#define WHITE 1
#define piii pair<int,pii>

void solve()
{
    int n;cin>>n;
    lli sum=0;
    lli lol[n];
    lli mn=INT_MAX,mx=-INT_MAX;
    for(int i=0;i<n;i++)
    {
        cin>>lol[i];
        sum+=lol[i];
        mn=min(mn,lol[i]);mx=max(lol[i],mx);
    }
    lli ans=INT_MAX;
    for(lli i=mn;i<=mx;i++)
    {
        lli res=0;
        for(lli j=0;j<n;j++)
        {
            res+=(lol[j]-i)*(lol[j]-i);
        }
        ans=min(ans,res);
    }
    cout<<ans<<endl;

}
int main()
{
    solve();
}


Measured memory_bytes: 3604
N = int(input())
X = list(map(int, input().split()))

ans = 10**9

for p in range(min(X),max(X)+1):
  sum_dist = 0
  for x in X:
    sum_dist += (x-p)**2
  if sum_dist < ans:
    ans = sum_dist
    
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    int n,d,x;
    cin>>n>>d>>x;
    rep(i,n){
        int a;
        cin>>a;
        for(int i=1;i<=d;i+=a)x++;
    }
    cout<<x<<endl;

    return 0;
}


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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int n,m;
	cin >> n>>m;
    cout<<(n*(n-1)/2)+(m*(m-1)/2);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(int argc, char const *argv[])
{
	int i,N;
	int cnt,cnt8 = 0;
	scanf("%d",&N);
	for (i = 1; i <= N; i += 2)
	{
		cnt = 0;
		for (int j = 1; j <= i ; j += 2)
		{
			if(i % j == 0)	++cnt;
		}
		if(cnt == 8)	++cnt8;
	}
	printf("%d\n", cnt8);
	return 0;
}


Measured memory_bytes: 128
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),* $(,)*) => {
        #[cfg(debug_assertions)]
        eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
    };
}

fn main() {
    input! {
        n: usize,
        x: usize,
        m: usize,
    }
    if n < 10000000 {
        let mut res = x;
        let mut y = x;
        for _ in 1..n {
            y = y * y % m;
            res += y;
        }
        println!("{}", res);
        return;
    }

    let mut a = vec![];
    let mut a_set = HashSet::new();
    let mut y = x;
    while !a_set.contains(&y) {
        a.push(y);
        a_set.insert(y);
        y = y * y % m;
    }
    if n <= a.len() {
        let mut result = 0usize;
        for i in 0..n {
            result += a[i];
        }
        println!("{}", result);
        return;
    }
    debug!(a, y);
    debug!(a_set);
    let start = (0..a.len()).filter(|&i| a[i] == y).nth(0).unwrap();
    let cycle = a.len() - start;
    debug!(start, cycle);
    debug!(n / cycle, n % cycle);
    let mut result = 0usize;
    for i in 0..cycle {
        result += a[start + i];
    }
    result *= (n - start) / cycle;
    debug!(result);
    for i in 0..min(n, start) {
        result += a[i];
    }
    debug!(result);
    if n >= start {
        for i in 0..(n - start) % cycle {
            result += a[start + i];
        }
    }
    println!("{}", result);

    // let mut res = x;
    // let mut y = x;
    // for _ in 1..n {
    //     y = y * y % m;
    //     res += y;
    // }
    // debug!(result, res, max(result, res) - min(result, res));
}


Measured memory_bytes: 3324
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	long long int r, d, x;
	cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		cout << r * x - d << endl;
		x = r * x - d;
	}
}

Measured memory_bytes: 256
n = int(input())
i = 0
while True:
    if 4*i > n:
        break
    j = 0
    while True:
        if 4*i + 7*j == n:
            print('Yes')
            exit()
        elif 4*i + 7*j > n:
            break
        j += 1
    i += 1
print('No')


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

int main() {
    int64_t a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;

    if(v <= w){
        cout << "NO" << endl;
        return 0;
    }

    int64_t length = max(a,b) - min(a,b);
    int64_t speed = v - w;

    if((length + (speed - 1)) / speed <= t){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	cin >> N;
	map<int, P> m;
	rep(i, 0, N) {
		int t, x, y;
		cin >> t >> x >> y;
		P p = make_pair(x, y);
		m[t] = p;
	}

	int idx = 0;
	int prev_time = 0;
	for(map<int, P>::iterator itr = m.begin(); itr != m.end(); itr++) {
		int ti = itr->first;
		int xi = itr->second.first, yi = itr->second.second;
		if(idx == 0) {
			if(ti < xi + yi) {
				cout << "No" << endl;
				return 0;
			} else if((ti - xi - yi) % 2 != 0) {
				cout << "No" << endl;
				return 0;
			}
			prev_time = ti;
		} else {
			int x = m[prev_time].first, y = m[prev_time].second;
			if(ti - prev_time < abs(xi - x) + abs(yi - y)) {
				cout << "No" << endl;
				return 0;
			} else if((ti - prev_time - abs(xi - x) - abs(yi - y)) % 2 != 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;


}


Measured memory_bytes: 6528
import java.util.*;

public class Main{
	public static void main(String[]$){
		long mod=(long)1e9+7;
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		sc.close();
		ArrayList<Integer>len=new ArrayList<>();
		int l=1;
		while(l<=n){
			int r=n/(n/l);
			len.add(r-l+1);
			l=r+1;
		}
		int q=len.size();
		long[]dp=new long[k*(q+1)];
		for(int j=1;j <=q;j++){
			dp[j]=len.get(j-1)+dp[j-1];
		}
		for(int i=1;i<k;i++){
			for(int j=1;j<=q;j++){
				int x=i*(q+1)+j;
				dp[x]=(dp[x-1]+dp[x-2*j]*len.get(j-1))%mod;
			}
		}
		System.out.println(dp[k*(q+1)-1]);
	}
}


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

int main(){
    int num[5],k;

    for(int i = 0; i < 5; i++)cin >> num[i];
    cin >> k;

    for(int i = 0; i < 4; i++){
        for(int j = i+1; j < 5; j++){
            if(num[j]-num[i] > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

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

    typedef long long ll;
    const ll MOD = 1e9+7;
    const int N = 1<<22;

    int n;
    int mat[22][22];
    ll dp[22][N];
    vector<int>v[22];

    int main()
    {
        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
        cin>>n;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                cin>>mat[i][j];
            }
        }

        dp[0][0]=1;
        for(int j=0;j<(1<<n);j++){
            int i=0;
            for(int e=0;e<n;e++)if(j&(1<<e))i++;
            for(int e=0;e<n;e++){
                if(mat[i][e+1]){
                    int p=(1<<e);
                    if(j&p)dp[i][j]=(dp[i][j]+dp[i-1][j-p]);
                    if(dp[i][j]>=MOD)dp[i][j]-=MOD;
                }
            }
        }

        cout<<dp[n][(1<<n)-1];
        return 0;
    }


Measured memory_bytes: 321792
// Prime Caves
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1189&lang=jp 

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct Point { int x, y; Point(int _x, int _y) : x(_x), y(_y) {} };

const int MAX = 1010;
const int OFFSET = 505;

const int RIGHT = 0, TOP = 1, LEFT = 2, BOTTOM = 3;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};

const int PRIME_MAX = 1000010;
bool is_prime[PRIME_MAX];

int M, N;
vector<vector<int>> caves;
vector<vector<pair<int, int>>> dp;

int next_direction(int x, int y) {
    if (caves[y][x+1] != 0 && caves[y+1][x] == 0) return BOTTOM;
    if (caves[y+1][x] != 0 && caves[y][x-1] == 0) return LEFT;
    if (caves[y][x-1] != 0 && caves[y-1][x] == 0) return TOP;
    return RIGHT;
}

void make_cave(int m) {
    dp.assign(MAX, vector<pair<int, int>>(MAX, {0, 0}));
    caves.assign(MAX, vector<int>(MAX, 0));
    int x = OFFSET, y = OFFSET;
    for (int i = 1; i <= m; ++i) {
        int d = next_direction(x, y);
        x += dx[d]; y += dy[d];
        caves[y][x] = i;
    }
}

Point get_start_point(int n) {
    for (int y = 0; y < MAX; ++y) {
        for (int x = 0; x < MAX; ++x) {
            if (caves[y][x] != n) continue;
            return {x, y};
        }
    }
    return {-1, -1};
}

void show() {
    for (int i = OFFSET - 10; i <= OFFSET + 10; ++i) {
        for (int j = OFFSET - 10; j <= OFFSET + 10; ++j) {
            cout << caves[i][j] << " ";
        }
        cout << endl;
    }
}

inline pair<int, int> dfs(int x, int y) {

    if (caves[y][x] == 0) return {0, 0};
    if(dp[y][x].first != 0) return dp[y][x];    

    pair<int, int> res = {0, 0};
    for (int dx = -1; dx <= 1; ++dx) {
        res = max(res, dfs(x + dx, y + 1));
    }
    
    if (is_prime[caves[y][x]]) {
        if (res.first == 0) res.second = caves[y][x];
        res.first++;
    }

    dp[y][x] = res;
    return res;
}

int main() { 

    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i < PRIME_MAX; ++i) is_prime[i] = true;
    for (int i = 2; i < PRIME_MAX; ++i) {
        if (is_prime[i]) {
            for (int j = i+i; j < PRIME_MAX; j += i) {
                is_prime[j] = false;
            }
        }
    }

    while (cin >> M >> N) {
        if (M == 0) break;
        make_cave(M);
        Point sp = get_start_point(N);
        pair<int, int> ans = dfs(sp.x, sp.y);
        cout << ans.first << " " << ans.second << endl;
    }
    return 0;
}

Measured memory_bytes: 16064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n=s.nextInt(),x=s.nextInt(),t=s.nextInt();
        long sum = n/x;
        sum *= t;
        if(n%x!=0)sum+=t;
        System.out.println(sum);

    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25312
#include<stdio.h>
 int main(void)
 {
     int A,B,S[3];
     int i,j,tmp;

     scanf("%d%d",&A,&B);

     S[0]=A+B;
     S[1]=A-B;
     S[2]=A*B;

     for(i=0;i<3;i++){
       for(j=i+1;j<3;j++){
         if(S[i]>S[j]){
           tmp=S[i];
           S[i]=S[j];
           S[j]=tmp;
         }
       }
     }

     printf("%d\n",S[2]);

     return 0;
 }


Measured memory_bytes: 128
N, x = map(int, input().split())
a = list(map(int, input().split()))
s1 = sum(a)

for i in range(N):
	if i == 0:
		if a[i] >= x:
			a[i] = x
	else:
		if a[i] + a[i-1] >= x:
			d = a[i] + a[i-1] - x
			a[i] = max(0, -a[i-1]+x)
s2 = sum(a)

print(s1-s2)

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

int main() {
    while(true) {
        int H, W;
        cin >>H >>W;
        if ((0==H)&&(0==W))
            break;
        for (int i=0; i<H; i++) {
            for (int j=0; j<W; j++)
                cout <<'#';
            cout <<endl;
        }
        cout <<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N = 0;
    cin >> N;


    //本文
    if(N==2){cout << 2; return 0;}
    if(N==1){cout << 0; return 0;}
    //出力
    ll ans = 1,ans2 =1, ans3 =1;
    for(int i =1; i<= N; i++){
      ans*=10;
      ans %= MOD;
    }
    for(int i =1; i<= N; i++){
      ans2*=9;
      ans2 %= MOD;
    }
    for(int i =1; i<= N; i++){
      ans3*=8;
      ans3 %= MOD;
    }
    ans -= 2*ans2;
    ans %= MOD;
    if(ans < 0) ans +=MOD;
    
    ans += ans3;
    ans %= MOD;
    cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3600
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
// 9/3
int main(void){
    int n;
    cin>>n;
    int a[100005];
    map<int,bool>m;
    map<int,int>num;
    vector<int>b;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(m[a[i]]==false){
        m[a[i]]=true;
        num[a[i]]++;
            b.push_back(a[i]);
        }else num[a[i]]++;
    }
    sort(b.begin(),b.end());
    int ans=1;
    if(b.size()==1){
        printf("%d\n",num[b[0]]);
        return 0;
    }
    if(b.size()==2){
        ans=num[b[0]];
        if(b[1]-b[0]<=2)ans+=num[b[1]];
        printf("%d\n",ans);
        return 0;
    }
    for(int i=0;i<=b.size()-3;i++){
        int tmp=num[b[i]];
        if(b[i+1]-b[i]<=2){
            tmp+=num[b[i+1]];
        }
        if(b[i+2]-b[i]<=2){
            tmp+=num[b[i+2]];
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6780
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(void)
{
	string s;
	cin>>s;
	if(s[s.size()-1] == 's') cout<<s<<"es";
	else cout<<s<<"s";
	return 0;
}

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

int main(){
  string S;
  string T;
  cin >> S;
  cin >> T;
  int count=0;
  for (int i=0;i<3;i++){
    if (S.at(i)==T.at(i)){
      count++;
    }
  } 
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+ 5;
int main()
{
  int n,k, i, j;
  cin>>n>>k;
  vector<int>dp(n,INF);
  vector<int>arr(n,0);
  dp[0]=0;
  for(i=0; i<n; i++)
    cin>>arr[i];
  for(i=0; i<n; i++)
    for(j=i+1; j<=i+k; j++)
        if(j<n)
          dp[j]=min(dp[j], dp[i]+abs(arr[j]-arr[i]));
  cout<<dp[n-1]<<endl;
  return 0;
}


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

const int MAX = 1100000;
vector<long long> cnt; // cnt[n] := n! が 2 で何回割れるか
void pre() {
    cnt.assign(MAX, 0);
    for (int i = 1; i < MAX; ++i) {
        int j = i;
        int add = 0;
        while (j % 2 == 0) ++add, j /= 2;
        cnt[i] = cnt[i-1] + add;
    }
}

int solve(const string &S) {
    pre();
    vector<int> a;
    for (int i = 0; i + 1 < S.size(); ++i) {
        int x = S[i] - '0';
        int y = S[i+1] - '0';
        a.push_back(abs(x - y));
    }
    long long parity = 0;
    for (int i = 0; i < a.size(); ++i) {
        long long ex = cnt[a.size()-1] - cnt[i] - cnt[a.size()-i-1];
        if (ex > 0) continue;
        parity += a[i];
    }

    if (parity & 1) return 1;
    else {
        bool exist_one = false;
        for (int i = 0; i < a.size(); ++i) if (a[i] == 1) exist_one = true;
        if (exist_one) return 0;
        else {
            parity = 0;
            for (int i = 0; i < a.size(); ++i) {
                long long ex = cnt[a.size()-1] - cnt[i] - cnt[a.size()-i-1];
                if (ex > 0) continue;
                parity += a[i] / 2;
            }
            if (parity & 1) return 2;
            else return 0;
        }
    }
  }

int main() {
    int N;
    string S;
    cin >> N >> S;
    cout << solve(S) << endl;
}

Measured memory_bytes: 16380
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(void) {
	long long N,K;
	cin >> N >> K;
	vector< pair<int,int> > data(N);
	for (int i = 0; i < N; ++i) {
		cin >> data[i].first >> data[i].second;
	}

	sort(data.begin(),data.end());

	bool find = false;
	long long count = 0;
	for (int i = 0; !find && i < N; ++i) {
		count += data[i].second;
		if (count >= K) {
			cout << data[i].first << endl;
			find = true;
		}
	}

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; i64 k; scanf("%d%lld", &n, &k);
	int cost = 0;
	std::vector<std::vector<int>> g(n), rg(n);
	for(int i = 0; i < n; i++) {
		int to; scanf("%d", &to); to--;
		
		if(!i) {
			cost = (i != to);
			continue;
		}
		
		g[i].push_back(to);
		rg[to].push_back(i);
	}
	
	int ans = 0;
	std::function<int (int)> solve = [&](int v) {
		int ma = 0;
		for(auto e: rg[v]) ma = std::max(ma, solve(e));
		
		if(v and ma == k - 1 and g[v][0]) {
			ans++;
			return 0;
		}
		return ma + 1;
	};
	solve(0);
	
	printf("%d\n", ans + cost);
	return 0;
}


Measured memory_bytes: 18944
# 初期入力
N,M = (int(x) for x in input().split())
A = set([int(input()) for i in range(M)])


#
mod_9 = 10**9 +7
dp =[0]*(N +1)
dp[0] = 1
if 1 not in A:
    dp[1] =1
for i in range(N-1):
    if i+2 in A:
        dp[i+2] = 0
    else:
        dp[i+2] = dp[i+1] + dp[i] 
        dp[i+2] %= mod_9
kotae =dp[N] # % mod_9
print(kotae )

Measured memory_bytes: 13212
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

char a[10][10];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int r, c, x, ans = 0;
    cin >> r >> c >> x;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < (1 << r); i++){
        for(int j = 0; j < (1 << c); j++){
            int kam = 0;
            for(int k = 0; k < r; k++){
                for(int l = 0; l < c; l++){
                    if((i >> k & 1) || (j >> l & 1)) continue;
                    kam += (a[k][l] == '#');
                }
            }
            if(kam == x) ans++;
        }
    }
    cout << ans;


    return 0;
}


Measured memory_bytes: 3684
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<deque>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define WHITE 0
#define BLACK 1
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
int INFi=1000000000;
ll INFl=1000000000000000;

struct UnionFind{
    vector<int> par;//初期化
    vector<int> rank;//高さ
    UnionFind(int n=0):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);//経路圧縮
    }
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        if(rank[rx]<rank[ry]) rank[rx]=ry;
        else rank[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
        }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

int main(){
    int n,q;cin>>n>>q;
    vector<int> v[1000];
    int d,t,x;
    for(int i=0;i<q;i++){
        cin>>d;
        switch(d){
            case 0:
            cin>>t>>x;
            v[t].push_back(x);
            break;

            case 1:
            cin>>t;
            if(v[t].size()==0) cout<<endl;
            else for(int j=0;j<v[t].size();j++){
                cout<<v[t][j]<<(j==v[t].size()-1?'\n':' ');
            }
            break;

            case 2:
            cin>>t;
            v[t].clear();
            break;
        }
    }
}


Measured memory_bytes: 5872
t = 'taro'
h = 'hanako'
score = { t: 0, h: 0}

n = int(input())

for _ in range(n):
    ls = input().split()
    
    t_card = ls[0]
    h_card = ls[1]
    
    new_ls = sorted(ls)
    if t_card == h_card:
        score[t] += 1
        score[h] += 1
    elif t_card == new_ls[0]:
        score[h] += 3
        
    elif h_card == new_ls[0]:
        score[t] += 3
    
print(score[t], score[h])


Measured memory_bytes: 5600
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B

x = int(input())
y = list(map(int,input().split()))
z = 0

for i in range(x):
	minj = i
	for j in range(i,x):
		if y[j] < y[minj]:
			minj = j
	if not i == minj:
		y[i], y[minj] = y[minj], y[i]
		z += 1

print(" ".join(list(map(str,y))))
print(z)

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

void get_probability(int N, double *P){
    double dp[N+1][N+1];
    for(int k=0; k<=N; k++)
	    for(int l=0; l<=N; l++)
	        dp[k][l] = 0.0;
    dp[0][0] = 1;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
	    dp[i+1][j] += dp[i][j]*(1-P[i]);
	    dp[i+1][j+1] += dp[i][j]*P[i];
	    //cout << dp[i][j] << " " << dp[i+1][j] << " " << dp[i+1][j+1] << endl;
        }
    }
    //for(int i=0; i<=N; i++){
//	    for(int j=0; j<=N; j++){
//		    cout << dp[i][j] << " ";
  //          }
    //    cout << endl;
    //}
    double prob = 0.0;
    for(int i=N/2+1; i<=N; i++)
        prob += dp[N][i];
    cout.precision(10);
    cout << prob << endl;

}

int main()
{
    int N;
    cin >> N;
    double P[N];
    for(int i=0; i < N; i++)
        cin >> P[i];
    /*for(int i=0; i<N; i++)
        cout << P[i] << " ";
    cout << endl;
    */
    get_probability(N, P);
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, p=0;
vector<ll> c;
ll d[200000];
vector<ll> edges[200000];

void dfs(int cur, int par) {
  d[cur] = c[p++];
  for (auto nxt: edges[cur]) {
    if (nxt == par)
      continue;
    dfs(nxt, cur);
  }
}

signed main() {
  cin >> N;
  rep(i,N-1){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }

  c.resize(N);
  rep(i,N) {
    cin >> c[i];
  }
  sort(begin(c),end(c));
  reverse(begin(c),end(c));

  ll sum = 0;
  for(ll i=1;i<N;i++)
    sum += c[i];

  dfs(0,-1);

  cout << sum << endl;
  rep(i,N)
    cout << d[i] << endl;
  return 0;
}



Measured memory_bytes: 7296
#include <stdio.h>

#define H 6
#define W 100

struct AOJ{
	int num;
	int lock;
};
typedef struct AOJ AOJ_0568;

void display00(AOJ_0568 data[][W], int height, int width){
	int i, k;
	for(i=0; i<height; i++){
		for(k=0; k<width; k++){
			printf("%d ", data[i][k].num);
		}
		printf("\n");
	}
	return;
}

int getResult(AOJ_0568 data[][W], int height, int width){
	int i;
	int result = 0;
	for(i=0; i<height; i++){
		result += data[i][width-1].num%10000;
	}
	return result%10000;
}


int main(){
	AOJ_0568 data[H][W];
	int n, k;
	int a, b;
	int i, m;
	int d = 10000;
	int result;
	scanf("%d %d", &n, &k);
	for(i=0; i<H; i++){
		if(i%2==0){
			data[i][0].num = 0;
			data[i][0].lock = 1;
		}
		else{
			data[i][0].num = 1;
			data[i][0].lock = 1;
		}
	}
	for(i=0; i<H; i++){
		for(m=1; m<n; m++){
			data[i][m].num = 0;
			data[i][m].lock = 1;
		}
	}
	//display00(data, 6, n);
	//printf("\n\n\n");
	for(i=0; i<k; i++){
		scanf("%d %d", &a, &b);
		if(b==1){
			data[2][a-1].num = 0;
			data[2][a-1].lock = 0;
			data[3][a-1].num = 0;
			data[3][a-1].lock = 0;
			data[4][a-1].num = 0;
			data[4][a-1].lock = 0;
			data[5][a-1].num = 0;
			data[5][a-1].lock = 0;
		}
		else if(b==2){
			data[0][a-1].num = 0;
			data[0][a-1].lock = 0;
			data[1][a-1].num = 0;
			data[1][a-1].lock = 0;
			data[4][a-1].num = 0;
			data[4][a-1].lock = 0;
			data[5][a-1].num = 0;
			data[5][a-1].lock = 0;
		}
		else if(b==3){
			data[0][a-1].num = 0;
			data[0][a-1].lock = 0;
			data[1][a-1].num = 0;
			data[1][a-1].lock = 0;
			data[2][a-1].num = 0;
			data[2][a-1].lock = 0;
			data[3][a-1].num = 0;
			data[3][a-1].lock = 0;
		}
	}
	
	for(m=1; m<n; m++){
		for(i=0; i<H; i++){
			switch(i){
				case 0:
				if(data[i][m].lock){
					data[i][m].num += data[i+1][m-1].num;
					data[i][m].num %= d;
				}
				break;
				
				case 1:
				if(data[i][m].lock){
					data[i][m].num += data[i+1][m-1].num;
					data[i][m].num += data[i+2][m-1].num;
					data[i][m].num += data[i+3][m-1].num;
					data[i][m].num += data[i+4][m-1].num;
					data[i][m].num %= d;
				}
				break;
				
				case 2:
				if(data[i][m].lock){
					data[i][m].num += data[i+1][m-1].num;
					data[i][m].num %= d;
				}
				break;
				
				case 3:
				if(data[i][m].lock){
					data[i][m].num += data[i-3][m-1].num;
					data[i][m].num += data[i-2][m-1].num;
					data[i][m].num += data[i+1][m-1].num;
					data[i][m].num += data[i+2][m-1].num;
					data[i][m].num %= d;
				}
				break;
				
				case 4:
				if(data[i][m].lock){
					data[i][m].num += data[i+1][m-1].num;
					data[i][m].num %= d;
				}
				break;
				
				case 5:
				if(data[i][m].lock){
					data[i][m].num += data[i-5][m-1].num;
					data[i][m].num += data[i-4][m-1].num;
					data[i][m].num += data[i-3][m-1].num;
					data[i][m].num += data[i-2][m-1].num;
					data[i][m].num %= d;
				}
				break;
			}
		}
	}
	
	//display00(data, 6, n);
	
	result = getResult(data, H, n);
	
	printf("%d\n", result);
	
	return 0;
}

Measured memory_bytes: 600
from numpy import *
N = int(input())
A = int32(input().split())
B = int32(input().split())
ans = 0

for k in range(29):
  a = sort(hstack((A%(2**(k+1)),A%(2**(k+1))-2**(k+1))))
  b = B%(2**(k+1))
  ans += (sum(searchsorted(a,2**(k+1)-b)-searchsorted(a,2**k-b)))%2*2**k

print(ans)

Measured memory_bytes: 55316
n = int(input())
l = []
for i in range(n):
    s,t = input().split()
    t = int(t)
    l.append([s,t])
x = input()
ans = 0
key = 0
for i in range(n):
    if key == 0:
        if l[i][0] == x:
            key = 1
    else:
        ans += l[i][1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;
#define MOD 1000000007

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    if(abs(N-M) >= 2){
        cout << 0 << endl;
        return 0;
    }
    long long ans = 1;
    for(int i=1; i<=N; i++){
        ans *= i;
        ans %= MOD;
    }
    for(int i=1; i<=M; i++){
        ans *= i;
        ans %= MOD;
    }
    if(N == M){
        ans *= 2;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <string>
#include <cassert>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

const int vx[4] = { -1, 0, 1, 0 }, vy[4] = { 0, -1, 0, 1 };

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

  int H, W;
  char s, t;
  std::string aagraph[51];

  cin >> H >> W >> s >> t;

  for (int i = 0; i < H; ++i) {
    cin >> aagraph[i];
  }

  int d[26][26];

  std::memset(d, 0x3f, sizeof d);

  for (int i = 0; i < 26; ++i) {
    d[i][i] = 0;
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if ('A' <= aagraph[i][j] && aagraph[i][j] <= 'Z') {

        for (int k = 0; k < 4; ++k) {
          int nx = i + vx[k] * 2, ny = j + vy[k] * 2;

          if (0 <= nx && nx < H && 0 <= ny && ny < W) {
            if (((k == 1 || k == 3) && aagraph[nx][ny] == '-') || ((k == 0 || k == 2) && aagraph[nx][ny] == '|')) {
              //if (aagraph[nx][ny] == '-' || aagraph[nx][ny] == '|') {

              while (aagraph[nx][ny] != 'o') {
                nx += vx[k], ny += vy[k];
              }
              nx += vx[k], ny += vy[k];

              assert('A' <= aagraph[nx][ny] && aagraph[nx][ny] <= 'Z');

              int u = aagraph[i][j] - 'A', v = aagraph[nx][ny] - 'A';
              d[u][v] = d[v][u] = 1;
            }
          }
        }
      }
    }
  }

  /*
  for (int i = 0; i < 26; ++i) {
    for (int j = 0; j < 26; ++j) {
      cerr << d[i][j] << " "[j == 25];
    }
  }
  //*/

  for (int k = 0; k < 26; ++k) {
    for (int i = 0; i < 26; ++i) {
      for (int j = 0; j < 26; ++j) {
        d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  int u = s - 'A', v = t - 'A';

  cout << d[u][v] << endl;

  return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

template<typename T>
bool SuffixErase(T &v,size_t suf){
  if(suf > v.size()) return false;
  for(auto it = v.begin(); it != v.end();){
    if(distance(v.begin(),it) == suf){
      v.erase(it);
      return true;
    }
    else{
      ++it;
    }
  }
  return false;
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

vector<vector<ll>> dp(1005,vector<ll>(1005,inf));

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  cin >> n >> m;
  vector<ll> c(m),d(n+1);
  rep(i,n){
    cin >> d[i];
  }
  rep(i,m){
    cin >> c[i];
  }
  dp[0][0] = 0;
  rep(i,m){
    rep(j,n){
      dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
      dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j] + c[i] * d[j]);
    }
  }
  ll ans = inf;
  rep(i,m+1){
    ans = min(ans,dp[i][n]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11092
#include <cstdio>
#include <algorithm>
#include <vector>
int n, m, lim, ans;
char a[15][1005];
int main(){
  scanf("%d%d%d", &n, &m, &lim), ans = n + m - 2;
  for (register int i = 0; i < n; ++i)
    scanf("%s", a[i]);
  for (register int p = 0; p < (1 << (n - 1)); ++p){
    std::vector<int> pos, now;
    for (register int i = 0; i < n - 1; ++i)
      if (p >> i & 1) pos.push_back(i);
    pos.push_back(n - 1);
    now.resize(pos.size(), 0);
    bool flag = 1;
    int cnt = (int)pos.size() - 1;
    for (register int i = 0; i < m; ++i){
      std::vector<int> tmp(pos.size());
      for (register int j = 0; j < (int)pos.size(); ++j)
        for (register int k = j ? pos[j - 1] + 1 : 0; k <= pos[j]; ++k)
          tmp[j] += a[k][i] ^ '0';
      bool cut = 0;
      for (register int j = 0; j < (int)pos.size(); ++j){
        now[j] += tmp[j];
        if (tmp[j] > lim) flag = 0;
        if (now[j] > lim) cut = 1;
      }
      if (!flag) break;
      if (cut) ++cnt, now.swap(tmp);
    }
    if (flag) ans = std::min(ans, cnt);
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256