akhauriyash/Code-Regression huggingface dataset:
import fractions
from functools import reduce


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
N = int(input())
Alist = list(map(int, input().split()))
l = lcm_list(Alist)
ans = 0
for a in Alist:
    ans += l//a
print(ans%(10**9+7))


Measured memory_bytes: 6136
#include<stdio.h>
int main(){
	int a,HH,MM;
	int i,j,k=0,l=0;
	int T[24][60]={};
	int flag=0;
	
	for(j=0;j<2;j++){
		scanf("%d",&a);
		for(i=0;i<a;i++){
			scanf("%d %d",&HH,&MM);
			T[HH][MM]=1;
		}
	}
	
	for(k=0;k<24;k++){
		for(l=0;l<60;l++){
			if(T[k][l]>0){
				
				if(flag!=0){
				printf(" ");
				}
				printf("%d:",k);
				flag=1;
				if(l<10){
 					printf("0%d",l);
				}else{
					printf("%d",l);
				}
			}
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 608
#include<stdio.h>

int binarySearch(int*, int, int);

int main() {
  int i, sl, tl, arrayS[100000], arrayT[50000], result=0;

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

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

  for(i=0 ; i<tl ; i++) {
    if(binarySearch(arrayS, sl, arrayT[i])) { result++; }
  }
  
  printf("%d\n", result);
  return 0;
}

int binarySearch(int* array, int l, int key) {
  int left=0, right=l, mid;

  while(left < right){
    mid = (left + right) / 2;
    if(array[mid] == key) { return 1; }
    else if(array[mid] < key) { left = mid+1; }
    else { right = mid; }
  }
  
  return 0;
}



Measured memory_bytes: 3264
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[31];
        int cnt = 0;

        for(int i = 0;i<n;i++){
            a[i] = 0;
        }


        for(int i = 0;i<n;i++){
            int k = sc.nextInt();
            for(int j = 0;j<k;j++){
                int num = sc.nextInt();
                a[num]++;               
            }
        }

        for(int i =0;i<31;i++){
            if(a[i]==n){
            cnt++;
            }
        }

        System.out.println(cnt);

    }
}


Measured memory_bytes: 22320
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;




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

	long long int a, b, c, d, e, f;
	cin >> a >> f >> e >> d >> c >> b;
	long long int g = min({ b,c,d,e,f });
	if (f == g) {
		cout << 4 + (a / f) + !!(a%f) << endl;
	}
	else if (e == g) {
		cout << 4 + (a / e) + !!(a%e) << endl;
	}
	else if (d == g) {
		cout << 4 + (a / d) + !!(a%d) << endl;
	}
	else if (c == g) {
		cout << 4 + (a / c) + !!(a%c) << endl;
	}
	else if (b == g) {
		cout << 4 + (a / b) + !!(a%b) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(int i=0; i<n; i++)
#define rep(i,start,n) for(int i=start; i<n; i++)

signed main(){
    fast;  

    int R, G, B, N;
	cin >> R >> G >> B >> N;
	int ans = 0;
	
	for (int i = 0; i <= 3000; i++)
		for (int j = 0; j <= 3000; j++) {
			int v = i * R + j * G;
			if (N >= v && (N - v) % B == 0) ans++;
		}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define de(x) cout<<#x<<"="<<x<<endl
ll x[55],y[55];
const ll inf = 5e18;
int main()
{

    int n,k,x1,y1,x2,y2,i;
    ll ans=inf;
    ll mix,miy,mx,my,num;
    scanf("%d %d",&n,&k);
    for(i=1;i<=n;i++) scanf("%lld%lld",&x[i],&y[i]);
    for(x1=1;x1<=n;x1++)
        for(x2=x1+1;x2<=n;x2++)
            for(y1=1;y1<=n;y1++)
                for(y2=y1+1;y2<=n;y2++)
                {
                    num=0;
                    mix=min(x[x1],x[x2]);miy=min(y[y1],y[y2]);
                    mx=max(x[x1],x[x2]);my=max(y[y1],y[y2]);
                    for(i=1;i<=n;i++)
                    {
                        if(x[i]<=mx&&x[i]>=mix&&y[i]>=miy&&y[i]<=my) num++;
                    }
                    if(num>=k)
                    {
                        //de(mx);de(mix);de(my);de(miy);
                        //de("-------------");
                        ll temp=(mx-mix)*(my-miy);
                       // cout<<temp;
                            if(ans>temp)  ans=temp;
                    }
                }
        cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{    long long int a,b,k,c=0,d=0,f,i,j,m,n,r=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n;j++)
    {
        for(k=1;k<=n;k++)
        {
            r=__gcd(i,j);
            r=__gcd(r,k);
            c=r+c;
        }
    }
    }
    cout <<c<< endl;
}


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

int main(void){
    string s;
    cin >> s;

    if (s[s.length()-1] == 's') {
        cout << s << "es" << endl;
    } else {
        cout << s << "s" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <list>
#include <cstdio>

int main()
{
	int n, v, i;

	char c[12];

	std::list<int> l;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%s", c);

		if (c[0] == 'i')
		{
			scanf("%d", &v);

			l.push_front(v);
		}
		else if (c[6] == 'F')
		{
			l.pop_front();
		}
		else if (c[6] == 'L')
		{
			l.pop_back();
		}
		else
		{
			scanf("%d", &v);

			std::list<int>::iterator it = l.begin();

			while (it != l.end())
			{
				if (*it == v)
				{
					l.erase(it); break;
				}

				it++;
			}
		}
	}

	std::list<int>::iterator it = l.begin();

	while (it != l.end())
	{
		if (it == l.begin())
		{
			printf("%d", *it);
		}
		else
		{
			printf(" %d", *it);
		}

		it++;
	}

	printf("\n");

	return 0;
}

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

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] Xt = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            Console.WriteLine(Xt[0]>Xt[1]?Xt[0]-Xt[1]:0);
        }
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // long N = NK[0];
            // long K = NK[1];
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int x = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int N = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            // string[] s = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // var hs=new Dictionary<long,long>();
            // for(int i=0;i<s[0];i++){
            //     long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            //     if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
            //     else{hs.Add(q[0],q[1]);}
            // }
        
        // //最小公倍数
        // static long Lcm(long a, long b)
        // {
        //     return a/Gcd(a,b)*b;
        // }

        // //最大公約数
        // static long Gcd(long m, long n)
        // {
        //     if(n==0)return m;
        //     return Gcd(n,m%n);
        // }
    }
}

Measured memory_bytes: 11092
class Node:
    def __init__(self, parent, left, right):
        self.parent, self.left, self.right = parent, left, right

T = {}
root = None

def insert_node(key):
    global root
    x = root
    y = None
    z = Node(None, None, None)
    while x != None:
        y = x
        if key < x:
            x = T[x].left
        else:
            x = T[x].right
    z.parent = y
    if y == None:
        root = key
    else:
        if key < y:
            T[y].left = key
        else:
            T[y].right = key
    T[key] = z

def in_print(key, ls):
    if key == None:
        return
    in_print(T[key].left, ls)
    ls.append(key)
    in_print(T[key].right, ls)

def pre_print(key, ls):
    if key == None:
        return
    ls.append(key)
    pre_print(T[key].left, ls)
    pre_print(T[key].right, ls)

def print_node():
    in_ls, pre_ls = [], []
    in_print(root, in_ls)
    pre_print(root, pre_ls)
    print('', *in_ls)
    print('', *pre_ls)

N = int(input())
for i in range(N):
    com = input().split()
    if com[0] == 'insert':
        insert_node(int(com[1]))
    elif com[0] == 'print':
        print_node()


Measured memory_bytes: 141312
INF=10**30
def Belman_Ford(s,N):
    dist=[INF]*N
    dist[s]=0
    cnt=0
    neg=False
    while True:
        if cnt==N:
            break
        update=False
        for f,t,c in Edge:
            if dist[t]>dist[f]+c:
                if cnt<N-1:
                    if dist[f]!=INF:
                        dist[t]=min(dist[t],dist[f]+c)
                        update=True
                else:
                    neg=True
        if not update:
            break
        cnt+=1
    if neg:
        return -1
    else:
        return dist
        
V,E,r=map(int,input().split())
Edge=[tuple(map(int,input().split())) for i in range(E)]

res=Belman_Ford(r,V)
if type(res) is int:
    print('NEGATIVE CYCLE')
else:
    for i in range(V):
        print(res[i] if res[i]!=INF else 'INF')


Measured memory_bytes: 6008
#include <iostream>

int main(){
    int n, k, p;
    std::cin >> n;
    for(int i = 0; i < n; i++){
        std::cin >> k >> p;
        int a = k % p;
        if(a == 0)a = p;
        std::cout << a << std::endl;
    }
    return 0;
}

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

const int sz = 3030;
int dp[sz][3];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  memset(dp, 0, sizeof dp);
  int n;
  vector<int> v(3);
  cin>>v[0]>>v[1]>>v[2]>>n;
  dp[0][0] = 1;
  for(int i=0;i<=n;i++) {
    for(int j=0;j<3;j++) {
      if(j) {
        dp[i][j] += dp[i][j-1];
      }
      if(i - v[j] >= 0) {
        dp[i][j] += dp[i-v[j]][j];
      }
    }
  }
  cout<<dp[n][2];
  return 0;
}


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

typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

int main(){
    int n, k;
    cin >> n >> k;
    ModComb mc(2*n+5);
    ll ans = mc.nCk(2*n-1, n-1);
    if(k+1 < n){
        for(int i = k+1; i < n; i++){
            ans += (mod-mc.nCk(n,i))*mc.nCk(n-i+i-1, i)%mod;
            ans %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
n = int(input())
l = list(map(int, input().split()))
c = 0
for i in range(1, n - 1):
    if (not (min(l[i - 1], l[i], l[i+1]) == l[i])) and (not (max(l[i - 1], l[i], l[i+1]) == l[i])):
        c += 1
print(c)

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


int main() {
    long long x;
    cin >> x;

    int v=0;
    long long  goukei=100;
    long ans=0;
    while(true){
        goukei += goukei /100;
        ans++;
        if(goukei >= x){
            break;
        }
        
    }
    cout << ans << endl;
}

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

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

fn main() {
    let n: i32 = read::<String>().parse().unwrap();
    let mut ans = 0;
    for i in 1..(n + 1) {
        let s = i.to_string();
        if s.len() % 2 == 1 {
            // dbg!(s.len(), s, i);
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+10;
int main(){
    ll arr[maxn],b=0,c=0,i,n;
    cin>>n;
    for(i = 1;i <= n;i++)
        cin>>arr[i];
    ll sum = 0,d;
    for(i = 1;i <= n;i++){
        if(i%2==0){
            if(sum+arr[i]>0){
                sum = sum+arr[i];
                continue;
            }
            d = abs(sum+arr[i])+1;
            b = b+d;
            sum = 1;
        }
        else{
            if(sum+arr[i]<0){
                sum = sum+arr[i];
                continue;
            }
            d = abs(sum+arr[i])+1;
            b = b+d;
            sum = -1;
        }
    }
    sum = 0;
    for(i = 1;i <= n;i++){
        if(i%2==0){
            if(sum+arr[i]<0){
                sum = sum+arr[i];
                continue;
            }
            d = abs(sum+arr[i])+1;
            c = c+d;
            sum = -1;
        }
        else{
            if(sum+arr[i]>0){
                sum = sum+arr[i];
                continue;
            }
            d = abs(sum+arr [i])+1;
            c = c+d;
            sum = 1;
        }
    }
    cout<<min(b,c)<<endl;
}


Measured memory_bytes: 1024
N = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
prod = 1
over = false
zero = false
A.each { |a|
  if not over and not zero
    prod *= a
  end
  if a == 0
    zero = true
  end
  if prod > 10**18
    over = true
  end
}

if zero
  puts 0
elsif over
  puts -1
else
  puts prod
end


Measured memory_bytes: 21516
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4

int main(){
  string S; cin >> S;
  int N = S.size();

  int longest = 0;
  rep(i,N){
    for (int j=1;j<=N-i;j++){
      string s = S.substr(i,j);
      bool flag = true;
      for (int k=0;k<j;k++){
        if (!(s[k]=='A' || s[k]=='T' || s[k]=='G' || s[k]=='C')) flag = false;
      }
      if (flag) longest = max(longest, j);
    }

  }

  cout << longest << endl;

  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<vector>

using namespace std;

int main(void){
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	if (A == B)
		printf("%d\n", C);
	if (A == C)
		printf("%d\n", B); 
	if (C == B)
		printf("%d\n", A);
	return 0;
}

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

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

bool isPrime(int n) {
    if (n < 2)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;

    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return false;
    }
    return true;
}

void main() {
    string s;
    while ((s = readln.chomp) != null) {
        int n = s.to!int;

        int ans = 0;
        for (int i = 1; i <= n; i++) {
            int a = i;
            int b = n - i + 1;
            if (isPrime(a) && isPrime(b))
                ans++;
        }
        writeln(ans);
    }
}

Measured memory_bytes: 2340
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int V[N], C[N];
    REP(i, N){
        cin >> V[i];
    }
    REP(i, N){
        cin >> C[i];
    }
    
    int res = 0, pos = 0, ans = 0;
    for (int bit = 0; bit < (1<<N); ++bit) {
        //cout << bit << endl;
        res = 0;
        pos = 0;
        REP(i, N) {
            if (bit & (1<<i)) {
                res += V[i];
                pos += C[i];
            }
        }

        ans = max(ans, res - pos);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
long long N;
vector<long long> X(1009), Y(1009), H(1009);
vector<tuple<long long, long long, long long>>vec;
void solve() {
    cin >> N;
    tuple<long long, long long, long long>G = make_tuple(-1, -1, -1);
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i] >> H[i];
        if (H[i] >= 1) G = make_tuple(X[i], Y[i], H[i]);
    }
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            long long V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j);
            V = max(V, 0LL);
            bool flag = true;
            for (int k = 0; k < N; k++) {
                long long VV = V - abs(X[k] - i) - abs(Y[k] - j);
                VV = max(VV, 0LL);
                if(H[k] != VV) flag = false;
            }
            if (flag == true) vec.push_back(make_tuple(i, j, V));
        }
    }
    if (vec.size() == 1) {
        cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
    }
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  string S;
  cin >> S;
  if(a % 2 != 0){
    cout <<"No"<<endl;
  }
  else{
    string T;
    bool flag = false;
    for(int i = 0; i < a/ 2; i++){
    	T[i] = S[i];
    }
    for(int j = 0; j < a/2; j++){
      if(T[j] != S[j+a/2]){
        flag = true;
        break;
      }
    }
    if(flag == true)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
}
      
    


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int s,d=0,f,g,h,j,i;
	char a[100001];
	scanf("%s",a);
	s=strlen(a);
	f=-1;
	while(1){
		//printf("%d %c\n",f+1,a[f+1]);
		if(a[f+1]=='e'&&a[f+2]=='r'&&a[f+3]=='a'&&a[f+4]=='s'&&a[f+5]=='e'&&a[f+6]=='r'){
			f+=6;
			if(a[f+1]!='e'&&a[f+1]!='d'&&f<s-1)
				f-=2;
		}
		else if(a[f+1]=='e'&&a[f+2]=='r'&&a[f+3]=='a'&&a[f+4]=='s'&&a[f+5]=='e')
			f+=5;
		else if(a[f+1]=='d'&&a[f+2]=='r'&&a[f+3]=='e'&&a[f+4]=='a'&&a[f+5]=='m'&&a[f+6]=='e'&&a[f+7]=='r'){
			f+=7;
			if(a[f+1]!='e'&&a[f+1]!='d'&&f<s-1)
				f-=2;
		}
		else if(a[f+1]=='d'&&a[f+2]=='r'&&a[f+3]=='e'&&a[f+4]=='a'&&a[f+5]=='m')
			f+=5;
		else break;
		if(f>=s-1)	break;
	}
	//printf("%d %d\n",f,s-1);
	if(f>=s-1)	printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#pragma optimize("unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// #include <ext/pb_ds/assoc_container.hpp>
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define sorts(v) sort(v.begin(),v.end())
#define sortg(v) sort(v.begin(),v.end(),greater<ll>())
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1e18)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define mem(x,y) memset(x,y,sizeof(x))
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"
#define sp(x) setprecision(x)
const ll N=405;
ll dp[N][N];
ll n,a[N];

ll fun(ll i,ll j)
{
    if(i==j)
    {
        return 0;
    }
    if(dp[i][j]!=-1)
    {
        return dp[i][j];
    }
    ll ans=1e18;
    f(k,i+1,j+1)
    {
        ans=min(ans,fun(i,k-1)+fun(k,j)+a[j+1]-a[i]);
        // +fun(0,i-1)+fun(j+1,n-1);
    }
    // ans+=a[j+1]-a[i];
    // ans+=fun((ll)0,i-1)+fun(j+1,n-1);
    return dp[i][j]=ans;
}


void solve()
{
   cin>>n;
   f(i,1,n+1)cin>>a[i],a[i]+=a[i-1];

   mem(dp,-1);
   cout<<fun(0,n-1)<<'\n';
   
}


    
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("ouput.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll te=1;
    // cin>>te;
    while(te--){
        solve();
    }
    
}


Measured memory_bytes: 4888
#include<stdio.h>
main(void)
{
	int n,x,a,b,c,S;
	
	while(EOF !=scanf("%d %d",&n,&x)){
		if(n==0 && x==0) break;
		S=0;
		for(a=1;a<=n;a++){
			for(b=a+1;b<=n;b++){
				for(c=b+1;c<=n;c++){
					if(a+b+c==x)S+=1;
				}
			}
		}
		printf("%d\n",S);
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong();
		if (n % 2 == 1) {
			System.out.println(0);
			return;
		}
		long count = 0;
		while (n > 0) {
			n /= 5;
			count += n / 2;
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 22996
n, k = map(int, input().split())
A = [False] * n
count = 0

for i in range(k):
    d = int(input())
    get = list(map(int, input().split()))
    for j in range(d):
        A[get[j] - 1] = True

for i in range(len(A)):
    if not A[i]:
        count += 1

print(count)

Measured memory_bytes: 9136
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(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 main(){
    string s; int x, y; cin >> s >> x >> y;
    map<int, int> X, Y;
    
    bool tox = true; int cx = 0, cy = 0;
    rep(i, s.size()){
        if(s[i] == 'F') tox ? cx++ : cy++;
        else if(tox){
            if(X.empty()) X[cx] = 1;
            else{
                vector<int> key;
                for(auto m: X) {
                    key.push_back(m.first); 
                    X.erase(m.first);
                    }
                for(int m: key){
                    X[m+cx] = true;
                    X[m-cx] = true;
                }          
            }
            cx = 0; tox = false;
        }else{
            if(Y.empty()){
                Y[cy] = true;
                Y[-cy] = true;
            }
            else{
                vector<int> key;
                for(auto m: Y) {
                    key.push_back(m.first);
                    Y.erase(m.first);
                }
                for(int m: key){
                    Y[m+cy] = true;
                    Y[m-cy] = true;
                }
            }
            cy = 0; tox = true;
        }
    }
    if(tox){
        if(Y.empty())Y[0] = 1;
        if(X.empty()) X[cx] = 1;
        else{
            vector<int> key;
            for(auto m: X) {
                key.push_back(m.first);
                X.erase(m.first);
            }
            for(int m: key){
                X[m+cx] = true;
                X[m-cx] = true;
            }  
        }
    }else{
        if(Y.empty()) Y[cy] = 1, Y[-cy] = 1;
        else{
            vector<int> key;
            for(auto m: Y){
                key.push_back(m.first);
                Y.erase(m.first);
            }
            for(int m: key){
                Y[m+cy] = true;
                Y[m-cy] = true;
            }
        }
    }
    
    if(X[x] == 1 && Y[y] == 1) cout << "Yes" << ln;
    else cout << "No" << ln;
}


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

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


int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll mx = b / x;
    if (a - 1 >= 0) {
        ll mn = (a - 1) / x;
        cout << (ll)(mx - mn) << endl;
    } else {
        cout << (mx + 1) << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    ll m;
    cin >> m;
    ll t[m];
    for(ll i = 0; i < m; i++)
        cin >> t[i];
    sort(a, a+n); sort(t, t+m);
    bool ok = true;
    ll count = 0;
    for(ll i = 0; i < m; i++){
        //cout << t[i] << endl;
        for(ll j = count; j < n; j++){
            //cout << t[i] << " " << a[j] << endl;
            if(t[i]>a[j]) continue;
            else if(t[i]==a[j]){
                count = j+1;
                //cout <<"aaa" << endl;
                break;
            }
            else if(t[i]<a[j]){
                ok = false; break;
            }
        }
        if(ok==false) break;
    }
    if(ok==true)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3328
import collections

n = int(input())
mod = 10**9 + 7
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[]:
        arr.append([n, 1])
 
    return arr

tmp = collections.defaultdict(int)

for i in range(1, n+1):
    for j , k in factorization(i):
        tmp[j] += k

ans = 1
for tei, si in tmp.items():
    if tei == 1:
        continue
    else:
        ans *= si + 1
        ans %= mod

print(ans)


Measured memory_bytes: 9620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
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 main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}


void solve(long long K){
    vector<int> v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << v[K-1] << endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <vector>

/// @brief Represents a 2D point.
class Point {
public:
    int x;  ///< x value.
    int y;  ///< y value.

    /// Sets values.
    void set(int x, int y) {
        this->x = x;
        this->y = y;
    }

    /// Check if this object is in the range.
    bool is_inside(int H, int W) {
        if (this->y < 1 || H < this-> y) {
            return false;
        } else if (this->x < 1 || W < this->x) {
            return false;
        }

        return true;
    }
};

static char s[51][51];
static int H;  ///< height.
static int W;  ///< width.
static bool visited[51][51];
static Point parents[51][51];  ///< Parent cells for the shortest path.

/// breadth first search
void bfs(Point *from) {
    std::queue<Point> q;

    for (int y = 0; y < 51; ++y) {  // initialization
        for (int x = 0; x < 51; ++x) {
            visited[y][x] = false;
        }
    }

    visited[from->y][from->x] = true;
    q.push(*from);

    while (!q.empty()) {
        Point top, btm, lft, rgt;
        std::vector<Point *> adjacent;

        Point *f = &q.front();
        q.pop();
        top.set(f->x - 1, f->y);
        btm.set(f->x + 1, f->y);
        lft.set(f->x, f->y - 1);
        rgt.set(f->x, f->y + 1);
        adjacent.push_back(&top);
        adjacent.push_back(&btm);
        adjacent.push_back(&lft);
        adjacent.push_back(&rgt);

        for (Point *p: adjacent) {
            if (!p->is_inside(H, W)) {  // not valid location.
                continue;
            }

            if (visited[p->y][p->x]) {  // already visited.
                continue;
            }

            if (s[p->y][p->x] == '#') {  // wall
                continue;
            }

            visited[p->y][p->x] = true;
            parents[p->y][p->x] = *f;
            q.push(*p);
        }
    }
}

/// @brief Counts maximum number of walls to be construct.
int main() {
    int sum = 0;
    Point from, parent;

    scanf("%d%d ", &H, &W);

    for (int h = 1; h <= H; ++h) {
        for (int w = 1; w <= W; ++w) {
            scanf("%c", &s[h][w]);
        }

        scanf("%*c");  // for newline.
    }

    from.set(1, 1);  // starting point.
    bfs(&from);

    if (!visited[H][W]) {
        puts("-1");
        return 0;
    }

    parent.set(W, H);  // goal point.

    while (true) {  // Paints the shortest path.
        s[parent.y][parent.x] = '#';

        if (parent.x == 1 && parent.y == 1) {
            break;
        }

        parent = parents[parent.y][parent.x];
    }

    for (int h = 1; h <= H; ++h) {
        for (int w = 1; w <= W; ++w) {
            sum += s[h][w] == '.' ? 1 : 0;
        }
    }

    printf("%d\n", sum);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <array>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 998244353;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(3e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    string s;
    cin >> s;
    int cnt[26]{};
    REP(i,s.size()){
        cnt[s[i]-'a']++;
    }
    REP(i,26){
        if(cnt[i]==0){
            cout << char('a'+ i)<< endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s;
  cin >> s;
  int q=(s[0]-'0')*10+(s[1]-'0');
  int p=(s[2]-'0')*10+(s[3]-'0');
  int a=0;
  int b=0;
  if(q<=12&&q>=1)a=1;
  if(p<=12&&p>=1)b=1;
  if(a==1&&b==1)cout << "AMBIGUOUS" << endl;
  if(a==0&&b==1)cout << "YYMM" << endl;
  if(a==1&&b==0)cout << "MMYY" << endl;
  if(a==0&&b==0)cout << "NA" << endl; 
}  


Measured memory_bytes: 256
#include <iostream>
#define foreach(i,upper) for (int i = 0; i < upper; ++i)
using namespace std;

#define MAX_R 10
#define MAX_C 10000
int R, C;
bool os[MAX_R][MAX_C];

int main() {
	while (true) {
		cin >> R >> C;
		if (R == 0 && C == 0) break;
		foreach (i,R) foreach (j,C) cin >> os[i][j];
		int result = 0;
		foreach (mask, 1 << R) {
			int acc = 0;
			bool masks[MAX_R];
			foreach (i,R) { masks[i] = !! (mask & (1 << i)); }
			foreach (i,C) {
				int cnt = 0;
				foreach (j,R) {
					if (os[j][i] == masks[j]) { ++cnt; }
				}
				acc += max(cnt,R-cnt);
			}
			result = max(result,acc);
		}
		cout << result << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  int h,w;
  cin >> h >> w;
  int a,b;
  cin >> a >> b;
  cout << (h-a)*(w-b) << endl;
  
  return 0;     
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,n;
    cin >> h >> n;
    int skill[n][2];
    for(int i = 0;i<n;i++){
        cin >> skill[i][0] >> skill[i][1];
    }
    int sp[200001];
    sp[0] = 0;
    for(int i=1;i<200001;i++){
        sp[i] = 2000000000;
    }
    for(int i = 1;i<200001;i++){
        for(int j = 0;j<n;j++){
            sp[i] = min(sp[i],sp[max(i - skill[j][0],0)]+skill[j][1]);
        }
    }
    cout << sp[h];
}


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

int main()
{
    string s;
    cin >> s;

    int x = (s[0] - '0') * 10 + s[1] - '0';
    int y = (s[2] - '0') * 10 + s[3] - '0';
    if (1 <= x && x <= 12) {
        if (1 <= y && y <= 12) {
            cout << "AMBIGUOUS" << endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else if (1 <= y && y <= 12) {
        if (1 <= x && x <= 12) {
            cout << "AMBIGUOUS" << endl;
        } else {
            cout << "YYMM" << endl;
        }
    } else {
        cout << "NA" << endl;
    }

    return 0;
}

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

using namespace std;

const int N = 1e5 + 5;

int n, a[N][4], dp[N][4];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i][1] >> a[i][2] >> a[i][3];
    memset(dp, -0x3f, sizeof dp);
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) {
            if (dp[i][j] > -1e9) {
                for (int k = 1; k < 4; k++) {
                    if (j == k) continue;
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i + 1][k]);
                }
            }
        }
    }
    
    int ans = 0;
    for (int i = 1; i <= 3; i++) ans = max(ans, dp[n][i]);
    cout << ans;
    return 0;
}

Measured memory_bytes: 3328
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    items = []

    for i in range(N):
        value, limit = map(int, input().split())
        items.append((limit, value))

    logging.info(items)

    items.sort()

    logging.info(items)

    total_time = 0
    for lim, val in items:
        total_time += val
        if total_time > lim:
            print("No")
            exit()

    print("Yes")

    
if __name__ == "__main__":
    main()


Measured memory_bytes: 37000
#include <iostream>
#include <cstdio>
using namespace std;
const int mod = 1e9 + 7;
int calc(int x){
    if(x <= 9) return 1;
    if(x <= 99) return 2;
    if(x <= 999) return 3;
    if(x <= 9999) return 4;
    if(x <= 99999) return 5;
    if(x <= 999999) return 6;
    if(x <= 9999999) return 7;
    return 8;
}
long long sum[23000005], S;
long long mypow(long long a, long long b){
    long long ans = 1;
    for(; b; b >>= 1) { if(b&1) (ans *= a) %= mod; (a *= a) %= mod; } return ans;
}
int main()
{
    cin>>S;
    for(int i = 1; i <= 23000004; i++){
        sum[i] = sum[i-1] + calc(i);
    }
    int j = 1;
    long long ans = 0;
    for(int i = 1; i <= 23000004; i++){
        while(sum[j] - sum[i-1] < S) j++;
        if(calc(i) > 7) break;
        if(sum[j] - sum[i-1] == S) ans++;
    }
    (ans += S/8) %= mod;
    for(int i = 1; i <= S/8; i++){
        if(S % i == 0){
            int x = S/i;
            ( (((ans += 9*mypow(10, x-1)) -= i) %= mod) += mod) %= mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
const ll M = 100000007;

ll extgcd(ll a,ll b,ll& x,ll& y){
  ll d = a ;
  if ( b != 0 ) {
    d = extgcd( b , a%b , y , x ) ;
    y -= ( a / b ) * x ;
  }else{
    x = 1 ; y = 0 ;
  }
  return d;
}
ll mod_inverse(ll a,ll m){
  ll x , y ;
  extgcd( a , m , x , y ) ;
  return ( m + x % m ) % m ;
}

ll combination(ll N,ll K){
  ll res = 1;
  for( int i = 0; i < K; i++ ) res = (res * ((N - i) % M )) % M;
  for( int i = 1; i <= K; i++ ) res = (res * mod_inverse(i,M)) % M;
  return res;
}

int main() {
	int cnt = 0;
	int mi = M;
	int r, c, a1, a2, b1, b2;

	cin >> r >> c >> a1 >> a2 >> b1 >> b2;
	for ( int i = -1; i <= 1; i++ ) {
		for ( int j = -1; j <= 1; j++ ) {
			int c1 = b1+r*i, c2 = b2+c*j;
			mi = min(mi, abs(c1-a1)+abs(c2-a2));
		}
	}
	//cout << combination(400, 200) << endl;
	//cout << mi << endl;
	for ( int i = -1; i <= 1; i++ ) {
		for ( int j = -1; j <= 1; j++ ) {
			int c1 = b1+r*i, c2 = b2+c*j;
			if ( abs(c1-a1)+abs(c2-a2) == mi ) {
				cnt += combination(mi, abs(c1-a1));
				//cout << cnt << endl;
				cnt %= M;
			}
		}
	}

	cout << cnt << endl;
	
	return 0;
}



Measured memory_bytes: 3108
#include <iostream>
using namespace std;
const int MAXN = (int)3e5;

int e[MAXN + 1];

int main() {
    int n; string s;
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        e[i + 1] = e[i] + (s[i] == 'E');
    }
    int ans = 1 << 30;
    for (int i = 0; i < n; i++) {
        ans = min(ans, i - e[i] + e[n] - e[i + 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include <string>

class Baseball{
	int point,out_count,runner;
public:
	Baseball(){
		point = 0;
		out_count = 0;
		runner = 0;
	}
	void game();
	void single_hit();
	void homerun();
	void out();
	int get_point(){ return point; }
	int get_out(){ return out_count; }
};

void Baseball::game(){
	std::string event;
	while(std::cin >> event){
		if(event == "HIT"){
			single_hit();
		}else if(event == "HOMERUN"){
			homerun();
		}else if(event == "OUT"){
			out();
		}
		if(get_out() == 3){
			break;
		}
	}
}

void Baseball::single_hit(){
	++runner;
	if(runner == 4){
		++point;
		--runner;
	}
}

void Baseball::homerun(){
	++runner;
	point += runner;
	runner = 0;
}

void Baseball::out(){
	++out_count;
}

int main(){
	int inning;
	std::cin >> inning;
	for(int i = 0; i < inning; ++i){
		Baseball baseball;
		baseball.game();
		std::cout << baseball.get_point() << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>

int main(void)
{
  int h,w,i,j,frag=1;
  scanf("%d %d",&h,&w);
  char s[51][51];
  for(i=0;i<h;i++)
    {
      scanf("%s",s[i]);
    }

  for(i=0;i<h;i++)
    {
      for(j=0;j<w;j++)
	{
	  if(s[i][j] == '#')
	    {
	      frag = 0;
	      if(i-1 >= 0 && s[i-1][j] == '#')
		{
		  frag = 1;
		}
	      if(i+1 < h && s[i+1][j] == '#')
		{
		  frag = 1;
		}
	      if(j-1 >= 0 && s[i][j-1] == '#')
		{
		  frag = 1;
		}
	      if(j+1 < w && s[i][j+1] == '#')
		{
		  frag = 1;
		}
	    }
	  if(frag == 0)
	    {
	      printf("No\n");
	      return 0;
	    }
	}
    }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
import re
def fac(n):
    s = 1
    for i in range(1,n+1):
        s *= i
    return(s)

while True:
    n = int(input().strip())
    if n==0:
        break

    num_str = '%d' % fac(n)
    zeros = re.sub(r'.*[^0](0*)$', '\\1', num_str)
    print(len(zeros))

Measured memory_bytes: 8036
#include<stdio.h>
#include<string.h>
int main(){

  int count=0,i,len;
  char Goo[10];

  scanf("%s",Goo);

  len = strlen(Goo);
  for(i=0;i<len-len/2;i++){
   
  if(Goo[i]=='('){
      if(Goo[len-i-1]!=')'){
	count++;
      }
    }else if(Goo[i]==')'){
      if(Goo[len-i-1]!='('){
	count++;
      }
    }else if(Goo[i]!=Goo[len-i-1]){
      count++;
    }
  }
  printf("%d\n",count);
return 0;
}

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

using namespace std;

typedef long long ll;
typedef __int128 lll;

lll phi(lll n) {
  lll result = n;
  for(int i = 2; i * i <= n; ++i) {
    if(n % i == 0) {
      while(n % i == 0)n /= i;
      result -= result / i;
    }
  }
  if(n > 1) result -= result / n;
  return result;
}

lll powMod(lll a, lll b, lll n) {
  if (b == 0) return 1;
  lll res = 1;
  while (b > 1) {
    if (b & 1) res = (a * res) % n;
    a = (a * a) % n;
    b /= 2;
  }
  return (a * res) % n;
}

lll extendedEuclid(lll a, lll b, lll &x, lll &y) {
  if (a == 0) { x = 0; y = 1; return b; }
  lll x1, y1, d = extendedEuclid(b % a, a, x1, y1);
  x = y1 - (b / a) * x1; y = x1;
  return d;
}

lll multInv(lll n, lll p) {
  lll x, y;
  extendedEuclid(n, p, x, y);
  x = ((x % p) + p) % p;
  return x % p;
}

ll solve(lll a, lll m) {
  if (m <= 1) {
    return 1e9;
    // lll power = 1;
    // for (lll k = 1; k <= m; k++) {
    //   power = power * a % m;
    //   if (power == (k % m)) {
    //     return (ll)k;
    //   }
    // }
    // return -1;
  } else {
    lll phim = phi(m);
    lll y, z;
    lll g = extendedEuclid(m, phim, y, z);
    lll solution = solve(a, g);
    lll power = powMod(a, solution, m);

    // lll mod = phim * (m / g);
    // lll minus = y * m % mod * ((power - solution) / g) % mod;
    // lll res = ((power - minus) % mod + mod) % mod;
    // return (ll)res;

    lll res = (((power - solution) % m / g % m) + m) % m;
    res *= multInv(phim / g, m / g);
    res = (res % m + m) % m;
    return solution + (ll)res * phim;
  }
}

int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    ll a, m;
    scanf("%lld %lld", &a, &m);
    printf("%lld\n", solve(a, m));
  }
  return 0;
}


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

int main(){
    int n;
    for(;;){
        scanf("%d",&n);
        if(n==-1) break;
        int ret=1150;
        if(n>10) ret+=125*min(n-10,10);
        if(n>20) ret+=140*min(n-20,10);
        if(n>30) ret+=160*(n-30);
        printf("%d\n",4280-ret);
    }
}

Measured memory_bytes: 0
N, *A = map(int, open(0).read().split())
A_set = set(A)

if len(A_set) == 1:
    print("Yes") if sum(A) == 0 else print("No")
elif len(A_set) == 2:
    a1, a2 = sorted(A_set)
    print("Yes") if a1 == 0 and A.count(a1) * 3 == N else print("No")
elif len(A_set) == 3:
    a1, a2, a3 = list(A_set)
    if a1 ^ a2 ^ a3 == 0 and A.count(a1) == A.count(a2) == A.count(a3):
        print("Yes")
    else:
        print("No")
else:
    print("No")


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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int64_t N;
	cin >> N;
	int64_t ans = 1e18;
	for (int64_t A = 1; A*A <= N; ++A) if (N%A == 0) {
		int64_t B = N/A;
		ans = min(ans, (int64_t)max(to_string(A).size(), to_string(B).size()));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256