akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline

N,Q = map(int, input().split())

edge = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

P = []
for i in range(Q):
    x,y = map(int, input().split())
    P.append((x,y))

V = [0]*N
for p in P:
    V[p[0]-1] += p[1]

parent = {1}
done = {1}
while parent:
    children = set()
    for p in parent:
        for i in edge[p]:
            if i not in done:
                V[i-1] += V[p-1]
                children.add(i)
                done.add(i)
    parent = children

print(*V)


Measured memory_bytes: 91832
#include<iostream>

using namespace std;

void solve(){
	int N;
	cin>>N;
	int arr[N];
	for(int i=0;i<N;i++){
		cin >> arr[i];
	}

	int dp[N];
	dp[0] = 0;
	for(int i=1;i<N;i++){
		if(i == 1){
			dp[i] = max(arr[1],arr[0]) - min(arr[1],arr[0]);
		}
		else{
			int p = arr[i] > arr[i-1]?arr[i] - arr[i-1]:arr[i-1]-arr[i];
			int q = arr[i] > arr[i-2]?arr[i] - arr[i-2]:arr[i-2]-arr[i];
			dp[i] = min(dp[i-1] + p,dp[i-2]+q);
		}
	}

	cout << dp[N-1]<<endl;



}
int main(){
	int test = 1;
	//cin>>test;
	for(int i=0;i<test;i++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3900
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  long double ans = 0;
  for(int i=0;i<n;i++) {
    long double money;
    string moneyT;
    cin >> money;
    cin >> moneyT;
    if(moneyT == "BTC") {
      ans += money * 380000;
    } else {
      ans += money;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
let print_array a =
  Array.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) a;
  print_newline ()

let insertion_sort a n =
  print_array a;
  let rec insert j v =
    if j < 0 || a.(j) <= v then a.(j + 1) <- v
    else (a.(j + 1) <- a.(j); insert (j - 1) v)
  in
  let rec doit i =
    if i < n then (insert (i - 1) a.(i); print_array a; doit (i + 1))
  in
  doit 1

let () =
  let n = read_int () in
  let a = Array.of_list (List.map int_of_string (Str.split (Str.regexp " ") (read_line ()))) in
  insertion_sort a n

Measured memory_bytes: 4064
#include<stdio.h>

int main(void){

    int m, d, d1, d10, count = 0;

    scanf("%d %d", &m, &d);

    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= d; j++){
            d10 = j / 10;
            d1 = j - d10 * 10;
            if(d1 >= 2 && d10 >= 2 && i == d1 * d10){
                count++;
            }
        }
    }

    printf("%d\n",count);

    return 0;
}

Measured memory_bytes: 128
while 1:
    n = int(input())
    if n == 0:break
    p = [0] * n
    s = 0
    f = input()
    for i in range(100):
        if f[i] == "M":p[i % n] += 1
        elif f[i] == "S":
            s += p[i % n] + 1
            p[i % n] = 0
        else:
            p[i % n] += s + 1
            s = 0
    p.sort()
    p += [s]
    print(*p)


Measured memory_bytes: 5608
#!/usr/bin/env python
def solve():
    N = int(input())
    ans = 0
    prev = None
    for _ in range(N):
        a = int(input())    
        if prev is None and a!=0:
            return -1
        if prev is not None:
            diff = a - prev
            if diff >= 2:
                return -1
            elif diff <= 0:
                ans += prev
        prev = a
    ans += prev
    return ans

if __name__=='__main__':
    print(solve())

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
typedef long long ll;
using namespace std;

const int MOD = 1000000007;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main() {
    long long L, R; cin >> L >> R;
    if (R - L > 3000) cout << 0 << endl;
    else {
        long long res = 2018;
        for (long long i = L; i < R; ++i)
            for (long long j = i+1; j <= R; ++j)
                res = min(res, (i * j) % 2019);
        cout << res << endl;
    }
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  vector<int> vec = {A,B,C};
  sort(vec.begin(),vec.end());
  vector<int> sorted = {5,5,7};
  if (vec == sorted){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
}

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

using namespace std;

typedef long long I64;

const int NMAX = 1000000;

int v[NMAX+2], d[NMAX+2], lim[NMAX+2];
long double LEN = 0.0, HALF = 0;
int ind = 0, N;

int main() {
    int a,b;
    cin >> a >> b;
    cout << b + (b - a) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=18,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int a[MAXn],b[MAXn];
int dp[1<<MAXn][MAXn];
int gt(int pos,int go){
    if ((pos-go)&1) return b[pos];
    return a[pos];
}
int main(){
    IOS();
    int n;
    cin >> n;
    REP (i,n) cin >> a[i];
    REP (i,n) cin >> b[i];
    RST(dp,INF);
    REP (mask,1<<n) {
        int cnt = __builtin_popcount(mask);
        debug(cnt,mask);
        if (!cnt) {
            REP (i,n) dp[1<<i][i] = 0;
            continue;
        }
        REP (i,n) {
            if (mask & (1<<i)) continue;
            REP (j,n) {
                if (dp[mask][j] == INF) continue;
                int iv = gt(i,cnt);
                int jv = gt(j,cnt-1);
                if (iv >= jv) {
                    int cost = 0;
                    for (int k=i+1;k<n;k++) if (mask & (1<<k)) cost++;
                    dp[mask|(1<<i)][i] = min(dp[mask|(1<<i)][i],dp[mask][j] + cost);
                }
            }
        }
    }
    int ans = INF;
    REP (i,n) ans = min(ans,dp[(1<<n)-1][i]);
    if (ans >= INF) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 22092
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n);
    int i;
    double sum=0;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        sum += 1/(double)a[i];
    }
    sum = 1/sum;
    printf("%.10lf\n", sum);

    return 0;
}


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

using namespace std ;

int n ;
int m ;
long long  dp[100001],v[101],w[101];
int main(){
    scanf("%d%d",&n,&m) ;
    for (int i=0;i<n;i++){
        scanf("%lld%lld",&w[i],&v[i]);
    }

    for (int i=0;i<n;i++){
        for (int j=m;j>=w[i];j--)
        {
            dp[j] = max(dp[j],dp[j-w[i]] + v[i]) ;
        }
    }
    printf("%lld",dp[m]);
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;


class Program
{
    static void Main(string[] args)
    {
        string[] SW = Console.ReadLine().Split(' ');
        int S = int.Parse(SW[0]);
        int W = int.Parse(SW[1]);

        if(S > W) {
            Console.WriteLine("safe");
        } else {
            Console.WriteLine("unsafe");
        }
    }
}

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

class Node:
  def __init__(self,key):
    self.key=key
    self.prev=None
    self.next=None

class LinkedList:
  first=None
  last=None
  current=first

  def insert(self,x):
    node=Node(x)
    self.current=node
    if self.first==None:
      self.first=node
      self.last=node
    else:
      self.first.prev=node
      node.next=self.first
      self.first=node
  
  def delete(self,x):
    if self.first==None:
      #print('Error')
      return
    if self.first==self.last and self.first.key==x:
      self.first=None
      self.current=None
      self.last=None
      return

    elif self.first.key==x:
      self.first.next.prev=None
      self.current=self.first.next
      self.first=self.first.next
      return

    tmp=self.first
    while tmp!=None:
      if self.last==tmp and tmp.key==x:
        self.last.prev.next=None
        self.last=self.last.prev
        break
      elif tmp.key==x:
        tmp.prev.next=tmp.next
        tmp.next.prev=tmp.prev
        break
      tmp=tmp.next

  def deleteFirst(self):
    if self.first==self.last:
      self.first=None
      self.last=None
      self.current=None
      return
    self.first.next.prev=None
    self.first=self.first.next
    self.current=self.first

  def deleteLast(self):
    if self.first==self.last:
      self.first=None
      self.last=None
      self.current=None
      return
    self.last.prev.next=None
    self.last=self.last.prev

  def next(self):
    if self.current==None:
      return None
    tmp=self.current
    self.current=self.current.next
    return tmp

if __name__ == '__main__':
  n=int(input())
  L=LinkedList()

  def answer():
    tmp=L.next()
    while tmp!=None:
      ans=tmp.key
      tmp=L.next()
      if tmp==None:
        print(ans)
      else:
        print(ans,end=' ')
    L.current=L.first

  for _ in range(n):
    S=input().split()
    #print('---')
    #print(*S)
    if S[0]=='insert':
      L.insert(S[1])
    elif S[0]=='delete':
      L.delete(S[1])
    elif S[0]=='deleteFirst':
      L.deleteFirst()
    elif S[0]=='deleteLast':
      L.deleteLast()
    #answer()
  answer()



Measured memory_bytes: 227584
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) 			a.begin(),a.end()
#define pb 				push_back
#define vi				vector<int>
#define vl 				vector<long long>
#define MOD 			1000000007
#define FOR(i,a,b) 		for(int i = a; i <= b ; i++)
#define forn(i,n) 		for(int i = 0 ; i < n; i++)
#define br 				cout<<endl;
#define testc()			int t;cin>>t;while(t--)
#define ll				long long
#define printv(v)		for(auto x : v) cout<<x<<' ';br;
#define ff				first
#define ss 				second
#define fast 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vb 				vector<bool>
#define INF				INT_MAX
#define INFL			LLONG_MAX

using namespace std;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using ld = long double;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


vi prime_generator()
{
	vector<int> pr;
	const int N = 10000000;
	vi lp(N+1);
	

	for (int i=2; i<=N; ++i) {
	    if (lp[i] == 0) {
	        lp[i] = i;
	        pr.push_back (i);
	    }
	    for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
	        lp[i * pr[j]] = pr[j];
	}
}


vi z_function(string t)
{
	int n = t.size();
	vi z(t.size());
	for(int i = 1,r = 0,l = 0 ; i <  n ; i++)
	{
		if(i <= r)
			z[i] = min(r - i + 1,z[i - l]);
		while(i + z[i] < n && t[z[i]] == t[i + z[i]])
			z[i]++;
		if(i + z[i] - 1 > r)
			r = i + z[i] - 1,l = i;
	}
	return z;
}


ll power(ll a,ll b,ll mod)
{
	ll res = 1;
	a = a % mod;
	while(b)
	{
		if(b & 1)
			res = (res * a) % mod;
		b = b >> 1;
		a = (a * a) % mod;
	}
	return res;
}

template<typename T>
void answer(T s)
{
	cout<<s<<endl;
	exit(0);
}
//use for string in strcpy([string],s.c_str())
//stringstream fs---->fs>>string_name**this will copy the value from fs to string_name
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/


int main()
{
	fast
	int n;cin>>n;
	vi a(n + 1);
	FOR(i,1 , n )cin>>a[i];
	int x = n ;
	vi ans(n + 1);
	while(x > n / 2)
	{
		if(a[x])
			ans[x]=1;
		x--;

	}
	//cout<<x<<endl;
	for(int i = x ; i >= 1; i--)
	{
		bool f = a[i];
		//cout<<f<<endl;
		for(int j = i * 2 ; j <= n ; j+=i)
		{

			f = f ^ ans[j];
		//	cout<<f<<endl;
		}
	//	cout<<f<<endl;
		if(f)
			ans[i] = 1;
	}
	vi b;
	FOR(i,1,n)
	{
		if(ans[i])
			b.pb(i);
	}
	cout<<b.size()<<endl;;
	if(b.size() == 0)
		return 0;
	printv(b)

}

Measured memory_bytes: 3192
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

int getans(vector<pair<int, int>>&ps) {
	if (ps.size() == 1) {
		return 1e9;
	}
	else if (ps.size() == 2) {
		auto p = ps[0];
		auto q = ps[1];
		return (p.first - q.first)*(p.first - q.first) + (p.second - q.second)*(p.second - q.second);

	}
	int bx = ps[ps.size() / 2].first;
	vector<pair<int, int>> lps(ps.begin(), ps.begin() + ps.size() / 2);
	vector<pair<int, int>> rps(ps.begin() + ps.size() / 2, ps.end());
	int lans = getans(lps);
	int rans = getans(rps);
	int nans = min(lans, rans);
	auto lt = lower_bound(ps.begin(), ps.end(), make_pair(bx - int(sqrt(nans)) - 2, int(-1e9)));
	auto rt = upper_bound(ps.begin(), ps.end(), make_pair(bx + int(sqrt(nans)) + 2, int(1e9)));
	for (auto it = lt; it != rt; ++it) {
		for (auto jt = next(it); jt != rt; ++jt) {
			auto p = *it;
			auto q = *jt;
			nans = min(nans, (p.first - q.first)*(p.first - q.first) + (p.second - q.second)*(p.second - q.second));

		}
	}
	return nans;
}

int main() {
	int N; cin >> N;
	vector<pair<int, int>>ps;
	for (int i = 0; i < N; ++i) {
		int x, y; cin >> x >> y;
		ps.emplace_back(x, y);
	}
	sort(ps.begin(), ps.end());
	int ans = getans(ps);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14608
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

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

void solve() {
        int x; cin >> x;
        for (int i= x;;i++) if (is_prime(i)) { cout << i; return; }
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int t = 1;
        //cin >> t;
        while ( t-- ) {
                solve();
        }
return 0;
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in(), t = in();
    vint v = in(n);
    ll ans = 0;
    rep(i, n - 1) ans += min(t, v[i + 1] - v[i]);
    ans += t;
    cout << ans << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    REP(i,m) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        v[a]++;
        v[b]++;
    }

    bool ans = true;
    REP(i,n) if (v[i] % 2 != 0) ans = false;

    CFYN(ans)

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P  = pair <int, int>;

#define rep(i, n)     for (int i = 0; i < (int) (n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp)   for (auto &i : mp)

const int INF = 1001001001;

int main()
{
  string s;
  cin >> s;
  char   ans    = 'A';
  string komoji = "qwertyuiopasdfghjklzxcvbnm";
  rep(i, komoji.size()) {
    if (s[0] == komoji[i]) {
      ans = 'a';
    }
  }
  cout << ans << endl;

  return 0;
}


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

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

    int A, B;
    cin >> A >> B;
    int price = -1;
    for (int i = B * 10; i < (B + 1) * 10; i++) {
        if (i * 8 / 100 == A) {
            price = i;
            break;
        }
    }
    cout << price << '\n';

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007

//証言用の配列
int claim[15][15];

int main(void)
{
    //人数
    int n;
    cin >> n;
    //配列初期化
    rep(i, n) rep(j, n) claim[i][j] = -1;
    
    rep(i,n){
        //証言の個数
        int m;
        cin >> m;

        rep(j,m){
            int toP, x; //toP -　対象者、x -　証言内容
            cin >> toP >> x;
            toP--;
            claim[i][toP] = x;
        }
    }

    int ans = 0;
    
    //bit演算
    rep(i,1<<n){
        vector<int> honest(n);//正直or嘘つきを格納
        rep(j,n){
            if((i>>j) & 1) honest[j] = 1;
        }
            bool check = true;
            rep(j,n){
                if(honest[j]){
                    rep(k,n){
                        if(claim[j][k]== -1)    //証言なしの時
                            continue;
                        if(claim[j][k] != honest[k])
                            check = false;
                    }
                }
            }
            if(check)
                ans = max(ans, __builtin_popcount(i));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 100000
#define Q 50000

int main(){
  int S[N],T[Q];
  int n,m,i,count=0;
  int right,left,mid;

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

  scanf("%d",&m);
  for(i=0; i<m ; i++){
    scanf("%d",&T[i]);
  }

  for(i=0; i<m; i++){
      left = 0;
      right = n;
      while(left < right){
	mid=(left + right)/2;
	if(T[i]==S[mid]){
	  count++;
	  break;
	}
	else if(T[i] > S[mid])
	  left = mid+1;
	else if(T[i] < S[mid])
	  right = mid;
      }
    }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1184
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>

#define rep(i,n) for(int i = 0;i < (n);i++)
#define repp(i,j, n) for(int i = (j);i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define INF 1e9

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x;
  cin >> x;
  cout << 2*((x-1)/11)+2+(x%11 <= 6 && x%11 >=1?-1:0) << endl; 
  return 0;
}


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

const int N = 18 + 1;
int n;
ll ans;
string s1, s2, s;
map <pss, int> mp;

void solve(int msk) {
	string tmp1, tmp2;
	for (int i = 0; i < n; i++)
		if (msk & (1LL << i))
			tmp1 += s[n + i];
		else
			tmp2 += s[n + i];
	
	reverse(tmp1.begin(), tmp1.end());
	reverse(tmp2.begin(), tmp2.end());
	mp[pss(tmp1, tmp2)]++;
}

void solve2(int msk) {
	string tmp1, tmp2;
	for (int i = 0; i < n; i++)
		if (msk & (1LL << i))
			tmp1 += s[i];
		else
			tmp2 += s[i];
	
	ans += mp[pss(tmp1, tmp2)];
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> s;
	for (int i = 0; i < n; i++)
		s1 += s[i];
	for (int i = n; i < n; i++)
		s2 += s[i];
	
	for (int msk = 0; msk < (1LL << n); msk++)
		solve(msk);
	
	for (int msk = 0; msk < (1LL << n); msk++)
		solve2(msk);
	cout << ans;
}

Measured memory_bytes: 87040
#include<bits/stdc++.h>
#define qwq 1000000007
using namespace std;
long long a,i,j,k,n,m,v,x,y,z,ans,f[41][131072];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>x>>y>>z; ans=1; f[0][0]=1;
    for (i=0;i<n;i++) (ans*=10)%=qwq;
    y+=z; x+=y; v=(1<<x-1)|(1<<y-1)|(1<<z-1); m=1<<x;
    for (i=1;i<=n;i++)
    for (j=0;j<m;j++)
    {
        if (!f[i-1][j]) continue;
        for (k=1;k<11;k++)
        {
            a=((j<<k)|(1<<k-1))&(m-1);
            if ((a&v)!=v) (f[i][a]+=f[i-1][j])%=qwq;
        }
    }
    for (i=0;i<m;i++) ans=(ans-f[n][i]+qwq)%qwq; cout<<ans;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N; cin >> N;
  string S[N]; rep(i,N) cin >> S[i];
  map<string, int> m; rep(i,N) m[S[i]]++;
  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;
  return 0;
}

Measured memory_bytes: 6760
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

   int n, k; cin>>n>>k;
   vi a(n);
   for(int &x : a)cin>>x;

   sort(all(a));
    int sum = 0;
   for(int i = 0; i < k; i++){
       sum += a[i];
   }
   cout<<sum<<"\n";

}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1) res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(0);

int main()
{
  Hello;
  
  string s;
  cin>>s;
  int a=s.length();
  
  for(int i=0; i<a; i++)  s[i]='x';
  
  cout<<s;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define N 101000
#define ll long long
#define mo 1000000007
using namespace std;
int n,a[N];
ll c[N];
ll ans=0;
void read(int *a)
{
	a[0]=0;
	char c=getchar();
	for(;c<'a'||c>'z';c=getchar());
	for(;c>='a'&&c<='z';c=getchar()) a[++a[0]]=c-96;
}
int main()
{
	scanf("%d",&n);read(a);
	fo(i,1,26) c[i]=1;
	fd(i,n,1)
	{
		ll jy=1;
		fo(j,1,26) if(a[i]!=j) jy=jy*c[j]%mo;
		ans=(ans+jy)%mo;
		c[a[i]]++;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 512
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
 
typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
 
#define ALL(a) (a).begin(),a.end()
#define MAXE(a) *max_element(ALL(a))
#define MINE(a) *min_element(ALL(a))

int main(){
  ll a,b,c;
  cin >> a; 
  cin >> b; 
  cin >> c; 
  ll p = c-(a-b); 
  if(p<0.0)p=0.0;
  cout << p << endl;
}


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

int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char>>data(h,vector<char>(w));
  for(int i = 0;i < h;i ++){
    for(int j = 0;j < w;j++){
      cin >> data.at(i).at(j);
    }
  }
  for(int i = 0;i < h;i++){
    int c =0;
    while(c < 2){
      for(int j = 0;j < w;j++){
        if(j != w-1){
          cout << data.at(i).at(j);
        }
        else{
          cout << data.at(i).at(j) << endl;
        }
      }
      c++;
    }
  }
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))


void solve(){
    int n,m;cin>>n>>m;
    int a[n+1]={0};
    int b,c;
    rep(i,0,m){
        cin>>b>>c;
        a[b]++;
        a[c]++;
    }
    rep(i,1,n+1)cout<<a[i]<<endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

fn main() {
    let n: usize = read_line();

    println!("0");

    let e: String = read_line();

    if e == "Vacant" {
        return;
    }
    let mut lo = (0, e);

    println!("{}", n-1);

    let e: String = read_line();

    if e == "Vacant" {
        return;
    }
    let mut hi = (n-1, e);

    for _ in 0..20 {
        let mid = (hi.0 + lo.0) / 2;
        println!("{}", mid);

        let e: String = read_line();

        if e == "Vacant" {
            return;
        }
        if (hi.0 - mid) % 2 == 0 {
            if hi.1 == e {
                hi = (mid, e);
            } else {
                lo = (mid, e);
            }
        } else {
            if hi.1 == e {
                lo = (mid, e);
            } else {
                hi = (mid, e);
            }
        }
    }
}


Measured memory_bytes: 3856
#include <iostream>
#include <vector>

int main(int argc, char** argv) {
  int N;
  std::cin >> N;
  std::vector<int> d(N);
  for (auto& e : d) std::cin >> e;
  long long sum {};
  for (auto i = 0;i < N;++i) {
    for (auto j = i+1;j < N;++j) {
      sum += d[i]*d[j];
    }
  }
  std::cout << sum << '\n';
}


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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  i64 x;
  cin >> x;

  i64 sum = 0;
  i64 i;
  for (i = 1; sum < x; ++i) {
    sum += i;
  }

  cout << i - 1 << "\n";

  return 0;
}

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

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

	if(a=='H'){
		if(b=='H'){
			cout << 'H' << endl;
		}else{
			cout << 'D' << endl;
		}
	}else{
		if(b=='H'){
			cout << 'D' << endl;
		}else{
			cout << 'H' << endl;
		}

	}

	return 0;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{   
      senky_bansal
      IIIT_ALLAHABAD
      
      ll n;
      cin>>n;
      ll a[n];
      
      vector<ll>v;
      ll sum=0;
      for(int i=1;i<=n;i++){
      cin>>a[i];
      }
      sum=2*a[1];
      for(int i=2;i<n;i++)
      {
          if(i%2==0)
          sum-=2*a[i];
          else
          sum+=2*a[i];
      }
      ll p1 = (sum+2*a[n])/2;
      v.pb(p1);
      for(int i=1;i<n;i++)
      {
          v.pb(2*a[i]-p1);
          p1=2*a[i]-p1;
      }
      for(auto it : v)
      cout<<it<<" ";
      
    
    
}









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

int main() {
  string S;
  cin >> S;
  
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  }
  if (S == "Cloudy") {
    cout << "Rainy" << endl;
  }
  if (S == "Rainy") {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,b,s=0,i,ar[100000];
    scanf("%d %d",&n,&b);
    for(i=0;i<b;i++)
    {
        scanf("%d",&ar[i]);
        s+=ar[i];
    }

    if(s>n){
        printf("-1\n");
    }
    else{
      printf("%d\n",n-s);
    }

    return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int ans = abs((H2 * 60 + M2) - (H1 * 60 + M1));
    cout <<ans - K << endl;
}

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

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

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    bool isok = false;
    rep(i, 2000){
        if(a <= k*i && k*i <=b){
            isok = true;
            break;
        }
    }
    cout << (isok ? "OK" : "NG") << endl;
    return 0;    
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
    using namespace std;
    #define F first
    #define S second
    #define mp make_pair
    #define pb push_back
    #define CLEAR(a) memset(a,0,sizeof a)
    #define REP(i,n) for(int i=0;i<n;i++)
    #define FOR(i,a,b) for(int i=a;i<=b;i++)
    #define fr freopen("input.txt", "r", stdin);
    #define fw freopen("output.txt", "w", stdout);
    #define int long long 
    typedef long long LL;
    typedef pair<int,int> pii;
    const int MOD = 1e9 + 7;
    const int MAX = 3e5 + 5;
    int a[MAX];
     
     main() {
        int n;
        cin >> n;
        n = 3*n;
        REP(i, n) cin >> a[i];
        sort(a,a+n);
        int ret = 0;
        int i=0, j=n-1;
        while(1){
            if(i > j || i >= n || j < 0) break;
            i++; j--;
            if(j < 0) break;
            ret += a[j];
            j--;
        }
        cout << ret;
        return 0;
    }

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
string S;
cin>>S;
int l=S.size();
string ans="AC";
if(S[0]!='A') ans="WA";

int cnt=0;
for(int i=1; i<=l; i++)
{
    if(isupper(S[i]))
    {
        if(i==1||i==l-1||S[i]!='C') {ans= "WA";}
        ++cnt;
    }

}
if(cnt!=1) ans="WA";

cout<<ans<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
import time
import re
import math

def main():
    n=int(input())
    H=list(map(int,input().split()))
    memo=[0]*n
    for a in range(n):
        if a==0:
            memo[a]=0
        elif a==1:
            memo[a]=memo[a-1]+abs(H[a-1]-H[a])
        else:
            memo[a]=min([memo[a-1]+abs(H[a-1]-H[a]),memo[a-2]+abs(H[a-2]-H[a])])
    print(memo[-1])


start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))

Measured memory_bytes: 14480
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll dp[3007][3007];
ll A[3007];

int main(){
  ll N;
  cin >> N;
  rep(i,N){
      cin >> A[i];
  }
  rep(j,N){
    rep(i,N){
      if(i+j>N){
        continue;
      }
      if((j+N)%2==0){
        if(j==0){
          dp[i][j]=-A[i];
        }
        else{
          dp[i][j]=min(dp[i+1][j-1]-A[i],dp[i][j-1]-A[i+j]);
        }
      }
      else{
        if(j==0){
          dp[i][j]=A[i];
        }
        else{
          dp[i][j]=max(dp[i+1][j-1]+A[i],dp[i][j-1]+A[i+j]);
        }
      }
    }
  }
  cout << dp[0][N-1] << endl;
}

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

int main(void){
    int m,f,r;
    while(true){
       cin >> m >> f >> r;
       if ((m == -1) && (f == -1) && (r == -1)){
          break;
       }
       else if ((m + f < 30) || (m == -1) || (f == -1)){
          cout << "F" << endl;
       }
       else if (m + f >= 80){
          cout << "A" << endl;
       }
       else if ((m + f >= 65) && (m + f < 80)){
          cout << "B" << endl;
       }
       else if ((m + f >= 50) && (m + f < 65)){
          cout << "C" << endl;
       }
       else if ((m + f >= 30) && (m + f < 50)){
          if (r >= 50){
            cout << "C" << endl;
          }
          else {
            cout << "D" << endl;
          }
       }
    }
    return 0;
}



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

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

typedef pair<string, string> pss;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

map<pss, ll> m;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    ll max = pow(2, N);
    REP(i, max)
    {
        string r, b;
        REP(j, N)
        {
            if (((i >> j) & 1) == 1)
                r = r + S[N + j];
            else
                b = S[N + j] + b;
        }
        m[pss(r, b)]++;
    }
    ll ans = 0;
    REP(i, max)
    {
        string r, b;
        REP(j, N)
        {
            if (((i >> j) & 1) == 1)
                r = r + S[j];
            else
                b = S[j] + b;
        }
        ans += m[pss(b, r)];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 84992
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 1e3 + 7, MOD = 1e9 + 7;
int cnt[N];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
  int n; cin >> n;
  rep(i, 1, n + 1) {
  	int d = i;
  	for (int j = 2; j * j <= d; j++)
  		while (d % j == 0) { d /= j; cnt[j]++; }
  	if (d > 1) cnt[d]++;
	}
	int ans = 1;
	rep(i, 1, n + 1) ans = ll(ans) * (cnt[i] + 1) % MOD ;
	cout << ans;
	return 0;
}


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

const int mxsz = 1e5 + 5;
int n, m;
int in[mxsz];
int dep[mxsz];
vector<int> adj[mxsz];
int pst[mxsz];

queue<int> q;
void toposort(){
	for (int i = 1; i <= n; i++)
		if (!in[i])
			q.push(i);// dep[i] = 1;
	int cnt = 0;
	while (!q.empty()){
		pst[++cnt] = q.front(); q.pop();
		for (auto v : adj[pst[cnt]]){
			in[v]--;
			if (!in[v])
				q.push(v);
		}
	}
}
void solve(){
	memset(dep, 0, sizeof(dep));
	toposort();
	int mx = 0;
	for (int i = 1; i <= n; i++){
		for (int j : adj[pst[i]]){
			dep[j] = max(dep[j], dep[pst[i]] + 1);
		}
		mx = max(mx, dep[pst[i]]);
	}
	printf("%d\n",mx);
}
int main(){
	scanf("%d %d",&n,&m);
	for (int i = 0, u, v; i < m; i++){
		scanf("%d %d",&u,&v);
		adj[u].push_back(v);
		in[v]++;
	}
	solve();
	return 0;
}


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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define PI         2*acos(0.0)
#define lb         lower_bound
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define btpc       __builtin_popcountll
#define spc(x)     cout<<fixed<<setprecision(x)

const   long long  cs=2e5+5;
const   long long  inf=1e18;
const   long long  mod=1e9+7;
void solve()
{
    int64_t t,n,m,a,b,c,d,e,i,j,k,x,y,cnt=0,cnt1=0;
    bool flag = false;   
    
    cin>>n;
    lve v(n);
    for(auto &ss:v) cin>>ss;
    lve v1{all(v)};
    sort(all(v1));
    if(v==v1)
    {
        cout<<"YES"<<endl;
        return ;
    }
    for(i=0;i<n;i++)
    {
        if(v[i]!=i+1 && !flag)
        {
            x=i;
            flag=true;
        }
        else if(v[i]!=i+1 && flag)
        {
            swap(v[i],v[x]);
            if(v==v1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
            break;
        }
    } 
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);

    // int32_t tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;
const double EPS = 1e-10;

const int table[4][4] = {
	{1,  2,  3,  4},
	{2, -1,  4, -3},
	{3, -4, -1,  2},
	{4,  3, -2, -1}
};

int main()
{
	int n;
	while(scanf("%d", &n), n){
		rep(i, n){
			int a[2][4];
			rep(j, 2) rep(k, 4)
				scanf("%d", &a[j][k]);
			
			int ans[4] = {0};
			rep(j, 4) rep(k, 4)
				ans[abs(table[j][k])-1] += a[0][j] * a[1][k] * (table[j][k]>0 ? 1 : -1);
			
			rep(j, 4)
				printf("%d%c", ans[j], j<3 ? ' ' : '\n');
		}
	}
	return 0;
}

Measured memory_bytes: 1028
const chunks = [];
process.stdin.on("data", (chunk) => {
  chunks.push(chunk);
});
process.stdin.on("end", () => {
  const data = Buffer.concat(chunks).toString("utf8").trim();
  const N = parseInt(data, 10);
  console.log(solve(N));
});

function solve(N) {
  const mod = N % 1000;
  if (mod === 0) return 0;
  return 1000 - mod;
}


Measured memory_bytes: 29908
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		boolean[] prime = new boolean[100001];
		boolean[] like = new boolean[100001];
		Arrays.fill(prime, true); prime[0] = false; prime[1] = false;
		Arrays.fill(like, false);
		for(int i = 2; i < prime.length; i++) {
			if(prime[i]) for(int j = 2; j * i < prime.length; j++) prime[j * i] = false;
		}
		for(int i = 3; i < prime.length; i += 2) {
			if(prime[i] && prime[(i + 1) / 2]) like[i] = true;
		}
		int[] query = new int[100001];
		for(int i = 1; i < query.length; i++) query[i] += query[i - 1] + ((like[i]) ? 1 : 0);
		int Q = sc.nextInt();
		while(Q > 0) {
			Q--;
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(query[r] - query[l - 1]);
		}
	}
}

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

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

using namespace std;

const int64_t INF = 1e+8;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<int> hp(n);
    REP(i,n)cin>>hp[i];
    int m;
    cin>>m;
    vector<tuple<int,int>> sg;
    vector<tuple<int,int>> al;
    REP(i,m){
      string name,tg;
      int mp,dm;
      cin>>name>>mp>>tg>>dm;
      if(tg=="Single")
        sg.emplace_back(mp,dm);
      else
        al.emplace_back(mp,dm);
    }
    int a=sg.size();
    int b=al.size();
    vector<vector<int>> dps(a+1, vector<int>(100001, INF));
    vector<vector<int>> dpa(b+1, vector<int>(100001, INF));
    dps[0][0] = 0;
    dpa[0][0] = 0;
    REP(i,a) {
      REP(j,100001) {
        dps[i+1][j] = dps[i][j];
        if (j >= get<1>(sg[i]))
          dps[i+1][j] = min(dps[i+1][j], dps[i+1][j-get<1>(sg[i])] + get<0>(sg[i]));
        else
          dps[i+1][j] = min(dps[i+1][j], get<0>(sg[i]));
      }
    }
    REP(i,b) {
      REP(j,100001) {
        dpa[i+1][j] = dpa[i][j];
        if (j >= get<1>(al[i]))
          dpa[i+1][j] = min(dpa[i+1][j], dpa[i+1][j-get<1>(al[i])] + get<0>(al[i]));
        else
          dpa[i+1][j] = min(dpa[i+1][j], get<0>(al[i]));
      }
    }
    vector<int64_t> costs(100001);
    REP(i,n){
      REP(j,hp[i]) {
        costs[j] += dps[a][hp[i] - j];
      }
    }
    int64_t mcos = INF;
    REP(i,100001) mcos = min(mcos, dpa[b][i] + costs[i]);
    cout << mcos << endl;
  }
  return 0;
}

Measured memory_bytes: 41608