akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
#ABC147 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)

ans = 0
t = s[:n//2]
u = s[n//2:][::-1]
for i in range(n//2):
    if t[i] != u[i]:
        ans += 1
print(ans)


Measured memory_bytes: 38256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, M: int, A: "List[int]"):
    ALL = sum(A)
    A.sort(reverse=True)

    for i in range(M):
        if A[i] < ALL/(4*M):
            print(NO)
            return
    
    print(YES)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void calc(string[] g) {
    auto rows = g.length;
    auto cols = g[0].length;

    // # が存在する行、列
    bool[int] mrow, mcol;

    for (int r = 0; r < rows; r++) {
        for (int c = 0; c < cols; c++) {
            if (g[r][c] == '#') {
                mrow[r] = true;
                break;
            }
        }
    }

    for (int c = 0; c < cols; c++) {
        for (int r = 0; r < rows; r++) {
            if (g[r][c] == '#') {
                mcol[c] = true;
                break;
            }
        }
    }

    for (int r = 0; r < rows; r++) {
        if (r !in mrow) continue;
        for (int c = 0; c < cols; c++) {
            if (c in mcol) write(g[r][c]);
        }
        writeln();
    }
}

void main() {
    auto hw = readints;
    int h = hw[0];

    string[] g;
    for (int i = 0; i < h; i++) {
        g ~= read!string;
    }
    calc(g);
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
int main()
{ int x;
  cin>>x;
  int m,n,c;
  m=x/100;
  n=x/10-m*10;
  c=x-m*100-n*10;

  if(m==9) m=1;
  else if(m==1) m=9;
  if(n==9) n=1;
  else if(n==1) n=9;
  if(c==9) c=1;
  else if(c==1) c=9;

  x=m*100+n*10+c;
  cout<<x;







}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
	char c;
	cin >> c;
	if(c=='A') c='T';
	else if(c=='T') c='A';
	if(c=='C') c='G';
	else if(c=='G') c='C';
	cout << c;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);

    double N = sc.nextDouble();
    double oddNum = (double)( ((int)N + 1) / 2 );
    double result = oddNum / N;
    System.out.println(result);
  }
}


Measured memory_bytes: 22868
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,ans;
    cin >> a >> b;
    ans = a * b;
    if(ans%2==0)
    {
        cout << "Even" << endl;
    }else{
        cout << "Odd" << endl;
    }
    
}


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

int main() {
	int n, k;
	cin >> n >> k;
	// あまりなく分配できる場合
	if (n % k == 0) {
		cout << 0 << endl;
	}
	// あまりがある場合
	else {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mod (1e9 + 7)
#define pb push_back
#define ll long long int
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){
  int x,y,a,b,c;

  cin>>x>>y>>a>>b>>c;
  vector<ll> p(a),q(b);
  vector<pll> r(c);
  for(int i=0;i<a;i++) cin>>p[i];
  for(int i=0;i<b;i++) cin>>q[i];
  for(int i=0;i<c;i++) cin>>r[i].first,r[i].second=0;

  sort(p.begin(),p.end(),greater<int>());
  sort(q.begin(),q.end(),greater<int>());

  for(int i=0;i<x;i++) r.pb(pll(p[i],1));
  for(int i=0;i<y;i++) r.pb(pll(q[i],2));
  sort(r.begin(),r.end(),greater<pll>());

  ll sum=0;
  for(int i=0;i<x+y;i++){
    sum+=r[i].first;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 9956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N ;
  cin >> N;
  string Coun = "Three";
  for(int i=0; i<N; i++){
    string S;
    cin >> S;
    if (S == "Y"){
      Coun = "Four";
      break;
    }
  }
  cout << Coun << endl;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<map>
#include<vector>
#include<ctime>
#include<stack>
#define mp make_pair
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long

using namespace std;

inline ll read()
{
    long long f=1,sum=0;
    char c=getchar();
    while (c<'0' || c>'9')
    {
        if (c=='-') f=-1;
        c=getchar();
    }
    while (c>='0' && c<='9')
    {
        sum=sum*10+c-'0';
        c=getchar();
    }
    return sum*f;
}
const int MAXN=200010;
const int Mod=998244353;
char s[MAXN];
int f[MAXN][3][3][2];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    if (n<=3)
    {
        if (n==1)
            cout<<1;
        else if (n==2)
        {
            if (s[1]==s[2])
                cout<<1;
            else
                cout<<2;
        }
        else
        {
            if (s[1]==s[2] || s[2]==s[3])
            {
                if (s[1]==s[2] && s[2]==s[3])
                    cout<<1;
                else 
                    cout<<6;
            }
            else
            {
                if (s[1]==s[3])
                    cout<<7;
                else
                    cout<<3;
            } 
        }
        return 0;
    }
    int sum=0,tot=0;
    for (int i=2;i<=n;i++)
        sum+=(s[i]==s[i-1]),tot+=s[i]-'a';
    tot+=s[1]-'a';
    tot%=3;
    if (sum==n-1)
    {
        cout<<1;
        return 0;
    }
    int ans=!sum,i,j,k,p,last;
    f[1][0][0][0]=f[1][1][1][0]=f[1][2][2][0]=1;
    for(i=2;i<=n;i++)
	    for(j=0;j<3;j++)
		    for(k=0;k<3;k++)
			    for(p=0;p<3;p++)
			    {
				    last=(j-k+3)%3;
				    f[i][j][k][1]=(f[i][j][k][1]+f[i-1][last][p][1])%Mod;
				    if(k==p)	f[i][j][k][1]=(f[i][j][k][1]+f[i-1][last][p][0])%Mod;
				    else	f[i][j][k][0]=(f[i][j][k][0]+f[i-1][last][p][0])%Mod;
			    }
	for(i=0;i<3;i++)	ans=(ans+f[n][tot][i][1])%Mod;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 14464
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
//const long long mod = 998244353;
const long long mod = 1e9 + 7, inf = 3e18;
const string sp = " ";

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

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n == r) return 1;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int nck[1010][1010];
void comb(int n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}


signed main() {
	int a, b;
	cin >> a >> b;
	cout << max(0LL, a - 2 * b) << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int n, m, k;
  vector<int> a, b;
  vector<int> sum_a, sum_b;
  int n_max, m_max;
  cin >> n >> m >> k;

  for (int i = 0; i < n; i++)
  {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  for (int i = 0; i < m; i++)
  {
    int tmp;
    cin >> tmp;
    b.push_back(tmp);
  }

  for (int i = 0; i < n; i++)
  {
    int tmp2;
    if (i == 0)
    {
      sum_a.push_back(a[0]);
      n_max = i + 1;
    }
    else
    {
      tmp2 = sum_a[i - 1] + a[i];
      if (tmp2 <= k)
      {
        sum_a.push_back(tmp2);
        n_max = i + 1;
      }
      else
      {
        break;
      }
    }
  }
  for (int i = 0; i < m; i++)
  {
    int tmp2;
    if (i == 0)
    {
      sum_b.push_back(b[0]);
      m_max = i + 1;
    }
    else
    {
      tmp2 = sum_b[i - 1] + b[i];
      if (tmp2 <= k)
      {
        sum_b.push_back(tmp2);
        m_max = i + 1;
      }
      else
      {
        break;
      }
    }
  }

  int max = 0;
  int sum = 0;

  // pick 0 books from A
  // pick j books from B
  int max_0;
  for (int j = 0; j < m_max; j++)
  {
    if (sum_b[j] <= k)
    {
      if (max < j + 1)
      {
        max = j + 1;
      }
    }
    else
    {
      break;
    }
  }
  max_0 = max;

  // pick i books from A
  // pick 0 books from B
  for (int i = 0; i < n_max; i++)
  {
    if (sum_a[i] <= k)
    {
      if (max < i + 1)
      {
        max = i + 1;
      }
    }
    else
    {
      break;
    }
  }

  // // pick max_0-1 to 0 books from A
  // // increase the number of books from B
  // for (int l = max_0 - 1; l >= 0; l--)
  // {
  //   sum = sum_b[l];
  //   for (int o = max - l - 1; o < n_max; o++)
  //   {
  //     sum = sum_b[l] + sum_a[o];
  //     if (sum <= k)
  //     {
  //       if (max < l + 1 + o + 1)
  //       {
  //         max = l + 1 + o + 1;
  //       }
  //     }
  //     else
  //     {
  //       break;
  //     }
  //   }
  // }

  // pick i books from A
  // pick j books from B
  for (int i = 0; i < n_max; i++)
  {
    for (int j = max - (i + 1); j < m_max; j++)
    {
      sum = sum_a[i] + sum_b[j];
      // cout << sum << endl;
      if (sum <= k)
      {
        if (max < i + 1 + j + 1)
        {
          max = i + 1 + j + 1;
        }
      }
      else
      {
        break;
      }
    }
  }

  cout << max << endl;
  return 0;
}

Measured memory_bytes: 7208
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here

        Scanner src = new Scanner(System.in);


        int n = src.nextInt();

        if(n%1000==0)
            System.out.println(0);
        else{
            int nn =n/1000;
            nn++;
            nn*=1000;
            System.out.println(nn-n);
        }





    }
}


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

#define pb push_back
#define all(a) (a).begin(), (a).end()

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

int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int h1, s1, h2, s2; cin >> h1 >> s1 >> h2 >> s2;

	bool tak = true;
	while (true) {
		if (tak)
			h2 -= s1;
		else
			h1 -= s2;

		if (h2 <= 0) {
			cout << "Yes\n";
			break;
		}

		if (h1 <= 0) {
			cout << "No\n";
			break;
		}

		tak ^= true;
	}
}
 


Measured memory_bytes: 3656
import collections

n=int(input())
arr=list(map(int,input().split()))
ans=0
cnt=collections.defaultdict(int)
for i in range(1,n+1):
	ans+=cnt[i-arr[i-1]] #すでに見た要素について、i-Aiと等しいものの個数を数える
	cnt[i+arr[i-1]]+=1 #i+Aiを付け加える
print(ans)

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

int N, Q;
vector<int> edges[200000];
int64_t num[200000];

void dfs(int i, int p){
    for(int j : edges[i]) if(j != p){
        num[j] += num[i];
        dfs(j, i);
    }
}

int main(){
    cin >> N >> Q;
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }
    for(int i=0; i<Q; i++){
        int p, x;
        cin >> p >> x;
        num[p-1] += x;
    }
    dfs(0, -1);
    for(int i=0; i<N; i++) cout << num[i] << " \n"[i==N-1];
    return 0;
}


Measured memory_bytes: 24320
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
int N, M; vector<pair<int, int>> v;
int main() {
  scanf("%d %d", &N, &M);
  for(int i = 0, A; i < N; ++i) {
    scanf("%d", &A);
    v.push_back({A, 1});
  }
  for(int i = 0, B, C; i < M; ++i) {
    scanf("%d %d", &B, &C);
    v.push_back({C, B});
  }
  sort(v.begin(), v.end(), greater<>());
  ll ans = 0;
  for(int i = 0; N > 0; ++i) {
    auto t = v[i];
    ans += 1LL*t.first*min(N, t.second);
    N -= t.second;
  }
  printf("%ld\n", ans);
}

Measured memory_bytes: 2420
#include <iostream>

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

int main() {
    int n;
    long  ans = 0LL;
    std::cin >> n;
    rep(i, n+1) {
        if (i*i > n) break;
        ans = i*i;
    }
    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <list>
#include <utility>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, s, n) for(int i = (s); i < (n); ++i)
#define MAX 100
typedef long long LL;
typedef unsigned long long ULL;
int open[MAX];
int profit[MAX][11];
int main(void){	
    int n; scanf("%d", &n);
    rep(i, n){
        int cnt = 0, buf;
        rep(j, 10){
            cnt <<= 1;
            scanf("%d", &buf);
            cnt += buf;
        }
        open[i] = cnt;
    }
    rep(i, n) rep(j, 11){
        scanf("%d", &profit[i][j]);
    }
    LL min = -1e9;
    rep1(i,1,1024){
        LL v = 0;
        rep(j, n) v += profit[j][__builtin_popcount(i & open[j])];
        if(v > min) min = v;
    }    
    printf("%lld", min);
    return 0;
} 


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      a: usize,
      b: usize,
      c: usize,
    }
    if a == b && b == c {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}


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

int main()
{
    ll h , w ;
    bool hashNow ;
    while(cin >> h >> w)
    {
        if(h == 0 && w == 0) break ;
        for(ll i = 0 ; i < h ; i++)
        {
            if(i%2 == 0) hashNow = true ;
            else hashNow = false ;
            for(ll j = 0 ; j < w ; j++)
            {
                if(hashNow)
                {
                    cout << '#' ;
                    hashNow = false ;
                }
                else
                {
                    cout << '.' ;
                    hashNow = true ;
                }
            }
            cout << endl ;
        }
        cout << endl ;
    }
}


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

struct UnionFind{
private:
  vector<int> data;
public:
  int N;
  UnionFind(int n) : data(n, -1), N(n){}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    --N;
    if(data[y] < data[x]) swap(x,y);
    data[x] += data[y];
    data[y] = x;
    return x != y;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
  int size(int x){ return -data[find(x)]; }
};

int main(){
  int N, Q;
  cin >> N >> Q;
  UnionFind uf(N);
  while(Q--){
    int t, u, v;
    cin >> t >> u >> v;
    if(t){
      cout << uf.same(u,v) << '\n';
    }else{
      uf.unite(u,v);
    }
  }
}


Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,n,i,b=1;
  cin>>n;
  for(i=0;i<n;i++)
  {
  	cin>>a;
  	if(b && a%2==0 && a%3!=0 && a%5!=0) b=0;
  	
  }
  if(b) cout<<"APPROVED\n";
  else cout<<"DENIED\n";
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def div2count(n):
  cnt = 0
  while n % 2 == 0:
    cnt += 1
    n = n / 2
  return cnt

N = I()

ans = 1
ans_cnt = 0

for n in range(1,N+1):
  cnt = div2count(n)
  if ans_cnt < cnt:
    ans_cnt = cnt
    ans = n
print(ans)


Measured memory_bytes: 12476
num_rows, num_cols, n = map(int, raw_input().split())
marks = {}
for i in range(n):
    r, c = map(int, raw_input().split())
    for ri in range(r - 2, r + 1):
        if ri < 1 or ri + 2 > num_rows:
            continue
        for ci in range(c - 2, c + 1): 
            if ci < 1 or ci + 2 > num_cols:
                continue
            k = ri * num_cols + ci
            marks[k] = marks.setdefault(k, 0) + 1
result = 10 * [ 0 ]
result[0] = (num_rows - 2) * (num_cols - 2) - len(marks)
for count in marks.values():
    result[count] += 1
print('\n'.join(map(str, result)))


Measured memory_bytes: 124812
#include <stdio.h>
#define mod 1000000007
#define LL long long
LL n,a,b;
LL quick_pow(LL a,LL b){	
	LL ans=1;	
	while(b){		
		if(b&1){
			ans=ans*a%mod;	
		}		
		a=a*a%mod;		
		b>>=1;	
	}	
	return ans;
}
LL C(LL a,LL b){	
	LL i,ans=1,c=1;	
	for(i=a;i>=a-b+1;i--){
		ans=ans*i%mod;	
	}
	for(i=b;i>=1;i--){
		c=c*i%mod;	
	}
	return ans*quick_pow(c,mod-2)%mod;
}
int main(){	
	LL ans=0;	
	scanf("%lld%lld%lld",&n,&a,&b);	
	ans+=quick_pow(2,n)-1;	
	ans-=C(n,a);	
	ans-=C(n,b);	
	ans=(ans%mod+mod)%mod;	
	printf("%lld\n",ans);	
	return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    N =INT()
    size = 0
    for i in range(1,10**3):
        if i*(i+1)//2 == N:
            size = i 
            break
    else:
        print("No")
        return
    
    k = size + 1
    answer = [[] for _ in range(k)]

    start = 1
    for i in range(k):
        answer[i] = list(range(start,start+size-i))
        start += size-i
    
    for i in range(k-1):
        for j in range(i+1,k):
            answer[j].append(answer[i][j-i-1])
    
    print("Yes")
    print(k)
    for i in range(k):
        print(size,*answer[i])
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9552
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1 << 30;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int h, n; cin >> h >> n;
    VI a(n), b(n);
    FOR(i, 0, n)cin >> a[i] >> b[i];

    VI dp(h + 1, INF);
    dp[0] = 0;
    FOR(i, 0, h)FOR(j, 0, n) {
        chmin(dp[min(i + a[j], h)], dp[i] + b[j]);
    }

    cout << dp[h] << "\n";
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> vec(M);
    rep(i, M)
    {
        int k;
        cin >> k;
        vec[i].resize(k);
        rep(j, k)
        {
            cin >> vec[i][j];
            vec[i][j]--;
        }
    }
    vector<int> p(M);
    rep(i, M) cin >> p[i];
    int ans = 0;

    for (int bit = 0; bit < (1 << N); bit++)
    {
        int cnt = 0;
        rep(i, M)
        {
            int on = 0;
            int n = vec[i].size();
            rep(j, n)
            {
                if (bit & (1 << vec[i][j]))
                {
                    on++;
                }
            }
            if (on % 2 == p[i])
            {
                cnt++;
            }
        }
        if (cnt == M)
            ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = readInts >>= putStrLn . which "Yes" "No" . ( == 2 ) . length . group . sort

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

int main() {
	long long n;
	cin >> n;
	if(n % 2 || n == 0)
		return cout << 0, 0;
	long long answer = 0;
	answer += n / 10;
	n /= 10;
	while(n >= 5) {
		answer +=  n / 5;
		n /= 5;
	}
	cout << answer;
}		


Measured memory_bytes: 3620
N,M,C=map(int,input().split())
stand=list(map(int,input().split()))
temp=[list(map(int,input().split())) for _ in range(N)]

res=0
for t in temp:
  ans=0
  for i in range(M):
    ans+=stand[i]*t[i]
  if ans+C>0:
    res+=1

print(res)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
using in = int64_t;


int sagasu(vector<char> s,int n, int x,int y){
   int ret=0;
  vector<char> a={'0','1','2','3','4','5','6','7','8','9'};
  for(int i=x;i<n;i++){
     if(s.at(i)==a.at(y)){
        ret=i;
        break;
      }
    else if(i==n-1) ret=-1;
  }
  return ret;
}

int main(){
  int x,y,z;
  int ans =0;
  int n;
  cin>>n;
  vector<char> s(n);
  rep(i,n) cin>> s.at(i);
  
  rep(i,10){
    x= sagasu(s,n,0,i);
    //cout<<"x="<<i<<endl;
    if(x==-1 || x>n-3) continue;
    //cout<<"x="<<x<<endl;
  rep(j,10){
    y= sagasu(s,n,x+1,j);
    //cout<<"y="<<y<<endl;
    if(y==-1 || y>n-2) continue;
  rep(k,10){
     /* x= sagasu(s,n,0,i);
    if(x==-1 || x>n-3) break;*/
      /*y= sagasu(s,n,x+1,j);
    if(y==-1 || y>n-2) break;*/
      z= sagasu(s,n,y+1,k);
    //cout<<z<<endl;
    if(z!=-1) ans ++;
         
    
  }  //if(x==-1 || x>n-3) break;
  } 
  }
  cout <<ans;
  
}


Measured memory_bytes: 256
input();a,b=[set(map(int,input().split())) for j in[0]*2];c=1;N=M=0;x=max(a)
for k in range(x,0,-1):
 A=k in a;B=k in b
 if A and B:M+=1;N+=1
 elif A:c*=M;N+=1
 elif B:c*=N;M+=1
 else:c*=M*N-x+k
 c%=10**9+7
print(c)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.length();i++)
    {
        sum+=s[i]-'0';
    }
    if(sum%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
    cout<<"No"<<endl;
    }
    return 0;
}

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

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a, b;
cin >> a >> b;
(a - 2*b > 0) ? cout << a - 2 * b : cout << 0;
cout << "\n";

return 0;
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    string s , t ;
    cin >> s >> t ;
    int n = (int)s.size() ;
    int m = (int)t.size() ;
    int ans = INF ;
    for(int i = 0; i + m <= n; i++){
        int cnt = 0 ;
        for(int j = 0; j < m; j++){
            if ( s[i + j] != t[j] ) cnt++ ;
        }
        ans = min(ans, cnt) ;
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,n;
  string h;
  cin>>a>>b>>h;
  
  for(int i=0;i<h.size();i++){
    if(h[i]=='-'){
      ++n;
    }
  }
  
  if(n==1&&h[a]=='-'){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();

        for (int i = 0; i < n.length(); i++) {
            if (n.charAt(i) == '7') {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 27004
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<memory.h>
using namespace std;


int main(){

   int n , res = 0;
   vector < int > arr;
   map < int , int > mp;
   map < int , int > :: iterator it;

   scanf ("%d" , &n);
   arr.resize(n);

   for ( int i = 0 ; i < n ; ++i){
	   scanf ("%d" , &arr[i]);
	   mp[arr[i]]++;
	   mp[arr[i] - 1]++;
	   mp[arr[i] + 1]++;

   }

   for (it = mp.begin() ; it != mp.end() ; ++it)
          res = max ( res , it->second);

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


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

int main(){
  int A, B, cnt = 0;
  cin >> A >> B;
  string S, S2;
  for (int i = A; i <= B; i++){
    S = to_string(i);
    S2 = S;
    reverse(S2.begin(), S2.end());
    if(S == S2) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3668
n,k =map(int ,input().split())
l=list(map(int ,input().split()))

dp=[float("inf")]*n
dp[0]=0
for i in range(n-1):
    for j in range(1,min(k+1,abs(n-i))):
        dp[i+j]=min(dp[i]+abs(l[i]-l[i+j]),dp[i+j])
print(dp[-1])

Measured memory_bytes: 55264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n,k;
  cin >> n >> k;
  ll cnt = 0;
  ll lower=0,upper=0;
  ll p = 1000000007;
  for(ll i=k;i<=n;i++){
    lower = i*(i-1)/2;
    upper = i*(2*n-i+1)/2;
    cnt = cnt + (upper - lower + 1) % p;
  }
  cout << cnt % p + 1<< endl;
  return(0);
}

Measured memory_bytes: 3624
#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 <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++
using namespace std;

int main() {
	int n,t,b,c,to=0,m=0;
	cin>>n>>t;
	vector<int> e(t+1,0),a(t+1,0),l(t+1,0);
	for (int i = 0; i < n;i++) {
		cin>>b>>c;
		a[b]++;
		l[c]++;
	}
	for (int i = 0; i < t; i++) {
		to += a[i] - l[i];
		m = max(m, to);
	}
	cout << m << endl;
}




Measured memory_bytes: 3864
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
    _ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max()/8;

template <class T>
struct FenwickTree {
    int n;
    vector<T> x;
    FenwickTree(int n_ = 0) : n(n_), x(n_+1){
        fill(x.begin(), x.end(), 0);
    }
    T sum(int r){
        int s = 0;
        while (r > 0) {
            s += x[r];
            r -= r & -r;
        }
        return s;
    }
    T sum(int l, int r){
        return sum(r) - sum(l-1);
    }
    void add(int i, T a) {
        while (i <= n) {
            x[i] += a;
            i += i & -i;
        }
    }
    void set(int k, T a){
        int x = sum(k, k+1);
        add(k, a-x);
    }
    vi to_a(int l = -1, int r = -1){
        if(l == -1) l = 0;
        if(r == -1) r = n;
        vi res(r-l);
        range(i,l,r) res[i-l] = sum(i,i+1);
        return res;
    }
};

int main(){
    fastios();
    int n,q;
    cin >> n >> q;
    FenwickTree<ll> t(n+1);
    rep(i,q){
        int c,x,y;
        cin >> c >> x >> y;
        if(c == 0) t.add(x,y);
        else cout << t.sum(x,y) << endl;
    }
}

Measured memory_bytes: 1788
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    bl = []
    while True:
        if n == 0:
            break
        else:
            bl.append(str(n & 1))
            n //= 2
            n *= -1
    bl.reverse()
    print("".join(bl) if len(bl) != 0 else 0)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
N = gets.to_i
A = gets.split.map(&:to_i)

sum = A.inject(&:+)

s = A[0]
a = sum - s

min = ( s - a ).abs

(1...N-1).each do |i|
  
  s += A[i]
  a -= A[i]
  
  v = ( s - a ).abs
  min = v if min > v

end

puts min

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    ll res = 0;
    REP(i, s.size())
    {
        ll cnt = 0;
        FOR(j, i, s.size())
        {
            if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T')
            {
                cnt++;
            }
            else
            {
                break;
            }
        }
        res = max(res, cnt);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[2010][2010];
int s[2010][2010];
const int INF=1000000007;

signed main()
{
	int n;
	cin>>n;
	dp[3][1]=dp[4][1]=dp[5][1]=1;
	s[3][1]=1,s[4][1]=2,s[5][1]=3;
	for(int i=6;i<=n;i++){
		dp[i][1]=1;
		s[i][1]=(s[i-1][1]+dp[i][1]) % INF;
		for(int j=2;j<=i/3;j++)
			if (3*j-3<=i-3) dp[i][j]=(dp[i][j]+(s[i-3][j-1]-s[3*j-4][j-1])) % INF,s[i][j]=(s[i-1][j]+dp[i][j])%INF;
	}
	int ans=0;
	for(int i=1;i<=n/3;i++)
		ans=(ans+dp[n][i])%INF;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 29900
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main() {
    int N;
    cin >> N;
    double ans = 0, x;
    const double rate = 380000;
    string u;
    for (int i = 0; i < N; i++) {
        cin >> x >> u;
        ans += x * (u == "JPY" ? 1.0 : rate);
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}


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




int main(void)
{
	int H, W;
	int a[8][8];
	char s[8];
	cin>>H;
	cin>>W;
	int i, j;
	char cnt = 0;
	for( i = 0; i < H; i++ ) {
		cin>>s;
		for( j = 0; j < W; j++ ) {
			a[i][j] = s[j];
			if (a[i][j] == '#') cnt++;
		}
	}
	if( (H + W - 1) == cnt ){
		cout<<"Possible"<<endl;
	} else {
		cout<<"Impossible"<<endl;
	}
	
	return 0;
	
}

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

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        list<bitset<5> > board(1, (1<<5)-1);
        while(--n >= 0){
            int d, p, q;
            cin >> d >> p >> q;
            bitset<5> bs;
            if(d == 1){
                for(int i=q-1; i<q-1+p; ++i)
                    bs[i] = true;
                p = 1;
            }else{
                bs[q-1] = true;
            }

            list<bitset<5> >::iterator it = board.begin();
            while(((*it) & bs).none())
                ++ it;

            while(--p >= 0){
                if(it == board.begin())
                    board.push_front(0);
                -- it;
                (*it) |= bs;
                if((*it) == (1<<5)-1)
                    it = board.erase(it);
            }
        }

        int ret = -5;
        list<bitset<5> >::iterator it;
        for(it=board.begin(); it!=board.end(); ++it)
            ret += it->count();
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
import sys
m = [4,1,4,1,2,1,2,1]

for l in sys.stdin:
    l = list(map(int, l.rstrip().split()))
    a = []
    for i in range(0, 8):
        _m = [m[j%8] for j in range(i, i+8)]
        n = 0
        for n1, n2 in zip(l, _m):
            n += max(0, n1-n2)
        a.append((n, "".join(map(str, _m))))
    print(" ".join(sorted(a)[0][1]))


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int d, mans=-imax, ans;
	vector<int> c, t, ld, at;
	vector< vector<int> >s;

	cin>> d;

	c.resize(26);
	rep(i, 26) cin>> c[i];
	s.resize(d);
	rep(i, d){
		s[i].resize(26);
		rep(j, 26) cin>> s[i][j];
	}
	t.resize(d);
	at.resize(d);
	rep(i, d){
		int tmp=1, ma=-1;
		rep(j, 26){
			if(ma<s[i][j]){
				tmp=j;
				ma=s[i][j];
			}
		}
		at[i]=tmp+1;
	}

	rep(i, d){
		//cout<< t[i] <<endl;
	}

	ld.resize(26);

	/*int m;
	vector<int> qd, qq;
	cin>> m;
	qd.resize(m);
	qq.resize(m);
	rep(i, m) cin>> qd[i] >> qq[i];*/
	
  	std::random_device seed_gen;
  	std::mt19937 engine(seed_gen());

	int ti = clock();
    while (clock() - ti < 169 * CLOCKS_PER_SEC / 100){
		
    	rep(i, d){
			int rs=engine();
			rs=abs(rs);
			//cout<< rs%26 <<endl;
			t[i]=rs%26;
		}
		ans=0;
		rep(i, 26) ld[i]=0;

		rep(i, d){
			ans+=s[i][t[i]];
			ld[t[i]]=i+1;
			rep(j, 26) ans-=(i-ld[j]+1)*c[j];
		}

		if(mans<ans){
			rep(i, d) at[i]=t[i]+1;
		}
	}

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

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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    char a;
    cin >> a;
    if(a <= 'z' and a >= 'a') {
        cout << 'a' << endl;
    }
    else {
        cout << 'A' << endl;
    }


    return 0;
}



Measured memory_bytes: 3568
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    GI3(A,B,C);
    int ans=0;
    if(A%2==B%2&&B%2!=C%2){
        A++;
        B++;
        ans+=1;
    }else if(B%2==C%2&&B%2!=A%2){
        B++;
        C++;
        ans+=1;
    }else if(C%2==A%2&&A%2!=B%2){
        C++;
        A++;
        ans+=1;
    }
    int maxN=max({A,B,C});
    print(ans+(maxN*3-A-B-C)/2);
    return 0;
}

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

using namespace std;

void solve()
{
	int a[3] = {1, 0, 0};
	char from, to, c;
	while(scanf("%c,%c%c", &from, &to, &c) != EOF)
	{
		if(from == 'A')
		{
			if(to == 'B')
			{
				int temp = a[0];
				a[0] = a[1];
				a[1] = temp;
			}
			else
			{
				int temp = a[0];
				a[0] = a[2];
				a[2] = temp;
			}
		}
		else if(from == 'B')
		{
			if(to == 'A')
			{
				int temp = a[0];
				a[0] = a[1];
				a[1] = temp;
			}
			else
			{
				int temp = a[1];
				a[1] = a[2];
				a[2] = temp;
			}
		}
		else
		{
			if(to == 'B')
			{
				int temp = a[1];
				a[1] = a[2];
				a[2] = temp;
			}
			else
			{
				int temp = a[0];
				a[0] = a[2];
				a[2] = temp;
			}
		}
	}
	if(a[0] == 1)
	{
		cout << "A" << endl;
	}
	else if(a[1] == 1)
	{
		cout << "B" << endl;
	}
	else if(a[2] == 1)
	{
		cout << "C" << endl;
	}
}

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

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

using namespace std;

int main()
{
    int ara[6];
    int d;
    for(int i = 1; i <= 5; i++)
    {
        cin >> ara[i];
        if(ara[i] == 0)
            d = i;
    }
    cout << d << endl;
    return 0;
}


Measured memory_bytes: 3620
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let d: Vec<usize> = sc.vec(n);
    let mut sum = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            sum += d[i] * d[j];
        }
    }
    println!("{}", sum);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352