akhauriyash/Code-Regression huggingface dataset:
main :: IO ()
main = getLine >>= print . solve 

solve :: String -> Int
solve s = foldr abcff 0 . zip s $ tail bcs
    where
        abcff ('A', x) acc = val $ acc + x
        abcff ('?', x) acc = val $ 3 * acc + x
        abcff _ acc = acc

        bcs = foldr bcff [0] . zip s $ tail cs
        
        bcff ('B', x) acc@(n : _) = (val $ n + x) : acc
        bcff ('?', x) acc@(n : _) = (val $ 3 * n + x) : acc
        bcff _ acc@(n : _) = n : acc

        cs = foldr cff [0] . zip s $ tail vs

        cff ('C', x) acc@(n : _) = (val $ n + x) : acc
        cff ('?', x) acc@(n : _) = (val $ 3 * n + x) : acc
        cff _ acc@(n : _) = n : acc

        vs = foldr vff [1] s

        vff '?' acc@(n : _) = (val $ 3 * n) : acc
        vff _ acc@(n : _) = n : acc

val :: Int -> Int 
val = (`mod` m)
    where
        m = 7 + 10 ^ 9

Measured memory_bytes: 30076
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x);
		y = y >> 1;
		x = (x * x);
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	cout << (n * n * n);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

int N, D, X[109][109];
bool square[1000009];

int main() {
	cin >> N >> D;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) cin >> X[i][j];
	}
	for (int i = 1; i <= 1000; i++) square[i*i] = true;

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int ret = 0;
			for (int k = 0; k < D; k++) ret += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			if (square[ret] == true) cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

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

    #ifdef FILIP_KADAK
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    string w;
    cin >> w;
    vi a(26);
    bool check=true;
    
    for(int i=0; i<w.size(); i++){
        a[w[i]-'a']++;
    }

    for(int x: a)
        if(x%2!=0)
            check=false;

    if(check)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
using Graph = vector<vector<int>>;

int main(){
    int n,m;cin >> n >> m;
    Graph G(n+1);
    vector<vector<bool>> p(n+1,vector<bool>(n+1,false));
    rep(i,m){
        int a,b;cin>>a>>b;
        p[a][b] = true;
        p[b][a] = true;
    }
    vector<int> v;
    rep(i,n){
        v.push_back(i+1);
    }
    int cnt=0;
    do{
        bool yes=true;
        if(v[0]!=1) continue;
        rep(i,n-1){
            if(!p[v[i]][v[i+1]]){
                yes = false;
                break;
            }
        }
        if(yes) cnt++;
    }while(next_permutation(v.begin(),v.end()));
    cout << cnt << endl;
}

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

const int mod = 1e9 + 7;

template <class T>
class matrix
{
public:
    size_t row, col;
    vector<vector<T>> mat;

    matrix(size_t n, size_t m, int populate = 0)
    {
        this->row = n;
        this->col = m;
        this->mat = vector<vector<T>>(row, vector<T>(col, populate));
    }

    void init()
    {
        for (int i = 0; i < row; ++i)
        {
            for (int j = 0; j < col; ++j)
            {
                scanf("%d", &mat[i][j]);
            }
        }
    }

    matrix<T> operator*(const matrix &rhs) const
    {
        int n = this->row;
        matrix<T> result(n, n);
        for(int i=0; i<n; ++i)
            for(int j=0; j<n; ++j)
                for(int k=0; k<n; ++k)
                    result.mat[i][k] = (result.mat[i][k] + ((long long)this->mat[i][j] * rhs.mat[j][k]) % mod) % mod;
        return result;
    }

    matrix<T> power(long long n)
    {
        matrix<T> M(this->row, this->col, 0);
        for (int i=0; i<this->row; ++i) {
            M.mat[i][i] = 1;
        }
        matrix<T> Te = *this;
        while (n) {
            if (n%2) {
                M = M * Te;
            }
            Te = Te * Te;
            n /= 2;
        }
        return M;
    }
};

void addSelf(int& a, int b) {
    a = a + b;
    if (a >= mod) {
        a -= mod;
    }
}

int main() {
    int n;
    long long k;
    scanf("%d%lld", &n, &k);
    matrix<int> can(n, n, 0);
    for (int i=0; i<n; ++i)
        for(int j=0; j<n; ++j)
            scanf("%d", &can.mat[i][j]);
    can = can.power(k);
    int ans = 0;
    for(int i=0; i<n; ++i)
        for(int j=0; j<n; ++j)
            addSelf(ans, can.mat[i][j]);
    printf("%d", ans);
}

Measured memory_bytes: 3820
A = int(input())
B = int(input())
C = int(input())
X = int(input())
res = 0
for a500 in range(A + 1):
    for b100 in range(B + 1):
        for c50 in range(C + 1):
            if a500 * 500 + b100 * 100 + c50 * 50 == X:
                res += 1
print(res)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans=700;
  string s;cin>>s;
  for(int i=0;i<3;i++)
  {
    if(s[i]=='o')
    {
      ans+=100;
    }
  }
  cout<<ans<<endl;
}

    

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

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

    int max_num = max({a, b, c});
    if((a + b + c) - max_num == max_num) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        r: usize,
    }
    println!("{}", r * r);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;

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

int n, d[10000], v[10000];
int main()
{
	while (scanf("%d", &n), n)
	{
		for (int i = 0; i < n; ++i)
			scanf("%d%d", d+i, v+i);

		int g;
		ll nume, deno;	// time
		g = gcd(d[0], v[0]);
		nume = d[0] / g;
		deno = v[0] / g;
		for (int i = 1; i < n; ++i)
		{
			g = gcd(d[i], v[i]);
			int td = d[i] / g;
			int tv = v[i] / g;
			nume *= td / gcd(nume, td);
			deno /= deno / gcd(deno, tv);
		}

		for (int i = 0; i < n; ++i)
			printf("%lld\n", (nume*v[i]/deno) / d[i]);
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void){
 int n,i;
 scanf("%d",&n);
 long long int a=1;
 for(i=1;i<=n;i++){
  a*=i;
  if(a>=1000000007) a%=1000000007;
 }
 printf("%lld",a);
 return 0;
}

Measured memory_bytes: 128
n,m = map(int,input().split())
ps = []
for i in range(m):
    ps.append([str(i) for i in input().split()])
    ps[i][0] = int(ps[i][0])

p = []
a = []
flag = []
for i in range(n):
    p.append(0)
    a.append(0)
    flag.append(True)

for i in range(m):
    if ps[i][1] == 'WA' and flag[ps[i][0] - 1]:
        p[ps[i][0] - 1] += 1
    else:
        a[ps[i][0] - 1] = 1
        flag[ps[i][0] - 1] = False

#print(p, a)

pen = 0
ac = 0
for i in range(n):
    if a[i] > 0:
        pen += p[i]
        ac += 1
print(ac, pen)

Measured memory_bytes: 26024
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int gCount = 0;
		int pCount = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'g') {
				gCount++;
			} else {
				pCount++;
			}
		}
		int maxp = (gCount + pCount) / 2;
		System.out.println(maxp - pCount);
	}
}


Measured memory_bytes: 24652
#include <bits/stdc++.h>
using namespace std;
char s[5];
char op[5];

int main(){
	int cnt;
	scanf("%s",s);
	for(int i=0;i<8;i++){
		cnt=s[0]-'0';
		for(int j=0;j<3;j++){
			if(i&(1<<j)){
				op[j]='+';
				cnt+=s[j+1]-'0';
			} else {
				op[j]='-';
				cnt-=s[j+1]-'0';
			}
		}
		if(cnt==7){
			printf("%c",s[0]);
			for(int j=1;j<=3;j++)printf("%c%c",op[j-1],s[j]);
			printf("=7\n");
			return 0;
		}
	}
}


Measured memory_bytes: 256
# import sys
# sys.stdin=open('input.txt','r')

def main():
    s = input()
    n = len(s)
    if n%2!=0:
        print('No')
        return
    else:
        q=s[:2]
        if q!='hi':
            print('No')
            return
        a=2
        while a<=n-2:
            if s[a:a+2]!=q:
                print('No')
                return
            a+=2
        print('Yes')
        return
main()

Measured memory_bytes: 3060
n = gets.to_s.to_i
s = gets.to_s.chomp
 
r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r * g * b
n.times do |i|
  t = 1
  while i + 2 * t < n
    ans -= 1 if s[i] != s[i+t] && s[i] != s[i+2*t] && s[i+t] != s[i+2*t]
    t += 1
  end
end

puts ans

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


class UnionFind(object):
    __slots__ = ["nodes"]

    def __init__(self, n: int):
        self.nodes = [-1]*n # 親: -(属するノード数), それ以外: (親ノードindex)

    def find(self, x: int) -> int:
        if self.nodes[x] < 0:
            return x
        else:
            self.nodes[x] = self.find(self.nodes[x]) # compression
            return self.nodes[x]

    def has_same_root(self, x, y) -> bool:
        return self.find(x) == self.find(y)
    
    def size(self, x) -> int:
        return -self.nodes[self.find(x)]

    def unite(self, x: int, y: int) -> None:
        if self.has_same_root(x, y):
            return

        root_x, root_y = self.find(x), self.find(y)
        if self.nodes[root_x] < self.nodes[root_y]:
            bigroot, smallroot = (root_x, root_y)
        else: 
            bigroot, smallroot = (root_y, root_x)
        self.nodes[bigroot] += self.nodes[smallroot]
        self.nodes[smallroot] = bigroot


def solve(N: int, K: int, L: int, p: "List[int]", q: "List[int]", r: "List[int]", s: "List[int]"):
    con_road = UnionFind(N)
    con_rail = UnionFind(N)
    for i in range(K):
        con_road.unite(p[i], q[i])
    for i in range(L):
        con_rail.unite(r[i], s[i])
    
    count = {}
    for i in range(N):
        key = (con_road.find(i), con_rail.find(i))
        count[key] = count.get(key, 0) + 1
    
    print(' '.join(str(count[(con_road.find(i), con_rail.find(i))]) for i in range(N)))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    p = [int()] * (K)  # type: "List[int]" 
    q = [int()] * (K)  # type: "List[int]" 
    for i in range(K):
        p[i] = int(next(tokens))-1
        q[i] = int(next(tokens))-1
    r = [int()] * (L)  # type: "List[int]" 
    s = [int()] * (L)  # type: "List[int]" 
    for i in range(L):
        r[i] = int(next(tokens))-1
        s[i] = int(next(tokens))-1
    solve(N, K, L, p, q, r, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 122844
import sys
bbn=1000000007
	
#+++++
		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	
	if 1 not in al:
		return -1
		
	cv = 1
	bn=0
	for v in al:
		if v == cv:
			cv += 1
		else:
			bn += 1
		
	print(bn)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 76364
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

int main() 
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int n;
  int res=0;
  char a[100];
  char b[100];
  char c[100];
  cin >> n >> a >> b >> c;
    
  for (int i=0; i<n; i++)
  {
      if (a[i]==b[i] && b[i]==c[i])
      {
          res+=0;
      }
      else if (a[i]!=b[i] && b[i]!=c[i] && c[i]!=a[i])
      {
          res+=2;
      }
      else
      {
          res+=1;
      }
  }
  cout << res << endl;
  return 0;
}



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

l = []
r = []
for i in range(m):
    temp = input().split()
    l.append(int(temp[0]))
    r.append(int(temp[1]))

a = max(l)
b = min(r)

ans = b - a + 1
if ans <= 0:
    ans = 0
print(ans)

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

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  long double theta =  M_PI * abs(30 * H + 0.5 * M - 6 * M) / 180;
  long double c = sqrt(A * A + B * B - 2 * A * B * cos(theta));
  cout << fixed << setprecision(20) << c << endl;
  
}

Measured memory_bytes: 4160
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include<map>
#include <utility>
#include <math.h>
using namespace std;
int c = 0, e[100010] = {}, f[100010];
double syo = 0, su = 0;
long long  a = 0, b = 0, mur=0, kmr=0, yju=0, counto = 0,counto1=0;
char mado[105];
string rik;
bool mazi[110], gi[110],zi,manji;
pair<int, int>n[110];
vector<int> aa[50] = {}, bb, cc;
map<int, int>kazu;
int gcd(int a,int b) {
	int d;
	if (a > b) {
		int t = b;
		b = a;
		a = t;
	}
	while ((d = b % a) != 0) {
		b = a;
		a = d;
	}
	return a;
}
int main() 
{
	cin >> a >> b;
	if (a == 1 && b == 1) {
		cout << '1' << endl;
		return 0;
	}
	else if (a == 2 && b == 2) {
		cout << '0' << endl;
		return 0;
	}
	else if (a == 1 || b == 1) {
		mur = a + b - 3;
		cout << mur << endl;
		return 0;
	}
	else {
		mur = a * b;
		mur = mur - (a + b - 2) * 2;
		cout <<mur <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
string s;
char t[100000];
char f(int i){
    int ch;
    if(i==0)ch=(1-2*(s[i]=='x'))*(1-2*(t[n-1]!=t[i]));
    else ch=(1-2*(s[i]=='x'))*(1-2*(t[i-1]!=t[i]));
    if(ch==1)return 'S';
    else return 'W';
}
int main(void){
    cin>>n>>s;
    char ss[4]={'S','S','W','W'};
    char tt[4]={'S','W','S','W'};
    for(int i=0;i<4;i++){
        t[0]=ss[i],t[1]=tt[i];
        for(int i=1;i<n-1;i++){
            t[i+1]=f(i);
        }
        if(f(n-1)==t[0]&&f(0)==t[1]){
            for(int i=0;i<n;i++)cout<<t[i];
            cout<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 640
# coding: utf-8
# Your code here!
import re
while True:
    name,type = input().split()
    if type == "X":
        break
    if "_" in name:
        X = name.split("_")
    else:
        tmp = name.upper()
        name = tmp[0]+name[1:]
        X = re.findall('[A-Z][^A-Z]*',name)
    if type == "U":
        for i in range(len(X)):
            X[i] = X[i].capitalize()
    elif type == "L":
        X[0] = X[0].lower()
        for i in range(1,len(X)):
            X[i] = X[i].capitalize()
    else:
        X[0] = X[0].lower()
        for i in range(1,len(X)):
            X[i] = "_"+X[i].lower()
    print("".join(X))


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

#define int     long long
#define inf 	1e18

int n;
vector<int> dp(1 << 16, -inf);
vector<vector<int> > v(18, vector<int> (18));
vector<int> group_val(1 << 16, -inf);

// calculates score that will be generated if we group all rabbits of mask(i.e all 1's) 
int cal_group_val(int mask) {
	int val = 0;

	if (group_val[mask] != -inf) {
		return group_val[mask];
	}

	for (int i = 0; i < 17; i++) {
		for (int j = i + 1; j < 17; j++) {
			if ((mask >> i) & 1 && (mask >> j) & 1) {
				val += v[i][j];
			}
		}
	}

	group_val[mask] = val;
	return val;
}
 
int solve(int mask) {
	if (mask == 0) {
		return 0;
	}
	// cannot keep -1 because score can be negative as well
	if (dp[mask] != -inf) {
		return dp[mask];
	}

	// generate all submask of mask
	for (int submask = mask; submask != 0; submask = (submask - 1) & mask) {
		dp[mask] = max(dp[mask], cal_group_val(submask) + solve (mask ^ submask)); // mask ^ submask = gives all mask of values that are not included in submask
	}

	return dp[mask];
}

void c_p_c()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
   #ifndef ONLINE_JUDGE
	freopen("/home/abhinav/c++ codes/input output c++/input.txt", "r", stdin);
	freopen("/home/abhinav/c++ codes/input output c++/output.txt", "w", stdout);
   #endif
   
   cin >> n;

   for (int i = 0; i < n; i++) {
   		for (int j = 0; j < n; j++) {
   			cin >> v[i][j];
   		}
   }
   //memset(dp, -1, sizeof dp);
   cout << solve((1 << n) - 1);
}
 
int32_t main()
{
    c_p_c();
    return 0;
}

Measured memory_bytes: 4124
h,n = map(int,input().split())

lst1 = [list(map(int,input().split())) for i in range(n)]
lst1.sort()

dp = [[float("inf")]*(10**4+10**4) for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(10**4+10**4):
        if j < lst1[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j],dp[i+1][j-lst1[i][0]]+lst1[i][1])

ans = 10**10
for i in range(h,len(dp[-1])):
    ans = min(ans,dp[-1][i])

print(ans)



Measured memory_bytes: 562952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

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

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

char toLowerCase(char c){
  if(isLowerCase(c)){
    return c;
  }else{
    return c+'a'-'A';
  }
}
char toUpperCase(char c){
  if(isLowerCase(c)){
    return c-('a'-'A');
  }else{
    return c;
  }
}
ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string n;cin>>n;
  if(n.size()==3){
    char c=n[0];
    n[0]=n[2];
    n[2]=c;
  }
  cout<<n<<endl;
  return 0;
}


Measured memory_bytes: 3592
from functools import cmp_to_key

N = int(input())
S_P = []
for i in range(N):
    s, p_str = input().split()
    p = int(p_str)
    S_P.append((s, p, i+1))

def cmp(a, b):
    if a[0] != b[0]:
        return -1 if a[0] < b[0] else 1
    else:
        return -1 if a[1] > b[1] else 1

sorted_S_P = sorted(S_P, key=cmp_to_key(cmp))
for _, _, i in sorted_S_P:
    print(i)



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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

u64 dp[110][100010];
const u64 Max_Val = 1000000000000;

int main() {
  cout << setprecision(18);
  u32 N, W;
  cin >> N >> W;
  vector<i32> weight(N), value(N);
  for (u32 i = 0; i < N; ++i) cin >> weight[i] >> value[i];
  for (u32 i = 0; i <= N; ++i) {
    for (u32 j = 0; j <= 100000; ++j) {
      dp[i][j] = Max_Val;
    }
  }
  dp[0][0] = 0;

  for (u32 i = 0; i < N; ++i) {
    for (i32 v = 0; v <= 100000; ++v) {
      if (v - value[i] >= 0)
        dp[i + 1][v] = min(dp[i][v - value[i]] + weight[i], dp[i + 1][v]);
      dp[i + 1][v] = min(dp[i][v], dp[i + 1][v]);
    }
  }
  u64 res = 0;
  for (u32 v = 0; v <= 100000; ++v) {
    if (dp[N][v] <= W) res = v;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 80256
#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;}

int dfs(int cur,vector<int>& x){
  if(cur==12){
    vector<int> ans;
    rep(i,24){
      if(x[i] == 1)ans.push_back(i);
    }
    int d = ans[0] + 24 - ans[ans.size()-1];
    int ret = min(d,24-d);
    repp(i,1,ans.size()){
      d = ans[i] - ans[i-1];
      ret = min({ret,d,24-d});
    }
    return ret;
  }

  if(x[cur] !=-1) return dfs(cur+1,x);
  x[cur] = 1;
  x[24-cur] = 0;
  int ret = dfs(cur+1,x);
  x[cur] = 0;
  x[24-cur] = 1;
  ret = max(ret,dfs(cur+1,x));
  x[cur] = -1;
  x[24-cur] = -1;
  return ret;
}

int solve(){
  int N;cin >> N;
  vector<int> v(N);
  vector<int> w(13);
  rep(i,N){
    cin >> v[i];
    ++w[v[i]];
  }
  //-1は未定
  vector<int> x(24,-1);
  if(w[0] > 0)return 0;
  x[0] = 1;
  if(w[12] > 1) return 0;
  if(w[12] == 1) x[12] = 1;
  else x[12] = 0;
  repp(i,1,12){
    if(w[i]>2) return 0;
    if(w[i] == 2){
      x[i] = 1;
      x[24-i] = 1;
    }
    if(w[i] == 0){
      x[i] = 0;
      x[24-i] = 0;
    }
  }
  return dfs(1,x);
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cout << solve() << endl;

  return 0;
}


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

typedef long long ll;

ll N, K;

int main() {
    cin >> N >> K;

    vector<ll> x(N);
    rep(i, N) {
        cin >> x[i];
    }

    vector<ll> minus;
    vector<ll> plus;
    bool zero = false;
    rep(i, N) {
        if (x[i] < 0) {
            minus.push_back(-1 * x[i]);
        } else if (x[i] > 0) {
            plus.push_back(x[i]);
        } else {
            zero = true;
        }
    }

    reverse(minus.begin(), minus.end());

    ll ans = 1e16;
    ll minus_cnt = minus.size();
    ll plus_cnt = plus.size();
    // printf("%lld %lld\n", minus_cnt, plus_cnt);

    if (zero) K--;
    rep(i, minus.size()) {
        if (i + 1 + plus_cnt < K) continue;
        ll rest_plus = K - (i + 1); 
        ll dist1 = minus[i]; 
        if (rest_plus > 0) dist1 += (dist1 + plus[rest_plus - 1]); 
        // printf("minus %lld plus %lld i_cnt: %lld, res_plus: %d\n", minus[i] * 2, plus[rest_plus - 1], i + 1, rest_plus);
        ans = min(dist1, ans);
    }
    rep(i, plus.size()) {
        if (i + 1 + minus_cnt < K) continue;
        ll rest_minus = K - (i + 1); 
        ll dist2 = plus[i];
        if (rest_minus > 0) dist2 += (dist2 + minus[rest_minus - 1]); 
        ans = min(dist2, ans);
    }

    cout << (K == 0 ? 0 : ans) << endl;
}

Measured memory_bytes: 2424
#include<bits/stdc++.h>
#include <cstring>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
ll a[100001],dp[100001];
int n,k;
ll f(int i){
    if (i>=n)
        return 1e9;
    if (i==n-1)
        return 0;
    if (dp[i]!=-1)
        return dp[i];
    ll road1=1e9;
    for (int j=1;j<=k;j++){
        road1=min(abs(a[i]-a[i+j])+f(i+j),road1);
    }
    return dp[i]=road1;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin>>n>>k;
    for (int i=0;i<n;i++)
        cin>>a[i];
    memset(dp,-1,sizeof dp);
    cout<<f(0);

    return 0;
}


Measured memory_bytes: 6528
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Ashish Karel rasensuriken
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            String s1 = in.nextString();
            String s2 = in.nextString();
            String s3 = in.nextString();
            StringBuilder ans = new StringBuilder();
            ans.append(s1.charAt(0));
            ans.append(s2.charAt(0));
            ans.append(s3.charAt(0));
            out.println(ans.toString().toUpperCase());
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int pnumChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22612
from heapq import heappush, heappop

class Solver(object):
    def __init__(self):
        self.n = int(input())
        self.items = list()
        for _ in range(self.n):
            heappush(self.items, int(input()))

    def solve(self):
        total = 0
        for _ in range(self.n - 1):
            total += heappop(self.items)
        total += heappop(self.items) / 2
        print (int(total))


if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 3064
N = int(input())
a_li = list(map(int, input().split()))
# 最初と最後を加えておく
total = abs(a_li[0]) + abs(a_li[-1])
for i in range(1, N):
    total += abs(a_li[i] - a_li[i - 1])
# 最初を取り除く
# 0, a[0], a[1]のうちa[0]が消えたら…
print(total - abs(a_li[0]) - abs(a_li[0] - a_li[1]) + abs(a_li[1]))
for i in range(1, N - 1):
    # a[i-1], a[i], a[i+1]のうちa[i]が消えたら…
    print(total - abs(a_li[i] - a_li[i - 1]) - abs(a_li[i + 1] - a_li[i]) + abs(a_li[i + 1] - a_li[i - 1]))
# 最後を取り除く
# a[-2], a[-1], 0のうちa[-1]が消えたら…
print(total - abs(a_li[-1]) - abs(a_li[-1] - a_li[-2]) + abs(a_li[-2]))


Measured memory_bytes: 84672
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	string S; cin >> S;
	bool isYes = true;
	while (!S.empty())
	{
		string five = S.substr(0, 5);
		if (five == "dream")
		{
			string seven = S.substr(0, 7);
			if (seven == "dreamer")
			{
				string eight = S.substr(0, 8);
				if (eight == "dreamera")
				{
					S = S.substr(5, S.length());
				}
				else
				{
					S = S.substr(7, S.length());
				}
			}
			else
			{
				S = S.substr(5, S.length());
			}
		}
		else if (five == "erase")
		{
			string six = S.substr(0, 6);
			if (six == "eraser")
			{
				S = S.substr(6, S.length());
			}
			else
			{
				S = S.substr(5, S.length());
			}
		}
		else
		{
			isYes = false;
			break;
		}
	}
	cout << (isYes ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3788
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#define SIZE 200005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char str[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",&str);
	int b=0,w=0;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='#') b++;
		else w++;
	}
	int ret=w;
	int b0=0,w0=0;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='#') b0++;
		else w0++;
		ret=min(ret,(w-w0)+b0);
	}
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 500005
#define eps 1e-8
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 998244353;
int N,K,fac[MAXN * 2],invfac[MAXN * 2],inv[MAXN * 2];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int C(int n,int m) {
    if(n < m) return 0;
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);read(K);
    inv[1] = 1;
    for(int i = 2 ; i <= 1000000 ; ++i) inv[i] = mul(inv[MOD % i],MOD - MOD / i);
    invfac[0] = fac[0] = 1;
    for(int i = 1 ; i <= 1000000 ; ++i) {
    fac[i] = mul(fac[i - 1],i);
    invfac[i] = mul(invfac[i - 1],inv[i]);
    }
    int ans = 0;
    for(int i = 0 ; i <= K ; ++i) {
    int r = i,b = K - i;
    if(r < b || r < N) continue;
    if(r - (N - 1) > b) {
        update(ans,C(K,r));
    }
    else if(r == b) {
        int t = r - (N - 1);
        update(ans,inc(C(K - 1,r),MOD - C(K - 1,r + t)));
    }
    else {
        int t = r - (N - 1);
        update(ans,inc(C(K,r),MOD - C(K,r + t)));
    }
    }
    out(ans);enter;
}
int main() {
    Solve();
    return 0;
//
}

Measured memory_bytes: 12032
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(){
	int  i,n,x,y,amo=0;
	for(i=0;i<4;i++){
		cin>>n;
		amo+=n;
	}
	x=amo/60;
	y=amo%60;
	cout<<x<<endl<<y<<endl;
	return 0;
}

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

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    string s; cin >> s;
    int n = s.size();

    // case 1: a__a
    //         s.size() must be even for p1 to win
    // case 2: a__b
    //         s.size() must be odd
    // case 3: a_(ab)_b
    //         s.size() must be odd

    if(s[0] == s[n - 1]){
        if(n % 2)
            cout << "Second";
        else
            cout << "First";
    } else {
        if(n % 2)
            cout << "First";
        else
            cout << "Second";
    }

    return 0;
}


Measured memory_bytes: 512
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//みんなどんだけ頭いいの

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


	int N = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';

	int L = 0;
	ll kotae = 1;
	ll mod = 1e9 + 7;
	rep1(i, N) kotae = kotae * i % mod;
	rep(i, N + N) {
		char c = getchar_unlocked();
		if (i & 1) {
			if (c == 'W') {
				L++;
			}
			else {
				kotae = kotae * L % mod;
				L--;
			}
		}
		else {
			if (c == 'B') {
				L++;
			}
			else {
				kotae = kotae * L % mod;
				L--;
			}
		}
	}

	if (L == 0) printf("%ld", kotae);
	else printf("0");

	Would you please return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>

using namespace std;

int main(void)
{
	int N,i;

	double rans=0,ans=0;

	cin >> N;

	int A[N];

	double B[N];

	for(i=0;i<N;i++)
	{
		cin >> A[i];

	}

	for(i=0;i<N;i++)
	{
		B[i]=1/(double)A[i];

	}

	for(i=0;i<N;i++)
	{
		rans=rans+B[i];

	}
	

	ans=1/rans;

	cout << fixed << setprecision(7) << ans << endl;
}



Measured memory_bytes: 256
N, X = map(int, input().split())
count = 0
 
def count_patty(N, X, count):
    if N == 0:
        return 1 + count
    elif X == 1:
        return 0 + count
    elif X == 2**(N+1) - 1:
        return 2**N + count
    elif X == 2**(N+2) - 3:
        return 2**(N+1) - 1 + count
    elif 1 < X < 2**(N+1) - 1:
        X -= 1
        N -= 1
        return count_patty(N, X, count)
    elif 2**(N+1) - 1 < X < 2**(N+2) - 3:
        count += 2**N
        X -= 2**(N+1) - 1
        N -= 1
        return count_patty(N, X, count)
 
print(count_patty(N, X, count))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

unsigned long ret[100002];

unsigned long pat(int sub) {
  int i;
  ret[1] = 0;
  ret[2] = 1;
  for (i=3;i<=sub;i++) {
    ret[i]=ret[i-1]+ret[i-2];
    if (ret[i]>1000000007) ret[i]-=1000000007;
  }
  return ret[sub];
}

int main() {
  int N, M, a[100002];
  int i;
  unsigned long tot;
  
  scanf ("%d %d", &N, &M);
  for (i=1;i<=M;i++) {
      scanf ("%d", &a[i]);
  }
  a[0] = -1;
  a[M+1] = N+1;
  
  tot = 1;
  
  for (i=1;i<=M+1;i++) {
    tot *= pat(a[i]-a[i-1]);
    tot %= 1000000007;
  }
  printf ("%d", tot);
}



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

#define ll long long int
#define INFTY (1<<21)

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    cout<<(((a*b)%2==0)?"No":"Yes")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N, Q;
	cin >> N >> Q;

	string S;
	cin >> S;

	vector<pair<int, int>> query_info(Q, make_pair(0, 0));

	for (int i = 0; i < Q; i++)
	{
		cin >> query_info[i].first >> query_info[i].second;
	}

	vector<int> ac_count(N + 1, 0);
	for (int i = 1; i < N; i++)
	{
		ac_count[i + 1] = ac_count[i];
		if (S[i - 1] == 'A' && S[i] == 'C')
		{
			ac_count[i + 1]++;
		}
	}

	for (int i = 0; i < Q; i++)
	{
		cout << ac_count[query_info[i].second] - ac_count[query_info[i].first] << "\n";
	}

	return 0;
}


Measured memory_bytes: 2256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

char T[202020];
int N;

map<string, int> memo;

i64 solve(string S)
{
	if (S.size() == 0) return 0;
	if (memo.count(S)) return memo[S];
	i64 ret = 0;
	for (int i = 0; i < S.size(); ++i) {
		string T = S;
		T.erase(T.begin() + i);
		ret = max(ret, solve(T));
	}
	for (int i = 0; i < S.size(); i += 2) if (S[i] == '1') ++ret;
	return memo[S] = ret;
}

void solve2(string S)
{
	if (S.size() == 0) return;
	i64 expected = solve(S);
	for (int i = 0; i < S.size(); i += 2) if (S[i] == '1') --expected;

	pair<int, int> gain{-1000, -1};
	for (int i = 0; i < S.size(); ++i) if (S[i] == '0') {
		int g = 0;
		for (int j = i + 1; j < S.size(); ++j) if (S[j] == '1') {
			if (j % 2 == 0) --g;
			else ++g;
		}
		gain = max(gain, {g, i});
	}
	if (gain.second != -1) {
		string T = S;
		T.erase(T.begin() + gain.second);
		if (solve(T) != expected) printf("sad %d %d\n", gain.first, gain.second);
	}
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == '1') continue;
		string T = S;
		T.erase(T.begin() + i);
		if (solve(T) == expected) {
			printf("%s ['0' %d]\n", S.c_str(), i);
			solve2(T);
			return;
		}
	}
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == '0') continue;
		string T = S;
		T.erase(T.begin() + i);
		if (solve(T) == expected) {
			printf("%s ['1' %d]\n", S.c_str(), i);
			solve2(T);
			return;
		}
	}
}
int main()
{
	scanf("%s", T);
	N = strlen(T);
	int zall = 0;
	for (int i = 0; i < N; ++i) if (T[i] == '0') ++zall;

	int n_zeros = 0;
	i64 ret = 0;
	for (int i = 0; i < N; ++i) {
		if (T[i] == '1' && T[i + 1] == '1') {
			ret += zall;
			i += 1;
			continue;
		}
		if (T[i] == '1') {
			ret += zall - (n_zeros + (i % 2)) / 2;
		} else {
			++n_zeros;
		}
	}
	int n_ones = N - zall;
	while (n_ones) {
		ret += (n_ones + 1) / 2;
		--n_ones;
	}
	printf("%lld\n", ret);
	return 0;
	printf("%d\n", solve(string(T)));
	solve2(T);
	return 0;
}


Measured memory_bytes: 3964
from collections import Counter
H,W = map(int,input().split())
A = [input() for i in range(H)]
ctr = Counter()
for row in A:
    ctr.update(row)

if H%2==0 and W%2==0:
    print('Yes' if all(v%4==0 for v in ctr.values()) else 'No')
    exit()

if H%2 and W%2:
    for k,v in ctr.items():
        if v%2:
            ctr[k] -= 1
            break
if any(v%2 for v in ctr.values()):
    print('No')
    exit()

if H%2 and W%2:
    two = W+H-1
elif H%2:
    two = W
else:
    two = H

for k,v in ctr.items():
    if v%4==0: continue
    if two <= 0:
        print('No')
        exit()
    two -= 2

print('No' if two%4==2 else 'Yes')

Measured memory_bytes: 3316
import sys
N, M = map(int, sys.stdin.readline().rstrip().split(" "))
bridges = []
for i in range(M):
    a, b = map(int, sys.stdin.readline().rstrip().split(" "))
    a, b = a - 1, b - 1
    bridges.append((a,b))

par = [k for k in range(N)]
siz = [1] * N

def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]

def issame(x, y):
    return root(x) == root(y)

def unite(x, y):
    tmpx = root(x)
    tmpy = root(y)

    if tmpx == tmpy:
        return

    if siz[tmpx] <= siz[tmpy]:
        tmpx, tmpy = tmpy, tmpx
    siz[tmpx] += siz[tmpy]

    par[tmpy] = tmpx


# 不便さの初期値は橋が無い状態
Inconv = (N*(N-1)) // 2

ans = [0 for _ in range(M)]
ans[M-1] = Inconv

# print(bridges)

for i in reversed(range(1, M)):
    a, b = bridges[i]
    if not issame(a, b):
        Inconv -= siz[root(a)] * siz[root(b)]
    ans[i - 1] = Inconv
    unite(a, b)

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


Measured memory_bytes: 23232
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
#define DD 1
#else
#define DD 0
#endif
#define Debug if(DD) printf("line %d\n",__LINE__)
#define deb(x) if(DD) cerr<<#x<<'='<<x<<endl
#define debug if(DD) printf
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void gg1(){write2(-1);exit(0);}
	void gg2(){puts("NO");exit(0);}
	
	const double eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int N=2e5+10;
	
	ll a[N];
	void main()
	{
		int n=qread();ll K=qread();fo(i,1,n) a[i]=qread();sort(a+1,a+n+1);
		ll fl=-bin(60),fr=bin(60),ans=-1;
		while(fl<=fr)
		{
			ll mid=(fl+fr)/2,sum=0;
			fo(i,1,n) if(a[i]>0) sum+=lower_bound(a+1,a+n+1,(ll)ceil((long double)1.0*mid/a[i]))-a-1;
			else if(a[i]<0) sum+=n-( upper_bound(a+1,a+n+1,(ll)floor((long double)1.0*mid/a[i]))-a-1 );
			else if(mid>0) sum+=n;
			fo(i,1,n) if(a[i]*a[i]<mid) sum--;assert(sum%2==0);sum/=2;
			debug("mid=%lld sum=%lld\n",mid,sum);
			if(sum<K) ans=mid,fl=mid+1; else fr=mid-1;
		}write(ans);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	#endif
	srand(time(0));
	mine::main();
	if(DD) cerr<<"Time: " <<1.0*clock()/CLOCKS_PER_SEC<<"s";
}

Measured memory_bytes: 1792