akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
	int n,div,cnt;
	while(scanf("%d",&n)){
		if(n==0)
		break;
		if(n<5)
		printf("0\n");
		else{
			cnt=0;
			div=5;
			while(div<=n){
				cnt+=n/div;
				div*=5;
			}
			printf("%d\n",cnt);
		}
	}
}

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

int main(void){
    int n; cin >> n;
    vector<int> d(n);
    
    for(int i = 0; i < n; i++){
        cin >> d.at(i);
    }
    
    sort(d.begin(), d.end());
    
    int low_bound = d.at(n/2 - 1);
    int upper_bound = d.at(n/2);
    
    
    cout << upper_bound - low_bound << endl;
        
    
}

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

#define MAX 200000
#define INF (1<<30)

int L[MAX],R[MAX];

long long Merge(int* A, int l, int mid, int r){
	int n1=mid-l, n2=r-mid;
	long long cnt=0;

	for(int i=0; i<n1; i++){
		// A [l<->mid) をLに格納
		L[i]=A[l+i];
	}
	for(int i=0;i<n2;i++){
		// A [mid<->r) をRに格納
		R[i]=A[mid+i];
	}

	L[n1]=INF;	R[n2]=INF;

	int i=0,j=0;
	for(int k=l; k<r; k++){
		if(L[i]<=R[j]){
			A[k]=L[i++];
		}else{
			cnt+=n1-i;
			/*
				Lの方の配列に残ってる個数が(n1-i)個。
				Rから要素を1個取り出す(これをxとする)たびに、その時Lに残ってる要素は
				xにとっての反転数。
			*/
			A[k]=R[j++];
		}
	}

	return cnt;
}
long long MergeSort(int* A, int l, int r){
	int cnt=0;
	long long v1=0,v2=0,v3=0;
	if(r-l>1){
		int mid=(l+r)/2;
		v1+=MergeSort(A, l, mid);
		v2+=MergeSort(A, mid, r);
		v3+=Merge(A, l, mid, r);
	}

	return v1+v2+v3;

}


int main(){
	int A[MAX];
	int n;	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];

	long long ans=MergeSort(A, 0, n);

	//for(int i=0;i<n;i++){
	//	if(i)cout<<" ";
	//	cout<<A[i];
	//}cout<<endl;
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 4656
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long LL;
LL a[maxn], b[maxn];
 
int main(void)
{
    LL N;
    scanf("%lld", &N);
    LL sum = 0;
    for(int i = 1; i <= N; i++) scanf("%lld", a + i), sum = sum + a[i];
    LL div = (1 + N) * (LL) N / 2;
    if(sum % div) {puts("NO"); return 0;}
    LL rd = sum / div;
    for(int i = 1; i < N; i++) b[i] = a[i+1] - a[i];
    b[N] = a[1] - a[N];
    LL ok = 1, cnt = 0;
    for(int i = 1; i <= N; i++)
    {
        b[i] -= rd;
        if(b[i] > 0 || b[i] % N) {ok = 0; break;}
        cnt -= b[i] / N;
    }
    if(cnt != rd) ok = 0;
    puts(ok ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 1792
function Main(input) {
	input = input.split(" ").map(a => parseInt(a));
	var N = input[0];
	var K = input[1];
	
	var ans = 0;
	if(K === 0) ans = N * N;
	else
	for(var b = K + 1; b <= N; b++){
		var t = Math.floor(N / b);
		ans += (b - K) * t;
		ans += Math.max((N - t * b) - K + 1, 0);
	}
	
	console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<stdio.h>
int main(void){
  int i,x,y,z,s,a;
    scanf("%d",&x);
    scanf("%d",&y);
    if(x<y){
      s=x;
      x=y;
      y=s;
    }
    scanf("%d",&z);
    if(x<z){
      s=x;
      x=z;
      z=y;
      y=s;
    }
    if(x>=z&&y<z){
    s=y;
    y=z;
    z=s;
}
    for(i=0;i<7;i++){
      scanf("%d",&a);
      if(a>x){
	s=x;
	x=a;
	z=y;
	y=s;
	a=0;
      }
      if(x>=a&&a>y){
	s=y;
	y=a;
	z=s;
	a=0;
      }
      if(y>=a&&z<a){
	z=a;
      }
    }
    printf("%d\n",x);
    printf("%d\n",y);
    printf("%d\n",z);
    return(0);
}

Measured memory_bytes: 2688
import java.util.Scanner;

//Rotation of a Pattern
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[][] s = new char[8][8];
		for(int i=0;i<8;i++)s[i]=sc.next().toCharArray();
		for(int r=90;r<=270;r+=90){
			System.out.println(r);
			char[][] t = new char[8][8];
			for(int i=0;i<8;i++){
				for(int j=0;j<8;j++)t[i][j]=s[7-j][i];
				System.out.println(new String(t[i]));
			}
			s = t;
		}
	}
}

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

using namespace std;

int k;
string s;

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

    cin >> k >> s;

    for(int i = 0; i < min(k, (int)s.size()); i++)
        cout << s[i];
    if(k < (int)s.size())
        cout << "...";

    return 0;
}


Measured memory_bytes: 3624
def main():
    n = int(input())
    xd = [map(int, input().split()) for _ in range(n)]
    mod = 998244353
    INF = 10 ** 10

    xx = [(x, x + d, i) for i, (x, d) in enumerate(xd, 1)]
    xx.sort()
    c = [[] for _ in range(n + 1)]
    stack = [(INF, 0)]
    for l, r, i in xx:
        while stack[-1][0] <= l:
            stack.pop()

        ip = stack[-1][1]
        c[ip].append(i)
        stack.append((r, i))

    dp = [1] * (n + 1)
    for _, _, u in xx[::-1]:
        for v in c[u]:
            dp[u] *= dp[v]
            dp[u] %= mod

        dp[u] += 1
        dp[u] %= mod

    for v in c[0]:
        dp[0] *= dp[v]
        dp[0] %= mod

    ans = dp[0]
    print(ans)


if __name__ == "__main__":
    main()


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

int A, B;

int main() {
    cin >> A >> B;

    cout << max({A + B, A - B, A * B}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string s;
    cin>>s;
    vector<string>week={"SAT","FRI","THU","WED","TUE","MON","SUN"};
    rep(i,7){
        if(s==week.at(i)){
            cout<<i+1<<endl;
        }
    }
}

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

int main() {
	long long L ,R,q1,q2,mi,pq;
	cin >> L>>R;
	mi = 2018;
	for (long long i=L;i<R;i++){
		for (long long k=i+1;k<=R;k++){
			q1=i%2019;
			q2=k%2019;
			pq=(q1*q2)%2019;
			mi = min(mi,pq);
			if(mi == 0){
				break;
			}
		}
		if (mi == 0){
			break;
		}
	}
	cout << mi << endl;
}


Measured memory_bytes: 256
s = input()
cnt = 0
for i in range(0,len(s),2):
    if s[i] == 'L':
        cnt += 1
        break
for i in range(1,len(s),2):
    if s[i] == 'R':
        cnt += 1
        break
if cnt == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

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

    for(int i=n-1;i>=0;i-=2){
        printf("%d ",a[i]);
    }
    for(int i=n%2;i<n;i+=2){
        printf("%d ",a[i]);
    }
    
    printf("\n");
}

Measured memory_bytes: 2816
N, K = map(int, input().split())
S = list(input())

s_ = S[K-1]
if s_ == 'A':
  s_ = 'a'
elif s_ == 'B':
  s_ = 'b'
elif s_ == 'C':
  s_ = 'c'

S[K-1] = s_

print(''.join(S))

Measured memory_bytes: 3060
#F
import math
N = int(input())

m = int(math.sqrt(N-1))
Myaku = []
for i in range(1,m+1):
    if (N-1)%i == 0:
        if i != 1:
            Myaku.append(i)
        if (N-1)//i != i:
            Myaku.append((N-1)//i)
            
ans = len(Myaku)

n = int(math.sqrt(N))
Nyaku = []
for i in range(1,n+1):
    if N%i == 0:
        if i != 1:
            Nyaku.append(i)
        if N//i != i:
            Nyaku.append(N//i)
            
for ny in Nyaku:
    X = N
    while X%ny == 0:
        X //= ny
    if X%ny == 1:
        ans+=1
        
print(ans)
#print(Myaku,Nyaku)




Measured memory_bytes: 40428
from collections import defaultdict
n, x, y = map(int, input().split())
x -= 1
y -= 1
dd = defaultdict(int)
for i in range(n-1):
    for j in range(i+1, n):
        sp = min(j-i, abs(i-x)+abs(j-y)+1)
        dd[sp] += 1
for i in range(1, n):
    print(dd[i])


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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    for (int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    auto bfs = [&] (int s) -> vector<int> {
        vector<int> ret(n, -1);
        queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (auto u : g[v]) if (ret[u] == -1) {
                ret[u] = ret[v] + 1;
                que.push(u);
            }
        }
        return ret;
    };
    
    int fennec = 0, snuke = 0;
    vector<int> fen = bfs(0), snu = bfs(n-1);
    for (int i = 0; i < n; i++) {
        if (fen[i] <= snu[i]) fennec++;
        else snuke++;
    }
    
    cout << (snuke < fennec ? "Fennec" : "Snuke") << endl;
    return 0;
}

Measured memory_bytes: 6528
import java.util.*;
import java.util.stream.IntStream;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
    int K = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = sc.nextInt();
    int[] dp = new int[N];
    int b = K;
    for (int i = 1; i < N; i++) {
      if (i <= K) b--;
      for (int j = 1; j <= K-b; j++) {
        if (j == 1) {
          dp[i] = dp[i-j] + Math.abs(a[i] - a[i-j]);
        } else {
          dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(a[i] - a[i-j]));
        }
      }
    }
    System.out.println(dp[N-1]);
  }
}

Measured memory_bytes: 50648
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <iostream>
using namespace std;
int main(){
	int n;
	int ans = 1;
	int cur = 0 ;
	cin >> n;
	for(int i = 1; ;i++){
		cur += i;
		if(cur >= n){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  map<char,int> m;
  REP(i, 4) {
    if(m.find(S[i]) == m.end()) {
      m.insert({S[i],1});
    } else {
      m.find(S[i])->second++;
    }
  }
  if (m.size() == 2 && m.begin()->second == 2 && (m.begin()++)->second == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("tree-vectorize")
#include <cstdio>

constexpr int MOD = 1e9 + 7;

constexpr long long exp(const int &a, const int &b) {
  // Calculate a ** b by binary exponentation
  long long ret  = 1;
  long long base = a;
  int exponent   = b;

  while (exponent) {
    if (exponent & 1) {
      ret *= base;
      ret %= MOD;
    }
    base *= base;
    base %= MOD;
    exponent >>= 1;
  }

  return ret;
}

constexpr long long binomial(const int &n, const int &r) {
  // Calculate binomial(n, r)
  //
  // to do this, we need to calculate these values:
  //  - n * (n-1) * (n-2) * ... * (n-r+1)
  //  - 1/r! (inverse of the r factorial)
  //
  // Calculate n * (n-1) * (n-2) * ... * (n-r+1) using for loop
  long long prod_r = 1;

  for (int i = n - r + 1; i <= n; i++) {
    prod_r *= i;
    prod_r %= MOD;
  }

  // Calculate a! using for loop
  long long r_factorial = 1;

  for (int i = 1; i <= r; i++) {
    r_factorial *= i;
    r_factorial %= MOD;
  }

  // Calculate 1/a! by Fermat's little theorem
  //
  // Fermat's little theorem:
  //   x^(p-2) = 1/x (mod p)
  constexpr int exponent    = MOD - 2;
  long long inv_r_factorial = exp(r_factorial, exponent);

  // Return binomial(n, a)
  return (prod_r * inv_r_factorial) % MOD;
}

int main() {
  // Input
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);

  // Want to calculate 2 ** n - binomial(n, a) - binomial(n, b) - 1
  //
  // Calculate 2 ** n
  long long two_to_the_n = exp(2, n);

  // Calculate binomial(n, a), binomial(n, b)
  long long binomial_n_a = binomial(n, a);
  long long binomial_n_b = binomial(n, b);

  // Output
  long long ans = (two_to_the_n - binomial_n_a - binomial_n_b - 1) % MOD;

  printf("%lld\n", ans < 0 ? ans + MOD : ans);
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


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

	int half_n = n / 2;

	for (int i = 0; i < n; i++) {
		if (x[i] < a[half_n]) cout << a[half_n] << endl;
		else cout << a[half_n - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 3712
//package reedeka;
import java.util.*;
import java.lang.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long x, y;
		x = sc.nextLong();
		y = sc.nextLong();
		long i;
		int count = 1;
		for(i=x; i<=y; i++) {
			if(x*2 <=y) {
				count++;
				x = x*2;
			}
			else {
				break;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 35800
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

int V[200001];
bool used[200001];

void dfs(int i, int n, const vector<vector<int>> &E){
    if (used[i])
        return;
    used[i] = true;
    V[i] += n;
    for (const auto &e: E[i])
        dfs(e, V[i], E);
}


class DKi {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int n, q;
    cin >> n >> q;

    vector<int> A(n), B(n);
    for (int i = 0; i < n - 1; i++)
        cin >> A[i] >> B[i];

    vector<int> P(q), X(q);
    for (int i = 0; i < q; i++)
        cin >> P[i] >> X[i];

    vector<vector<int>> E(n + 1);
    for (int i = 0; i < n; i++)
        E[A[i]].push_back(B[i]);


    for (int i = 0; i < q; i++)
        V[P[i]] += X[i];

    dfs(1, 0, E);

    for (int i = 1; i <= n; i++)
        cout << V[i] << " ";
    cout << endl;

}
};

int main() {
	DKi solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 26880
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main()
{ 
    int n;
    cin>>n;
    string s;
    cin>>s;
    int count=0, ans=0;
    for(int i=0;i<n;i++) {
        if(s[i]=='R') count++;
    }
    for(int i=0;i<count;i++){
        if(s[i]!='R') ans++;
    }
    cout<<ans;
}
            

Measured memory_bytes: 3760
#include <stdio.h>
int main(void){
    int n,p,max=0,sum;
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&p);
        if(p>max){
            sum+=p/2;
            sum+=max/2;
            max=p;
        }else{
            sum+=p;
        }
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 128
<?php
  
fscanf(STDIN,"%d",$n);
$li = array();
$count = 0;
$max=0;
$max_i = 1;
for($i=1;$i<=$n;$i++){
  $i_update = $i;
  for($j=0;$j<$i;$j++){
    if($i_update%2==0){
      $i_update /= 2;
      $count++;
    }
  }
  if($max<$count){
    $max = $count;
    $max_i = $i;
  }
  $count = 0;
}
      

echo $max_i."\n";




 

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

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

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      s: String,
    }
    if s == "Sunny" {
        puts!("{}\n", "Cloudy");
    } else if s == "Cloudy" {
        puts!("{}\n", "Rainy");
    } else {
        puts!("{}\n", "Sunny");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

struct UnionFind{
    int sz;     // vertex number
    vector<int> par;
    vector<int> rank;

    UnionFind(int n) : sz(n) {
        par.resize(sz);
        rank.assign(sz, 0);
        for(int i = 0; i < sz; ++i){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x) return x;
        else    return par[x] = find(par[x]);
    }

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

    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)  return;
        if(rank[x] < rank[y])   par[x] = y;
        else{
            par[y] = x;
            if(rank[x] == rank[y])  ++rank[x];
        }
    }
};

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

    int N, K, L;
    cin >> N >> K >> L;
    UnionFind road(N), railway(N);
    for(int i = 0; i < K; ++i){
        int x, y;
        cin >> x >> y;
        road.unite(x - 1, y - 1);
    }
    for(int i = 0; i < L; ++i){
        int x, y;
        cin >> x >> y;
        railway.unite(x - 1, y - 1);
    }
    map<P, int> mp;
    for(int i = 0; i < N; ++i){
        ++mp[P(road.find(i), railway.find(i))];
    }
    for(int i = 0; i < N; ++i){
        cout << mp[P(road.find(i), railway.find(i))];
        cout << ((i == N - 1) ? '\n' : ' ');
    }
}

Measured memory_bytes: 17640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=22,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll n;
ll d[MAXn][MAXn];
ll dp[1<<(MAXn-1)];
void add(ll &x,ll y){
  x = x+y;
  while (x >= MOD) x -= MOD;
}
ll cal(ll mask){
  if (mask == 0) return 1;
  if (dp[mask] != -1) return dp[mask];

  ll ct = 0;
  REP (i,n) if ((1<<i)&mask) ct++;

  ll ret = 0;
  REP1 (i,n) if ((1<<(i-1))&mask && d[ct][i]) add(ret,cal(mask^(1<<(i-1))));
  return dp[mask] = ret;
}
int main(){
  IOS();
  cin >> n;
  REP1 (i,n) REP1 (j,n) cin >> d[i][j];
  RST(dp,-1);

  cout << cal((1<<n)-1) << endl;
}


Measured memory_bytes: 16640
mod = 10**9+7
from bisect import bisect
from collections import defaultdict
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

dp = [[0]*(M+1) for _ in range(N+1)]

for n in range(N):
    for m in range(M):
        dp[n][m] = dp[n-1][m]+dp[n][m-1]-dp[n-1][m-1]
        if S[n]==T[m]:
            dp[n][m] += dp[n-1][m-1]+1
        dp[n][m] %= mod

print(dp[N-1][M-1]+1)

Measured memory_bytes: 73308
from itertools import chain
 
R = lambda: map(int, input().split())
n, k = R()
v = list(R())
a = sorted((x, i) for i, x in enumerate(v) if x < 0)
r = 0
for i in range(1, min(n, k) + 1):
    for j in range(i):
        r1, r2 = range(i - j), range(n - j, n)
        s = sum(v[m] for m in chain(r1, r2))
        j = i
        for x, m in a:
            if j == k:
                break
            if m in r1 or m in r2:
                s -= x
                j += 1
        r = max(r, s)
print(r)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    int N; cin >> N;
    vector<ll> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    ll ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 30; j >= 1; j--){
            if(A[i] % (ll)pow(2, j) == 0){
                ans+=j;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include<algorithm>  
using namespace std; 
   
long long computeXOR(const long long int n) 
{ 
      
    switch(n & 3)  
    { 
    case 0: return n;     
    case 1: return 1;        
    case 2: return n + 1;      
    case 3: return 0;       
    } 
} 


int main() 
{ 

    long long int A,B;
    cin >> A>>B;
    long long int b = computeXOR(A-1) ^ computeXOR(B);
    cout << b << endl;

    return 0; 
}

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

int main() {
    int R[200000];
    int n;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> R[i];
    }

    int maxv = -2000000000;
    int minv = R[0];

    for (int i = 1; i < n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;

}



Measured memory_bytes: 3872
def main():
    N, T = map(int, input().split())
    data = [tuple(map(int, input().split())) for _ in range(N)]

    less_than_T_data = list(filter(lambda ct: ct[1] <= T, data))

    if less_than_T_data:
        print(min(less_than_T_data, key=lambda ct: ct[0])[0])
    else:
        print('TLE')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
use std::io;
use std::str::FromStr;
use std::cmp::min;

fn input_tuple() -> (usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let (n, k) = input_tuple();
    let mut h_vec: Vec<u64> = Vec::new();
    for _ in 0..n {
        let h: u64 = input();
        h_vec.push(h);
    }
    h_vec.sort();
    let mut ans = std::u64::MAX;
    for i in 0..(n-k+1) {
        ans = min(ans, h_vec[i+k-1] - h_vec[i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 3192
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout);
using namespace std;
const int MAXN = 1000005;
int n, s[MAXN], Q;
int ne[MAXN][27], ST[MAXN][19];

void get_str() {
    char ch = getchar();
    while (ch < 'a' && ch > 'z')
        ch = getchar();
    while (ch >= 'a' && ch <= 'z')
        s[++n] = ch - 'a', ch = getchar();
}

int main() {
    get_str();
    for (int i = n; i; i--) {
        ne[i][s[i]] = i + 1;
        for (int j = s[i] + 1; j <= 26; j++)
            ne[i][j] = ne[ne[i][j - 1]][j - 1];
        for (int j = 0; j < s[i]; j++)
            ne[i][j] = ne[ne[i][26]][j];
        ST[i][0] = ne[i][26];
    }
    for (int j = 1; j <= 18; j++)
        for (int i = 1; i <= n; i++)
            ST[i][j] = ST[ST[i][j - 1]][j - 1];
    scanf("%d", &Q);
    for (int t = 1, l, r; t <= Q; t++) {
        scanf("%d %d", &l, &r);
        for (int i = 18; ~i; i--)
            if (ST[l][i] <= r + 1 && ST[l][i])
                l = ST[l][i];
        printf(l == r + 1 ? "Yes\n" : "No\n");
    }
    return 0;
}


Measured memory_bytes: 96768
from collections import defaultdict
from math import atan2
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m
def solve():
    H, W = map(int, readline().split())

    MP = []
    MP.append([0]*(W+2))
    MP.extend([[0] + list(map(".#".index, readline().strip())) + [0] for i in range(H)])
    MP.append([0]*(W+2))

    R = defaultdict(int)
    for i in range(H+1):
        for j in range(W+1):
            if MP[i+1][j] != MP[i][j+1] or MP[i][j] == MP[i+1][j+1]:
                continue
            if MP[i][j] == MP[i][j+1]:
                v = 1
            else:
                v = -1
            x = j; y = H-i
            if x == 0:
                R[0, 1] += v
            elif y == 0:
                R[1, 0] += v
            else:
                g = gcd(x, y)
                R[x//g, y//g] += v
    *PS, = R.items()
    PS.sort(key = lambda p: atan2(p[0][1], p[0][0]), reverse=1)
    ans = 0; cur = 1
    for (x, y), v in PS:
        cur += v
        ans = max(ans, cur)
    write("%d\n" % ans)
solve()


Measured memory_bytes: 25276
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

rest = 0
c = 0
for i in range(len(Bs)):
    if As[i] >= rest:
        ene = As[i] - rest
        c += rest
        if ene >= Bs[i]:
            c += Bs[i]
            rest = 0
        else:
            c += ene
            rest = Bs[i] - ene
    else:
        c += As[i]
        rest = Bs[i]
if As[i+1] >= rest:
    c += rest
else:
    c += As[i+1]
print(c)



Measured memory_bytes: 18624
#include <bits/stdc++.h>
#define endl        '\n'
#define pi          2*acos(0.0)
#define pb(a)       push_back(a)
#define db          double
#define ld          long double
#define ll          long long
#define ull         unsigned long long
#define mod         1000000007
#define inf         1000000000000000001
#define sqr(x)      (x) * (x)
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   ((a/gcd(a,b)) * b)
#define debug(x) 	cerr << #x << " = " << (x) <<endl
#define all(x)      (x).begin(), (x).end()
#define unsyncIO    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;

int main()
{
    //freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
    int n;
    string s;
    int cnt = 0;
    cin >> n;
    cin >> s;
    for (int i = 0; i < n; i++) {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3624
n = int(input())
ans = []
start = "a"
stack = []
stack.append(start)
num = ord("a")
while stack:
    v = stack.pop()
    if len(v) == n:
        ans.append(v)
        continue
    s = list(v[::])
    s.sort()
    nex_num = ord(s[-1])
    for i in range(num, nex_num + 2):
        tuika = chr(i)
        stack.append(v + tuika)
print(*ans[::-1], sep="\n")


Measured memory_bytes: 14396
#include<stdio.h>

int main(void){

  int a,b,r,tmp;

  scanf("%d %d",&a,&b);
 
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  printf("%d\n", b);
 
  return 0;
}



Measured memory_bytes: 2144
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

const int MAX_N = 100100;

int main()
{
  int n;
  cin >> n;
  ll a[3 * MAX_N];
  for (int i = 0; i < 3 * n; i++)
  {
    cin >> a[i];
  }
  priority_queue<ll> pque;
  ll red[3 * MAX_N], blue[3 * MAX_N];
  memset(red, 0, sizeof(red));
  memset(blue, 0, sizeof(blue));
  for (int i = 0; i < n; i++)
  {
    pque.push(-1 * a[i]);
    red[n - 1] += a[i];
  }
  for (int i = n; i < 2 * n; i++)
  {
    pque.push(-1 * a[i]);
    ll p = pque.top();
    red[i] = red[i - 1] + a[i] + p;
    pque.pop();
  }

  while (!pque.empty())
  {
    pque.pop();
  }

  for (int i = 3 * n - 1; i >= 2 * n; i--)
  {
    pque.push(a[i]);
    blue[2 * n - 1] += a[i];
  }
  for (int i = 2 * n - 2; i >= n - 1; i--)
  {
    pque.push(a[i + 1]);
    ll p = pque.top();
    blue[i] = blue[i + 1] + a[i + 1] - p;
    pque.pop();
  }
  ll ans = -1 * 1e15;
  for (int i = n - 1; i < 2 * n; i++)
  {
    ans = max(ans, red[i] - blue[i]);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 8440
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
    int X, Y, Z;
    cin >> X >> Y >> Z;

    swap(X, Y);
    swap(X, Z);

    cout << X << " " << Y << " " << Z << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  n = ni()
  t = 0
  for i in range(1, n + 1):
    t += i
    if t >= n:
      print(i)
      return
main()

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

int main(){
    int n;
    cin >> n;
    int v[n];
    rep(i, n) cin >> v[i];
    int a[100010] = {}, b[100010] = {};
    rep(i, n / 2){
        a[v[2 * i]] ++;
        b[v[2 * i + 1]] ++;
    }
    vector<pair<int, int>> A, B;
    rep(i, 100010){
        if(a[i] != 0) A.push_back(make_pair(a[i], i));
        if(b[i] != 0) B.push_back(make_pair(b[i], i));
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    reverse(A.begin(),A.end());
    reverse(B.begin(),B.end());

    int cnta1 = A[0].first, cntb1 = B[0].first;
    int cnta2, cntb2;
    if (A.size() >= 2) cnta2 = A[1].first;
    if (B.size() >= 2) cntb2 = B[1].first;

    if (A[0].second != B[0].second) cout << n - (cnta1 + cntb1) << endl;
    else cout << min(n - (cnta2 + cntb1), n - (cnta1 + cntb2)) << endl;

    return 0;
}

Measured memory_bytes: 2428
#include <stdio.h>

int main(void){
 
  int r,d,x,set;
  set = 0;
  scanf("%d %d %d",&r,&d,&x);
  set = x;
  for(int i=0;i<10;i++){
    set = set * r -d;
  	printf("%d\n",set);
  }
  
  return 0;
}


Measured memory_bytes: 128
local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1], x) then return 1 end
  if comp(ary[num], x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid], x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, m = io.read("*n", "*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
table.sort(a)
local asum = {a[1]}
for i = 2, n do
  asum[i] = asum[i - 1] + a[i]
end

local function solve(x)
  local cnt = 0
  for i = 1, n do
    local dst = x - a[i]
    local pos = lower_bound(a, dst)
    cnt = cnt + n + 1 - pos
  end
  return m <= cnt
end

local min, max = 0, 200001
while 1 < max - min do
  local mid = mfl((max + min) / 2)
  if solve(mid) then
    min = mid
  else
    max = mid
  end
end
local ret = 0LL
local mcnt = 0
for i = 1, n do
  local dst = min - a[i]
  local pos = lower_bound(a, dst)
  if pos == 1 then
    ret = ret + asum[n] + n * a[i]
  else
    ret = ret + asum[n] - asum[pos - 1] + (n + 1 - pos) * a[i]
  end
  mcnt = mcnt + n + 1 - pos
end
if m < mcnt then
  ret = ret - (mcnt - m) * min
end
local str = tostring(ret):gsub("LL", "")
print(str)


Measured memory_bytes: 5504
#include <iostream>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
    int l[11]; l[0] = 0;
    int v1, v2;
    while(cin >> l[1]) {
        int sum = l[1];
        rep(i,2,11) {scanf(",%d", &l[i]); sum += l[i]; l[i] += l[i-1];}
        scanf(",%d,%d", &v1, &v2);

        double r = (double)sum / (v1 + v2);
        double dist = r * v1;
        rep(i,0,11) {
            if(dist <= l[i]) {cout << i << endl; break;}
        }
    }
    return 0;
}

Measured memory_bytes: 1240
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
 int N;
 cin >> N;
 
 int p[5000];
 for(int i=0; i<N; i++){
  cin >> p[i];
 }
 
 int min_sum = 20000;
 
 for(int  I=0; I<=p[0]; I++){
  int q[5000];
  for(int i=0; i<N; i++){
   q[i] = p[i];
  }
 
  int sum = I;
  q[0] -= I;
 
  for(int i=0; i<=N-2; i++){
   if(q[i]<=0) continue;
    
   sum += q[i]*2;
   q[i+1] -= q[i];
  }
  
  if(q[N-1]>0){
   sum += q[N-1];
  }
 
  min_sum = min(min_sum, sum);
 }
 
 cout << min_sum << endl;
  
 return 0;
} 

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define RALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    VI a(n);
    REP(i,n) cin >> a[i];
    int lb=0, ub=1e9;
    while ( ub-lb>1 ) {
        int x=(lb+ub)>>1;
        auto ok=[&] {
            int cnt=0;
            REP(i,n) {
                cnt+=(a[i]-1)/x;
            } 
            return cnt<=k;
        }();
        if ( ok ) {
            ub=x;
        } else {
            lb=x;
        }
    }
    cout << ub << '\n';
    return 0;
}

Measured memory_bytes: 3988
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}
use input::*;
use std::cmp;

fn main() {
    let (n, h, w): (usize, usize, usize);
    input!(n, h, w);
    let mut ans = 0;

    for _ in 0..n {
        let (a, b): (usize, usize);
        input!(a, b);
        if a >= h && b >= w {
            ans += 1;
        }
    }
    p(ans);
}


Measured memory_bytes: 4352
from collections import deque

N = int(input())


q = deque([str(3), str(5), str(7)])
cnt = 0

while(int(q[0]) <= N):
  x = q.popleft()
  if(('3' in x) and ('5' in x) and ('7' in x)):
    cnt += 1
    
  x3 = x + '3'
  x5 = x + '5'
  x7 = x + '7'
  q.append(x3)
  q.append(x5)
  q.append(x7)
  
print(cnt)

Measured memory_bytes: 7540
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    int N;
    cin >> N;
    if(N == 3){
        cout << "2 5 63" << endl;
        return;
    }
    else if(N == 4){
        cout << "2 5 20 63" << endl;
        return;
    }
    else if(N == 5){
        cout << "2 5 20 30 63" << endl;
        return;
    }
    ll sum = 0;
    vector<int> ans;
    int k = 0;
    while(N > 0){
        if(N > 0){
            ans.push_back(6*k + 2);
            N--;
            sum += 6*k + 2;
        }
        if(N > 0){
            ans.push_back(6*k + 3);
            N--;
            sum += 6*k + 3;
        }
        if(N > 0){
            ans.push_back(6*k + 4);
            N--;
            sum += 6*k + 4;
        }
        if(N > 0){
            ans.push_back(6*k + 6);
            N--;
            sum += 6*k + 6;
        }
        k++;
    }
    cerr << sum << endl;
    if(sum % 6 == 2){
        auto itr = lower_bound(ans.begin(), ans.end(), 8);
        ans.erase(itr);
        for(int i=3e4;i>ans.back();i--) if(i % 6 == 0){
            ans.emplace_back(i);
            break;
        }
    }
    if(sum % 6 == 3){
        auto itr = lower_bound(ans.begin(), ans.end(), 9);
        ans.erase(itr);
        for(int i=3e4;i>ans.back();i--) if(i % 6 == 0){
            ans.emplace_back(i);
            break;
        }
    }
    if(sum % 6 == 5){
        auto itr = lower_bound(ans.begin(), ans.end(), 9);
        ans.erase(itr);
        for(int i=3e4;i>ans.back();i--) if(i % 6 == 4){
            ans.emplace_back(i);
            break;
        }
    }
    for(auto x : ans) cout << x << " ";
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int n; cin >> n;
        vector<pair<int,int>> a(n);
        for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;

        auto good = [](pair<int,int> a) -> bool {
                return a.first == a.second;
        };

        for (int i = 0; i + 2 < n; i++) {
                if(good(a[i]) && good(a[i + 1]) && good(a[i + 2])) {
                        cout << "Yes";
                        return;
                }
        }

        cout << "No";
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3632
//This is not my solution
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int N=1e5+5;
const int inf=0x3f3f3f3f;
ll dp[3][N]={inf},v[3][N],k,n;

ll check(int index);


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
ll i,j,m;
memset(dp,-1,sizeof(dp));

    cin>>n;
    for(i=0;i<n;i++)
        cin>>v[0][i]>>v[1][i]>>v[2][i];
    for(auto it:{0,1,2})
        dp[it][0]=v[it][0];
    for(i=1;i<n;i++){
        for(auto it:{0,1,2}){
            for(auto iit:{0,1,2}){
                if(it!=iit)
                    dp[it][i]=max(dp[it][i],v[it][i]+dp[iit][i-1]);
            }
        }
    }
    cout<<max({dp[0][n-1],dp[1][n-1],dp[2][n-1]})<<"\n";
    // for(auto it:{0,1,2})
    //     for(i=0;i<n;i++)
    //         cout<<dp[it][i]<<" \n"[i==n-1];
    return 0;
}

Measured memory_bytes: 4992
program probC
  implicit none
  integer a,b,c,x,y,ans,tmp

  read(*,*) a,b,c,x,y

  ans = 0
  if(a+b>=2*c) then
     tmp = min(x,y)
     ans = tmp*2*c
     x = x - tmp
     y = y - tmp

  end if
  
     
  if ( a>=2*c .and. x.ne.0) then
     ans = ans + x*2*c
     x = 0


  end if
  if ( b>=2*c .and. y.ne.0) then
     ans = ans + y*2*c
     y = 0

  end if

     ans = ans + x*a + y*b

  write (*,*) ans


     
end program probC



Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(register sign i=(sign)a;i>=(sign)b;--i)
const int N=100+5;
bool cmax(sign &a,sign b){return (a<b)?a=b,1:0;}
bool cmin(sign &a,sign b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
void file()
{
	#ifndef ONLINE_JUDGE
		freopen("test.in","r",stdin);
		freopen("test.out","w",stdout);
	#endif
}
char s[500];
int len;
void init()
{
	scanf("%s",s+1);
	len=strlen(s+1);
}
void work()
{
	For(i,1,len-8)printf("%c",s[i]);
	printf("\n");
}
int main()
{
	//file();
	init();
	work();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5,oo=0x3f3f3f3f,mod=1e9+7;

int memo[N][N],h,w;
char maze[N][N];

bool valid(int x, int y){
    return(x<h&&y<w&&maze[x][y]!='#');
}

int dp(int i, int j){
    if(i==h-1&&j==w-1)return 1;
    if(memo[i][j]!=-1) return memo[i][j];
    int r=0,d=0;
    if(valid(i,j+1))r=dp(i,j+1);
    if(valid(i+1,j))d=dp(i+1,j);
    return memo[i][j]=(r+d)%mod;

}

int main(){
    memset(memo,-1,sizeof memo);
    cin >> h >> w;
    for(int i=0;i<h;i++) cin >> maze[i];
    dp(0,0);
    cout << memo[0][0];
    return 0;
}



Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i,N) cin >> L[i];
  sort(L.begin(),L.end());
  int ans=0;
  rep(a,N-2){
    for(int b=a+1; b<N-1; b++){
      ans+=lower_bound(L.begin(),L.end(),L[a]+L[b])-L.begin()-b-1;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b;
    cin >> a >> b;
    int c = 1;
    while (a <= b) { a *= 2; c++; }
    out(c - 1);
    
}



Measured memory_bytes: 256