akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int H, W, n;
int sx, sy;
char s[200010], t[200010];
bool inrange(int x, int y) {
	return x>=1&&y>=1&&x<=W&&y<=H;
}
void move(int& x, int& y, char ch, int dx, int dy) {
	if(ch == 'L' && dx == 0) x--;
	else if(ch == 'R' && dx == 1) x++;
	else if(ch == 'U' && dy == 0) y--;
	else if(ch == 'D' && dy == 1) y++;
}
bool f(int x1, int y1, int x2, int y2) {
	int x = sx, y = sy;
	for(int i=0; i<n; i++) {
		move(x, y, s[i], x1, y1);
		if(!inrange(x, y)) return 1;
		int tx = x, ty = y;
		move(tx, ty, t[i], x2, y2);
		if(inrange(tx, ty)) x = tx, y = ty;
	}
	return 0;
}
int main() {
	scanf("%d%d%d", &H, &W, &n);
	scanf("%d%d", &sy, &sx);
	scanf("%s%s", s, t);
	for(int i=0; i<2; i++) {
		for(int j=0; j<2; j++) {
			bool flag = true;
			for(int k=0; k<2; k++) {
				for(int l=0; l<2; l++) {
					if(!f(i,j,k,l)) {
						flag = 0;
					}
				}
			}
			if(flag) {
				puts("NO");
				return 0;
			}
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  int n = s.size();
  int m = n/2;
  REP(i, n){
    if(s[i] != s[n-1-i]){
      cout << "No" << endl;
      return 0;
    }
  }
  REP(i, m){
    if(s[i] != s[m-1-i] || s[m+1+i] != s[n-1-i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long max = 0L;
        int Bi = 0;
        int save = Integer.MAX_VALUE;
        for (int i = 0; i < N - 1; i++) {
        	Bi = sc.nextInt();
        	if (Bi < save) {
        		max += Bi;
        		save = Bi;
        	} else {
        		max += save;
        		save = Bi;
        	}
        }
        System.out.println(max + save);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int a[500];
int main()
{
    int n;
    cin>>n;
    int len=0;
    int t=n;
    if(n==0){ cout<<0<<endl;return 0;}
    while(n)
    {
        int k=n/(-2);
        if(k*(-2)!=n)
        {
            if(k>0)
            {
                k++;
            }
                a[len++]=1;
        }
        else a[len++]=0;
        n=k;
    }
    if(t>0&&len%2==0)
    a[len++]=1;
    if(t<0&&len%2)
        a[len++]=1;
    //cout<<len<<endl;
    for(int i=len-1;i>=0;i--)
        cout<<a[i];cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;
 
int main(){
    int n; cin >> n;
    vector<int> s(n);
    rep(i,n) cin >> s[i];
    int ans=0;
    rep(i,n-2){
        if((s[i+1]<s[i] && s[i+1]>s[i+2]) || (s[i+1]>s[i] && s[i+1]<s[i+2])) ans++;
    }
    cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


A, B, C = ds_in()
if A == B and B == C:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    
    // Nターン
    int g = 0, p = 0, ans = 0;
    for(int i=0;i<s.size();i++){
        if(s.at(i) == 'g'){
            if(p < g){
                p++;
                ans++;
            }else{
                g++;
            }
        }else{
            if(p < g){
                p++;
            }else{
                g++;
                ans--;
            }
        }

    }
    
    cout << ans << endl;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char pe[10];
main()
{
	int s,t,co=0;
    scanf("%d%d",&s,&t);
    for(int i = s;i <= t;i++)
    {
        int tmp=i;
        for(int j = 0;tmp !=0;j++)
        {
            pe[j]=tmp%10;
            tmp/=10;
        }
        int ck=1;
        for(int j = 0;j <= 2;j++)
        {
            if(pe[j]!=pe[4-j])
            ck=0;
        }
        co+=ck;
    }
    printf("%d",co);
}


Measured memory_bytes: 256
/*
    It is the level of one's commitment that determines the success, far more than the knowledge one possess.
    
    I never lose, I either win or I learn.
                - Competitive Programming

*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.IllegalCharsetNameException;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());

        st = new StringTokenizer(br.readLine());
        int[] a = new int[n+1];
        for(int i=1 ; i<=n ; i++) {
            a[i] = Integer.parseInt(st.nextToken());
        }

        int[] dp = new int[n+1];

        for(int i=2 ; i<=n ; i++) dp[i] = Integer.MAX_VALUE-1000000000;

        for(int i=2 ; i<=n ; i++) {
            for(int j=i-1 ; j>=i-k && j>=1 ; j--) {
                dp[i] = Math.min(dp[i], dp[j] + Math.abs(a[i]-a[j]));
            }
        }

        pw.println(dp[n]);
        
        
        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


Measured memory_bytes: 33812
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N,K;
  cin>>N>>K;
  vector<int>B(N);
  REP(i,K){
    int d;
    cin>>d;
    REP(i,d){
      int A;
      cin>>A;
      A--;
      B[A]++;
    }
  }
  int ans=0;
  REP(i,N){
    if(B[i]==0)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3656
#define ENABLE_DEBUG 1
// hidden common codes{{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(lint ngtkana_is_a_genius=0; ngtkana_is_a_genius<(lint)k; ngtkana_is_a_genius++)
using lint=long long;
using ld=long double;
template<class T> using numr=std::numeric_limits<T>;
struct input_t {
    template<class T> operator T() {
        T t;
        std::cin>>t;
        return t;
    }
} input;
#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    lint k=input,a=input,b=input;
    std::cout<<((a+k-1)/k<=b/k?"OK":"NG")<<'\n';
}


Measured memory_bytes: 3648
def main():
    import heapq
    t = int(input())
    for i in range(t):
        n, a, b, c, d = map(int, input().split())
        h = [(0, n)]
        heapq.heapify(h)
        s = set()
        while h:
            cost, now = heapq.heappop(h)
            if now in s:
                continue
            else:
                s.add(now)
            if now == 0:
                print(cost)
                break
            heapq.heappush(h, (cost+now*d, 0))
            # 2について
            if now % 2 == 0:
                heapq.heappush(h, (cost+a, now//2))
            else:
                heapq.heappush(h, (cost+a+d, (now+1)//2))
                heapq.heappush(h, (cost+a+d, now//2))
            # 3について
            if now % 3 == 0:
                heapq.heappush(h, (cost+b, now//3))
            else:
                temp = now % 3
                heapq.heappush(h, (cost+b+(3-temp)*d, (now+3-temp)//3))
                heapq.heappush(h, (cost+b+temp*d, now//3))
            # 5について
            if now % 5 == 0:
                heapq.heappush(h, (cost+c, now//5))
            else:
                temp = now % 5
                heapq.heappush(h, (cost+c+(5-temp)*d, (now+5-temp)//5))
                heapq.heappush(h, (cost+c+temp*d, now//5))


main()


Measured memory_bytes: 12824
#include<iostream>

//????????????(??????)
const int INF=1000;

//??????????????§
int n,m;
int s1[INF];
int s2[INF];

int tarouSum;
int hanakoSum;

int main() {
	while (true) {
		//?????????
		tarouSum=0;
		hanakoSum=0;

		//??\???1
		std::cin>>n>>m;
		//???????????¶
		if(n==0 && m==0)break;
		
		//??\???2
		for(int i=0;i<n;i++) {
			std::cin >> s1[i];
			hanakoSum+=s1[i];
		}
		for(int i=0;i<m;i++){
			std::cin >> s2[i];
			tarouSum+=s2[i];
		}
		//?????¬??????????????°
		int needPoint=hanakoSum-tarouSum;

		//???????\???°????????????????????????
		if (needPoint % 2 != 0) {
			std::cout<<-1<<std::endl;
			continue;
		}
		//????????¶??°?????¨??????????????????????????????????????????????????????????????????????????????
		needPoint/=2;
		bool ansExist=false;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (s1[i] - s2[j] == needPoint) {
					std::cout<<s1[i]<<" "<<s2[j]<<std::endl;
					ansExist=true;
					break;
				}
			}
			if(ansExist)break;
		}
		if(!ansExist)std::cout<<-1<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 3048
import itertools
n,m,x=map(int,input().split())
lis=tuple(tuple(map(int,input().split())) for _ in range(n))
ans=float("inf")

def dfs(progress,skills,nowcost):
    global ans
    if progress==n:
        if all(v>=x for v in skills):
            ans=min(ans,nowcost)
        return ans
    dfs(progress+1,skills,nowcost)
    dfs(progress+1,[a+b for a,b in zip(skills,lis[progress][1:])],nowcost+lis[progress][0])

dfs(0,[0]*m,0)
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9240
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)
	answer := isStrongParlindrome(s)
	if answer {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func isStrongParlindrome(s string) bool {
	return isParlindrome(s) && isConditionA(s) && isConditionB(s)
}

func isConditionA(s string) bool {
	start := 0
	end := (len(s) - 1) / 2
	return isParlindrome(s[start:end])
}

func isConditionB(s string) bool {
	start := (len(s)+3)/2 - 1
	end := len(s)
	return isParlindrome(s[start:end])
}

func isParlindrome(s string) bool {
	for i := 0; i < len(s)/2+1; i++ {
		if s[i] != s[len(s)-i-1] {
			return false
		}
	}
	return true
}


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

int main(void) {
    vector<int> x(3);
    for (int i = 0; i < 3; i++)
    {
        cin >> x[i];
    }
    
    sort(x.begin(), x.end(), greater<int>());

    int ans = x[0] * 10 + x[1] + x[2];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i) 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 1e3+10;
const int N = 1e5+10;
const int E = 1e6+10;  
int n,k;
int a[maxn];

int main(){
	cin>>n>>k;
	F(i,1,n){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	int sum = 0;
	F(i,1,k) sum+=a[i];
	cout<<sum<<endl; 
}

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int y;
    cin >> y;
    int ans = -1;
    double a = 0;
    for (int i = 0; i < n; i++) {
      int b, r, t;
      cin >> b >> r >> t;
      double tmp;
      if (t == 1) tmp = 1 + y * r / 100.0;
      else tmp = pow(1.0 + r / 100.0, y);
      if (tmp > a) ans = b, a = tmp;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3332
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define INF 1000000007
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define CLR(a) memset((a), 0, sizeof(a))

using ll = long long;
using ull = unsigned long long;
using namespace std;

ll gcd(ll a, ll b){
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

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

int main(void){

    ll n, m;
    cin >> n >> m;

    string s, t;
    cin >> s;
    cin >> t;

    ll x_len = lcm(n, m);
    ll s_index = x_len / m;
    ll t_index = x_len / n;

    for(ll i=0;s_index*i<n;i++){
        //cout << "s[" << s_index*i << "]=" << s[s_index*i] << endl;
        //cout << "t[" << t_index*i << "]=" << t[t_index*i] << endl;

        if(s[s_index*i] != t[t_index*i]){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << x_len << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double a = sc.nextInt();
		double b = sc.nextInt();
		double s=a*25/2;
		double t=b*10;
		double min;
		if(s<t){
			min=t;
		}else{
			min=s;
		}
		double max;
		if(s+25/2<t+10){
			max=s+25/2;
		}else{
			max=t+10;
		}
		if(min%1!=0){
			min=min-min%1+1;
		}
		if(max%1!=0){
			max=max-max%1;
		}else{
			max=max-1;
		}

		if(min<=max){
			System.out.println((int)min);
		}else{
			System.out.println(-1);
		}
	}
}

Measured memory_bytes: 23764
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	stdInScanner.Scan()
	i, _ := strconv.Atoi(stdInScanner.Text())
	return i
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	N := nextInt()
	R := nextInt()

	if N >= 10 {
		fmt.Println(R)
	} else {
		fmt.Println(R + (100 * (10 - N)))
	}
}


Measured memory_bytes: 640
// Author            -  Ranadev Varma
// Codeforces Handle -  Ranadev_CaptainR
// Codechef Handle   -  ranadev
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("unroll-loops")
 
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <iterator>
#include <iomanip>
#include <set>

using namespace std ;

#define MOD 1000000007LL
#define LOD 1000000006
#define pi 3.14159

#define lol1 ios::sync_with_stdio(false)
#define lol2 cin.tie(NULL);cout.tie(NULL)

#define FOR(i,a,b)  for(int i = a ; i < b ; i++)
#define RFOR(i,a,b) for(int i = a ; i > b ; i--)

#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
    lol1;
    lol2;
    int n,i;
    cin >> n >> i;
    cout << n-i+1 << "\n";
    return 0;
}

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

int main(){
	int  count=0;
	long long n,m;
	cin >> n >> m;

	int x=n%4,y=m%4;
	x = 4-x;
	x %= 4;
	y++;
	y%=4;
	long long ans = x==0 ? m : n;
	long long un = n+x, lm = m-y;
	while(n<un){
		if(count)ans ^= n;
		n++;
		count++;
	}
	while(m>lm){
		if(count)ans^=m;
		m--;
		count++;
	}
	if(x==0 && y==0)ans=0;
	
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
#include <map>
#include <climits>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    string a, b; cin >> a >> b;
    cout << (a[0] == b[2] && a[1] == b[1] && a[2] == b[0] ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#include<string>
#include<sstream>
#include<iostream>
using namespace std;
int main()
{
	int n{0};
	cin>>n;
	int d[n]={0};
	for(int i=0;i<n;i++)
	{
		cin>>d[i];
	}
	sort(d,d+n);
	int k=n/2;
	cout<<d[k]-d[k-1];
return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include<map>
#include<climits>
#include<cstring>
using namespace std;
using ll = long long;
int main() {
	int n, * arr, t;
	cin >> n;
	arr = new int[n];
	memset(arr, 0, sizeof(int) * n);
	for (int i = 1; i < n; i++) {
		scanf("%d", &t);
		arr[t - 1]++;
	}
	for (int i = 0; i < n; i++) {
		printf("%d\n", arr[i]);
	}
	return 0;
}

Measured memory_bytes: 4008
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int k, u, p, c;
int main() {
	string h;
	cin >> h;
	for (int i = 0; i < h.length(); ++i) {
		if (h[i] == 'K') { ++k; }
		if (h[i] == 'U') { ++u; }
		if (h[i] == 'P') { ++p; }
		if (h[i] == 'C') { ++c; }
	}
	cout << min(k, min(u, min(p, c))) << endl;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
main()
{
    ll n,i,k,mx=-1,sum=0;
    cin >> n;
    for(i=1;i<=n;i++){
        cin >> k;
        mx = max(mx,k);
        sum += k;
    }
    sum -= mx; sum += (mx/2);
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char in[110000];
int main(){
	int a,b,c;scanf("%d%d%d%s",&a,&b,&c,in);
	int A=0;
	int B=0;
	for(int i=0;i<a;i++){
		if(in[i]=='c'){
			printf("No\n");continue;
		}
		if(in[i]=='a'){
			if(A+B<b+c){
				printf("Yes\n");A++;
			}else printf("No\n");
		}else{
			if(A+B<b+c&&B<c){
				printf("Yes\n");B++;
			}else printf("No\n");
		}
	}
}

Measured memory_bytes: 640
n,k = map(int, input().split())
pn = list(map(int, input().split()))
qn = [(i+1)/2 for i in pn]
ans = sum(qn[:k])
t=ans
for i in range(1, n-k+1):
    t =t-qn[i-1]+qn[i+k-1]
    ans = max(ans, t)
print(ans)

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

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;



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

    int n, m;
    cin >> n >> m;
    int temp1 = m / n;

    for (int i = temp1; i >= 1; --i)
    {
        if (m % i == 0)
        {
            if (m / i >= n)
            {
                cout << i << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

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

	int n,x,t;

	cin >> n >> x >> t;

	int counter = 0, ans = 0;
	while(n > counter){
		counter += x;
		ans += t;
	}

	cout << ans;

    return 0;
}


Measured memory_bytes: 3608
class dice:
	def __init__(self,data):
		self.faces = data
	
	def turn(self,direction):
		if direction == 'N':
			idx = [1,5,2,3,0,4]
			self.faces = [self.faces[i] for i in idx]
		elif direction == 'S':
			[self.turn('N') for i in range(3)]
		elif direction == 'E':
			idx = [3,1,0,5,4,2]
			self.faces = [self.faces[i] for i in idx]
		elif direction == 'W':
			[self.turn('E') for i in range(3)]
		elif direction == 'c':
			self.turn('N')
			self.turn('W')
			self.turn('S')

def isunique(d1,d2):
	for o in 'cccWcccEcccNcccWcccWccc':
		if d1.faces == d2.faces:
			break
		else:
			d2.turn(o)
	if d1.faces == d2.faces:
		return False
	else:
		return True

if __name__ == '__main__':
	from itertools import combinations
	n = int(input())
	dices = []
	for i in range(n):
		dices.append(dice([int(s) for s in input().split()]))
	ans = True
	check = [isunique(d1,d2) for d1,d2 in combinations(dices,2)]
	if all(check):
		print('Yes')
	else:
		print('No')

Measured memory_bytes: 7824
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = readline().rstrip().decode()
t = readline().rstrip().decode()
cnt = 0
for i in range(3):
    if s[i] == t[i]:
        cnt += 1
print(cnt)


Measured memory_bytes: 2940
fun main(arr:Array<String>) {
    val(n, m) = readLine()!!.split(" ").map { it.toInt() }
    pointCount = n
    (1..m).forEach {
        val (p1,p2) = readLine()!!.split(" ").map { it.toInt() }
        if(!path.containsKey(p1)) {
            path[p1] = mutableMapOf()
        }
        if(!path.containsKey(p2)) {
            path[p2] = mutableMapOf()
        }
        path[p1]!![p2] = true
        path[p2]!![p1] = true
    }

    val ans = getAns(1, 0)
    println(ans)

}

var pointCount = 0
val path = mutableMapOf<Int, MutableMap<Int, Boolean>>()

fun getAns(pos:Int, key:Int):Long {
    val newKey = key + (1 shl (pos - 1))
    if(newKey >= (1 shl pointCount) - 1) {
        return 1
    }
    var ans = 0L
    for(next in path[pos]!!.keys) {
        val nextKey = 1 shl (next - 1)
        if((key and nextKey) != 0) {
            continue
        }
        ans += getAns(next, newKey)
    }
    return ans
}



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

const int INF = 1000000007;

int main(){
	ll n;
	cin >> n;
	ll tmp10 = 1;
	ll tmp9 = 1;
	ll tmp8 = 1;
	while(n--){
		tmp10 *= 10;
		tmp9 *= 9;
		tmp8 *= 8;
		tmp10 %= INF;
		tmp9 %= INF;
		tmp8 %= INF;
	}
	ll ans = (tmp10 - tmp9*2 + tmp8 + (ll)INF*10)%INF;
	cout << ans << endl;
	return 0;
}

// cout << fixed << setprecision(15) <<  << endl;

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<string>
 
using namespace std;
 
 
int main()
{
  long int L,R,ans = 2019;
  
  cin >> L >> R;
  
  if(((R/2019)-(L/2019))>0)
  {
    cout << 0 << endl;
  }
  else
  {
    for(long int i=L;i<R;i++)
    {
      for(long int j=i+1;j<=R;j++)
      {
        ans = min(ans,(i*j)%2019);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define INF 0x3f3f3f3f
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
using namespace std;
const int sz=1e5+1, mod=1e9+7;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int i,j,n; ll x;
    cin>>n;
    unordered_map<ll,int> mp;
    for(i=0;i<n;i++){
        cin>>x;
        mp[x]++;
    }
    vector<ll> v;
    for(auto x:mp){
        if(n%3==0&&x.yy==n/3) v.pb(x.xx);
    }

    if(mp[0]==n){
        cout<<"Yes";
    }else if(n%3==0&&mp[0]==n/3&&mp.size()==2){
        cout<<"Yes";
    }else if(v.size()==3){
        if( (v[0]^v[1])==v[2]||(v[1]^v[2])==v[0]||(v[0]^v[2])==v[1] ) cout<<"Yes";
        else cout<<"No";
    } else cout<<"No";
}


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

pub 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")
}

use std::cmp::max;
use std::cmp::min;

fn main() {
    let a: usize = read();
    let b: usize = read();
    if a + b >= 10 {
        println!("{}", "error");
    } else {
        println!("{}", a + b);
    }
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;

class Main {

    void solve(){

	Scanner sc = new Scanner( System.in );
	int w = sc.nextInt();
	int h = sc.nextInt();

	Integer[] col = new Integer[w];
	Integer[] row = new Integer[h];
	int sumC = 0, sumR = 0;
	for ( int i=0; i<w; ++i ) {
	    col[i] = sc.nextInt();
	    sumC += col[i];
	}
	for ( int i=0; i<h; ++i ) {
	    row[i] = sc.nextInt();
	    sumR += row[i];
	}
	if ( sumR != sumC ) {
	    System.out.println("0");
	    return;
	}

	for ( int i=0; i<w; ++i ) {

	    Arrays.sort( row, Comparator.reverseOrder() );
	    
	    for ( int j=0; j<h; ++j ) {
		if ( col[i] == 0 || row[j] == 0 ) break;
		--row[j];
		--col[i];
	    }

	    if ( col[i] > 0 ) {
		System.out.println("0");
		return;
	    }
	}

	System.out.println("1");
    }

    public static void main( String[] a ) {new Main().solve(); }
}



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

using namespace std;

const int INF = 1 << 30;

struct edge
{
  int to, cost;
};

int main()
{
  int N, M, D[50], E[50];
  int dp[50][50][1 << 10];

  while(scanf("%d %d", &N, &M), N) {
    vector< edge > gg[50], rg[50];
    D[0] = E[0] = D[N - 1] = 0, E[N - 1] = 1000;
    int comp[1001] = {}, rev[50];
    for(int i = 1; i < N - 1; i++) {
      scanf("%d %d", &D[i], &E[i]);
    }
    for(int i = 0; i < N; i++) {
      rev[i] = comp[E[i]]++;
    }

    for(int i = 0; i < M; i++) {
      int a, b, c;
      scanf("%d %d %d", &a, &b, &c);
      --a, --b;
      gg[a].emplace_back((edge) {b, c});
      rg[b].emplace_back((edge) {a, c});
    }

    using T = tuple< int, int, int, int >;
    priority_queue< T, vector< T >, greater< >> que;
    fill_n(**dp, 50 * 50 * (1 << 10), INF);
    dp[0][0][0] = 0;
    que.emplace(0, 0, 0, 0);

    auto push = [&](int latte, int malta, int beet, int cost)
    {
      if(cost < dp[latte][malta][beet]) {
        dp[latte][malta][beet] = cost;
        que.emplace(cost, latte, malta, beet);
      }
    };

    bool reach = false;

    while(!que.empty()) {
      int latte, malta, beet, cost;
      tie(cost, latte, malta, beet) = que.top();
      que.pop();
      if(latte == N - 1 && malta == N - 1) {
        printf("%d\n", cost);
        reach = true;
        break;
      }
      for(auto &e : gg[latte]) {
        if(E[latte] <= E[e.to]) {
          if(E[e.to] < E[malta]) {
            push(e.to, malta, beet, cost + e.cost + D[e.to]);
          } else if(E[e.to] == E[malta] || E[latte] == E[e.to]) {
            if((beet >> rev[e.to]) & 1) push(e.to, malta, beet, cost + e.cost);
            else push(e.to, malta, beet | (1 << rev[e.to]), cost + e.cost + D[e.to]);
          } else {
            push(e.to, malta, 1 << rev[e.to], cost + e.cost + D[e.to]);
          }
        }
      }


      for(auto &e : rg[malta]) {
        if(E[malta] <= E[e.to]) {
          if(E[e.to] < E[latte]) {
            push(latte, e.to, beet, cost + e.cost + D[e.to]);
          } else if(E[e.to] == E[latte] || E[malta] == E[e.to]) {
            if((beet >> rev[e.to]) & 1) push(latte, e.to, beet, cost + e.cost);
            else push(latte, e.to, beet | (1 << rev[e.to]), cost + e.cost + D[e.to]);
          } else {
            push(latte, e.to, 1 << rev[e.to], cost + e.cost + D[e.to]);
          }
        }
      }


    }


    if(!reach) puts("-1");
  }

}

Measured memory_bytes: 29376
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MAX_INF = 9223372036854775807;
//constexpr ll MOD = (1e9 + 7);
constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T> &v) {
	T ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}
/*
ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}
*/
bool sortreverse(ll a, ll b) {
	return a > b;
}

bool kansu(pll a, pll b) {
	return a.first < b.first;
}

ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

ll n,m,x,y,t;
vl a, b;
vl h,s,ls,mihon(100000);

class UnionFind {
public:
	vl parent;
	UnionFind(ll n) {
		parent = vl(n, -1);
	}

	ll root(ll n) {
		if (parent.at(n) < 0)return n;
		parent.at(n) = root(parent.at(n));
		return parent.at(n);
	}

	ll size(ll n) {
		return -parent.at(root(n));
	}

	bool connect(ll a, ll b) {
		if (root(a) == root(b))return false;
		a = root(a); b = root(b);
		if (size(a) < size(b))swap(a, b);
		parent[a] += parent[b];
		parent[b] = a;
		return true;
	}
};

int main() {
	cin >> n >> m;
	vl h(n);
	rep(i, 0, n) {
		cin >> h[i];
	}
	vvl graph(n, vl(0));
	a = vl(m); b = vl(m);
	rep(i, 0, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		graph[a[i]].push_back(b[i]);
		graph[b[i]].push_back(a[i]);
	}
	ll ans = 0;
	rep(i, 0, n) {
		ll hi = h[i];
		bool check = true;
		rep(j, 0, graph[i].size()) {
			if (h[graph[i][j]] >= h[i])check = false;
		}
		if (check)ans++;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 12232
n = int(input())

arr = [int(s) for s in input().split(" ")]

def calculate(n, arr):
    evenDict = {}
    oddDict = {}

    for i in range(0, n, 2):
        if oddDict.get(arr[i]) == None:
            oddDict.__setitem__(arr[i], 1)
        else:
            oddDict.__setitem__(arr[i], oddDict.get(arr[i]) + 1)

    for i in range(1, n, 2):
        if evenDict.get(arr[i]) == None:
            evenDict.__setitem__(arr[i], 1)
        else:
            evenDict.__setitem__(arr[i], evenDict.get(arr[i]) + 1)

    if (len(evenDict.values()) == 1) and (len(oddDict.values()) == 1):
        if arr[0] == arr[1]:
            return n // 2

    evenMaxIndex = max(evenDict, key=evenDict.get)
    oddMaxIndex = max(oddDict, key=oddDict.get)
    s1 = (n // 2) - evenDict[evenMaxIndex]
    s2 = (n - n // 2) - oddDict[oddMaxIndex]
    m1 = s1 + s2

    if evenMaxIndex == oddMaxIndex:
        if len(evenDict.items()) != 1 and len(oddDict.items()) != 1:
            evenDict.pop(evenMaxIndex)
            evenSecondMaxIndex = max(evenDict, key=evenDict.get)
            evenSecondMaxvalue = evenDict[evenSecondMaxIndex]
            oddDict.pop(oddMaxIndex)
            oddSecondMaxIndex = max(oddDict, key=oddDict.get)
            oddSecondMaxValue = oddDict[oddSecondMaxIndex]

            m2 = (n - n // 2) - oddSecondMaxValue
            m3 = (n // 2) - evenSecondMaxvalue

            return min(s2+m2,s1+m3)

        if len(evenDict.items()) == 1 and len(oddDict.items()) != 1:
            oddDict.pop(oddMaxIndex)
            oddSecondMaxIndex = max(oddDict, key=oddDict.get)
            oddSecondMaxValue = oddDict[oddSecondMaxIndex]
            m2 =  s1 + (n - n // 2) - oddSecondMaxValue
            return m2

        if len(evenDict.items()) != 1 and len(oddDict.items()) == 1:
            evenDict.pop(evenMaxIndex)
            evenSecondMaxIndex = max(evenDict, key=evenDict.get)
            evenSecondMaxvalue = evenDict[evenSecondMaxIndex]
            m3 =  s2 + (n // 2) - evenSecondMaxvalue
            return m3




    return (s1 + s2)


result = calculate(n, arr)

print(result)

Measured memory_bytes: 18016
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
ll a,b,c,d;
int main(){
    cin>>a>>b>>c>>d;
    ll ans=b/c-a/c+b/d-a/d-(b/(c*d/gcd(c,d))-a/(c*d/gcd(c,d)));
    if(a%c==0)ans++;
    if(a%d==0)ans++;
    if(a%(c*d)==0)ans--;
    ans=b-a+1-ans;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3528
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

monster = []
for i in range(N):
    monster.append(min(A[i]+A[i+1],B[i]))
    A[i+1] = min((A[i]+A[i+1])-monster[i],A[i+1])
print(sum(monster))

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

using namespace std;
#define PB push_back
#define REP(x,l,u) for(ll x=l;x<u;x++)
#define PII pair<int,int>
#define sz(v) (int)v.size()
#define MP(a,b) make_pair(a,b)
#define all(x) x.begin(),x.end()
#define dbg(x) cerr<<#x<<" is "<<x<<endl;
#define  fi first
#define se second
typedef long long ll;

ll n;
PII cur = MP(0,0);
ll t = 0;
int main(){
	cin>>n;
	REP(i,0,n){
		PII pos;
		ll nt;cin>>nt;
		ll d = nt-t;
		cin>>pos.fi>>pos.se;
		ll dis = abs(pos.fi-cur.fi)+abs(pos.se-cur.se);
		if(dis>d || (d-dis) %2== 1)cout<<"No",exit(0);
		
		
		
		cur = pos;
		t = nt;
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
using namespace std;
int main()
{
    vi v1,v2;
    int a,b,c,d,i,sum=0,ma=0;
    cin>>a>>b;
    for(i=0 ; i<b ; i++)
    {
        cin>>c;
        ma=c;
        v1.pb(c);


    }
    for(i=1;i<b ;i++)
    {
       v2.pb(v1[i]-v1[i-1]);
    }


    //cout<<v[v.size()-1]<<endl<<endl;
    v2.pb(a-ma+v1[0]);



    sort(v2.begin(),v2.end());
    //cout<<v[v.size()-2];
    for(i=0 ; i<v2.size()-1 ; i++)
    {
        //cout<<v[i]<<endl;
        sum+=v2[i];
    }

    cout<<sum<<endl;



    return 0;
}


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

using namespace std;
#define endl "\n"

const int MOD = 1e9 + 7;

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

    int64_t h;
    cin >> h;
    int64_t sum = 1;
    if(h == 1)
		cout << "1\n";
	else {
		while(sum <= h){
			sum *= 2;
		}
		cout << sum - 1 << "\n";
	}


	return 0;
}


Measured memory_bytes: 256
import math
a,b=(int(i) for i in input().split()) 
s=[int(i) for i in input().split()] 
n=[0,1,2,3,4,5,6,7,8,9]
n1 = [val for val in n if val not in s]
n1.sort()
keta=int(math.log10(a) + 1)
n_number=10-b
aa=str(a)
answer=[]
OKANE1=0
OKANE2=0
OKANE3=0
OKANE4=0
OKANE5=0

for i in range(n_number+1):
  for j in range(n_number+1):
    for k in range(n_number+1):
      for l in range(n_number+1):
        for m in range(n_number):
          if i!=0: 
            OKANE1=n1[i-1]
          if j!=0:          
            OKANE2=n1[j-1]
          if k!=0:           
            OKANE3=n1[k-1]
          if l!=0:           
            OKANE4=n1[l-1]
            
          OKANE5=n1[m]
          OKANE=10000*OKANE1+1000*OKANE2+100*OKANE3+10*OKANE4+OKANE5  
          if a<=OKANE:
            answer.append(OKANE)
print(min(answer))



Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,0,n){
        cin>>a[i];
    }
    ll res=0;
    ll sum=0;
    rep(i,0,n){
        sum+=a[i];
        if(i%2==0){
            if(sum<=0){
                // ng
                res+=abs(sum-1);
                sum=1;
            }
        }else{
            if(sum>=0){
                // ng
                res+=abs(sum+1);
                sum=-1;
            }
        }
        // debug(res);
        // debug(sum);
    }
    ll ans=res;
    // cout<<endl;
    res=0;
    sum=0;
    rep(i,0,n){
        sum+=a[i];
        if(i%2==1){
            if(sum<=0){
                // ng
                res+=abs(sum-1);
                sum=1;
            }
        }else{
            if(sum>=0){
                // ng
                res+=abs(sum+1);
                sum=-1;
            }
        }
        // debug(res);
        // debug(sum);
    }
    cout<<min(res,ans)<<endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = 2; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

//ll mpow(ll x, ll n) { ll y = 1; for (; n; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }
//struct Combination_ModP {
//    vector<ll> fact, inv;
//    Combination_ModP() : fact(MOD), inv(MOD) {
//        fact[0] = 1; for (int i = 1; i < MOD; ++i) fact[i] = fact[i - 1] * i % MOD;
//        for (int i = MOD - 1; i >= 0; --i) inv[i] = mpow(i, MOD - 2);
//    }
//    pair<ll, ll> mfact(ll n) const {
//        if (n == 0) return pair<ll, ll>(1, 0);
//        auto res = mfact(n / MOD);
//        res.first = res.first * (n / MOD % 2 ? MOD - fact[n % MOD] : fact[n % MOD]) % MOD;
//        res.second += n / MOD;
//        return res;
//    }
//    ll operator ()(int n, int k) const {
//        if (n < 0 || k < 0 || k > n) return 0;
//        auto f1 = mfact(n), f2 = mfact(n - k), f3 = mfact(k);
//        if (f1.second > f2.second + f3.second) return 0;
//        return f1.first * inv[f2.first * f3.second % MOD] % MOD;
//    }
//};

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

    //Combination_ModP C;
    if (A.find('2') == string::npos) {
        int ans = 0;
        //rep(i, N) ans = (ans + C(N - 1, i) * (A[i] == '3')) % MOD;
        rep(i, N) ans = (ans + (((N - 1) & i) == i) * (A[i] == '3')) % MOD;
        write(2 * ans);
    }
    else {
        int ans = 0;
        //rep(i, N) ans = (ans + C(N - 1, i) * (A[i] == '2')) % MOD;
        rep(i, N) ans = (ans + (((N - 1) & i) == i) * (A[i] == '2')) % MOD;
        write(ans);
    }
}

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

struct tree{
    int children_counter;
    bool if_leaf;
    tree* children[26];
};

vector<string> strings;
vector<vector<vector<int>>> border_alphabets;
vector<int> border_back;

tree* prefix_tree = new tree();
tree* prefix_tree_root;

void fill_border_alphabets(int strings_number_looking){
    border_alphabets[strings_number_looking].resize(26);
    for(int j = 0; j < 26; j++){
        border_alphabets[strings_number_looking][j].resize(26);
        for(int k = 0; k < 26; k++){
            border_alphabets[strings_number_looking][j][k] = 0;
        }
    }
    border_back[strings_number_looking] = 0;
    for(int j = 0; j < strings[strings_number_looking].size(); j++){
        for(int k = 0; k < 26; k++){
            if(prefix_tree -> children[k]){
                border_alphabets[strings_number_looking][strings[strings_number_looking][j] - 'a'][k] += prefix_tree -> children[k] -> children_counter;
            }
        }
        prefix_tree = prefix_tree -> children[strings[strings_number_looking][j] - 'a'];
        border_back[strings_number_looking] += prefix_tree -> if_leaf;
    }
    prefix_tree = prefix_tree_root;
}

int main(){
    int N;
    cin >> N;
    prefix_tree -> if_leaf = false;
    prefix_tree_root = prefix_tree;
    strings.resize(N);
    for(int i = 0; i < N; i++){
        cin >> strings[i];
        for(int j = 0; j < strings[i].size(); j++){
            if(prefix_tree -> children[strings[i][j] - 'a']){
                prefix_tree = prefix_tree -> children[strings[i][j] - 'a'];
            }else{
                prefix_tree -> children[strings[i][j] - 'a'] = new tree();
                prefix_tree = prefix_tree -> children[strings[i][j] - 'a'];
                prefix_tree -> if_leaf = false;
            }
            prefix_tree -> children_counter++;
        }
        prefix_tree -> if_leaf = true;
        prefix_tree = prefix_tree_root;
    }
    border_alphabets.resize(N);
    border_back.resize(N);
    for(int i = 0; i < N; i++){
        fill_border_alphabets(i);
    }
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int strings_number;
        string order;
        cin >> strings_number >> order;
        int ans = border_back[strings_number - 1];
        for(int j = 0; j < 26; j++){
            for(int k = 0; k < j; k++){
                ans += border_alphabets[strings_number - 1][order[j] - 'a'][order[k] - 'a'];
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 381824
#include<iostream>
#include<cstdio>
#include<utility>
#include<climits>
#include<cmath>
using namespace std;

int main()
{
	int i, j;

	char str[20] = {};
	for (i = 0; cin >> str[i]; i++)
	{}

	for (j = i - 1; j >= 0; j--)
	{
		cout << str[j] ;
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 1132
#include <cstdio>

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if(n & 1)
    for(int i = 1; i <= m; i++) printf("%d %d\n", i, n - i);
  else
    for(int i = 1; i <= m; i++)
      printf("%d %d\n", i, n - i - (i >= (n + 3) / 4));
}

Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

#define INF (int)1E6

struct seg
{
    int log, size;
    vector<int> v;
    seg(int n)
    {
        log = 0;
        while ((1 << log) < n)
        {
            log++;
        }
        size = (1 << log);
        v = vector<int>(2 * size, 0);
    }

    void set(int p, int x)
    {
        p += size;
        v[p] = x;
        for (int i = 1; i <= log; i++)
        {
            int parent = p >> i;
            v[parent] = max(v[2 * parent], v[2 * parent + 1]);
        }
    }

    int query(int l, int r)
    {
        int sml = 0, smr = 0;
        l += size;
        r += size;
        while (l < r)
        {
            if (l & 1)
                sml = max(sml, v[l++]);
            if (r & 1)
                smr = max(v[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return max(sml, smr);
    }

    int get(int p)
    {
        return v[p + size];
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    seg s(300010);
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int l = max(0, a[i] - k);
        int r = min(300000, a[i] + k);
        int tmp = s.query(l, r + 1) + 1;
        s.set(a[i], tmp);
        ans = max(ans, tmp);
    }

    cout << ans << endl;
}

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

#define ll long long 
#define pll pair<ll,ll> 

int main(){

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

	ll k;
	cin>>k;
	ll A[k];
	A[0]=7%k;
	for(ll i=1;i<k;i++){
		A[i]=(A[i-1]*10+7)%k;
	}
	ll ans=-1;
	for(ll i=0;i<k;i++){
		if(A[i]==0){
			ans=i+1;
			break;
		}
	}

	cout<<ans<<endl;

}


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

int main() {
	// your code goes here
	int a,b;
	while (cin >> a >> b) {
		
		int wa = a + b;
		//判定開始
		int ans = 1;
		while(1) {
			wa = wa/10;
			ans++;
			if (wa<10) break;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

# まだ解いてない配点を nokori として持つ
ans = float("inf")


def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        # G 点に満たなければ nokori のうち一番大きいものを解く
        if sum < g:
            use = max(nokori)
            # 解く問題が問題数を超えないように注意
            n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
            count += n
            sum += n * use * 100

        if sum >= g:
            ans = min(ans, count)
    else:
        # 総合スコア、解いた問題数、まだ解いてない問題を更新
        dfs(i + 1, sum, count, nokori)
        dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 +
            pc[i][1], count + pc[i][0], nokori - {i + 1})


dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)


Measured memory_bytes: 68092
import itertools
N = int(input())
arr = list(map(int, input().split()))
ans = 0
while sum(arr) != 0:
    tmp = [0]*N
    tmp2 = 0
    for i in range(N):
        if arr[i] != 0:
            tmp[i] = 1
            arr[i] -= 1
    gr = itertools.groupby(tmp)
    for key, group in gr:
        if key != 0:
            tmp2 += 1
    ans += tmp2
print(ans)

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

int main(){
    int n,r,ans=INT_MAX,tep=0;
    cin >> n ;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin >> x.at(i);
    }

    for(int i=1;i<=100;i++){
        for(int l=0;l<n;l++){
            tep+=(x.at(l)-i)*(x.at(l)-i);
        }
        ans=min(ans,tep);
        tep=0;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

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

                int N = scan.nextInt();

                long sum = 0;

                long mae = 0;
                long now = 0;

                for (int i = 0; i < N; i++) {
                	now = scan.nextLong();
                	if (now < mae) {
                		sum += mae - now;
                		now = mae;
                	}
                	mae = now;
                }

                System.out.println(sum);

                scan.close();

        }

}

Measured memory_bytes: 60260