akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict

n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr = [x - k for x in arr]

dct = defaultdict(int)
dct[0] = 1

for x in arr:
    for k, v in list(dct.items()):
        dct[k + x] += v

print(dct[0] - 1)


Measured memory_bytes: 3572
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn dividers(n: u32) -> u32 {
    let mut count = 0;
    for i in 1..n + 1 {
        if n % i == 0 {
            count += 1
        }
    }
    count
}

fn main() {
    let n = read::<u32>();
    let mut count = 0;
    for i in 1..n + 1 {
        if i % 2 != 0 && dividers(i) == 8 {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
ll s[N];
int main()
{
	ll i,j,k;
	for(i = 0;i < 4;i++)
		sl(s[i]);
	sort(s,s+4);
	if(s[0] == 1 && s[1] == 4 && s[2] == 7 && s[3] == 9)
		puts("YES");
	else
		puts("NO");
	return 0;
}

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

int N, M;
bool path[8][8];
bool used[8];
int ans = 0;

// 深さ優先探索（s:今いる頂点）
void dfs(int s) {
  bool all_used = true;
  for (int i = 0; i < N; i++) {
    if (!used[i]) all_used = false;
  }
  if (all_used) ans++;

  for (int i = 0; i < N; i++) {
    if (path[s][i] && !used[i]) {
      used[i] = true;
      dfs(i);
      used[i] = false;
    }
  }
}

int main() {
  cin >> N >> M;
  int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    path[a-1][b-1] = path[b-1][a-1] = true;
  }

  used[0] = true;
  dfs(0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> A >> B;
  if(A<10&&B<10)Out(A*B);
  else Out(-1);
}

Measured memory_bytes: 256
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
mod = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class UnionFind:
	def __init__(self, n):
		self.par = [i for i in range(n + 1)]
		self.rank = [0] * (n + 1)
		self.size = [1] * (n + 1)

	def find(self, x):
		if self.par[x] == x:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]

	def union(self, x, y):
		x = self.find(x); y = self.find(y)
		if x == y:
			return

		if self.rank[x] < self.rank[y]:
			self.size[y] += self.size[x]
			self.size[x] = 0
			self.par[x] = y
		else:
			self.size[x] += self.size[y]
			self.size[y] = 0
			self.par[y] = x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1

	def same_check(self, x, y):
		return self.find(x) == self.find(y)

	def getsize(self, x):
		x = self.find(x)
		return self.size[x]


def main():
	N, M = getlist()
	UF = UnionFind(N)
	for i in range(M):
		a, b = getlist()
		a -= 1; b -= 1
		UF.union(a, b)

	#最後に根更新
	for i in range(N):
		UF.par[i] = UF.find(i)

	res = 0
	for i in range(N):
		if UF.size[i] != 0:
			res += 1

	print(res - 1)




if __name__ == '__main__':
	main()

Measured memory_bytes: 76840
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

ans = 'No'
for i in range(N-M+1):
    for j in range(N-M+1):
        flg = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    flg = False
        if flg:
            ans = 'Yes'
print(ans)


Measured memory_bytes: 3060
n,k,q = map(int,input().split())
a = [int(input()) for i in range(q)]
point = [0]*n
for i in range(len(a)):
   point[a[i] - 1] += 1
ans = []
for i in range(n):
    point[i] = len(a) - point[i]
    if point[i] < k:
        ans.append("Yes")
    else:
        ans.append("No")
for i in ans:
    print(i)

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

int main(){
  int n,z,w;
  cin >> n >> z >> w;
  int a[n];
  for(int  i = 0; i < n; i++){
    cin >> a[i];
  }
  int x = abs(w - a[n-1]);
  if(n-2 >= 0){
    int y = abs(a[n-2] - a[n-1]);
    if(x > y){
    cout << x;
    }else{
      cout << y;
    }
  }else{
    cout << x;
  }
  cout << endl;
  return 0;
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner stdIn = new Scanner(System.in);

		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		int hantei=0;

		if (a<b)
			if(b<c)
				hantei=1;
			else
				hantei=0;
		else
			hantei=0;

		if(hantei==1)
			System.out.println("Yes");
		else
			System.out.println("No");

	}

}


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

bool dp[30001][4][1009];

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

	dp[0][0][0] = true;
	REP(i, n) REP(j, 4) REP(k, 1000) {
		if (dp[i][j][k] == false) continue ;
		dp[i + 1][j][k] = true;
		if (j < 3)
			dp[i + 1][j + 1][k * 10 + (s[i] - '0')] = true;
	}

	int cnt = 0;
	REP(i, 1000)
		if (dp[n][3][i])
			cnt++;

	cout << cnt << '\n';
	return 0;
}

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

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

  vector<int> a_s(a);
  int min_a;
  for (int i = 0; i < a; ++i) {
    cin >> a_s[i];
  }
  min_a = *min_element(a_s.begin(), a_s.end());

  vector<int> b_s(b);
  int min_b = 10000;
  for (int i = 0; i < b; ++i) {
    cin >> b_s[i];
  }
  min_b = *min_element(b_s.begin(), b_s.end());

  int answer = min_a + min_b;

  int temp = 0;
  int x, y, c;
  for (int i = 0; i < m; ++i) {
    cin >> x >> y >> c;
    temp = a_s[x-1] + b_s[y-1] - c;
    answer = min(answer, temp);
  }

  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 1024
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    S = SI()
    T = SI()
    ls, lt = len(S), len(T)
    ans = 1100
    for i in range(ls-lt+1):
        tmp = 0
        tS = S[i:i+lt]
        for k, t in zip(tS, T):
            if k != t:
                tmp += 1
        ans = min(ans, tmp)
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 9236
h,w = map(int,input().split())
grid = [list(input()) for i in range(h)]
row = {}
col = {}

for i in range(h):
    if "#" in grid[i]:
        row[i] = True
    else:
        row[i] = False

for j in range(w):
    c = False
    for i in range(h):
        if grid[i][j] == "#":
            c = True
    else:
        if c:
            col[j] = True
        else:
            col[j] = False

for i in range(h):
    o = False
    for j in range(w):
        if row[i] and col[j]:
            print (grid[i][j], end="")
            o = True
            pass
        else:
            pass
    if o:
        print ()


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

int main() {
	int N, A[200010], X=0; cin >> N;
	for(int i=0; i<N; ++i) cin >> A[i];
	long ans=0;
	for(int i=N-1; i>=0; --i){
	    if(X>0) --X;
	    if(X>A[i]){
	        cout << -1 << endl;
	        return 0;
	    }
	    if(X<A[i]){
	        if(A[i]>i){
	            cout << -1 << endl;
	            return 0;
	        }
	        ans += A[i];
	        X=A[i];
	    }
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int cost[90005];

int main()
{
    long long int h,w,d,q,l,r,loc[90005][2],x;
    cin>>h>>w>>d;
    for (int i=1;i<=h;i++)
        for (int j=1;j<=w;j++)
        {
            cin>>x;
            loc[x][0]=i;
            loc[x][1]=j;
        }
    for (int i=d+1;i<=w*h;i++)
        cost[i]=cost[i-d]+abs(loc[i][0]-loc[i-d][0])+abs(loc[i][1]-loc[i-d][1]);
    cin>>q;
    for (int i=1;i<=q;i++)
    {
        cin>>l>>r;
        cout<<cost[r]-cost[l]<<'\n';
    }
    return 0;
}


Measured memory_bytes: 2816
//01
#include<iostream>

using namespace std;

int main(){
  int d[101]={100000};
  for(int i=1;i<=100;i++){
    d[i]=d[i-1]+d[i-1]/20;
    if(d[i]%1000){
      d[i]=(d[i]/1000+1)*1000;
    }
  }
  for(int n;cin>>n;){
    cout<<d[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import numpy as np
ans=[0]*9
A=[0]*3
answer=0
for i in range(3):
    A[i]=list(map(int,input().split()))
N=int(input())
b=[0]*N
for j in range(N):
    b[j]=int(input())
def checkyoko(card):
    a=0
    for k in range(3):
        if card[k]==[1,1,1]:
            a=1
    return a
def checktate(card):
    a=0
    for l in range(3):
        if [card[0][l],card[1][l],card[2][l]]==[1,1,1]:
            a=1
    return a
def nanamecheck(card):
    a=0
    if [card[0][0],card[1][1],card[2][2]]==[1,1,1] or [card[0][2],card[1][1],card[2][0]]==[1,1,1]:
        a=1
    return a
counter=0
for m in range(3):
    for n in range(3):
        if A[m][n]in b:
            ans[counter]=1
        counter+=1
ans=np.array(ans)
ans=ans.reshape(3,3)
ans=ans.tolist()
answer=(checktate(ans)==1 or checkyoko(ans)==1 or nanamecheck(ans)==1)

if answer:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 12756
package main

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

const BUFSIZE = 10000000

var rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)

func main() {
	var n, k int
	var s string

	fmt.Scanf("%d %d", &n, &k)
	fmt.Scanf("%s", &s)

	for i, v := range s {
		if i == k-1 {
			fmt.Print(string(v + (97 - 65)))
		} else {
			fmt.Print(string(v))
		}
	}
	fmt.Println()
}

func NextLineInt() []int {
	buf := make([]byte, 0, BUFSIZE)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}

		buf = append(buf, l...)

		if !p {
			break
		}
	}
	str := strings.Split(string(buf), " ")
	l := len(str)

	ret := make([]int, l)

	for i := range str {
		// ret[i], ok = strconv.Atoi(str[i])
		v, ok := strconv.Atoi(str[i])

		if ok == nil {
			ret[i] = v
		}
	}

	return ret
}

func Bool2Int(b bool) int {
	if b {
		return 1
	} else {
		return 0
	}
}

func Abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func Min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func Distance(a, b int) int {
	return Abs(a - b)
}


Measured memory_bytes: 2944
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
# include <climits>
#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define yes(b) std::cout<< (b ? "Yes" : "No")
#define YES(b) std::cout<< (b ? "YES" : "NO")
using namespace std;
/*int ketawa(ll num) {
	int dig, sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}
*/
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, a[100], m = 10001, count = 1, sum = 0;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (a[i] == m) {
			count++;
		}
		else {
			sum += count / 2;
			count = 1;
		}
		if (i == n - 1) {
			sum += count / 2;
		}
		m = a[i];
	}
	cout << sum;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX(A,B) ((A) > (B) ? (A) : (B)) 

int dp[101][10001],v[100],w[100];
int n,W;
int main(void){
    scanf("%d%d",&n,&W);
    for(int i = 0;i < n;i++)
        scanf("%d%d",&v[i],&w[i]);

    for(int i = n - 1;i >= 0;i--){
        for(int j = 0;j <= W;j++){
            if(W < j + w[i])
                dp[i][j] = dp[i + 1][j];
            else{
                dp[i][j] = MAX(dp[i + 1][j],dp[i + 1][j + w[i]] + v[i]);
            }
        }
    }
    printf("%d\n",dp[0][0]);
    return 0;
}

Measured memory_bytes: 6588
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <unordered_map>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <random>
#include <chrono>
#include <bitset>
#include <fstream>
#include <sstream>

using namespace std;
using namespace std::chrono;

/*
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
*/

typedef long long ll;
typedef long double ld;

ll big = 1000000007ll;
ll n,m,k,r;



int main()
{

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll c1,c2,c3,c4,c5,c6;
    ll a,b,c,e;
    ll x;
    cin >> n >> x;
    vector<ll> A;
    for(c1 = 0; c1 < n; c1++){
        cin >> a;
        A.push_back(a);
    }
    ll ans = 0;

    for(c1 = 0; c1 < n-1; c1++){
        a = A[c1];
        b = A[c1+1];
        c = max(a+b-x,0ll);
        ans += c;
        A[c1+1] = max(b-c, 0ll);
    }
    cout << ans << "\n";


    return 0;
}


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

int main() {
    int n,res=0,x;
    cin>>n;
    x=n;
    while(x) {
        res+=x%10;
        x/=10;
    }
    if (n%res==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

#define ll long long
#define ld long double
#define ff first
#define ss second
#define eps 1e-9
#define pi acos(-1.0)
#define all(v) v.begin(),v.end()

#define MAX 500005

vector<ll> p;
bool vis[MAX];

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

    ll n;
    cin >> n;

    string s;
    cin >> s;

    map<char,ll> mp;
    for(char x:s)
        mp[x]++;

    ll ans = 0;

    ll tot = mp['R'];

    for(int i=0;i<tot;i++)
    {
        if(mp[s[i]] && s[i] == 'R')
        {
            mp[s[i]]--;
        }
    }

    cout << mp['R'] << endl;

    return 0;
}

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

int main() {

  int A,B;
  cin >> A >> B;
  int result = 0;
  for(int i = A;i<=B;i++){
    int top = i/1000;
    int bottom = (i%10)*10 + (i%100)/10;
   if(top == bottom) result++; 
  }
  cout << result << endl;	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>
#include <complex>

using namespace std;

#define endl '\n'

typedef complex<long long> point;

int semi(point &a) {
    if (a.imag() == 0 && a.real() >= 0) return 0;
    if (a.imag() > 0) return 0;
    return 1;
}

long long cross(point &a, point &b) {
    return imag(conj(a) * b);
}

long long dot(point &a, point &b) {
    return real(conj(a) * b);
}

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

    int n; cin >> n;

    vector<point> p(n);

    for (int i = 0; i < n; ++i) {
        long long x, y; cin >> x >> y;
        p[i] = point(x, y);
    }

    long long ans = 0;

    sort(p.begin(), p.end(), [&](point &a, point &b){
        int sa = semi(a), sb = semi(b);
        if (sa != sb) return sa < sb;
        if (cross(a, b) == 0)
            return dot(a, a) < dot(b, b);
        return cross(a, b) > 0;
    });

    for (int i = 0; i < n; ++i){
        auto x = p[i];
        p.push_back(x);
    }

    for (int i = 0; i < n; ++i) {
        point u(0);
        for (int j = 0; j < n; ++j) {
            u += p[i + j];
            ans = max(ans, real(conj(u) * u));
        }
    }

    cout.precision(15);
    cout << fixed << sqrtl((long double)ans) << endl;

    return 0;
}

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

typedef long long ll;

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

int N;
int p[51];

int main() {
  scanf("%d", &N);

  REP(i,N) scanf("%d", &p[i]);
  int cnt = 0;
  REP(i,N) {
    if (p[i] != i+1) cnt++;
  }

  if (cnt <= 2) printf("YES\n");
  else printf("NO\n");
  
  return 0;
}


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

set<int> st;

int N;
int main () {
    cin >> N;
    for(int i=0; i<N; i++) {
        int a;
        cin >> a;
        if( st.count(a) ) st.erase(a);
        else st.insert(a);
    }
    cout << st.size() << endl;
    return 0;
}


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

main() {
    map<pair<int,int>,bool> m;
    int N,M; cin >> N >> M;
    bool can=false;
    rep(i,M){
        int a,b; cin >> a >> b;
        pair<int,int> p;
        p=make_pair(a,b);
        m[p]=true;
    }
    for(int i=2;i<N;i++){
        pair<int,int> p1=make_pair(1,i),p2=make_pair(i,N);
        if(m[p1]&&m[p2]){can=true; break;} 
    }
    if(can)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;

    return 0;
}

Measured memory_bytes: 25216
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
#include <queue>
typedef long long int ll;
using namespace std;
int main(){
	int H,W,nowh,noww,nowdepth,count=0,mcount=0;
	char s;
	struct Corr{
		int x;
		int y;
		int depth;
	};
	queue<Corr> q;
	cin>>H>>W;
	vector<vector<int>> M(H+2,vector<int>(W+2,2));
	vector<int> y_vec={0,0,-1,1};
	vector<int> x_vec={-1,1,0,0};
	for(int i=1;i<H+1;i++){
		for(int j=1;j<W+1;j++){
			cin>>s;
			if(s=='.'){
				M[i][j]=-1;
			}
		}
	}
	for(int i=1;i<H+1;i++){
		for(int j=1;j<W+1;j++){
			count=0;
			if(M[i][j]==-1){
				Corr start={j,i,0};
				q.push(start);
				M[i][j]=0;
				while(!q.empty()){
					Corr now=q.front();
					q.pop();
					noww=now.x,nowh=now.y,nowdepth=now.depth;
					for(int k=0;k<4;k++){
						Corr next={noww+x_vec[k],nowh+y_vec[k],nowdepth+1};
						if(M[next.y][next.x]==-1){
							q.push(next);
							M[next.y][next.x]=0;
						}
					}
					count=nowdepth;
				}
				for(int k=0;k<H+2;k++){
					for(int l=0;l<W+2;l++){
						if(M[k][l]==0){
							M[k][l]=-1;
						}
					}
				}
			}
			if(mcount<count){
				mcount=count;
			}
			
		}
	}
	cout<<mcount<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev(i,n) for(int i = n-1; i >= 0; --i)
#define rev1(i,n) for(int i = n; i > 0; --i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};


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

  vector<mint> dp(3);
  mint tmp(1);
  rep(i,n) {
    vector<mint> ndp = dp;
    if(s[i] == 'A') {
      ndp[0] += (mint)tmp;
    }
    if(s[i] == 'B') {
      ndp[1] += dp[0];
    }
    if(s[i] == 'C') {
      ndp[2] += dp[1];
    }
    if(s[i] == '?') {
      ndp[0] = dp[0] * (mint)3 + tmp;
      ndp[1] = dp[1] * (mint)3 + dp[0];
      ndp[2] = dp[2] * (mint)3 + dp[1];
      tmp *= (mint)3;
    }
    dp = ndp;
  }
  cout << dp[2].x << "\n";
  return 0;
}


Measured memory_bytes: 3728
from sys import stdin
import itertools
import numpy as np
from numba import njit

@njit(cache=True)
def f():
    max_res=0
    for i in range(l):
        res=0
        for j in range(Q):
            if arrays[i][b[j]-1]-arrays[i][a[j]-1]==c[j]:
                res+=d[j]
        max_res=max(max_res,res)
    return max_res

#入力
readline=stdin.readline
N,M,Q=map(int,readline().split())
a=np.zeros(Q,dtype=np.int64)
b=np.zeros(Q,dtype=np.int64)
c=np.zeros(Q,dtype=np.int64)
d=np.zeros(Q,dtype=np.int64)
for i in range(Q):
    a[i],b[i],c[i],d[i]=map(int,readline().split())

arrays=np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)),dtype=np.int64)
l=len(arrays)

print(f())

Measured memory_bytes: 136408
import java.util.Scanner;

public class Main {

    public int findChoices(char[][] grid, int k) {
        int ans = 0;
        for (int mask = 0; mask < 1 << (grid.length + grid[0].length); mask++) {
            int count = 0;
            for (int i = 0; i < grid.length; i++) {
                for (int j = 0; j < grid[i].length; j++) {
                    if (grid[i][j] != '#') {
                        continue;
                    }
                    if ((mask & (1 << i)) != 0 || (mask & (1 << (grid.length + j))) != 0) {
                        continue;
                    }
                    count++;
                }
            }
            if (count == k) {
                ans++;
            }
        }
        return ans;
    }

    public static void main(String args[]) {
        Main chv = new Main();
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();
        char[][] grid = new char[h][w];
        for (int i = 0; i < grid.length; i++) {
            String row = sc.next();
            for (int j = 0; j < row.length(); j++) {
                grid[i][j] = row.charAt(j);
            }
        }
        System.out.println(chv.findChoices(grid, k));
    }
}


Measured memory_bytes: 35728
#include<stdio.h>
int main() {
	int a,b,c,i,s=0;
	scanf("%d %d",&a,&b);
	if(b<10) {
		c=a*10+b;
		for(i=1; i<c; i++) {
			if(c==i*i) {
				printf("Yes\n");
				s++;
				break;
			}
		}
		if(s==0) {
			printf("No\n");
		}
	} else if(b>=10&&b<100) {
		c=a*100+b;
		for(i=1; i<c; i++) {
			if(c==i*i) {
				printf("Yes\n");
				s++;
				break;
			}
		}
		if(s==0) {
			printf("No\n");
		}

	} else if(b=100) {
		c=a*1000+b;
		for(i=1; i<c; i++) {
			if(c==i*i) {
				printf("Yes\n");
				s++;
				break;
			}
		}
		if(s==0) {
			printf("No\n");
		}
	}
}

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

using namespace std;

int gcd(long long int a,long long int b){
    if(b == 0)return a;
    return gcd(b,a%b);
}

int main(){
    long long int n,k,tmp;
    cin >> n >> k;

    if(n%k == 0){
        cout << 0 << endl;
    }else{
        //out << gcd(max(n,k),min(n,k)) << endl;
        tmp = n%k;
        if(tmp < abs(tmp-k))
            cout << tmp << endl;
        else 
            cout << abs(tmp-k) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(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;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>=22){
        puts("bust");
    }else{
        puts("win");
    }

    return 0;
}

Measured memory_bytes: 256
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            List<string> spokeList = new List<string>();
            for (int i = 0; i < N; i++)
            {
                var tmpSpoke = Console.ReadLine();
                if (spokeList.Count > 0 && (spokeList.Last().Last() != tmpSpoke.First() || spokeList.Contains(tmpSpoke)))
                {
                    Console.WriteLine("No");
                    return;
                }
                spokeList.Add(tmpSpoke);
            }
            Console.WriteLine("Yes");
        }
        //static void Main(string[] args)
        //{
        //    var temp = new Atcoder.ABC130.D();
        //    temp.Run();
        //}

    }
}

Measured memory_bytes: 13152
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
using Graph=vector<vector<int>>;
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 n;
    cin>>n;
    vector<string> s(n);
    for(int i=0;i<n;++i) cin>>s[i];

    string t[4]={"AC","WA","TLE","RE"};
    vector<int> ans(4,0);
    for(int i=0;i<n;++i){
        for(int j=0;j<4;++j){
            if(s[i]==t[j]) ++ans[j];
        }
    }

    for(int i=0;i<4;++i){
        cout<<t[i]<<"  x  "<<ans[i]<<endl;
    }
}

Measured memory_bytes: 6432
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
      int n , m, k , s;
      cin >> n >> m;
      vector<vector<int>> sm;
      vector<int> pm;
      for(int i = 0; i < m ; i++){
          cin >> k;
          vector<int> ss;
          for(int j = 0; j < k ; j++){
              cin >> s;
              ss.push_back(s);
          }
          sm.push_back(ss);
      }
      int p;
      for(int i = 0; i < m ; i++){
          cin >> p;
          pm.push_back(p);
      }
      long ans = 0;
      bool flg;
      int t;
      for(int i = 0; i <  (1<<n)   ; i++){
          flg = true;
          for(int j = 0 ; j < m ; j++){
              t = 0;
              for(int l = 0; l < sm[j].size() ; l++){
                  if ((i>>(sm[j][l]-1)) & 1) t += 1;
              }
              if ( t % 2 != pm[j]) flg = false;
          }
          if(flg) ans += 1;
      }
      cout << ans << endl;
      
      return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map> 
using namespace std;

#define LL long long

//127
int main() {
	LL N, M;

	scanf("%lld %lld", &N, &M);

	LL pass_count[100010];
	memset(pass_count, 0, sizeof(pass_count));

	for (int i = 1; i <= M; i++) {
		LL L, R;

		scanf("%lld %lld", &L, &R);

		pass_count[L]++;
		pass_count[R + 1]--;
	}

	LL result = 0;
	for (int i = 1; i <= N; i++) {
		pass_count[i] += pass_count[i - 1];
		if (pass_count[i] == M) {
			result++;
		}
	}

	printf("%lld\n", result);

	return 0;
}

//126
/*
int main() {
	LL N, K;

	cin >> N >> K;

	static double dp[200100];
	memset(dp, 0, sizeof(dp));

	for (int i = 1; i <= N; i++) {
		dp[i] = 1.0 / (double)N;
	}

	for (LL i = 1; i < K; i++) {
		dp[i * 2] += dp[i] * 0.5;
	}

	double result = 0;

	for (LL i = K; i < 200100; i++) {
		result += dp[i];
	}

	printf("%0.11f\n", result);

	return 0;
}
*/

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String s = sc.next();
        String t = sc.next();
        String ans = " ";
        for(int i=0;i<a;i++){ans+=s.substring(i,i+1);
                             ans+=t.substring(i,i+1);
                            }
      
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
mod = 10**9+7

n = int(input())
c = list(map(int, input().split()))
c.sort()
left = 1
ans = 0
for i in range(n):
    k = n-1-i
    if k:
        cnt = pow(2, k, mod) + k*pow(2, k-1, mod)
        cnt *= pow(2, k, mod)
    else:
        cnt = 1
    ans += left*2*c[i]*cnt
    ans %= mod
    left *= 4
    left %= mod
print(ans)

Measured memory_bytes: 87628
s = input()
n = len(s)-1
ans = 0

for i in range(2**n):
    num = s[0]
    for j in range(n):
        if (i >> j) & 1:
            num += "+"
        num += s[j + 1]
    ans += sum(map(int, num.split("+")))
print(ans)

Measured memory_bytes: 9184
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w=sc.nextInt();
        int h=sc.nextInt();
        int max1=0;
        int min2=w;
        int max3=0;
        int min4=h;
        int n=sc.nextInt();
        int tmpx;
        int tmpy;
        for(int i=0;i<n;i++){
            tmpx=sc.nextInt();
            tmpy=sc.nextInt();
            switch(sc.nextInt()){
                case 1:
                    max1=Math.max(max1,tmpx);
                    break;
                case 2:
                    min2=Math.min(min2,tmpx);
                    break;
                case 3:
                    max3=Math.max(max3,tmpy);
                    break;
                case 4:
                    min4=Math.min(min4,tmpy);
            }
            
        }
        System.out.println(min2-max1<=0||min4-max3<=0?0:Math.abs((min2-max1)*(min4-max3)));
        
        
    }
 
    
}

Measured memory_bytes: 24020
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int n;string s;cin>>n>>s;
  vector<int> R;
  vector<int> G;
  set<int> B;
  for(int i = 0; n > i; i++){
    if(s[i]=='R')R.push_back(i);
    else if(s[i]=='G')G.push_back(i);
    else B.insert(i);
  }
  long long ans = 0;
  for(int i = 0; R.size() > i; i++){
    for(int j = 0; G.size() > j; j++){
      int mn = min(R[i],G[j]);
      int mx = max(R[i],G[j]);
      ans += B.size();
      if(B.find(mx+mx-mn) != B.end())ans--;
      if(B.find(mn-(mx-mn)) != B.end())ans--;
      if(!((mx-mn)%2) && B.find((mx+mn)/2) != B.end())ans--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i, 1, 5) --> {1,2,3,4}
// rep(i, 5, 1) --> {4,3,2,1}
// rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> va(n+1);
    vector<int> vb(n+1);
    vector<int> vc(n+1);
    vector<int> dpa(n+1, 0);
    vector<int> dpb(n+1, 0);
    vector<int> dpc(n+1, 0);
    rep(i, 1, n+1)
        cin >> va[i] >> vb[i] >> vc[i];
    rep(i, 1, n+1)
    {
        dpa[i] = va[i] + max(dpb[i-1], dpc[i-1]);
        dpb[i] = vb[i] + max(dpa[i-1], dpc[i-1]);
        dpc[i] = vc[i] + max(dpa[i-1], dpb[i-1]);
    }
    cout << max({dpa[n], dpb[n], dpc[n]});
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);//Ai-i
    ll sumation=0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        a[i]-=i+1;
        sumation+=a[i];
    }
    sort(a.begin(), a.end());
    ll b;
    if(n%2==1){
        b=a[n/2];
    }else{
        ll tmp=a[n/2]+a[n/2-1];
        b=tmp/2;
        if(tmp%2>0.5) b++;
        else if(tmp%2<-0.5) b--;
    }
    ll ans=0;
    for(int i=0; i<n; i++){
        ans+=abs(a[i]-b);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include <string>
#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

const double EPS = 1e-9;


int main(){
    int a, b;
    int n;
 
	while(cin >> a >> b >> n){
		int s = 0;
		int f = a;

		for(int i = 0; i < n; i++){
			f = f%b*10;
			s += f/b;
		}

		cout << s << endl;
	}
	

    return 0;
}

Measured memory_bytes: 1160
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B = map(int, input().split())

first = A
last = B
left = 0
if A % 2 == 1:
    first += 1
    left ^= A
if B % 2 == 0:
    last -= 1
    left ^= B

if ((last - first) // 2 + 1) % 2 == 0:
    print(left)
else:
    print(1 ^ left)

    

Measured memory_bytes: 3312
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<malloc.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, s[220], X;
int dp[220][100100];

signed main(){
    cin >> N >> X;
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }
    dp[0][X] = 1;
    sort(s, s + N, greater<int>() );
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= X; j++){
            (dp[i + 1][j] += dp[i][j] * (N - 1 - i) % mod) %= mod;
            (dp[i + 1][j % s[i]] += dp[i][j]) %= mod;
        }
    }
    int ans = 0;
    for(int i = 0; i <= X; i++){
        (ans += (dp[N][i] * i) % mod) %= mod;
    }
    cout << ans << endl;

    return 0;
}

/*

*/

Measured memory_bytes: 157184
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+1],b[n];
	for(int i=0;i<n+1;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	long long c=0;
	for(int i=0;i<n;i++)
	{
		if(b[i]>a[i])
		{
			c+=a[i];
			b[i]-=a[i];
			if(b[i]>a[i+1])
			{
				c+=a[i+1];
				a[i+1]=0;
			}
			else
			{
				c+=b[i];
				a[i+1]-=b[i];
			}
		}
		else 
		{
			c+=b[i];
		}
	}
	cout<<c<<endl;
	
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const int L = 1e5;

void dfs(const vec<int,2>& G, vector<int>& seen, int v, int& X, int& Y, int& M) {
  if (seen[v]) return;
  seen[v] = 1;
  M += G[v].size();
  if (v < L) {
    ++X;
  } else {
    ++Y;
  }
  for (int u : G[v]) {
    dfs(G, seen, u, X, Y, M);
  }
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vec<int, 2> G(2 * L);
    for (int i = 0; i < N; i++) {
      int X, Y;
      cin >> X >> Y;
      --X;
      --Y;
      G[X].push_back(Y + L);
      G[Y + L].push_back(X);
    }
    ll res = 0;
    vector<int> seen(2 * L, 0);
    for (int v = 0; v < 2 * L; v++) {
      if (seen[v]) continue;
      int X = 0, Y = 0, M = 0;
      dfs(G, seen, v, X, Y, M);
      res += 1ll * X * Y - M / 2;
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 13696
#include<iostream>
#include<cstdio>
using namespace std;
long long p[100005],N,Q,A;
int main() {
    cin>>N>>Q;
    for (int i=0;i<N;i++)scanf("%lld",&p[i]);
    for (int i=0;i<Q;i++){
        long long sum=0,R=0;cin>>A;
        long long cnt=0;
        for(int i=0;i<N;i++){
            while (R<N && sum+p[R]<=A) {
                sum+=p[R++];
            }
            if(sum>0){sum-=p[i];}
            cnt+=R-i;
            if(R<i+1)R=i+1;
        }
        cout << cnt << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* [💭] [💡] [🎈] */

using namespace std;

const ll mod = 1'000'000'007;
const int fctmax = 2000000;
ll fct[fctmax + 1], inv[fctmax + 1];

ll modpow(ll n, ll x) {
    ll p = 1;
    while (x) {
        if (x & 1) {
            p *= n;
            p %= mod;
        }
        n *= n;
        n %= mod;
        x /= 2;
    }
    return p;
}

ll modinv(ll n) {
    return modpow(n, mod - 2);
}

ll binom(ll n, ll k) {
    if (n < k) return 0;
    return (fct[n] * inv[k] % mod) * inv[n - k] % mod;
}

int cnt['z' + 1];

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

    fct[0] = 1;
    for (int i = 1; i <= fctmax; i++) fct[i] = fct[i - 1] * i % mod;
    inv[fctmax] = modinv(fct[fctmax]);
    for (int i = fctmax - 1; i >= 0; i--) inv[i] = (inv[i + 1] * (i + 1)) % mod;

    int k;
    string s;
    cin >> k >> s;

    ll sum = 0;
    for (ll i = k; i >= 0; i--) {
        sum += binom(k - i + s.length() - 1, s.length() - 1) * modpow(26, i) % mod * modpow(25, k - i) % mod;
        sum %= mod;
    }
    cout << sum;

    return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        var k = E.Range(1, n).Count(x => x.ToString().Length % 2 == 1);
        Console.WriteLine(k);
    }
}


Measured memory_bytes: 13268
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin >> s;
    map<char, int> mp;
    for(auto &x : s){
        mp[x]++;
        if(mp[x] > 1){
            cout << "no";
            return 0;
        }
    }
    cout << "yes";
    return 0;
}


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

rt = 0
res = 0
x = 0
s = 0

for lt in range(N):
    while rt < N and x ^ A[rt] == s + A[rt]:
        x ^= A[rt]
        s += A[rt]
        rt += 1
    res += rt - lt
    x ^= A[lt]
    s -= A[lt]

print(res)

Measured memory_bytes: 32092
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

#define MOD (1000000007)


main() {
    ll N,K; cin >> N >> K;
    int A[N]; rep(i,N) cin >> A[i];
    int cnt1=0,cnt2=0;
    rep(i,N){
        rep(j,N){
            if(i==j) continue;
            if(A[i]>A[j]){
                cnt2++;
                if(i<j) cnt1++;
            }
        }
    }
    ll a=(cnt1*K)%MOD; ll b=(K*(K-1)/2%MOD*cnt2)%MOD;
    cout << (a+b)%MOD << endl; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int a,b;cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b))<<endl;
	return 0;
}


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

int main() {
  int A, B, C, D, T;
  cin >> A >> B >> C >> D;
  T = (A + B) - (C + D);

  if (T > 0)
  {
    cout << "Left" << endl;
  }
  else if (T < 0)
  {
    cout << "Right" << endl;
  }
  else
  {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;

#define int long long 

const int M = 200;

int dp[M][M][2];   
int K; 
  
int countInRangeUtil(int pos, int cnt, int tight, vector<int> num) { 
    if (pos == num.size()) { 
        if (cnt <= K) 
            return 1; 
        return 0; 
    } 
  
    if (dp[pos][cnt][tight] != -1) 
        return dp[pos][cnt][tight]; 
  
    int ans = 0; 
   int limit = (tight ? 9 : num[pos]); 
  
    for (int dig = 0; dig <= limit; dig++) { 
        int currCnt = cnt; 
  
        if (dig != 0) 
            currCnt++; 
  
        int currTight = tight; 
  
        if (dig < num[pos]) 
            currTight = 1; 
  
        ans += countInRangeUtil(pos + 1, currCnt,currTight, num); 
    } 
    return dp[pos][cnt][tight] = ans; 
} 
  
int countInRange(string x) { 
    vector<int> num; 
    while (x.size()) { 
        num.push_back(x[x.size()-1] - '0'); 
        x.pop_back();
    } 
    reverse(num.begin(), num.end()); 
    memset(dp, -1, sizeof(dp)); 
    return countInRangeUtil(0, 0, 0, num); 
} 

int32_t main(){
   IOS;
 //    #ifndef ONLINE_JUDGE
 //        freopen("in.txt",  "r",  stdin);
 //        freopen("out.txt", "w", stdout);
 //    #endif
      
      string R;
      cin>>R;
      cin>>K;

       int val = countInRange(R);
      K--;
       int val2 = countInRange(R);

      cout<<val-val2; 

   return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int A, B;
	A = abs(a - x);
	B = abs(b - x);

	if (A <= B) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}
}

Measured memory_bytes: 3640