akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int w[105], val[105];
long long dp[100005];
int main()
{
    int t,m,res=-1;    
    scanf("%d%d",&m,&t);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&w[i],&val[i]);
    }
    for(int i=1;i<=m;i++) 
    {
        for(int j=t;j>=0;j--) 
        {
            if(j>=w[i])
            {
                dp[j]=max(dp[j-w[i]]+val[i], dp[j]);
            }
        }
    }    
    printf("%lld\n",dp[t]);
    return 0;
}


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

int n, nn;

int main(){
    scanf("%d", &n); nn = n | 1;
    printf("%d\n", n&1 ? (n-1)*(n-1)/2 : n*(n-2)/2);
    for(int i = 1; i <= n; i++) for(int j = i+1; j <= n; j++)
        if(i != j && i + j != nn) printf("%d %d\n", i, j);
}

Measured memory_bytes: 256
/*　ITP1_10_D: Distance II */
/* 20181125 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
#define N 100

int main(void) {
	double D1, D2, D3, D4, diff0, diff1, diff2, diff3;
	int i, n;
	double x[N] = {0.0};
	double y[N] = {0.0};
	D1 = D2 = D3 = D4 = 0.0;

	scanf("%d", &n);
	
	for(i = 0; i < n; i++) scanf("%lf", x + i);
	for(i = 0; i < n; i++) scanf("%lf", y + i);

	for(i = 0; i < n; i++) {
		diff0 = x[i] - y[i];
		diff2 = pow(diff0, 2);
		diff3 = pow(diff0, 3);
		diff3 = pow(diff3, 2);
		diff3 = sqrt(diff3);
		diff1 = sqrt(diff2);
		D1 += diff1;
		D2 += diff2;
		D3 += diff3;
		if(D4 < diff1) D4 = diff1;
	}
	D2 = sqrt(D2);
	D3 = pow(D3, 1.0 / 3);

	printf("%.8f\n%.8f\n%.8f\n%.8f\n", D1, D2, D3, D4);

	return 0;
}


Measured memory_bytes: 2128
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
      	int c = sc.nextInt();
      if(a+b+c>21)
      {
        System.out.println("bust");
      }
      else
      {
        System.out.println("win");
      }
    }
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int doll[200][2];
int memo[200];
int n,m;

int solve(int p) {
	if(memo[p]) return memo[p];
	memo[p]=1;
	for(int i=0;i<n+m;i++) {
		if(doll[p][0]>doll[i][0]&&doll[p][1]>doll[i][1]) memo[p]=max(1+solve(i),memo[p]);
	}
	return memo[p];
}

int main() {
	while(scanf("%d",&n),n) {
		for(int i=0;i<n;i++) {
			scanf("%d %d",&doll[i][0],&doll[i][1]);
		}
		scanf("%d",&m);
		for(int i=n;i<n+m;i++) {
			scanf("%d %d",&doll[i][0],&doll[i][1]);
		}
		int ans=0;
		memset(memo,0,sizeof(memo));
		for(int i=0;i<n+m;i++) {
			ans=max(ans,solve(i));
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

vector<PCL> lanlength(string s){
  vector<PCL> v;
  char pre = s[0];
  ll count = 0;
  s.push_back(' ');
  rep(i,s.length()){
    if(pre==s[i])++count;
    else{
      v.push_back(PCL(pre,count));
      count = 1;
    }
    pre = s[i];
  }
  return v;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >>s;
  vector<PCL> w = lanlength(s);
  int N = s.length()+1;
  ll pre = 0;
  ll ans = 0;
  for(const PCL& p : w){
    if(p.first == '<'){
      ans += (p.second+1)*p.second/2;
      pre = p.second;
    }else{
      ans += p.second*(p.second-1)/2;
      ans += max(0ll,p.second - pre);
      pre = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


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

n, a, b, c = map(int, input().split())
ans = []
ss = []
for _ in range(n):
    ss.append(input().strip())
ss.append('')

def ab():
    global a
    global b
    global c
    ans.append('B')
    a -= 1
    b += 1
def ba():
    global a
    global b
    global c
    ans.append('A')
    a += 1
    b -= 1
def ac():
    global a
    global b
    global c
    ans.append('C')
    a -= 1
    c += 1
def ca():
    global a
    global b
    global c
    ans.append('A')
    a += 1
    c -= 1
def bc():
    global a
    global b
    global c
    ans.append('C')
    b -= 1
    c += 1
def cb():
    global a
    global b
    global c
    ans.append('B')
    b += 1
    c -= 1


for i, s in enumerate(ss):
    if i == n:
        break

    if s == 'AB':
        if a == 0 and b == 0:
            print('No')
            exit()
        elif a == 1 and b == 1:
            nx = ss[i + 1]
            if nx == 'BC':
                ab()
            else:
                ba()
        elif a >= b:
            ab()
        else:
            ba()
    elif s == 'BC':
        if b == 0 and c == 0:
            print('No')
            exit()
        elif b == 1 and c == 1:
            nx = ss[i + 1]
            if nx == 'AC':
                bc()
            else:
                cb()
        elif b >= c:
            bc()
        else:
            cb()
    elif s == 'AC':
        if a == 0 and c == 0:
            print('No')
            exit()
        elif a == 1 and c == 1:
            nx = ss[i + 1]
            if nx == 'AB':
                ca()
            else:
                ac()
        elif a >= c:
            ac()
        else:
            ca()

print('Yes')
for s in ans:
    print(s)


Measured memory_bytes: 86064
#include<stdio.h>
#define N 100000

int a[N];
int ans;
int n;


void check(int a[],int x,int mid,int com){
	int i;
	
	if(com==1){/*down*/
		for(i=mid;i>=0;i--){
			if(a[i] < x){
				ans=i+1;
				return;
			}
		}
	}
	else {/*up*/
		for(i=mid;i<=n-1;i++){
			if(a[i] >= x){
				ans=i;
				return;
			}
		}
	}

}
		


void lower_bound(int a[],int x,int start,int last,int past){
	int mid=(last+start)/2;
	
	if(start > last)return;
	
	if(a[mid]==x){
		for(int i=mid-1;i>=0;i--){
			if(a[i]!=x){
				ans=i+1;
				return;
			}
		}
	}
	
	if(past==1){
		if(a[mid] < x)lower_bound(a,x,mid+1,last,1);
		else check(a,x,mid,1);
	}
	
	else if(past==-1){
		if(a[mid] > x)lower_bound(a,x,start,mid-1,-1);
		else check(a,x,mid,-1);
	}
	
	else {
		if(a[mid] < x)lower_bound(a,x,mid+1,last,1);
		if(a[mid] > x)lower_bound(a,x,start,mid-1,-1);
	}
	
	return;
	
}

int main(){
	int q,i,x;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);

	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&x);
		if(x <= a[0])ans=0;
		else if(x > a[n-1])ans=n;
		else lower_bound(a,x,0,n-1,0);
		printf("%d\n",ans);
		
	}
	
	return 0;
	
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> > 
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int n, i;
	string s;
	cin >> n;
	vector <string> v(n);
	fo(i, 0, n)
	cin >> v[i];
	
	map <string, int> mp;
	fo(i, 0, n)
	mp[v[i]]++;
	
	vector <string> ans;
	int mx = 0;
	fo(i, 0, n)
	mx = max(mx, mp[v[i]]);
	
	fo(i, 0, n){
		if(mx == mp[v[i]]){
			ans.pb(v[i]);
			mp[v[i]] = 0;
		}
	}
	sort(all(ans));
	for(auto x : ans)
	cout << x << '\n';
}

Measured memory_bytes: 27120
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <functional>
#include <queue>
#include <tuple>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using ll = long long;
using vll = vector<ll>;
using pii = pair<int, int>;
using vb = vector<char>;
using vvb = vector<vb>;

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

#define fi first
#define sn second
#define decpii(p) p.fi--,p.sn--;


#ifdef LOCAL
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define dumpn(c) cerr << "> " << #c << " = " << (c) << ", ";
#else
#define dump(c) ;
#define dumpn(c) ;
#endif


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, (int) a.size())os << (i ? " " : "") << a[i];
    return os << ']';
}


int dxf[] = {1, 0, -1, 0};
int dyf[] = {0, -1, 0, 1};

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

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

inline vi uni(vi &vec) {
    sort(vec.begin(), vec.end());
    vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll fpow(ll x, ll p) {
    ll ans = 1;
    while (p > 0) {
        if ((p & 1) == 1) {
            ans *= x;
        }
        x *= x;
        p >>= 1;
    }
    return ans;
}

struct ____ {
    ____() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} ________;


class UnionFind {
public:
    vi par;
    vi rank;

    UnionFind(int n) {
        par = vi(n);
        iota(all(par), 0);
        rank = vi(n, 0);
    }

    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);

        if (rank[x] < rank[y])
            swap(x, y);
        par[y] = x;

        if (rank[x] == rank[y])
            rank[x]++;
    }
};


int solve() {
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
        --p[i];
    }

    UnionFind uf(N);

    vector<int> x(M), y(M);
    for (int i = 0; i < M; ++i) {
        cin >> x[i] >> y[i];
        --x[i], --y[i];
        uf.unite(x[i], y[i]);
    }

    int res = 0;
    rep(i,N) {
        if(uf.same(p[i], i))
            res++;
    }

    return res;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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

template<typename T>
map<T, int> factorize(T x){
  map<T, int> res;
  for(int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}


signed main(void) {
    int n;
    cin >> n;
    vi v;
    for(int i = 1; i*i <= n; i++)if(n%i == 0){
        v.push_back(i);
        if(i != 1 && i*i<n)v.push_back(n/i);
    }
    int cnt = factorize(n).size();
    cout << cnt << " " << v.size() << endl;
}



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

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

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Cube cube01 = new Cube(br);
		Cube cube02 = new Cube(br);
		
		
		
		//char[] act = br.readLine().toCharArray();
		//cube.roll(act);
		//int count = Integer.parseInt(br.readLine());
		//for(int i = 0; i < count; i++){
		boolean ans = cube01.trace(cube01,cube02);
			if(ans == true){
				System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
		//}
		//System.out.println(cube.top);
	}
}

class Cube {
	String[] num;
	String top;
	String center;
	String back;
	String bottom;
	String right;
	String left;
	String temp;

	Cube(BufferedReader br) throws IOException {
		num = br.readLine().split(" ");
		this.top = num[0];
		this.center = num[1];
		this.right = num[2];
		this.left = num[3];
		this.back = num[4];
		this.bottom = num[5];
	}

	void south() {
		temp = this.top;
		this.top = this.back;
		this.back = this.bottom;
		this.bottom = this.center;
		this.center = temp;
	}

	void north() {
		temp = this.top;
		this.top = this.center;
		this.center = this.bottom;
		this.bottom = this.back;
		this.back = temp;
	}

	void east() {
		temp = this.top;
		this.top = this.left;
		this.left = this.bottom;
		this.bottom = this.right;
		this.right = temp;
	}

	void west() {
		temp = this.top;
		this.top = this.right;
		this.right = this.bottom;
		this.bottom = this.left;
		this.left = temp;
	}

	void roll(char[] act) {
		for (int i = 0; i < act.length; i++) {
			switch (act[i]) {
			case 'S':
				south();
				break;
			case 'N':
				north();
				break;
			case 'E':
				east();
				break;
			case 'W':
				west();
				break;
			}
		}
	}
	
	void turnRight(){
		temp = this.center;
		this.center = this.left;
		this.left = this.back;
		this.back = this.right;
		this.right = temp;
	}
	
	void search(BufferedReader br) throws IOException {
		
		String[] numList = br.readLine().split(" ");
		for (int i = 0; i < 6; i++) {
			if (i == 3) {
				this.east();
				}
			if (numList[1].equals(this.center)){
				break;
				} else {
				this.north();
				}
		}
		while (true) 
			if (numList[0].equals(this.top)) {
				break;
				} else {
				this.west();
				}
		System.out.println(right);
	}
	
	void setUpside(int top,Cube cube) throws IOException{
		
		for(int i = 0; i < 7; i++){
			if(cube.top.equals(top)){
				break;
			}
			if(i == 3){
				cube.east();
				
			}
			cube.north();	
		}
	}

	boolean trace(Cube cube01, Cube cube02) {

		boolean ans = false;

		for (int i = 0; i < 8; i++) {
			cube02.north();
			//System.out.print("???");
			if (cube02.top.equals(cube01.top)) {
				for (int j = 0; j < 5; j++) {
					cube02.turnRight();
					if (cube02.right.equals(cube01.right) && cube02.center.equals(cube01.center)
							&& cube02.left.equals(cube01.left) && cube02.back.equals(cube01.back)
							&& cube02.bottom.equals(cube01.bottom)) {
						ans = true;
					}
				}
			}
			if (i == 3) {
				cube02.east();
				//System.out.print("?\?");
			}
		}
		return ans;
	}
}

Measured memory_bytes: 24484
#include <bits/stdc++.h>
using namespace std ;
map< string , bool > mp ;
int n , ans ; string a ;
signed main() {
	cin >> n ;
	for( int i = 1 ; i <= n ; ++i ) {
		cin >> a ;
		if( !mp[ a ] ) mp[ a ] = true , ++ ans ;
	}
	printf( "%d\n" , ans ) ;
	return 0 ;
}

Measured memory_bytes: 19288
import sys

stdin = sys.stdin

ni = lambda: int(ns())
ns = lambda: stdin.readline()

N = ni()

ans = "No"
for i in range(1, 10):
    for j in range(1, 10):       
        if (i * j ) == N:
            ans="Yes"
            break
    else:
        continue
    break

print(ans)




Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

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

typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  int n; cin >> n;
  string s; cin >> s;
  map<char, bool> mng_char;
  for (int i = 0; i < 26; i++) {
    mng_char['a'+i] = false;
  }

  string former, latter;
  int cur_max = 0;
  rep(i, n) 
  {
      former = s.substr(0,i);
      latter = s.substr(i,n);
      int max_comb = 0; 
      for (int j = 0; j < former.size(); j++) {
           if (latter.find(former[j]) != string::npos && 
               mng_char[former[j]] == false)
           {
               max_comb++;
               mng_char[(char)former[j]] = true;
              //  cout << former[j] << max_comb << endl;
           }
      }
      cur_max = max(max_comb, cur_max);
      // cout << former << " " << latter << endl;
      // cout << cur_max << " " << max_comb << endl;
      for (int k = 0; k < 26; k++) {
        mng_char['a'+k] = false;
      }
  }
  cout << cur_max << endl;
  return 0;
}

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


long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){
int N;
cin>>N;
int A[N][N]={};//選手とその相手
int a;
for(int i=0;i<N;i++){
    for(int k=0;k<N-1;k++){
    cin>>a;
    a--;
    A[i][k]=a;
}
A[i][N-1]=10000;
}
int list[N];
for(int i=0;i<N;i++){
    list[i]=0;
    }

long long ans=-1;
for(int k=1;k>0;k++){
    bool match[N]={};
    int  finish=0;
    int count=0;
    for(int i=0;i<N;i++){
        if(list[i]==N-1){
        finish++;
        }
        int t=A[i][list[i]];
        if(t==10000)continue;
        if(A[t][list[t]]==i && !match[i] && !match[t]){
        list[i]++;
        match[i]=true;
        list[t]++;
        match[t]=true;
        count++;
        }
    
    
    }
    if(finish==N){
        ans=k;
        break;
    }

    if(count==0){
        cout<<"-1"<<endl;
        return 0;
    }

}


cout<<ans-1<<endl;

 return 0;
}

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 1 << 16;
const int MOD = 1e9 + 7;
vector<int> specials;
int memo[17][MAX];
int fat[MAX], pot[17];

inline int add(int a, int b) {
	a += b;
	if(a >= MOD) {
		a -= MOD;
	}
	return a;
}

inline int sub(int a, int b) {
	a -= b;
	if(0 > a) {
		a += MOD;
	}
	return a;
}

inline int mult(int a, int b) {
	return (1LL * a * b) % MOD;
}

int f_exp(int x, int exp) {
	if(exp == 0) {
		 return 1;
	}
	else if(exp & 1) {
		return mult(x, f_exp(x, exp - 1));
	}
	return f_exp(mult(x, x), exp / 2);
}

inline int inv(int x) {
	return f_exp(x, MOD - 2);
}

inline int comb(int n, int k) {
	return mult(fat[n], mult(inv(fat[n - k]), inv(fat[k])));
}

int n, m;
int roll(int index, int mask) {
	int &ans = memo[index][mask];
	if(~ans) {
		return ans;
	}

	int left = pot[n] - 1;
	fori(i, 0, n) {
		if(mask & (1 << i)) {
			left -= pot[i];	
		}
	}

	if(index == m) {
		int bits = __builtin_popcount(mask);

		ans = fat[left];
		if(bits & 1) {
			ans = ((-ans % MOD) + MOD) % MOD;
		}
	}
	else {
		int used = pot[n] - 1 - left;
		ans = roll(index + 1, mask);
		fori(i, 0, n) {
			if(!(mask & (1 << i))) {
				int available = pot[n] - specials[index] - used;
				int need = (1 << i) - 1;
				if(available >= need) {
					int cur = mult(comb(available, need), fat[need + 1]); 
					cur = mult(cur, roll(index + 1, mask | (1 << i)));
					ans = add(ans, cur);		
				}
			}
		}
	}
	
	return ans;
}

int main() {
	fat[0] = 1;
	fori(i, 1, MAX) {
		fat[i] = mult(fat[i - 1], i);
	}

	pot[0] = 1;
	fori(i, 1, 17) {
		pot[i] = mult(pot[i - 1], 2);
	}

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

	specials.resize(m);
	fori(i, 0, m) {
		scanf("%d", &specials[i]);
	}

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

	memset(memo, -1, sizeof memo);

	int ans = roll(0, 0);
	ans = mult(ans, pot[n]);

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

	return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  ll N;
  N = s.size();
  vector<ll> cnt(2020);
  ll ans = 0;
  cnt[0] = 1;
  int tot = 0;
  int p = 1;
  for(int i = N - 1; i >= 0; i--) {
    tot = (tot + (s[i] - '0') * p) % 2019;
    ans += cnt[tot];
    p = (p * 10) % 2019;
    cnt[tot]++;
  }
  
  cout << ans << endl;
}

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

char calc(char A, int n) {
	int next = (int) (A - 'A' + n);
	next %= 26;
	return (char)(next + 'A');
}

int main() {
	int N, n;
	string S;
	cin >> N >> S;
	n = S.size();
	
	for(int i = 0; i < n; i++) {
		cout << calc(S[i], N);
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define __ cout<<fixed;cout<<setprecision(10);
#define int signed long long

int32_t main() {
	_ __

#ifdef LOCAL_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int x, k, d;
	cin >> x >> k >> d;
	int answer;
	x = abs(x);
	int best;
	if (x % d <= abs((x % d) - d)) {
		best = x % d;
	}
	else {
		best = (x % d) - d;
	}
	if ((x - best) / d < k) {
		int steps = k - (x - best) / d;
		if (steps % 2 == 0) {
			answer = abs(best);
		}
		else {
			answer = min(abs(best + d), abs(best - d));
		}
	}
	else {
		answer = abs(x - k * d);
	}
	cout << answer << "\n";

#ifdef LOCAL_JUDGE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif

	return 0;
}

Measured memory_bytes: 3628
/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int h,w; cin>>h>>w;
    swap(h,w);

    vector<string> s(w);
    for(string &st : s) cin>>st;
    vector<int> xdir = {0,0,1,-1};
    vector<int> ydir = {1,-1,0,0};

    auto legal = [&](int x, int y){
        if(x<0||y<0||x>=w||y>=h||s[x][y]=='#') return false;
        return true;
    };
    int dis[w][h][w][h];
    for(int i = 0 ; i < w; i++){
        for(int j = 0; j < h; j++){
            for(int k = 0; k < w; k++){
                for(int l = 0; l < h; l++){
                    dis[i][j][k][l] = 1e5;
                }
            }
        }
    }
    for(int i = 0; i < w; i++){
        for(int j = 0; j < h; j++){
            if(!legal(i,j)) continue;
            for(int k = 0; k < 4; k++){
                int x = i + xdir[k];
                int y = j + ydir[k];
                if(legal(x,y)){
                    dis[i][j][x][y] = 1;
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < w; i++){
        for(int j = 0; j < h; j++){
            for(int a = 0; a < w; a++){
                for(int b = 0; b < h; b++){
                    for(int c = 0; c < w ; c++){
                        for(int d =0 ;d < h; d++){
                            if(c==a&&d==b) continue;
                            dis[a][b][c][d] = min(dis[a][b][c][d], dis[a][b][i][j] + dis[i][j][c][d]);
                        }
                    }
                }
            }
        }
    }
    for(int i = 0 ; i < w; i++){
        for(int j = 0; j < h; j++){
            for(int k = 0; k < w; k++){
                for(int l = 0; l < h; l++){
                    if(dis[i][j][k][l]!=100000)
                       ans = max(ans, dis[i][j][k][l]);
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
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;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector <vector <ll>> v(n, vector <ll> (3));
  rep(i, n) {
    ll x, y, h;
    cin >> x >> y >> h;
    v.at(i).at(0) = h, v.at(i).at(1) = x, v.at(i).at(2) = y;
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  rep(i, 101) {
    rep(j, 101) {
      ll tmp = v.at(0).at(0) + abs(i-v.at(0).at(1)) + abs(j-v.at(0).at(2));
      bool flag = 1;
      rep(k, n) {
        if (v.at(k).at(0) != max(tmp-abs(i-v.at(k).at(1))-abs(j-v.at(k).at(2)), (ll)0)) {
          flag= 0;
        }
      }
      if (flag) {
        cout << i << ' ' << j << ' ' << tmp << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std ;
 
int main(){
  int a,b,c,d,e ;
  cin >> e ;
  d = e%10 ; e /= 10 ;
  c = e%10 ; e /= 10 ;
  b = e%10 ; e /= 10 ;
  a = e ;
  if(a+b+c+d==7)
    cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl ;
  else if(a+b+c-d==7)
    cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl ;
  else if(a+b-c+d==7)
    cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl ;
  else if(a+b-c-d==7)
    cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl ;
  else if(a-b+c+d==7)
    cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl ;
  else if(a-b+c-d==7)
    cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl ;
  else if(a-b-c+d==7)
    cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl ;
  else 
    cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl ;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val ab = List.fill(n)((sc.nextInt(), sc.nextInt()))
  val cd = List.fill(m)((sc.nextInt(), sc.nextInt()))
  for ((a, b) <- ab) {
    val ans = cd.map{ case (c, d) =>
      (a - c).abs + (b - d).abs
    }.zipWithIndex.min._2 + 1
    println(ans)
  }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> cards(N);

  for (int i=0; i<N; i++){
    cin >> cards.at(i);  
  }

  sort(cards.begin(), cards.end());
  
  int Alice, Bob; 
  Alice = 0;
  Bob = 0;

  for (int i=0; i<N; i++){
    if (i % 2 ==0){
      Alice += cards.at(N-i-1);
    }else{
      Bob += cards.at(N-i-1);
    }
    cards.pop_back();
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
N,M = [int(x) for x in input().split()]
a = []
b = []
c = []
for i in range(M):
  A,B = [int(x) for x in input().split()]
  C = [int(x) for x in input().split()]
  a.append(A)
  b.append(B)
  c.append(C)
c1 = []
for i in range(M):
  l = 0
  for j in c[i]:
  	l = l|1<<(j-1)
  c1.append(l)
cnt = [0]*(1<<N)
dp = [[float('inf')]*(1<<N) for _ in range(M+1)]
dp[0][0] = 0
for i in range(M):
  for j in range(1<<N):
    dp[i+1][j] = min(dp[i][j],dp[i+1][j])
    dp[i+1][j|c1[i]] = min(dp[i][j]+a[i],dp[i+1][j|c1[i]])
if dp[M][-1]!=float("inf"):
  print(dp[M][-1])
else:
  print(-1)
"""
for s in range(1<<N):
    for i in range(N):
        if not s & (1 << i) and s & edges[i] == edges[i]:
            nextS = s| (1 << i)
            disk[nextS] = disk[s] + x[i]
            dp[nextS] = min(dp[nextS], max(dp[s], disk[nextS]))
            disk[nextS] -= cost[i]
print(dp[-1])
"""

Measured memory_bytes: 137176
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define pb(x)                       push_back(x)
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;
ll n,k;
ll arr[110];
ll mn;
ll tmp;
ll dp[MAXN];

int main()
{
    fast_io;
    mn = INF;
    cin >> n >> k;
    for (int i = 1;i <= n;i++){
        cin >> arr[i];
        mn = min(mn,arr[i]);
    }
    for (int i = 0;i <= k;i++){
        dp[i] = 2;
    }
    for (int i = 0;i < mn;i++){
        dp[i] = 1;
    }
    for (int i = 0; i < k;i++){
        tmp = dp[i];
        //cout << i << ": " << tab << tmp << endl;
        if (tmp == 2){
            continue;
        }
        for (int j = 1;j <= n;j++){
            ll cnt = min((ll)MAXN - 1,(ll)i + arr[j]);
            if (cnt < mn)
                continue;
            if (dp[cnt] == 2)
            {
                //cout << "lk ";
                dp[cnt] = 1 - tmp;
            }
            if (dp[cnt] == 1 and tmp == 1){
                dp[cnt] = 0;
            }
            //cout << cnt << tab << dp[cnt] << endl;
        }
    }
    if (dp[k] == 0){
        cout << "First";
    }
    else{
        cout << "Second";
    }
}


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

// modint: mod 計算を int を扱うように扱える構造体
template <int MOD>
struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0) val += MOD;
  }
  constexpr int getmod() {
    return MOD;
  }
  constexpr Fp operator-() const noexcept {
    return val ? MOD - val : 0;
  }
  constexpr Fp operator+(const Fp& r) const noexcept {
    return Fp(*this) += r;
  }
  constexpr Fp operator-(const Fp& r) const noexcept {
    return Fp(*this) -= r;
  }
  constexpr Fp operator*(const Fp& r) const noexcept {
    return Fp(*this) *= r;
  }
  constexpr Fp operator/(const Fp& r) const noexcept {
    return Fp(*this) /= r;
  }
  constexpr Fp& operator+=(const Fp& r) noexcept {
    val += r.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  constexpr Fp& operator-=(const Fp& r) noexcept {
    val -= r.val;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr Fp& operator*=(const Fp& r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp& operator/=(const Fp& r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr bool operator==(const Fp& r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Fp& r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream& operator<<(ostream& os, const Fp<MOD>& x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
    if (n == 0) return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1) t = t * a;
    return t;
  }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

int main() {
  int n;
  cin >> n;

  vector<ll> zeros(65, 0);
  vector<ll> ones(65, 0);
  REP(i, n) {
    ll num;
    cin >> num;
    auto b = bitset<65>(num);
    REP(j, 65) {
      if (b[j]) {
        ones[j]++;
      } else {
        zeros[j]++;
      }
    }
  }

  mint ans = 0;
  REP(i, 65) {
    mint tmp = ones[i] * zeros[i];
    tmp *= pow(2, i);
    ans += tmp;
  }
  ANS(ans);
  return 0;
}


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



int main() {
  int n;
  cin>>n;
  vector<int> v(n);
//  vector<int> r(n/2);
  rep(i,n){
    cin>>v[i];
  }
  map<int,int> mpl,mpr;
  pair<int,int> ml1(0,INF);
  pair<int,int> ml2(0,INF);
  pair<int,int> mr1(0,INF);
  pair<int,int> mr2(0,INF);
  rep(i,n){
    if (i%2==0){
      mpl[v[i]]++;
      if (mpl[v[i]]>ml1.first) ml1=make_pair(mpl[v[i]],v[i]);
      else if (mpl[v[i]]>ml2.first) ml2=make_pair(mpl[v[i]],v[i]);
    }
    if (i%2==1){
      mpr[v[i]]++;
      if (mpr[v[i]]>mr1.first) mr1=make_pair(mpr[v[i]],v[i]);
      else if (mpr[v[i]]>mr2.first) mr2=make_pair(mpr[v[i]],v[i]);

    }
  }
  int ans=INF;
  if (ml1.second!=mr1.second) {
    ans=n-ml1.first-mr1.first;}
  else{
    if (ml2.second!=INF){
      ans=n-ml2.first-mr1.first;
    }
    if (ml2.second==INF) ans=n-mr1.first;
   if (mr2.second!=INF)ans=min(ans,n-ml1.first-mr2.first);
    if (mr2.second==INF)ans=min(ans,n-ml1.first);
  }
  cout<<ans;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

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

void solve() {
    ll n, x; cin >> n >> x;
    ll res = 0;
    FOR(i, 0, n) {
        ll tmp; cin >> tmp;
        res = gcd(res, abs(x - tmp));
    }
    cout << res;    
}

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	vector<int>cache(n,0);
	cache[0]=0;
	cache[1]=abs(v[1]-v[0]);
	for(int i=2;i<n;i++)
	{
		cache[i]=min(cache[i-1]+abs(v[i]-v[i-1]),cache[i-2]+abs(v[i]-v[i-2]));
	}
	cout<<cache[n-1]<<endl;
}

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

using namespace std;

#define ll long long 
#define Coming ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

int main()
{
	
	string ch;

	cin >> ch;
	
    int ans1 = ((ch[0] - '0') *10) + (ch[1] - '0');
    int ans2 = 	((ch[2] - '0') *10) + (ch[3] - '0');
	
	if((ans1 >= 1 && ans1 <= 12) && (ans2 >= 1 && ans2 <= 12))
	{
		cout << "AMBIGUOUS\n";
	}
	else if(ans1 >= 1 && ans1 <= 12)
	{
		cout << "MMYY\n";
	}
	else if(ans2 >= 1 && ans2 <= 12)
	{
		cout << "YYMM\n";
	}
	else cout << "NA\n";
	
	return 0;
}


Measured memory_bytes: 384
#include<stack>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
int n,tot,etot,ans,_clock,cnt,head[100010],to[800010],nxt[800010],scc[100010],low[100010],dfn[100010],idx[80010];
stack<int>Stack;
struct node{
	int idx,val;
	friend bool operator<(node a,node b){
		return a.val<b.val;
	}
}a[20010];
int rd(){
	int x=0;
	char c;
	do c=getchar();
	while(!isdigit(c));
	do{
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}while(isdigit(c));
	return x;
}
void add_edge(int u,int v){
	nxt[++tot]=head[u];
	to[tot]=v;
	head[u]=tot;
	return;
}
void build(int o,int l,int r){
	if(l==r){
		idx[o]=a[l].idx+(n<<1);
		return;
	}
	idx[o]=++etot;
	int mid=(l+r)>>1;
	build(o<<1,l,mid);
	build(o<<1|1,mid+1,r);
	add_edge(idx[o],idx[o<<1]);
	add_edge(idx[o],idx[o<<1|1]);
	return;
}
void update(int o,int l,int r,int L,int R,int u){
	if(L<=l&&r<=R){
		add_edge(u,idx[o]);
		return;
	}
	int mid=(l+r)>>1;
	if(L<=mid)
		update(o<<1,l,mid,L,R,u);
	if(R>mid)
		update(o<<1|1,mid+1,r,L,R,u);
	return;
}
void tarjan(int u){
	low[u]=dfn[u]=++_clock;										   
	Stack.push(u);
	for(int i=head[u];~i;i=nxt[i]){
		int v=to[i];
		if(!dfn[v]){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else
			if(!scc[v])
				low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u]){
		cnt++;
		int x;
		do{
			x=Stack.top();
			Stack.pop();
			scc[x]=cnt;
		}while(x!=u);
	}
	return;
}
bool check(int m){
	memset(head,-1,sizeof(head));
	memset(scc,0,sizeof(scc));
	memset(low,0,sizeof(low));
	memset(dfn,0,sizeof(dfn));
	tot=0; 
	_clock=0;
	cnt=0;
	etot=(n<<2);
	build(1,1,n<<1);
	int l=1,r=1;
	for(int i=1;i<=n;i++){
		add_edge(i,i+n+(n<<1));
		add_edge(i+n+(n<<1),i);
		add_edge(i+(n<<1),i+n);
		add_edge(i+n,i+(n<<1));
	}
	for(int i=1;i<=(n<<1);i++){
		while(a[i].val-a[l].val+1>m&&l<i)
			l++;
		while(a[r+1].val-a[i].val+1<=m&&r<(n<<1))
			r++;
		if(l<i)
			update(1,1,(n<<1),l,i-1,a[i].idx);
		if(i<r)
			update(1,1,(n<<1),i+1,r,a[i].idx);
	}
	for(int i=1;i<=(n<<1);i++)
		if(!scc[i])
			tarjan(i);
	for(int i=1;i<=(n<<1);i++)
		if(scc[i]==scc[i+(n<<1)])
			return 0;
	return 1;
}
int main(){
	n=rd();
	for(int i=1;i<=n;i++){
		a[i].val=rd();
		a[i+n].val=rd();
	}
	for(int i=1;i<=(n<<1);i++)
		a[i].idx=i;
	sort(a+1,a+(n<<1)+1);
	int l=0,r=1e9;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)){
			ans=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 11008
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long long ll;
ll num[205];
int flag, ans;
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1;i <= n;i++)
		scanf("%lld", num + i);
	FA:for(int i = 1;i <= n;i++){
		if(num[i]%2) flag = 1;
	}
	if(!flag){
		ans++;
		for(int i = 1;i <= n;i++)
			num[i] /= 2;
		goto FA;
	}
	else 
		printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;

int digit_sum(int num){
  int sum=0,dig;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  if(n%digit_sum(n) == 0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


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

using namespace std;

#define int long long
#define sz(x) (int)x.size()
#define yes cout << "Yes\n"
#define  no cout << "No\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ft first
#define sd second
#define FOR(i, b, n) for(int i=b;i<n;i++)
#define REP(i, n) FOR(i, 0, n)
using pii = pair<int, int>;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vd = vector<double>;
mt19937_64 rnd(time(0));

void start() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    // cerr << fixed << setprecision(10);
#ifdef MY
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
}

signed main() {
    start();
    int n;
    cin >> n;
    ld ans = 0;
    vector<ld> a(n + 1);
    vector<vector<ld>> d(n + 1, vector<ld>(n + 1));
    for (int i = 0; i < n; ++i) cin >> a[i + 1];
    d[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            d[i][j] = d[i - 1][j] * (1 - a[i]);
            if (j)
                d[i][j] += d[i - 1][j - 1] * a[i];
        }
    }
    for (int j = 0; j <= n; ++j) {
        int k = n - j;
        if (j >= k)
            ans += d[n][j];
    }
    cout << ans;


}






Measured memory_bytes: 144100
#include<iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main()
{
    int n,m;
    int sum = 1;
    cin >> n >> m;
    
    sum = ((n*(n-1))/2+(m*(m-1))/2);
    cout << sum <<endl;

    return 0;
}

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

typedef long long ll;

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

    while(1){
        if(a%11==0){
            break;
        }
        a--;
    }
    while(1){
        if(b%11==0){
            break;
        }
        b++;
    }

    //cout << a <<" "<< b << endl;
    ll y,z;
    y = (2*a)/11; z = (2*b)/11;
    if((b-5)<x){
        cout << z << endl;
    }
    else {
        z--;
        cout << z << endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mpp make_pair
#define int long long int
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define F first
#define S second
#define MOD 998244353
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define MAXN 200008
#define MAXI 10000000000007

 
signed main(){
 
    fast;
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int n, k;
    cin>>n>>k;
    int x = n/k;
    int r = n-x*k;
    cout<<min(r, abs(r-k))<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();

        if (B % A == 0) {
            System.out.print(B + A);
        } else {
            System.out.print(B - A);
        }
    }
}

Measured memory_bytes: 21844