akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(s);

            for (int i = 0; i < s.Length-1; i++)
            {
                if (s[i] == s[i+1])
                {
                    WriteLine("NO");
                    return;
                }
            }
            WriteLine("YES");
        }
    }
}

Measured memory_bytes: 36316
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int a,n,x;
	double b;
	cin>>a>>b>>n;
	if(n<b)x=n;
	else x=b-1;
	cout<<floor(a*(x/b))<<endl;
	return 0;
}


Measured memory_bytes: 3788
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

// Use g++ compiler for this include to work.
#include <bits/stdc++.h>

using namespace std;

// Constants 
#define INF 1e18
#define EPsecond 1e-9
#define MOD 1000000007
 
// // for using in pairs
// #define first first
// #define second second
 
// Macros
#define all(x) begin(x), end(x)
 
// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

// Temporary macro.
#define int long long

// Operator overloads.
/**
 * The type of element in the vector should have overload for << operator with ostream. 
 */
template<typename T>
ostream& operator<<(ostream &stream, vector<T> v)
{
	for (const auto &it : v)
		stream << it << " ";
	return stream;
}

/**
 * Both types in the pair should have overload for << operator with ostream. 
 */
template<typename T1, typename T2>
ostream& operator<<(ostream &ostream, pair<T1, T2> p)
{
	ostream << p.first << " " << p.second;
	return ostream;
}

// Utility functions.
void swap(int a, int b)
{
	int t = a;
	a = b;
	b = t;
}

///////////////////////////////////////////////////////////////////////

void solve(int tc)
{
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];

	int suff[n];
	suff[n - 1] = a[n - 1];
	for (int i = n - 2; i >= 0; i--)
	{
		suff[i] = suff[i + 1] + a[i];
		suff[i] %= MOD;
	}

	int ans = 0;

	for (int i = 0; i < n - 1; i++)
	{
		ans += (a[i] * suff[i + 1]);
		ans %= MOD;
	}

	cout << ans ;
}	

int32_t main()
{	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	// cin >> t;		
	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int rec(int ix, int turn, int me, int other, vector<int>& A, vector<vector<int>>& memo)
{
  int n = A.size();
  if (ix == n) { return abs(me - other); }
  if (memo[ix][turn] != -1) { return memo[ix][turn]; }
  int ret = (turn == 0) ? -INF : INF;
  for (int i = ix; i < n; ++i) {
    int score = rec(i + 1, 1 - turn, other, A[i], A, memo);
    ret = (turn == 0) ? max(ret, score) : min(ret, score);
  }
  return memo[ix][turn] = ret;
}

int main()
{
  int N, Z, W; scanf("%d %d %d", &N, &Z, &W);
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }

  vector<vector<int>> memo(2005, vector<int>(2, -1));
  int ans = rec(0, 0, Z, W, A, memo);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s;
	cin >> s;
	int num = (s[0] == 'o') + (s[1] == 'o') + (s[2] == 'o');
	cout << 700 + 100 * num << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
const int MOD=2019;
int main()
{
    ll L,R;
    cin>>L>>R;
    if(R-L>=2019)
        return 0*printf("0\n");
    R++;
    L%=2019,R%=2019;
    int ans=2019;
    for(int i=L;i!=R;i=(i+1)%MOD)
        for(int j=(i+1)%MOD;j!=R;j=(j+1)%MOD)
            ans=min(ans,i*j%MOD);
    cout<<ans;
    return 0;
}


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

int main(){
  string T;cin>>T;
  rep(i,T.size()){
    if(T[i]=='?') T[i]='D';
  }
  cout<<T<<endl;
}

Measured memory_bytes: 3752
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

vector<ll> A;
int N;
ll X;

bool check(int x){
    //cout<<abs(A[N-x+1]-X)<<" "<<abs(A[N-x+1-x+1]-X)<<endl;
    if(x==0) return true;
    else if(x>(N+1)/2) return false;
    if(abs(A[N-x+1]-X)>=abs(A[N-x+1-x+1]-X)) return true;
    else return false;
}

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

    int Q;
    cin>>N>>Q;
    A.resize(N+1,0);
    for(int i=1;i<=N;i++) cin>>A[i];
    vector<ll> T(N+1,0),S(N+1,0);
    if(N%2==0){
        for(int i=2;i<=N;i++){
            if(i%2==0) T[i]=A[i]+T[i-1];
            else T[i]=T[i-1];
        }
    }else{
        for(int i=1;i<=N;i++){
            if(i%2==1) T[i]=A[i]+T[i-1];
            else T[i]=T[i-1];
        }
    }
    for(int i=1;i<=N;i++){
        S[i]=S[i-1]+A[i];
    }

    while(Q--){
        cin>>X;
        int ng=55000,ok=0;
        while(ng-ok!=1){
            int mid=(ng+ok)/2;
            if(check(mid)) ok=mid;
            else ng=mid;
        }
        //cout<<X<<" "<<ok<<endl;
        ll ans=0;
        ans=S[N]-S[N-ok];
        ans+=T[max(N-2*ok,0)];
        cout<<ans<<endl;
    }
}

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

int main() {
	int n, q;
	string s;
	cin >> n >> s >> q;
	vector<set<int>> is(26);
	rep(i, n) is[s[i] - 'a'].insert(i);
	rep(ri, q) {
		int t; cin >> t;
		if (t == 1) {
			int i; char c;
			cin >> i >> c;
			i--;
			is[s[i] - 'a'].erase(i);
			s[i] = c;
			is[s[i] - 'a'].insert(i);
		}
		else {
			int l, r; cin >> l >> r;
			l--; r--;
			int ans = 0;
			rep(i, 26) {
				auto itr = is[i].lower_bound(l);
				if (itr != is[i].end() && *itr <= r) ans++;
			}
			cout << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 24196
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let n: u32 = read();

    let el: Vec<u32> = (1..n+1).filter(|&x| ((x as f32 * 1.08).floor()) as u32 == n).collect();
    println!("{}", if el.len() == 0 {":(".parse().unwrap()} else {el[0].to_string()});
}

Measured memory_bytes: 4352
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int n,ans;

main(){
	cin>>n;
	rep(i,n){
		int t;
		cin>>t;
		ans+=t;
	}
	ans-=n;
	dans;
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n;
  cin >> n;
  int a[n+1];
  a[0] = 0;
  for(int i=1; i<=n; i++) cin >> a[i];
  int s = 0;
  for(int i=0; i<n; i++){
    s += abs(a[i+1]-a[i]);
  }
  s += abs(a[0]-a[n]);
  int de[n];
  for(int i=0; i<n-1; i++){
    de[i] = abs(a[i+2]-a[i]) - abs(a[i+1]-a[i]) -abs(a[i+2]-a[i+1]);
  }
  de[n-1] = abs(a[0]-a[n-1]) -abs(a[n] - a[n-1]) - abs(a[n]-a[0]);
  for(int i=0; i<n; i++){
    cout << s+de[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 2048
n,m = gets.chomp.split.map(&:to_i)
ans = 0
array = []
(1..Math.sqrt(m)).each do |i|
	if m % i == 0
		array << i
		array << m / i
	end
end

array.each do |d|
	ans = d if ans < d && n*d <= m
end

puts ans

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };



int main() {
	fastIO;
	int n, k;
	cin >> n >> k;
	vector<pair<int, int>> v;
	map<int, int> frq;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		frq[x]++;
	}

	for (auto i : frq) {
		v.push_back({i.second, i.first});
	}

	sort(v.rbegin(), v.rend());
	ll ans = 0;
	while(v.size() > k) {
		ans += v.back().first;
		v.pop_back();
	}


	cout << ans;


}


Measured memory_bytes: 11764
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
a = LIST()

check = [0]*(n+1)

kaburi = 0
idx1 = 0
idx2 = 0

mod = 10**9 + 7
N = 10**6  # 必要そうな階乗の限界を入れる
factorial = [1]
for i in range(1, N):
    factorial.append(factorial[i-1] * i % mod)
def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, int(y/2)) ** 2 % mod
    else:
        return power(x, int((y-1)/2)) ** 2 * x % mod
def C(n, r):
    return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod
x_inv = [0] * (N)
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(N-2, -1, -1):
    x_inv[i] = x_inv[i+1] * (i+1) % mod

for i in range(n+1):
	if check[a[i]]:
		kaburi = a[i]
		idx1 = check[a[i]]
		idx2 = i + 1
		break
	check[a[i]] = i + 1

# print(kaburi)
# print(idx1, idx2)
l = idx1-1
r = n-idx2+1
idx1 -= 1
idx2 -= 1

thre = n-(idx2-idx1)+2
# print(l, r)

for k in range(1, n+2):
	if k >= thre:
		print(C(n+1, k)%mod)
	else:
		print((C(n+1, k)-C(r+l, k-1))%mod)


Measured memory_bytes: 95188
N, K = gets.split(' ').map(&:to_i)
x = gets.split(' ').map(&:to_i)

ds = []
(K - 1).upto(N - 1) do |i|
  l = x[i - K + 1]
  r = x[i]
  ds.push((r - l) + [l.abs, r.abs].min)
end

puts ds.min

Measured memory_bytes: 11524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    bool a_f = false;
    bool b_f = false;
    bool c_f = false;
    string s;
    cin >> s;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'a') a_f = true;
        if(s[i] == 'b') b_f = true;
        if(s[i] == 'c') c_f = true;
    }
    if(a_f && b_f && c_f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        if(y % 2 != 0){
            System.out.println("No");
            return;
        }
        for(int i = 0; i <= x; i++){
            int a = i;
            int b = x - i;
            if(a * 2 + b * 4 == y){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
        scan.close();
    }
}

Measured memory_bytes: 27024
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int r=0;
  int b=0;
  int n;
  cin >> n;
  cin >> str;
  for(int i = 0; i < (int)str.size(); ++i){
    if(str[i]=='R'){
      r=r+1;
    }else{
      b=b+1;
    }
  }
  if(r>b){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;
#define sign(a) ((a>0)-(a<0))
#define LL long long
#define INF (LL)(1LL<<60)


const long long MOD = 1000000007;

void solve(long long N, std::vector<std::string> S){
    LL i=0, ans=0;
    if(S[0][0]==S[1][0]){
        i=1;
        ans=3;
    }else{
        i=2;
        ans=6;
    }
    while(i<N){
        auto curr = S[0][i]==S[1][i];
        auto prev = S[0][i-1]==S[1][i-1];
        if(curr&&prev)ans=(2*ans)%MOD;
        if(!curr && prev)ans=(2*ans)%MOD;
        if(!curr && !prev)ans = (3*ans)%MOD;

        if(curr)i++;
        else i+=2;
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(2);
    for(int i = 0 ; i < 2 ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  int sum;
  int m = 100000000;
  for (int i = 0; i < n; i++) {
    sum = 0;
    int a;
    cin >> a;
    
    for (int j = 0; ; j++) {
      if (a % 2 == 0)
        a /= 2;
      else {
        sum = j;
        break;
      }
    }
    if (sum < m)
      m = sum;
  }
    cout << m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
	bool erfolg = regex_match(s, regex("(dream|dreamer|erase|eraser)*"));
    if( erfolg ) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 39808
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
const int maxn=16001;

int dp[2][maxn];
int main(){
  string s;
  cin>>s;
  int x,y;
  cin>>x>>y;
  vector<int> cx,cy;
  bool flag=true;
  int now=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='F'){
      now++;
    }
    else{
      if(flag){
        cx.push_back(now);
        flag=false;
      }
      else {
        cy.push_back(now);
        flag=true;
      }
      now=0;
    }
  }
  if(flag){
    cx.push_back(now);
    }
  else {
    cy.push_back(now);
  }
  int cent=8000;
  int *crt=dp[0],*next=dp[1];
  crt[cent]=1;
  for(int i=0;i<cx.size();i++){
    
    for(int j=0;j<maxn;j++){
      if(crt[j]==i+1){

        if(i==0){
          next[j+cx[i]]=i+2;
        }
        else{
            next[j-cx[i]]=i+2;
            next[j+cx[i]]=i+2;
        }
      }
    }
    swap(crt,next);
  }
  bool xflag=false;

  if(crt[x+cent]==cx.size()+1)xflag=true;
  fill(dp[0],dp[0]+maxn,0);
  fill(dp[1],dp[1]+maxn,0);
  int *crt2=dp[0],*next2=dp[1];
  crt2[cent]=1;

  for(int i=0;i<cy.size();i++){
    
    for(int j=0;j<maxn;j++){
      if(crt2[j]==i+1){  
          next2[j-cy[i]]=i+2;
          next2[j+cy[i]]=i+2;
        
      }
      
    }
    swap(crt2,next2);
  }
  if(xflag and crt2[y+cent]==cy.size()+1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;












}


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

using namespace std;

string s;
vector<bool> A;
bool flag = false;

int ctoi(char c){
    return c-'0';
}

void showExp(int res){
    for(int i=0; i<s.size()-1; i++){
        cout << s.at(i);
        if(A.at(i))cout << "+";
        else cout << "-";
    }
    cout << s.at(s.size()-1) << "=" << res << endl;
}

void dfs(int pos){
    if(flag)return;
    if(pos == s.size()-1){
        // calc exp
        int res=ctoi(s.at(0));
        for(int i=0; i<s.size()-1; i++){
            if(A.at(i))res += ctoi(s.at(i+1));
            else res -= ctoi(s.at(i+1));
        }
        if(res == 7){
            showExp(res);
            flag = true;
        }
        return;
    }

    // +
    A.at(pos) = true;
    dfs(pos+1);

    // -
    A.at(pos) = false;
    dfs(pos+1); 
}

int main(){
    cin >> s;
    A = vector<bool>(s.size()-1, false);

    dfs(0);
}

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

int main() {
	int A;
	int B;
	int C;	
	scanf("%d%d%d", &A,&B,&C );
	int d = B / A;
	if (B - A * C>0) printf("%d", C);
	else printf("%d", d);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

ll mod_pow(ll x, ll n) {
	ll ret = 1;
	while (n > 0) {
		if (n % 2)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}

void solve() {
	string a, b; cin >> a >> b;
	string rb = b;
	reverse(rb.begin(), rb.end());
	ll n; cin >> n;
	if (n < b.size()) {
		string z;
		z += rb.substr(0, n);
		z += a; z += rb.substr(0, n);
		z += b;
		int len = z.size();
		rep(i, len) {
			if (z[i] != z[len - 1 - i]) {
				cout << 0 << endl; return;
			}
		}
		cout << 1 << endl; return;
	}
	else {
		string z = a + rb;
		int len = z.size();
		rep(i, len) {
			if (z[i] != z[len - 1 - i]) {
				cout << 0 << endl; return;
			}
		}
		ll dif = n - b.size();
		ll ans = mod_pow(26, (dif + 1) / 2);
		cout << ans << endl;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	//stop
		return 0;
}


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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A*B>C*D)
	{
		cout << A * B << endl;
	}
	else
	{
		cout << C * D << endl;
	}

}


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

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

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

int main() {
	int n; scanf("%d", &n);
	
	std::vector<std::string> v = {"sat", "sun", "mon", "tue", "wed", "thu", "fri"};
	printf("%s\n", v[(n - 2 + (int)v.size()) % v.size()].c_str());
	return 0;
}



Measured memory_bytes: 3276
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=1e5+2;
int n,m,ans;
int sum[maxn];
bool red[maxn];
int main(){
	scanf("%d%d",&n,&m);
	red[1]=true;
	for (int i=1;i<=n;i++) sum[i]=1;
	for (int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		sum[x]--,sum[y]++;
		red[y]|=red[x];
		if (!sum[x]) red[x]=false;
	}
	for (int i=1;i<=n;i++)
		if (red[i]) ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	ll N, W;
	cin >> N >> W;
	vector<ll> w(N+1), v(N+1);
	for (int i = 0; i < N; i++)cin >> w[i+1] >> v[i+1];
	vector<vector<ll> > dp(N+1, vector<ll>(W+1, 0)); //iまでの荷物を容量wのナップザックに詰めたときの価値
	for (int i = 1; i <= N; i++)for (int j = 0; j <= W; j++) {
		if (w[i] > j) {
			dp[i][j] = dp[i - 1][j];
		}
		else {
			dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,sum;
  cin >> N;
  sum=0;
  for (int i=0;i<N;i++){
    int a,b;
    cin >> a>> b;
    sum+=b-a+1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var k int
	var s int
	fmt.Scan(&k)
	fmt.Scan(&s)

	count := 0
	for i := 0; i <= k; i++ {
		c := k
		if s-i < k {
			c = s - i
		}
		for j := 0; j <= c; j++ {
			if s-i-j <= k {
				count++
			}
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
PROGRAM ATCODER

implicit none
integer :: n,m,i,j,k
integer,allocatable :: count(:)
integer :: a(30,30),a1(30),ans

a = 0
a1 = 0

read(*,*) n,m
allocate(count(m))
count = 0

do i = 1, n
	read(*,*) a1(i), (a(i,j), j=1,a1(i))
end do

do i = 1, m
	do j = 1, 30
    	do k = 1, 30
			if(a(j,k) == i)then
    			count(i) = count(i) +1
   			end if
		end do
	end do
end do

ans = 0
do i = 1, m
	if(count(i) == n)then
    	ans = ans + 1
    end if
end do

write(*,'(i0)') ans

END PROGRAM ATCODER

Measured memory_bytes: 768
K, N = map(int, input().split())

distlist = list(map(int, input().split()))

maxdist = distlist[0] + K - distlist[N-1]
for i in range(0, N-1):
  dist2houses = distlist[i+1] - distlist[i]
  if (dist2houses > maxdist):
    maxdist = dist2houses

print(K - maxdist)

Measured memory_bytes: 26060
#include<stdio.h>
#include<math.h>
#define NUMBER 10000
int main()
{
   int n, m;
   int ans = 0;
   int i = 0;
   int array[NUMBER];
   
   scanf("%d", &n);
   
   do {
      scanf("%d", &array[i]);
      ++i;
   } while (i < n);
   
   for (i = 0; i < n; ++i){
      m = 2;
      while (m < sqrt(array[i])){
         if (array[i] % m == 0)
            break;
         else 
            ++m;
      }
      if(array[i] != 1 && m > sqrt(array[i]))
         ++ans;
   }
   
   printf("%d\n", ans);
   return 0;
}

Measured memory_bytes: 1800
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int AB, BC, CA;
  cin >> AB >> BC >> CA;
  cout << AB * BC / 2 << endl;
  return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	REP(i,N){
		double x[4],y[4];
		cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3];
		double vx[2],vy[2],vn[2];
		vx[0]=x[1]-x[0],vy[0]=y[1]-y[0],vn[0]=hypot(x[1]-x[0],y[1]-y[0]);
		vx[0]/=vn[0];
		vy[0]/=vn[0];
		vx[1]=x[3]-x[2],vy[1]=y[3]-y[2],vn[1]=hypot(x[3]-x[2],y[3]-y[2]);
		vx[1]/=vn[1];
		vy[1]/=vn[1];
		if(abs(vx[0]*vy[1]-vy[0]*vx[1])<=1e-7) out("YES");
		else out("NO");
	}
	
	return 0;
}



Measured memory_bytes: 3284
n = gets.chomp.to_i
a = gets.chomp.split().map(&:to_i)

a.sort!

if a.size==2
  puts [a.last, a.first].join(' ')
  exit
end


amax = a.last

center = a.bsearch{|x| x >= amax/2}
cindex = a.index(center)
center2 = a[cindex-1]

if (center - amax/2).abs > (center2 - amax/2).abs
  center = center2
end

puts [amax, center].join(' ')

Measured memory_bytes: 10248
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

ll N,M;
ll d[301][301];
bool used[301];
ll Start[301];

ll Solve(ll x){
    if(!used[d[x][Start[x]]]) return d[x][Start[x]];
    Start[x]++;
    return Solve(x);
}

ll SOLVE(){
    vec kari(M+1,0);
    rep(i,N) kari[Solve(i)]++;
    ll MAX=-INF, basho=-1;
    rep(i,M) if(kari[i]>MAX){
        MAX=kari[i];
        basho=i;
    }
    //rep(i,M) cout<<kari[i]<<' ';
    //cout<<endl;
    //cout<<MAX<<' '<<basho+1<<endl;
    used[basho]=true;
    return MAX;
}
ll MAIN(){
    if(M==1) return N;
    ll ret=INF;
    rep(i,M-1) {
        //cout<<i<<':';
        ll K=SOLVE();
        ret=min(ret,K);
    }
    return ret;
}
int main(){
    cin>>N>>M;
    rep(i,N) rep(j,M) {cin>>d[i][j]; d[i][j]--;}
    cout<<MAIN()<<endl;

}

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

using namespace std;

using int64 = long long;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int add = 0;
  for(int i = min(A, B); i >= 1; i--) {
    if(A % i == 0 && B % i == 0) {
      ++add;
      if(add == K) {
        cout << i << endl;
        return 0;
      }
    }
  }
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T &a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T &a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T &a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	int n;
	cin >> n;

	cout << n * n * n << endl;

	return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

int N;
vector<int> A;

enum Graph { UP = 0, DOWN = 1 };

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

    cin >> N;
    A.resize(N);
    REP(i, N) { 
        cin >> A[i];
    }

    int cur_m = 1000;
    int cur_s = 0;
    int flag = DOWN;
    int buy = -1, sell = -1;

    for(int i = 1; i < N; ++i) {
        DBG("A[i-1]: %lld A[i]: %lld\n", A[i-1], A[i]);
        if(A[i-1] < A[i]) {
            if(flag == DOWN) {
                // 買いポイント
                buy = i - 1;
                flag = UP;
                DBG("  buy: %lld flag: UP\n", buy);
            }
        }
        else if(A[i-1] > A[i]) {
            if(flag == UP) {
                // 売りポイント
                sell = i - 1;
                flag = DOWN;
                DBG("  sell: %lld flag: DOWN\n", sell);

                cur_s = cur_m / A[buy];
                cur_m %= A[buy];
                cur_m += cur_s * A[sell];
                cur_s = 0;
                DBG("cur_m: %lld cur_s: %lld\n", cur_s, cur_m);
            }
        }
    }
    if(flag == UP) {
        sell = N - 1;
        cur_s = cur_m / A[buy];
        cur_m %= A[buy];
        cur_m += cur_s * A[sell];
        cur_s = 0;
    }
    printf("%lld\n", cur_m);

    return 0;
}


Measured memory_bytes: 3788
# ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬
# ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬
# ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬     ╬╬╬╬╬
# ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬          ╬   ╬
# ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬     ╬╬
# ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬  ╬ ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬     ╬
# ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬  ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╬    ╬╬╬╬╬╬╬   ╬╬╬╬╬╬╬╬╬╬      ╬
# ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬  ╬   ╬╬╬╬╬╬╬  ╬      ╬╬╬╬  ╬╬╬╬
# ╬╬╬╬╬╬╬╬╬╬╬╬╬ ╬╬ ╬    ╬╬╬╬╬╬╬╬╬        ╬ ╬        ╬╬ ╬╬╬
# ╬╬╬╬╬╬╬╬╬╬╬╬╬╬    ╬     ╬╬╬           ╬ ╬╬╬    ╬  ╬╬  ╬╬╬╬╬╬╬╬
# ╬╬╬╬╬╬ ╬╬╬╬╬╬╬╬                        ╬╬╬╬╬╬╬╬╬  ╬   ╬╬╬╬╬╬╬╬   ╬╬╬
# ╬╬  ╬╬╬  ╬╬╬╬     ╬╬╬╬╬                  ╬╬╬╬╬╬╬       ╬╬ ╬╬╬╬  ╬    ╬
# ╬╬      ╬   ╬╬╬╬╬╬╬╬╬╬╬ ╬                 ╬╬╬╬         ╬  ╬╬╬           ╬
# ╬╬       ╬╬╬╬╬    ╬                                  ╬    ╬╬               ╬
# ╬╬     ╬╬╬╬╬╬╬╬                                    ╬╬    ╬
# ╬╬     ╬╬╬╬╬╬╬╬╬╬╬╬╬╬                      ╬          ╬
# ╬╬╬╬  ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬                                      ╬
# ╬╬╬╬╬       ╬╬╬╬╬                                          ╬
# ╬╬╬╬╬╬╬                                    ╬╬╬
# ╬╬╬╬╬╬╬╬╬╬                          ╬  ╬╬╬╬╬╬╬╬
# ╬╬╬╬╬╬╬╬╬ ╬  ╬                  ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬         ╬
# ╬╬╬╬╬╬╬╬╬╬╬╬                  ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬        ╬
# ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬                ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬       ╬
# ╬    ╬╬╬╬╬╬╬╬╬╬╬                 ╬╬╬╬╬╬╬╬╬╬

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    if v[i] - c[i] > 0:
        ans += v[i] - c[i]

print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100001];
vector<int>v(100000,-1);
int mod(int x,int y)
{
	if(x>=y)
	return(x-y);
	else
	return(y-x);
}
int f(int x)
{
	if(x==n-2)
	{
		return(mod(a[n-1],a[n-2]));
	}
	if(x==n-1)
	return 0;
	if(v[x]!=-1)
	return(v[x]);
    v[x]=min(mod(a[x],a[x+1])+f(x+1),mod(a[x],a[x+2])+f(x+2));
	return v[x];
	
}
int main()
{
	cin>>n;
	int res;
	for(int i=0;i<n;i++)
	cin>>a[i];
	res=f(0);
	cout<<res<<endl;
}

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

using namespace std;

int main(){
    int n, i, j;
    scanf("%d", &n);
    int height[n+5];
    for(i = 1; i<=n; i++){
        scanf("%d", &height[i]);
    }
    int dp[n+5];
    for(i = 0; i <=n; i++) dp[i] = 1e9;
    dp[1] = 0;
    for(i = 2; i <= n; i++){
        if(i > 1) dp[i] = dp[i-1] + abs(height[i] - height[i-1]);
        if(i > 2) {
            for(j = 1; j <= 2; j++){
                dp[i] = min(dp[i], dp[i-j] + abs(height[i] - height[i-j]));
            }
        }
    }

    printf("%d", dp[n]);

    return 0;
}


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

#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

int main() {
    lli a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
}


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

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

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

int main() {
	int n; scanf("%d", &n); auto a = make_v<int>(n, n);
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) scanf("%d", &a[i][j]);
	
	auto ppc = make_v<i64>(1 << n);
	for(int i = 0; i < ppc.size(); i++) for(int j = 0; j < n; j++) ppc[i] += (i >> j & 1);
	
	const int MOD = 1e9 + 7;
	auto dp = make_v<i64>(1 << n); dp[0] = 1;
	for(int i = 0; i < (1 << n) - 1; i++) {
		int count = ppc[i];
		for(int j = 0; j < n; j++) {
			if(!a[count][j] or (i >> j & 1)) continue;
			(dp[i | (1 << j)] += dp[i]) %= MOD;
		}
	}
	printf("%lld\n", dp[dp.size() - 1]);
	return 0;
}


Measured memory_bytes: 33024
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] c = new long[n];
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt()-1;
        }
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }

        long max = Long.MIN_VALUE;

        if(k < n * 2) {
            for(int s = 0 ; s < n; s ++) {
                int pos = s;
                long score = 0;
                for(int i=0; i<k; i++) {
                    pos = p[pos];
                    score += c[pos];
                    max = Math.max(max, score);
                }
            }
            System.out.println(max);
            return;
        }

        OUTER: for(int s = 0 ; s < n; s ++) {
            boolean[] v = new boolean[n];
            v[s] = true;
            long a = 0;
            long mm = Long.MIN_VALUE;
            long[] d = new long[n];
            int pos = s;
            for(int i=0; i<n; i++) {
                pos = p[pos];
                a += c[pos];
                mm = Math.max(mm, a);
                if(v[pos]) {
                    int kk = k - (i+1);
                    int ep = pos;
                    long b = 0;
                    long m2 = Long.MIN_VALUE;
                    for(int j=0; j<n; j++) {
                        pos = p[pos];
                        b += c[pos];
                        m2 = Math.max(m2, b);
                        if(pos == ep) {
                            int kkk = kk - (j+1);
                            int ll = j+1;
                            max = Math.max(max, mm);
                            max = Math.max(max, a + m2);
                            if(b > 0) {
                                int div = kkk / ll;
                                long score = a + div * b;
                                kk -= div * ll;
                                for(int q=0; q<kk; q++) {
                                    pos = p[pos];
                                    score += c[pos];
                                    max = Math.max(max, score);
                                }
                            }
                            continue OUTER;
                        }
                    }
                }
                v[pos] = true;
            }
        }
        System.out.println(max);

    }




}

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

const int zero = 8010;

string S;
int X, Y, D;
vector<int> V, H, T;

vector<vector<int> > cc;
int dp(int idx, int x) {
    if(idx == T.size()) return x == zero + D;
    int &ret = cc[idx][x];
    if(ret != -1) return ret;

    ret = 0;
    ret |= dp(idx + 1, x + T[idx]);
    ret |= dp(idx + 1, x - T[idx]);
    return ret;
}

bool solve(int x) {
    D = x;
    cc = vector<vector<int> >(T.size(), vector<int>(2*zero, -1));
    return dp(0, zero);
}

int main() {
    cin >> S >> X >> Y;

    bool isV = true;
    int sum = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'T') {
            if(isV) V.push_back(sum);
            else H.push_back(sum);

            sum = 0;
            isV ^= 1;
        }
        else sum++;
    }
    if(isV) V.push_back(sum);
    else H.push_back(sum);

    X -= V[0];
    for(int i = 1; i < V.size(); i++) T.push_back(V[i]);
    if(!solve(X)) {
        printf("No");
        return 0;
    }

    T.clear();
    for(int i = 0; i < H.size(); i++) T.push_back(H[i]);
    if(!solve(Y)) {
        printf("No");
        return 0;
    }

    printf("Yes");
}


Measured memory_bytes: 486656
// ------------------------------------
// Date:2018/ 3/31
// Problem:Digit Sum 2 021.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  SCIN(N);
  ll ans = 0ll;
  ll sub = 0ll;
  bool flag = false;
  REP(i, N.size()) {
    sub += N[i] - '0';
  }
  REP(i, N.size()) {
    if (i == 0) {
      // 最初
      if (N[i] == '9') {
	flag = true;
	ans += 9;
      } else {
	ans += (N[i] - '0');
	ans--;
	// OK(true);
      }
    } else {
      if (flag) {
	if (N[i] != '9') {
	  ans -= 1;
	  flag = false;
	}
      }
      ans += 9;
      // debug(ans);
    }
  }

  cout << max(ans, sub) << endl;
  
  return 0;
}



Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let h: usize = sc.cin();
    let w: usize = sc.cin();
    let f: Vec<Vec<char>> = (0..h).map(|_| sc.cin::<String>().chars().collect()).collect();

    let inf = (h * w + 1000) as i64;
    let mut memo = vec![vec![inf; w]; h];
    memo[0][0] = 1;

    fn neigh(i: usize, j: usize, h: usize, w: usize) -> Vec<(usize, usize)> {
        let mut r = vec![];
        if i > 0 { r.push((i - 1, j)); }
        if j > 0 { r.push((i, j - 1)); }
        if i < h - 1 { r.push((i + 1, j)); }
        if j < w - 1 { r.push((i, j + 1)); }
        r
    }

    use std::collections::BinaryHeap;
    let mut q = BinaryHeap::new();
    q.push((0, (0, 0)));
    while let Some((_, (i, j))) = q.pop() {
        for &(i2, j2) in neigh(i, j, h, w).iter() {
            if f[i2][j2] == '#' { continue }
            if memo[i2][j2] > memo[i][j] + 1 {
                memo[i2][j2] = memo[i][j] + 1;
                q.push((-memo[i][j]-1, (i2, j2)));
            }
        }
    }

    if memo[h-1][w-1] == inf {
        put!(-1);
    } else {
        let counts: usize = f.iter().map(|row| row.iter().filter(|&c| *c == '.').count()).sum();
        put!(counts as i64 - memo[h-1][w-1]);
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
use rustc_hash::FxHashSet;
fn main() {
    input! {
        n: usize,
        ai: [i64; n],
    }
    let mut ai: Vec<_> = ai.into_iter().enumerate().map(|(i,a)| (a, i as i64)).collect();
    ai.sort_unstable();
    ai.reverse();

    let mut dp = vec![vec![0i64; n+1]; n+1];
    for i in 0..n {
        for low in 0..=i {
            let high = i - low;
            let (score, pos) = ai[i];

            let low_dist = (pos - low as i64).abs();
            let high_dist = (n as i64 - 1 - high as i64 - pos).abs();

            let low_score = dp[low][high] + score * low_dist;
            let high_score = dp[low][high] + score * high_dist;

            dp[low+1][high] = max(dp[low+1][high], low_score);
            dp[low][high+1] = max(dp[low][high+1], high_score);
        }
    }
    let mut ans = 0;
    for i in 0..=n {
        ans = max(ans, dp[i][n-i]);
    }
    println!("{}", ans);
}


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

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素


int main(){
    string s;
    cin>>s;
    if(s[0]==s[1]&&s[1]==s[2])cout<<"No";
    else cout<<"Yes";
    cout<<endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int n;
  cin >> n;
  vector<bool> m(1000005);
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  for(int i=0; i<=1000000; i++){
    m[i] = true;
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for(int i=0; i<n-1; i++){
    if(a[i]==a[i+1] && m[a[i]]){
      m[a[i]] = false;
      for(int j=1; j*a[i]<=1000000; j++){
        m[j*a[i]] = false;
      }
    }
  }
  for(int i=0; i<n; i++){
    if(m[a[i]]){
      ans++;
      for(int j=1; j*a[i]<=1000000; j++){
        m[j*a[i]] = false;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4320
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int INF = 1e9+5;
int n, m, l, a, b, c, d[305][305];
void wf(){rep(k,n) rep(i,n) rep(j,n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);}
int main(){
	scanf("%d%d%d", &n, &m, &l); n++;
	fill(d[0], d[n], INF);
	rep(i,m){
		scanf("%d%d%d", &a, &b, &c);
		d[a][b] = d[b][a] = c;
	}
	wf();
	rep(i,n) rep(j,n) d[i][j] = d[i][j] <= l ? 1 : INF;
	wf();
	scanf("%d", &c);
	rep(i,c){
		scanf("%d%d", &a, &b);
		printf("%d\n", d[a][b] == INF ? -1 : d[a][b] - 1);
	}
}

Measured memory_bytes: 896
#include<stdio.h>
#include<math.h>
int main(void)
{
  int n;
  int d;
  int x[10][10];
  int i,j,k;
  int a=0;
  int s=0;
  
  scanf("%d %d",&n,&d);
  
  for(i=0;i<n;i++)
  {
    for(j=0;j<d;j++)
      scanf("%d",&x[i][j]);
  }
  for(i=0;i<n-1;i++)
  {
    for(j=i+1;j<n;j++)
    {
      a=0;
      for(k=0;k<d;k++)
      {
        a+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      /*printf("%d ",a);
      printf("%d\n",sqrt(a)-floor(a));*/
      if(sqrt(a)-floor(sqrt(a))==0)
        s++;
    }
    
  }
  
  printf("%d",s);
  return 0;
  
}

Measured memory_bytes: 256