akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
 
void err(istream_iterator<string> it) {cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " : ";
    err(++it, args...);
}
 
 
#define F first
#define S second
#define ll long long
#define pb push_back
#define db double
#define ld long double
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define all(x) (x).begin(),(x).end()
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define TEST int T; cin >> T; while(T--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//#define int long long
 
const int N = 1e5 + 5, inf = 2e9 + 7, mod = 1e9 + 7;
const ll INF = 2e18 + 7, MOD = 1e15 + 7;

int n, a[16][16];
ll pre[1 << 16], dp[1 << 16]; // dp[mask] = max ans if rabbits already taken

bool has(int n, int i) {
    return (n >> i) & 1;
}

void rec(int i, vector<int>& v, ll cur, int mask, int group) {
    if(i == v.size()) {
        dp[mask] = max(dp[mask], cur + pre[group]);
        return;
    }
    rec(i + 1, v, cur, mask ^ (1 << v[i]), group ^ (1 << v[i]));
    rec(i + 1, v, cur, mask, group);
}

signed main() { __
//    freopen("lcm.in", "r", stdin);
//    freopen("lcm.out", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    
    for (int mask = 0; mask < (1 << n); mask++) {
        for (int i = 0; i < n; i++) {
            if (!has(mask, i)) continue;
            for (int j = i + 1; j < n; j++) {
                if (!has(mask, j)) continue;
                pre[mask] += a[i][j];
            }
        }
    }
//    for (int i = 0; i < (1 << n); i++) dp[i] = -INF;
    dp[0] = 0;
    for (int mask = 0; mask < (1 << n); mask++) {
        vector<int> v;
        for (int i = 0; i < n; i++) {
            if(!has(mask, i)) {
                v.pb(i);
            }
        }
        rec(0, v, dp[mask], mask, 0);
    }
    cout << dp[(1 << n) - 1];
    return 0;
}



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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int S[100100];
std::vector<ll> T[100100], U[100100];

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> S[i];
    }

    for(int i=1;i<N;++i){
        int n = (N - 1) / i;

        T[i].resize(n + 1);
        T[i][0] = 0;

        for(int j=1;j<=n;++j){
            T[i][j] = T[i][j-1] + S[(N-1)-i*j];
        }
    }

    for(int i=1;i<N;++i){
        int n = (N - 1) / i;

        U[i].resize(n + 1);
        U[i][0] = 0;

        for(int j=1;j<=n;++j){
            U[i][j] = U[i][j-1] + S[i*j];
        }
    }

    ll res = 0;

    for(int D=1;D<N;++D){
        for(int A=N-1-D;A>0;A-=D){
            int B = A - D;
            if(B <= 0 || A <= B){continue;}
            if(B % D == 0 && (N - 1 - A) - D >= B){continue;} // Move to the same position twice

            // std::cout << A << ", " << B << std::endl;
            
            res = std::max(res, U[D][(N-1-A)/D] + T[D][(N-1-A)/D]);
        }
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 27776
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int cnt = 0;
    string ans = "";
    rep(i,N){
        cin >> A[i];
        if(A[i] % 2 == 1)++cnt;
    }
    if(cnt % 2 == 1)ans = "NO";
    else ans = "YES";
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
const int w=8000;
int n,x,y;bool f[2][2][20000];
char s[8010];
int main()
{
	scanf("%s %d %d",s+1,&x,&y);x+=w;y+=w;
	n=strlen(s+1);int t=0,i=1;
	while(i<=n&&s[i]=='F') t++,i++;
	int p=0,q=0;f[0][0][w+t]=true;f[1][0][w]=true;
	while(i<=n)
	{
		i++;p^=1;q^=p;
		int sum=0;
		while(i<=n&&s[i]=='F') sum++,i++;
		for(int i=w-n;i<=w+n;i++) f[p][q][i]=f[p][q^1][i-sum]|f[p][q^1][i+sum];
	}
	if(p==1&&f[0][q^1][x]&&f[1][q][y]||p==0&&f[0][q][x]&&f[1][q][y]) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 384
import sys
from collections import deque
finput=lambda: sys.stdin.readline().strip()

n=int(finput())
a=finput().split()
b=deque()

for i in range(n):
  if (n-i)%2==0:
    b.append(a[i])
  else:
    b.appendleft(a[i])
print(' '.join(b))

Measured memory_bytes: 30500
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  if(c>=a && c<=b) cout<<"Yes"<<'\n';
  else cout<<"No"<<'\n';
  return 0;
}


Measured memory_bytes: 256
double*p,s[99],v;short t[9];main(c){for(p=s+2;~scanf("%[^ \n]%c",t,&c);c-10||printf("%f\n",*--p))v=*--p,*t-43?*t-45?*t-42?*t-47?(sscanf(t,"%lf",&v,p++),*p++=v):(p[-1]/=v):(p[-1]*=v):(p[-1]-=v):(p[-1]+=v);}

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

int main() {
    long long int n, k;
    cin >> n >> k;
    int a[n], next[65][n];
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i]--;
    }
    for(int i = 0; i < n; ++i) next[0][i] = a[i];

    for(int j = 0; j < 64; ++j) {
        for(int i = 0; i < n; ++i) {
            next[j + 1][i] = next[j][next[j][i]];
        }
    }
    int now = 0;
    for(int i = 0; k > 0; ++i) {
        if(k&1) now = next[i][now];
        k >>= 1;
    }

    cout << now + 1 << '\n';

    return 0;
}


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

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  rep(i, H) {
    cin >> S[i];
  }
  ll ans = 1000000000;
  rep(div, 1<<(H-1)) {
    int g = 0;
    vector<int> id(H);
    rep(i, H) {
      id[i] = g;
      if(div>>i & 1) g++;
    }
    g++;
    vector<vector<int>> c(g, vector<int>(W, 0));
    rep(i, H) {
      rep(j, W) {
        c[id[i]][j] += (S[i][j] - '0');
      }
    }

    bool can = true;
    rep(i, g) {
      rep(j, W) {
        if (c[i][j] > K) {
          can = false;
          break;
        }
      }
      if (!can) break;
    }
    if (!can) continue;
    ll cnt = g - 1;
    vector<int> sum(g, 0);
    rep(i, W) {
      rep(j, g) {
        sum[j] += c[j][i];
      }
      rep(j, g) {
        if (sum[j] > K) {
          cnt++;
          rep(k, g) sum[k] = c[k][i];
          break;
        }
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S;
  cin >> S;
  SORT(S);
  cout << (S=="abc"? "Yes":"No") << endl;

  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
# 正答数, ペナルティー数
q_list = [False] * n
p_count = 0

data = []
for _ in range(m):
    a, b = map(str, input().split())
    data.append([a, b])

# 正解してるものだけオーダーmで回収
for _ in range(m):
    q_num, j = data[_]
    q_num = int(q_num)
    q_num -= 1
    if j == "AC":
        q_list[q_num] = True


q2_list = [False] * n
# 正解してるものだけ途中のWAをカウント
for i in range(m):
    q_num, j = data[i]
    q_num = int(q_num)
    q_num -= 1
    if q2_list[q_num] == False:
        if j == "WA" and q_list[q_num]:
            p_count += 1
        else:
            q2_list[q_num] = True

print(q_list.count(True), p_count)


Measured memory_bytes: 25848
#include <bits/stdc++.h>
using namespace std;
signed  main(){
  map<string,bool> mp;
  int n;
  string w;
  bool can=true;
  cin>>n;
  char c;
  for(int i=0;i<n;i++){
    cin>>w;
    if(mp[w] == true)
      can=false;
    mp[w] = true;
    if(i > 0){
      if(c != w[0])
	can=false;
    }
    int end=w.size();
    c=w[end-1];
  }

  if(can == true)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return(0);
}
    

Measured memory_bytes: 256
using System;

class A{
  public static void Main(){
    string N = Console.ReadLine();
    if (N.Substring(N.Length - 1,1) == "3"){
      Console.WriteLine("bon");
    }
    else if (N.Substring(N.Length - 1,1) == "0" || N.Substring(N.Length - 1,1) == "1" || N.Substring(N.Length - 1,1) == "6" || N.Substring(N.Length - 1,1) == "8"){
      Console.WriteLine("pon");
    }
    else Console.WriteLine("hon");
  }
}

Measured memory_bytes: 25892
from collections import Counter
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
ctr = Counter()
for row in src:
    ctr += Counter(row[1:])

ans = 0
for v in ctr.values():
    if v==N:
        ans += 1
print(ans)

Measured memory_bytes: 3316
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut h = read_vec::<i64>();
    h[0] -= 1;
    for i in 1..n {
        if h[i] > h[i - 1] {
            h[i] -= 1;
        }
        if h[i] < h[i - 1] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4296
#include<stdio.h>
int main(void)
{
	int a, b, c;
	int i , j;
	i = 0;
	j = 0;
	scanf("%d %d %d", &a, &b, &c);
	if (a == 5) i++;
	if (b == 5) i++;
    if (c == 5) i++;
    if (a == 7 || b == 7 || c == 7) j++;

	if (i == 2 && j == 1) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N,K;
int fr[200005];
vector<int> V;
int main() {
    cin >> N >> K;
    for(int i = 1;i <= N;i++){
       int val;
       cin >> val;
       fr[val]++;
    }
    for(int i = 1;i <= N;i++){
       if(fr[i] != 0){
          V.push_back(fr[i]);
       }
    }
    sort(V.begin(),V.end());
    reverse(V.begin(),V.end());
    long long rez = 0;
    for(int i = 0;i < min((int)V.size(),K);i++){
       rez += V[i];
    }
    rez = N - rez;
    cout << rez;
    return 0;
}

Measured memory_bytes: 2168
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n, ww = 0;
    cin >> n;
    vector<int> w(n);
    for(int i=0;i<n;++i){
        cin >> w[i];
        ww += w[i];
    }

    int ans = 1<<30, a = 0;
    for(int i=0;i<n;++i) {
        a += w[i];
        ans = min(ans, abs(a - (ww-a)));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main{
	public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out, true);
		int n=in.nextInt();
		int count=0;
		for(int i=0;i<n;i++){
			int a=in.nextInt();
			if(check_prime(a))
				count++;
		}
		out.println(count);
	}
	public static boolean check_prime(int n){
		if(n<=1)
			return false;
		if(n<=3)
			return true;

		if(n%2==0 || n%3==0)
			return false;

		for(int i=5; i*i<=n; i=i+6){
			if(n%i==0 || n%(i+2)==0)
				return false;
		}
		return true;
	}
}


Measured memory_bytes: 42760
#include<bits/stdc++.h>
using namespace std;
int n;
vector<pair<pair<string,int>,int> > v;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string x;
		int y;
		cin>>x>>y;
		v.push_back(make_pair(make_pair(x,y),i+1));
	}
	sort(v.begin(),v.end());
	string tmp=v[0].first.first;
	vector<pair<pair<string,int>,int> > u;
	for(int i=0;i<v.size();i++)
	{
		if(v[i].first.first==tmp)
		{
			u.push_back(v[i]);
			continue;
		}
		for(int j=u.size()-1;j>=0;j--)
			cout<<u[j].second<<endl;
		tmp=v[i].first.first;
		u.clear();
		u.push_back(v[i]);
	}
	for(int i=u.size()-1;i>=0;i--)
		cout<<u[i].second<<endl;
	return 0;
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%d", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long
#define float long double 
#define ll long long

const int inf = (int) 1e16;
const int upper = (int) 4e5 + 15;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;

long double dp[3000][3000];
long double prob[3000];

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	memset(dp, 0.00, sizeof dp);

	int n; cin >> n;
	for (int i = 1; i <= n; i += 1) {
		cin >> prob[i];
	}
	dp[0][0] = 1;
	for (int i = 1; i <= n; i += 1) {
		for (int cnt = 0; cnt <= n; cnt += 1) {
			if (cnt >= 1) dp[i][cnt] += dp[i - 1][cnt - 1] * prob[i];
			dp[i][cnt] += dp[i - 1][cnt] * (1.0 - prob[i]);
		}
	}

	long double ans = 0;
	for (int cnt = 1; cnt <= n; cnt += 1) {
		if (cnt > n - cnt) ans += dp[n][cnt];
	}

	cout.precision(100);
	cout << ans;
 	end_routine();	
}

Measured memory_bytes: 140928
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string line = System.Console.ReadLine().Trim();

        line = line.Replace('1', 'a');
        line = line.Replace('9', '1');
        line = line.Replace('a', '9');

        System.Console.WriteLine(line);

    }
}


Measured memory_bytes: 11092
n,k=map(int,input().split())
box=list(map(int,input().split()))

count=0
for i in range(n):
    for j in box[i:]:
        if box[i]>j:
            count +=1

count_2=0
for i in range(n):
    for j in box:
        if box[i]>j:
            count_2 +=1

ans=(count*k)%(10**9+7) + ((count_2*k*(k-1))//2)%(10**9+7)
print(ans%(10**9+7))

Measured memory_bytes: 3188
//    >File Name: 2.cpp
//    > Author: Webwei

#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a,c;
	cin >> a >> c;
	if(a>c)	cout <<">\n";
	else if(a<c)	cout <<"<\n";
	else cout <<"=\n";
	return 0;
}


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

int main(){

    vector<int> P={2,3},S(100001,0);
    map<int,int> M,L;
    M[2]++;M[3]++;
    for(int i=5;i<100000;i+=2){
        bool flag=true;
        for(int j=3;j<=sqrt(i);j+=2){
            if(i%j==0){
                flag=false;
                break;
            }
        }
        if(flag){
            P.push_back(i);
            M[i]++;
        }
    }
    int N=P.size();
    for(int i=0;i<N;i++){
        if(M[(P[i]+1)/2]==1) L[P[i]]++;
    }
    for(int i=1;i<=100000;i++){
        if(L[i]==1) S[i]=S[i-1]+1;
        else S[i]=S[i-1];
    }
    int Q;cin>>Q;
    for(int i=0;i<Q;i++){
        int a,b;cin>>a>>b;
        cout<<S[b+1]-S[a-1]<<endl;
    }
}




Measured memory_bytes: 8448
sub f{$M[$_]=1;$M[$_]||&f for@$_;unshift@s,$_;}$%=<>;/ /,push@
$`,$'+0for<>;$M[$_]||f for 1..$%;map{$\+=$-=($p=$p[$_])-$\;$p[$_]+=$-=$p+1-$p[$_]for@$_}@s;print

Measured memory_bytes: 111232
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, d;
    cin >> n >> d;

    vector<vector<int>> count(d, vector<int>(d));
    vector<pair<int64_t, int64_t>> xy(n);
    for(auto&& p : xy) {
        cin >> p.first >> p.second;
        ++count[p.first % d][p.second % d];
    }

    int64_t a = 0;
    for (auto i : irange(0L, d)) {
        for (auto j : irange(0L, d)) {
            auto c = count[i][j];
            auto s = int64_t(sqrt(c));
            if (s * s < c) {
                ++s;
            }
            a = max(a, s - 1);
        }
    }

    vector<vector<int64_t>> num_inner(2 * d + 1, vector<int64_t>(2 * d + 1));
    vector<vector<int64_t>> num_outer(2 * d + 1, vector<int64_t>(2 * d + 1));
    for (auto i : irange(0L, 2 * d)) {
        for (auto j : irange(0L, 2 * d)) {
            bool in_inner = (count[i % d][j % d] - a * (a + 1) > 0);
            bool in_outer = (count[i % d][j % d] - a * a > 0);
            num_inner[i + 1][j + 1] = num_inner[i + 1][j] + num_inner[i][j + 1] - num_inner[i][j] + in_inner;
            num_outer[i + 1][j + 1] = num_outer[i + 1][j] + num_outer[i][j + 1] - num_outer[i][j] + in_outer;
        }
    }

    int64_t ans = numeric_limits<int64_t>::max();
    for (auto x : irange(0L, d)) {
        for (auto y : irange(0L, d)) {
            auto total_inner = num_inner[x + d][y + d] - num_inner[x + d][y] - num_inner[x][y + d];
            auto total_outer = num_outer[x + d][y + d];

            const auto& range = irange(0L, d);
            auto it = partition_point(range.begin(), range.end(), [&](int64_t b) {
                auto e = b + 1;
                auto ni = num_inner[x + e][y + e] - num_inner[x + e][y] - num_inner[x][y + e];
                if (ni < total_inner) {
                    return true;
                }

                auto no = num_outer[x + d][y + e] + num_outer[x + e][y + d] - num_outer[x + e][y + e];
                if (no < total_outer) {
                    return true;
                }

                return false;
            });

            ans = min(ans, *it);
        }
    }

    ans += a * d;

    cout << ans << endl;
}

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

int main(void)
{
    char s[5];
    while(cin >> s && s !=NULL)
    {
        int sum = 0;
        for(int i = 0; s[i] !='\0'; ++i)
        {
            if(s[i] == 'x')
                sum++;
        }
        cout << (3-sum)*100+700 <<endl;
    }
}


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

int main(){
  int a,b;
  while(1){
    cin>>a>>b;
    if(a==0&&b==0)break;
    for(int i=0;i<a;i++){
      for(int j=0;j<b;j++){
	if(i%2==0&&j%2==0)cout<<"#";
	else if(i%2!=0&&j%2==0)cout<<".";
	else if(i%2==0&&j%2!=0)cout<<".";
	else if(i%2!=0&&j%2!=0)cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3076
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

int main() {
	int n; cin >> n;
	string S, T; cin >> S >> T;
	vector<int> a(26), b(26);
	for (int i = 0; i < n; i++) {
		a[S[i] - 'a']++;
		b[T[i] - 'a']++;
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int sum = 0;
	for (int k = 0; k < 26; k++)
		sum += abs(a[k] - b[k]);
	cout << sum / 2 << endl;
}

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


def main():
    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))
    i = 0
    ans = [[0 for _ in range(w)] for _ in range(h)]

    # 一筆書きの要領で，a[i]の数だけ数字を順番に埋めていく
    for hi in range(h):
        for wi in range(w):
            if a[i] >= 1:
                ans[hi][wi] = i + 1
                a[i] -= 1
            else:
                i += 1
                ans[hi][wi] = i + 1
                a[i] -= 1

    # 出力のときに，奇数番目の行(0-index)だけ反転させる
    for index, a in enumerate(ans):
        if index % 2 == 1:
            a = a[::-1]

        print(' '.join(map(str, a)))


if __name__ == '__main__':
    main()


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

int s_num[26];
int p_num[26];

int main()
{
		int i, j;
		char c;
		bool is=false;
		string s, p, comp;
		getline(cin, s);
		getline(cin, p);

		for (i = 0; i < s.size(); i++) {
				j = i;
				comp.clear();
				while (comp.size()!=p.size()) {
						comp += s[j]; 
						if (j==s.size()-1) j=-1;
						j++;
				}
				if (comp == p) {
						is = true; 
						break; 
				} else {
						is = false; 
				}
		} 
		if (is) cout << "Yes\n";
		else cout << "No\n";
}

Measured memory_bytes: 3168
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            
            int H=sc.nextInt();
            int W=sc.nextInt();
            if(H==0&&W==0) break;
            
            for(int i=0;i<H;i++){
                
                for(int j=0;j<W;j++){
                    if((i+j)%2==0){
                       System.out.print("#");
                    }else{
                       System.out.print(".");
                    }
                }
                
                System.out.println("");
            }
            System.out.println("");
        }
     
    }
}


Measured memory_bytes: 35376
#include<stdio.h>
 
int main(void) {
    int b, f, r, v, A[4][3][10] = { 0 }, n, i, j, k;
    scanf("%d", &n);
    for (i = 0; i < n; ++i) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        A[b-1][f-1][r-1] += v;
    }
 
    for (i = 0; i < 4; ++i) {
        for (j = 0; j < 3; ++j) {
            for (k = 0; k < 10; ++k) printf(" %d", A[i][j][k]);
            puts("");
        }
        if (i != 3) {
            for (j = 0; j < 20; ++j) printf("#");
            puts("");
        }
    }
}


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

using namespace std;

#define ll long long
#define mod 1000000007

struct item{
    int wt;
    int val;
};

void solve(){

    int n, w; cin >> n >> w;
    item arr[n];
    for(int i = 0; i < n; ++i){
        cin >> arr[i].wt >> arr[i].val;
    }
    vector<ll> dp (w+1, -1);
    dp[0] = 0;

    for(int i = 0; i < n; ++i){
        for(int j = w; j-arr[i].wt >= 0; --j){
            if(dp[j-arr[i].wt] != -1)
                dp[j] = max(dp[j], (ll)dp[j-arr[i].wt] + arr[i].val);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
    
    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
	return 0;
}

Measured memory_bytes: 3944
import fractions

x = input().split(" ")
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])

c_count = (b//c)-((a-1)//c)
d_count = (b//d)-((a-1)//d)

cd = c*d // fractions.gcd(c,d)
cd_count = (b//cd) - ((a-1)//cd)
ans = (b+1-a)-c_count-d_count+cd_count

print(ans)

Measured memory_bytes: 5600
import java.util.*;
class Main{
	static Scanner scan = new Scanner(System.in);
	static void crackers(){
		int n = scan.nextInt(), k = scan.nextInt();
		int m;
		if(n%k==0)
			m = 0;
		else
			m = 1;
		System.out.println(m);
	}
	static void buy(){
		int n = scan.nextInt();
		for(int i=0;i<=n/4;i++){
			for(int j=0;j<=n/7;j++){
				if(4*i + 7*j == n){
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
	public static void main(String[] argv){
		//crackers();
		buy();
	}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 1050000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	vvi a(n, vi(n));
	vvi d(n, vi(n));
	rep(i, n)rep(j, n) {
		cin >> a[i][j];
		d[i][j] = a[i][j];
	}

	rep(k, n)rep(i, n)rep(j, n) {
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}

	bool road = true;
	rep(i, n)rep(j, n) {
		if (d[i][j] < a[i][j])road = false;
	}

	ll ans = 0;

	rep(i, n)rep(j, n) {
		if (i <= j)continue;
		bool path = true;
		rep(k, n) {
			if (i == k || j == k)continue;
			if (a[i][j] == a[i][k] + a[k][j])path = false;
		}
		if (path)ans += a[i][j];
	}

	if (!road)cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 1024
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int main()
{
  int n;
  scanf("%d",&n);
  double sisan;//初期運用資金
  int nensu;//運用年数
  int k;//種類
  int l;//単離か福利
  double riritu,tesuu;
  int ans = 0;
  for(int i = 0;i < n;i++){
    cin >>sisan>>nensu>>k;
    int ans1=0;
    int ans2=0;
    for(int j = 0;j < k;j++){
      int tanans=0;
      int hukuans=0;
      
      cin >>l>>riritu>>tesuu;
      if(l ==0){
	tanans = sisan;
	int sum =0;//利子累計
	for(int m = 0; m <nensu ;m++){
	  sum +=tanans*riritu;
	  tanans -=tesuu;
	}
	tanans +=sum;
	ans1 =max(ans1,tanans);
      }else{
	hukuans = sisan;
	for(int m = 0;m <nensu;m++){
	  hukuans +=(hukuans)*riritu-tesuu;
	}
	ans2 = max(ans2,hukuans);
      }
      ans = max(ans1,ans2);
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1272
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    int x;
    cin >> x;
    cout << (x == 0 ? 1 : 0) << endl;
    return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int x = sc.nextInt();
    
    int cou = 0;
    for(int i=0; i<=a; i++) {
    for(int j=0; j<=b; j++) {
    for(int k=0; k<=c; k++) {
    	if(500*i + 100*j + 50*k == x){
    		cou++;
    	}
    	}
    }
    }
    	System.out.println(cou);
      }
}


Measured memory_bytes: 35880
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

ll n,f[100][10],p[100][11];

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin >> f[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 11; j++){
			cin >> p[i][j];
		}
	}

	ll ans = -(1<<30);

	for(int bit = 1; bit < (1<<10); bit++){
		ll x = 0;
		for(int i = 0; i < n; i++){
			int cnt = 0;
			for(int j = 0; j < 10; j++){
				if((bit>>j&1) && f[i][j]) cnt++;
			}
			x += p[i][cnt];
		}
		if(ans<x) ans = x;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), Q = in.nextInt();
        in.nextLine();
        char[] S = in.nextLine().toCharArray();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        }
        int[] ac = new int[N + 1];
        for (int i = 1; i < N; i++) {
            ac[i] = ac[i - 1] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ac[r[i] - 1] - ac[l[i] - 1]);
        }
    }
}

Measured memory_bytes: 84840
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n

for i in range(1, n):
  s = max(i-k, 0)
  dp[i] = min(dp[j] + abs(h[j]-h[i]) for j in range(s, i))

print(dp[n-1])

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

int main() {
	int h, m, s, num;
	cin >> num;
	h = num / 3600;
	m = (num - 3600 * h)/60;
	s = num - (h * 3600 + m * 60);
	cout << h << ":" << m << ":" << s << endl;


	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define all(v) v.begin(),v.end()
#define fi first
#define se second
const int inf = 1e9;

signed main(){
	int n;
	scanf("%lld", &n);
	int ans = n*800-200*(n/15);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  vector<tuple<string,ll,ll> > vec(n);
  rep(i,n){
    cin>>get<0>(vec[i])>>get<1>(vec[i]);
    get<2>(vec[i])=i+1;
  }
  sort(vec.begin(),vec.end());
  map<string,vector<pair<ll,ll> > >M;
  rep(i,n){
    M[get<0>(vec[i])].push_back(make_pair(get<1>(vec[i]),get<2>(vec[i])));
  }
  for(auto v:M){
    sort(v.second.begin(),v.second.end());
    reverse(v.second.begin(),v.second.end());
    for(ll i=0;i<v.second.size();i++){
      cout<<v.second[i].second<<endl;
    }
  }
}
   
  

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 1e6 + 5;
const int INF = 1001001001;
const int MOD = 1000000007;

int dp[105][105][305];

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

    vector<int> w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    int base = w[0];
    rep(i, N) w[i] -= base;

    rep(i, N) {
        rep(j, N) {
            rep(k, 3*N) {
                int ni = i + 1, nj = j, nk = k;
                dp[ni][nj][nk] = max(dp[ni][nj][nk], dp[i][j][k]);
                nj++, nk += w[i];
                dp[ni][nj][nk] = max(dp[ni][nj][nk], dp[i][j][k] + v[i]);
            }
        }
    }

    int ans = 0;
    rep(i, N + 1)rep(j, 3*N) {
        if ((ll)base * i + j <= W) ans = max(ans, dp[N][i][j]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pii make_pair
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }

main()
{
    //fastio;
    string s;
    map<char, int>mp;
    cin>>s;
    for(int i=0; i<s.size(); i++) mp[s[i]]++;
    for(char i='a'; i<='z'; i++) {
        if(mp[i]%2) {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


Measured memory_bytes: 3656
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<numeric>
#include<set>
using namespace std;

int main(void)
{
    long long N, K;
    cin >> N >> K;

    long long x = N;

    set<long long> st;
    st.insert(x);
    while (1) {
        long long nx;
        if (x >= K) {
            nx = x % K;
        }
        else {
            nx = K - x;
        }

        if (st.count(nx))
            break;

        x = nx;
        st.insert(x);

        if (x == 0)
            break;
    }

    cout << *st.begin() << endl;

    return 0;
}


Measured memory_bytes: 256
# GET AX
N, Q = map(int, input().split())
S = str(input())
lr = [list(map(int, input().split())) for _ in range(Q)]
#N, Q = 8, 3
#S = 'ACACTACG'
#lr = [[3,7],[2,3],[1,8]]

a = [0]*len(S)
ac_num = 0
for i in range(N-1):
	a[i] = ac_num
	if S[i] == 'A' and S[i+1] == 'C':
		ac_num += 1
a[-1] = ac_num

for q in range(Q):
	l, r = lr[q]
	nl = a[l-1]
	nr = a[r-1]
	print(nr - nl)

Measured memory_bytes: 30672
from bisect import *


def p_e():
    N = int(input())
    # A = [int(input()) for _ in range(N)]
    ans = [-1] * N

    for _ in range(N):
        a = int(input())
        ans[bisect(ans, a - 1) - 1] = a

    print(N - bisect(ans, -1))


if __name__ == '__main__':
    p_e()


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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 22, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

int a[N][N];

int dp[(1 << N)];

void add(int &x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

int main() {
	FREOPEN();
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d ", &a[i][j]);
	dp[0] = 1;
	for (int mask = 0; mask < (1 << n); mask++) {
		int j = __builtin_popcountll(mask);
		for (int i = 0; i < n; i++) {
			if (mask & (1 << i) || !a[i][j]) continue;
			add(dp[mask | (1 << i)], dp[mask]);
		}	
	}
	printf("%d ", dp[(1 << n) - 1]);
	return 0;
}


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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	int n, x, count = 1;
	cin >> n;
	
	for (int i = 0; i < n; ++i) {
		cin >> x;
		if (x == count) {
			++count;
		}
	}
	
	if (count == 1) {
		cout << "-1";
	} else {
		cout << n - count + 1;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>


std::vector<std::vector<int>> mats, cost;


int calcMin(int start, int end) {
    if (cost[start][end] != -1) return cost[start][end];

    int min_cost;
    for (int i = start; i < end; i++) {
        int tmp_cost = calcMin(start, i) + calcMin(i + 1, end)
            + mats[start][0] * mats[i][1] * mats[end][1];
        if (i == start) {
            min_cost = tmp_cost;
        }
        if (min_cost > tmp_cost) min_cost = tmp_cost;
    }
    cost[start][end] = min_cost;
    return cost[start][end];
}

int main() {
    int n;
    std::cin >> n;
    
    mats = std::vector<std::vector<int>>(n, std::vector<int>(2));
    cost = std::vector<std::vector<int>> (n, std::vector<int>(n, -1));

    for (int i = 0; i < n; i++) {
        std::cin >> mats[i][0] >> mats[i][1];
    }

    for (int i = 0; i < n; i++) {
        cost[i][i] = 0;
    }

    std::cout << calcMin(0, n - 1) << std::endl;
}



Measured memory_bytes: 3160
#include<cstdio>

/*#### modular_arithmetic */
class modular_arithmetic{
public:
	int mod;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	void set_mod(int _mod){mod = _mod;}
	int add(int x,int y){return (x+y)%mod;}
	int sub(int x,int y){return (x-y+mod)%mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
};
/*####*/
modular_arithmetic ma;
void addto(int&x,int y){
	x = ma.add(x,y);
}

int n,res;
int d0[1<<15],d1[1<<15],cnt[1<<15],p2[111];bool g[15][15];
void pre(int x,int*d){
	for(int mask=0; mask<(1<<n); mask++)if(mask&(1<<x)){
		if(mask==(1<<x)){
			d[mask] = 1;
			continue;
		}
		d[mask] = p2[cnt[mask]];
		int sub_mask = 0;
		do{
			d[mask] = ma.sub(d[mask], ma.mul(d[sub_mask], p2[cnt[mask - sub_mask]]));
		}while((sub_mask = (sub_mask - mask)&mask) != mask);
	}
}
void dfs(int x,int mask0,int mask1){
	if(x == n){
		res = ma.sub(res, ma.mul(ma.mul(d0[mask0], d1[mask1]), p2[cnt[(1<<n) - 1 - mask0 - mask1]]));
		return;
	}
	dfs(x + 1, mask0, mask1);
	bool ff = true;
	for(int i=0; i<x; i++)if(mask1&(1<<i))if(g[x][i]){
		ff = false;
		break;
	}
	if(ff)dfs(x+1, mask0|(1<<x), mask1);
	ff = true;
	for(int i=0; i<x; i++)if(mask0&(1<<i))if(g[x][i]){
		ff = false;
		break;
	}
	if(ff)dfs(x+1, mask0, mask1|(1<<x));
}
int main(){
	int m,x,y;
	scanf("%d%d",&n,&m);
	p2[0] = 1;
	for(int i=1; i<=m; i++)
		p2[i] = ma.add(p2[i-1],p2[i-1]);
	while(m--){
		scanf("%d%d",&x,&y);
		--x;--y;
		g[x][y] = g[y][x] = true;
	}
	for(int mask=0; mask<(1<<n); mask++)
		for(int i=0; i<n; i++)if(mask&(1<<i))
		for(int j=i+1; j<n; j++)if(mask&(1<<j))
		if(g[i][j])cnt[mask]++;
	pre(0,d0);
	pre(1,d1);
	res = p2[cnt[(1<<n)-1]];
	if(!g[0][1])dfs(2,1,2);
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main()
{
    int N;
    cin >> N;
    vector<int> P(N), P_min(N); //P_min: i番目までの最小値
    int cnt = 0;
    rep(i, N)
    {

        cin >> P[i];
        if (i == 0)
        {
            P_min[i] = P[i];
            cnt++;
        }
        else
        {
            if (P[i] <= P_min[i - 1])
            {
                P_min[i] = P[i];
                cnt++;
            }
            else
            {
                P_min[i] = P_min[i - 1];
            }
        }
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 1792
n,m=map(int,input().split())

def prime(n):#素数かどうか＿素数なら1、そうでないなら0
    for i in range(2,n):
        if n%i==0:
            return 0
    return 1

#def prime_l(n):
#    for i in range(2,n+1):
#        if prime(i)==1:
#            yield i
#def prime_l(n):#n以下の素数のリスト
#    l=[1 for i in range(2,n+1)]#2からnの、n-1個 インデは-2
#    for i in range(n-1):#0からn-2 上記−２=インデ
#        if prime(i+2):
#            for j in range(2,n//(i+2)+1):#何倍のが0になるか
#                l[(i+2)*j-2]=0
#    return l

def prime_l(n):
    l=[1 for i in range(2,n+1)]#2からn インデは-2
    #sq_n=n**(1/2)
    for i in range(n-1):
        if l[i]==1:
            for j in range(2*(i+2),n+1,i+2):
                l[j-2]=0
    l1=[]
    for i in range(n-1):
        if l[i]==1:
            l1.append(i+2)
    return l1


def modpow(a,n,p):#a^n mod p
    res=1
    while n>0:
        if n&1:#１とのビット論理積が１、つまり奇数
            res=res*a%p
        a=a*a%p
        n>>=1
        #ビットの右シフト_2進数表記のnを小数点を固定して右に１桁ずらす_１桁小さくなる
    return res

if m==1:
    print(1)
else:
    #l=[i+2 for i in prime_l(int(1e9))]
    #l=prime_l(int(m**(1/2))) if m>=4 else prime_l(m)
    l=prime_l(int(m**(1/2)))#√までにしておくと、1にならずに残ったものは素数
    #ll=next(l)
    i=0
    d={}
    while m!=1 and i!=len(l):
        if m%(l[i])==0:
            d[l[i]]=1
            m/=l[i]
            while m%(l[i])==0:
                d[l[i]]+=1
                m/=l[i]
        #ll=next(l)
        i+=1
        #while l[i]==0:
        #    i+=1
    if m!=1:
        d[m]=1
    #s_k=0
    #for i in d.values():
    #    s_k+=i
    #print(d.values())
    mod=int(1e9+7)
    n_fac=1
    fac_l=[1]#0!
    d_max=max(d.values())
    #for i in range(n+d_max-1):# 1!,2!,,,,(n+d_max-1)!
    #    n_fac*=i+1
    for i in range(n+d_max-1):# 0!,1!,2!,,,,(n+d_max-1)!
        n_fac*=i+1
        n_fac=n_fac%mod
        fac_l.append(n_fac)

    fac_1_l=[]
    for i in range(n+d_max):
        fac_1_l.append(modpow(fac_l[i],mod-2,mod))
    w=1
    for dv in d.values():
        w*=fac_l[n+dv-1]
        w=w%mod
        #n_n_fac=fac_l[n-dv]
        #div=int((fac_l[n-1-1]*fac_l[dv-1])%(1e9+7))
        #print(div)
        #if div>w:
        #    w+=1e9+7
        #w=int(w/div)
        w=w*fac_1_l[n-1]%mod
        w=w*fac_1_l[dv]%mod
    print(w)


Measured memory_bytes: 11388
#include <iostream>
#include <vector>
#include <queue>
using namespace std; typedef long long ll; int an=0; const ll INF = 1e18; const ll MOD = 1e9+7;
typedef pair<int,int> P; const int xx[4]={1,-1,0,0}, yy[4]={0,0,1,-1};
int a[90][90]; int n,m; struct tlp {int x,y,cs;};

int main(){
  int h,w; cin>>h>>w; string a[h]; int wh=0;
  for(int i=0;i<h;i++) {
    cin>>a[i];
    for(int j=0;j<w;j++) {wh+=a[i][j]=='.';}
  }
  queue<tlp> que; que.push({0,0,1}); int b[h][w]; fill(b[0], b[h], 1e9); b[0][0] = 1;
  while(!que.empty()) {
    tlp gt = que.front(); que.pop();
    if (gt.cs > b[gt.x][gt.y]) continue;
    for(int i=0;i<4;i++) {
      int px=gt.x+xx[i], py=gt.y+yy[i];
      if (0<=px&&px<h&&0<=py&&py<w&&a[px][py]=='.'&&b[px][py]>gt.cs+1) {
        b[px][py]=gt.cs+1; que.push({px,py,gt.cs+1});
      }
    }
  }
  /*
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cout<<b[i][j]<<" ";
    } cout<<endl;
  }*/
  if (b[h-1][w-1] == 1e9) cout<<-1<<endl;
  else cout<<wh-b[h-1][w-1]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
    int x, a, b;
    cin >> x >> a >> b;
    int da = abs(x - a), db = abs(x - b);
    if ( da < db ) 
    cout << "A" <<endl;
    else cout << "B" <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;

#define ll long long

ll n,minn = 2e18,maxn = -2e18,m;
ll a[1000007];

int main(){
	cin >> m >> n; 
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1,a+1+n);
	ll tot = 0,l,ans;
	ans = a[n]-a[1];
	for(int i = 1; i <= n; i++){
		if(a[i] - a[i-1] > tot){
			tot = a[i]-a[i-1];
			l = i;
		}
	}
	cout << min(ans,m-tot);
}

Measured memory_bytes: 1792
#https://atcoder.jp/contests/abc120/tasks/abc120_d
#Thanks for this submission: https://atcoder.jp/contests/abc120/submissions/10531572

class UnionFind():
    def __init__(self, N):
        self._root = [-1 for _ in range(N)]

    def find(self, x):
        if self._root[x] < 0: return x
        self._root[x] = self.find(self._root[x])
        return self._root[x]

    def unite(self, x, y):
        gx = self.find(x)
        gy = self.find(y)
        if gx == gy: return False
        if self._root[gx] > self._root[gy]:
            gx, gy = gy, gx
        self._root[gx] += self._root[gy]
        self._root[gy] = gx
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -(self._root[self.find(x)])

    def roots(self):
        return [i for i in self._root if i < 0]


n, m = map(int, input().split())
ilands = []
for _ in range(m):
    a, b = map(int, input().split())
    ilands.append((a-1, b-1))
rev_ilands = list(reversed(ilands))

uf = UnionFind(n)
ans = [0] * m
#Number of bridges connecting N islands
ans[m-1] = n*(n-1)//2

for i in range(m-1):
    if uf.find(rev_ilands[i][0]) != uf.find(rev_ilands[i][1]):
      n_bridgs= uf.size(rev_ilands[i][0])*uf.size(rev_ilands[i][1])
      ans[m-2-i] = ans[m-1-i] - n_bridgs     
      uf.unite(rev_ilands[i][0], rev_ilands[i][1])
    else:
      ans[m-2-i] = ans[m-1-i]

for i in range(m):
    print(ans[i])

Measured memory_bytes: 23292
#include<bits/stdc++.h>
using namespace std;
int n,t[9];

int main(){
    cin >> n;
    if(n==3)printf("2 5 63");
    else
    {
        if(n&1)
            t[0]=6,t[1]=2,t[2]=10,t[3]=3,t[4]=9,t[5]=4,t[6]=8,t[7]=12;
        else
            t[0]=2,t[1]=10,t[2]=3,t[3]=9,t[4]=4,t[5]=8,t[6]=6,t[7]=12;
        for(int i=0; i<min(n,8); i++) cout << t[i] << ' ';
        for(int i=8; i<n; i++){
          t[i%8]=t[i%8]+12;
          cout << t[i%8] << ' ';
        }
    }
    return 0;
}


Measured memory_bytes: 384