akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


# 挿入dp
def solve():
    n,x = LI()
    s = LI()
    s.sort()
    dp = [[0]*(x+1) for i in range(n+1)] # dp[i][j] := スタート時点の値がjの時に最初のi個の順列すべてを試し、えられる総和
    for j in range(x+1):
        dp[0][j] = j # dpの定義より明らか
        for i in range(n):
            si = s[i]
            ni = i+1
            nd = dp[i][j%si] # 先頭にsiを挿入 (スタートの値がj%siとなる)
            nd += i*dp[i][j] # 先頭以外にsiを挿入 (スタートの値も間の値も変わらない)
            dp[ni][j] += nd
            if dp[ni][j] >= mod:
                dp[ni][j] %= mod
    print(dp[n][x])
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 192664
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


int prime[200000];
bool is_prime[300000];

int sieve(int n)
{
	int p = 0;
	for (int i=0; i<=n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i=2; i<=n; i++)
	{
		if (is_prime[i])
		{
			prime[p++] = i;
			for (int j=2*i; j<=n; j+=i) is_prime[j] = false;
		}
	}
	return p;
}


int main()
{
	int n;
	
	while (cin >> n, n)
	{
		cout << sieve(2 * n) - sieve(n) << endl;
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

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

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

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

int main()
{
	int h,w;

	while (1) {
		cin >> w >> h;
		if (w == 0 && h == 0) break;
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < h; j++) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
import { readFileSync } from 'fs'

function main(input: string) {
  const [N, ...list] = input.trim().split(/\s/).map(Number)

  list.sort((a, b) => a - b)

  const abcMax = list[list.length / 2 - 1]
  const arcMin = list[list.length / 2]

  console.log(arcMin - abcMax)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 25792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define fi first
#define sc second

int main() {
    ld X;
    cin >> X;
    ll ans = 100;
    int year = 0;
    while(ans < X) {
        ans = ans*1.01;
        year++;
    }
    cout << year << endl;
}

Measured memory_bytes: 3728
import java.util.Arrays;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

//Network Mess
public class Main{

	class R{
		int id, con;
		int[] dist;
		Set<Integer> adj;
		public R(int id) {
			con = 0;
			this.id = id;
			dist = new int[n];
			Arrays.fill(dist, -1);
			adj = new HashSet<Integer>();
		}
		void add(int k){
			R v = new R(ID);
			sw[ID] = v;
			adj.add(ID);
			v.adj.add(id);
			for(int i=0;i<n;i++){
				if(dist[i]==-1)continue;
				v.dist[i] = dist[i]+1;
			}
			ID++;
			if(a[0][k]-1==v.dist[0]){
				v.con++;
				v.assign(k, 1);
			}
			else v.add(k);
		}
		void assign(int k, int d){
			if(dist[k]!=-1)return;
			dist[k] = d;
			for(int i:adj)sw[i].assign(k, d+1);
		}
	}
	
	int n, ID;
	R[] sw;
	int[][] a;
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			n = sc.nextInt();
			if(n==0)break;
			a = new int[n][n];
			for(int i=0;i<n;i++)for(int j=0;j<n;j++)a[i][j]=sc.nextInt();
			sw = new R[1500];
			ID = 0;
			sw[0] = new R(ID++);
			sw[0].con++;
			sw[0].assign(0, 1);
			for(int k=1;k<n;k++){
				boolean s = true;
				for(int i=0;i<ID;i++){
					boolean f = true;
					for(int j=0;j<k;j++){
						if(sw[i].dist[j]!=a[j][k]-1){
							f = false; break;
						}
					}
					if(f){
						s = false; sw[i].con++; sw[i].assign(k, 1); break;
					}
				}
				if(!s)continue;
				for(int i=0;i<ID;i++){
					boolean f = true;
					int dif = a[0][k]-sw[i].dist[0];
					for(int j=1;j<k;j++){
						if(dif!=a[j][k]-sw[i].dist[j])f = false;
					}
					if(f){
						sw[i].add(k);
						break;
					}
				}
				
			}
			PriorityQueue<Integer> q = new PriorityQueue<Integer>();
			for(int i=0;i<ID;i++)q.add(sw[i].adj.size()+sw[i].con);
			System.out.print(q.poll());
			while(!q.isEmpty())System.out.print(" "+q.poll());
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,k,a[510],sum,ans;
bool func(int t){
	int x[510],y[510],cnt=0;
	rep(i,n){
		x[i]=a[i]%t;
		y[i]=t-x[i];
		cnt+=x[i];
	}
	if(cnt%t)return false;
	sort(y,y+n);
	int memo=0;
	rep(i,cnt/t)memo+=y[i];
	return memo<=k;
}
signed main(){
	cin>>n>>k;
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=1;i*i<=sum;i++){
		if(sum%i==0){
			if(func(i))ans=max(ans,i);
			if(func(sum/i))ans=max(ans,sum/i);
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++)
        cin >> h[i];
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <list>
#include <algorithm>
#include <set>

using namespace std;

typedef unsigned long long u64;

int main()
{
	u64 n, k;
	u64 a[1000];

	map<u64, u64> s;

	cin >> n >> k;

	u64 sum = 0;

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

		++s[sum];

		for (int j = 0; j < i; ++j)
		{
			++s[sum - a[j]];
		}
	}

	u64 ans = 0;

	for (int bit = 63; bit >= 0; --bit)
	{
		u64 mask = 1ULL << bit;

		u64 count = 0;

		for (const pair<u64, u64> & v : s)
		{
			if (v.first & mask)
			{
				count += v.second;
			}
		}

		if (count >= k)
		{
			ans += mask;

			for (auto i = s.begin(); i != s.end(); )
			{
				if (!(i->first & mask))
				{
					i = s.erase(i);
				}
				else
				{
					++i;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 33536
def solve(N, A):
    ret = 0
    for idx in range(N):
        ret += A[idx] // 2
        A[idx] %= 2
        if A[idx] and idx + 1 < N and A[idx + 1]:
            ret += 1
            A[idx + 1] -= 1
    return ret

if __name__ == "__main__":
    N = int(input())
    A = [0 for _ in range(N)]
    for idx in range(N):
        A[idx] = int(input())
    print(solve(N, A))

Measured memory_bytes: 45168
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >>n;
    FOR(i,1,n+1){
        if( int(i * 1.08) == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;

}

Measured memory_bytes: 256
a, b = map(int, input().split())
b_list = input()
a_list = list(b_list.split("-"))

ans = "No"
if (len(a_list) == 2) and (b_list.count("-") == 1) and (len(a_list[0]) == a) and (len(a_list[1]) == b):
  ans = "Yes"
  
print(ans)

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

bool checkP(int a){
    for(int i = 2; i * i <= a; i++){
        if(a%i == 0) return false;
    }
    return true;
}

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

    vector<int> a;
    int num = 2;

    for(int i = 2; i < 55555; i++){
        if(checkP(i) && i%5 == 1) a.push_back(i);
        if(a.size() == N) break;
    }
    
    cout << a[0];
    for(int i = 1; i < N; i++){
        cout << " " << a[i];
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

random_device seed_gen;
mt19937 engine(seed_gen());
// 0, 1, 2 のどれかが得られる一様分布
// uniform_int_distribution<> dist(0, 2);
// cout << dist(engine) << endl;
// みたいに、先に確率分布を宣言して、そこにengineを与えて使う。

// =========ここまでテンプレ============

int main()
{
    ll n, x, m;
    cin >> n >> x >> m;
    vector<ll> stepAt(m, -1);
    vector<ll> scoreAt(m, -1);

    // スタート地点への移動
    ll nowAt = x;
    ll step = 0;
    ll score = nowAt;

    // ここでは、歩き過ぎないようチェック
    // while文に入ると移動するので、まだ移動できる場合にだけtrue
    // この問題では、移動はn-1回なことに注意
    while (step < n - 1)
    {
        // 判定(先にステップ続行を書く。elseでループ部分をまとめて処理してstepとscoreを一気に増やす。)
        if (stepAt[nowAt] == -1)
        {
            // 記録(stepAtとscoreAtを更新)
            stepAt[nowAt] = step;
            scoreAt[nowAt] = score;

            // 移動(現在地と歩数とスコアを更新)
            step++;
            nowAt = (nowAt * nowAt) % m;
            score += nowAt;
        }
        else
        {
            // この瞬間、「ループのスタート地点に移動済み」で記録上書き前
            ll periodStep = step - stepAt[nowAt];
            ll periodScore = score - scoreAt[nowAt];
            // あと一歩も動かずに終わることがないようにする。最後1ループちょうど残ってても自力で歩く。
            // 1引いてから周期で割ればいいね
            ll remainingLoops = ((n - 1) - step - 1) / periodStep;
            step += remainingLoops * periodStep;
            score += remainingLoops * periodScore;
            // 訪問済みフラグを全て消します。
            stepAt = vector<ll>(m, -1);
            scoreAt = vector<ll>(m, -1);
            // あとは通常処理に戻って、歩数の限界まで歩きます。
        }
    }

    cout << score << endl;
    return 0;
}

Measured memory_bytes: 5228
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
#include <map>
#include <cstring>
#include <cassert>
 
using namespace std;

int main(){

	int n;
	cin>>n;

	vector<int> a(n),b(n),c(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++) cin>>c[i];

	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());

	set<int> sb(b.begin(),b.end());
	map<int,long long> cnt_ab,cnt_bc;

	for(int i=0;i<n;i++){
		cnt_ab[b[i]]+=lower_bound(a.begin(),a.end(),b[i])-a.begin();
	}
	for(auto x : sb){
		cnt_bc[x]+=c.end()-upper_bound(c.begin(),c.end(),x);
	}

	long long res=0;
	for(auto x : sb) res+=cnt_ab[x]*cnt_bc[x];
	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 18560
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());

        Integer[][] A = new Integer[N][2];
        for (int i = 0; i < N; i++) {
            A[i][0] = i;
            A[i][1] = Integer.parseInt(scanner.next());
        }
        scanner.close();

        // 値の降順ソート
        Arrays.sort(A, (a, b) -> b[1] - a[1]);

        // 最大値のindexであれば index: 1, そうでなければ index: 0
        for (int i = 0; i < N; i++) {
            if (A[0][0] == i) {
                System.out.println(A[1][1]);
            } else {
                System.out.println(A[0][1]);
            }
        }
    }
}


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

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

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

    int N; cin >> N;

    vector<int> G[200005];

    for (int i = 0;i < N-1;i++){
        int a,b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<int> que;
    int dist[200005]; memset(dist,-1,sizeof(dist));
    que.push(1);
    dist[1] = 0;
    int f = -1;

    while(que.size()){
        int from = que.front(); que.pop();
        f = from;
        for (int i = 0;i < G[from].size();i++){
            int to = G[from][i];
            if(dist[to] == -1){
                dist[to] = dist[from]+1;
                que.push(to);
            }
        }
    }
    
    memset(dist,-1,sizeof(dist));
    que.push(f);
    dist[f] = 0;
    int L = -1;

    while(que.size()){
        int from = que.front(); que.pop();
        f = from;
        for (int i = 0;i < G[from].size();i++){
            int to = G[from][i];
            if(dist[to] == -1){
                dist[to] = dist[from]+1;
                que.push(to);
                L = dist[to];
            }
        }
    }

    if(L%3 == 1) cout << "Second" << endl;
    else cout << "First" << endl; 

    return 0;

}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
#define pb                emplace_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (ll)((x).size())
#define ff                first
#define ss                second
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define isBitset(S,i)     ((S>>i)&1)
#define print(x) 		  for(auto it:x) cout<<it<<" "; cout<<"\n"; 
#define MOD 1000000007
ll gcd(ll a, ll b){
    while(true){
        if(a>b)
            swap(a,b);
        if (a == 0) 
            return b; 
        ll p = b % a  , q = a;
        a = p;
        b = q;
    }
}
 
ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}
 
string binary(ll s) {
    string res = "";
    while(s != 0) {
        res += (char)('0' + s % 2);
        s /= 2;
    }
    reverse(res.begin() , res.end());
    return res;
}
void solve()
{
	string s,r;cin>>s>>r;
	ll k=0;
	ll kk=-1;
	ll c=0;
	for(ll i=0;i<sz(s)-(sz(r)-1);++i)
	{
		k=0;
		c=0;
		for(ll j=i;j<i+sz(r);++j)
		{
			if(s[j]==r[c])
				k++;
			c++;
		}
		kk=max(kk,k);
		k=0;
	}
	cout<<sz(r)-kk;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);    
        solve();
    return 0;
}

Measured memory_bytes: 3660
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = new ListBuffer[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map(l(1))
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Boolean](721)
    log.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = true)
    })
    time.count(_ == true)
  }

  def solve(s:String):Unit = {
    // val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


Measured memory_bytes: 58848
#include <bits/stdc++.h>
#define  rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;


int main()
{
    int N,z=0,ans=0;
    cin>>N;
    vi a(N);
    rep(i,N) { cin>>a[i]; z+=a[i]; }
    z=round((double)z/(double)N);
    rep(i,N) ans+=pow(z-a[i],2);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#include <boost/sort/spreadsort/spreadsort.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
//#include <boost/graph/graph_utility.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
//using namespace boost::multiprecision;
//using namespace boost::math;

typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS,
        boost::no_property, boost::property<boost::edge_weight_t, int> > Graph;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define bsort boost::sort::spreadsort::spreadsort
#define int int_fast64_t
using pii = pair<int,int>;

constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
template <class Func>

class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}
 
    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};
 
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;

template <typename T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

struct negrightshift {
    inline int operator() (const int &x, const unsigned offset) {
        return -(x >> offset);
    }
};
//}}}


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    int n, x, t;
    cin >> n >> x >> t;

    cout << updiv(n, x) * t << endl; 

    return 0;
}

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

int main() {
  std::string s;
  std::cin >> s;
  long long sum = 0, tmp;
  for (int bit = 0; bit < (1 << (s.length() - 1)); ++bit) {
    long long a = 0;
    for (int i = 0; i < s.length(); ++i) {
      a *= 10;
      a += s[i] - '0';
      if (bit & (1 << i)) {
        sum += a;
        a = 0;
      }
    }
    sum += a;
  }
  std::cout << sum << "\n";
  return 0;
}

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

#define DEBUG(C) cerr << #C << " = " << C << endl

using namespace std;

char S[30];
bool vis[30];

int main() {
  scanf("%s", S);
  const int sz = strlen(S);
  for (int i = 0; i < sz; i++) {
    if (vis[S[i] - 'a']) {
      puts("no");
      return 0;
    }
    vis[S[i] - 'a'] = true;
  }
  puts("yes");
  return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    al = list(map(int,input().split()))
    al_p = 1

    if 0 in al:
        print(0)
        return

    for i in range(n):
        al_p *= al[i]
        if al_p > 10**18:
            print(-1)
            return
        
    print(al_p)

main()
    

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

using namespace std;
# define M_PI 3.14159265358979323846
# define epsi 1e-9
# define F first
# define S second
# define REP(i,a,b) for(int i=a;i<=b;i++)
# define my_sizeof(type) ((char *)(&type+1)-(char*)(&type))
using ll = long long int;
const int MOD = 1e9 + 7;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    char ch;
    cin>>ch;
    if(ch>=65 && ch<=90)
    {
        cout<<'A';
    } else
    {
        cout<<'a';
    }
}

Measured memory_bytes: 3648
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < 10; j++) {
				set.add(i * j);
			}
		}
		if (set.contains(n)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	bool f = 0;
	int n;
	cin >> n;
	rep(i, 3) {
		if (n % 10 == 7) { cout<<"Yes"; return 0; }
		n /= 10;
	}
	cout << "No";
}

Measured memory_bytes: 3652
const main = (input) => {
  var s = input[0];
  var t = input[1];

  var smap = {};
  for(var i=0;i<s.length;i++){
    var w = s[i];
    if(!smap[w])smap[w]=[];
    smap[w].push(i+1);
  }
  var ans = 0;
  var now = 0;
  for(var i=0;i<t.length;i++){
    var w = t[i];
    if(!smap[w] || smap[w].length == 0){ans = -1; break;}
    var idx = bsearch(smap[w], now+1);
    if(idx==-1){
      ans+=s.length;
      if(i==t.length-1){
        ans += smap[w][0];
      }else{
        now = smap[w][0];
      }
    }else{
      if(i==t.length-1){
        ans += smap[w][idx];
      }else{
        now = smap[w][idx];
      }
    }
  }
  console.log(ans);
}

function bsearch(arr, n){
  var a = 0;
  var b = arr.length-1;
  var ans = -1;
  while(a<=b){
    var ave = ~~((a+b)/2);
    if(arr[ave]<n){
      a = ave+1;
    }else{
      ans = Math.min(ans==-1?ave:ans,ave);
      b = ave-1;
    }
  }
  return ans;
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 15308
// *********************************************************************************
// *                        MURTAZA MUSTAFA KHUMUSI                                *
// *                        NIT-DGP,CSE - 2019-2023                                *
// *********************************************************************************

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loop1(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloop1(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);

void solve()
{
    string str;
    cin >> str;
    int ans = 0, r = 0;

    loop(i, 0, str.size())
    {
        if (str[i] == 'R')
            r++;
        else
        {
            ans = max(ans, r);
            r = 0;
        }
    }
    cout << max(r, ans) << "\n";
}
int main()
{
    io;

    solve();

    return 0;
}


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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int a[N];
string s;

void sol (int x, int y) {
	for (int i = 1; i <= n; i ++) {
		a[i] = -1;
	}

	a[1] = x;
	a[2] = y;
	a[n+1] = x;
	for (int i = 2; i < n; i++) {
		bool nxt = 0; 
		if (a[i] == 1) nxt ^= 1;
		if (s[i] == 'x') nxt ^= 1;
		a[i+1] = (a[i-1] ^ nxt);
	}

	for (int i = 1; i <= n; i ++) {
		int l = i-1;
		int r = i+1;
		if (r > n) r = 1;
		if (l < 1) l = n;

		bool nxt = 0; 
		if (a[i] == 1) nxt ^= 1;
		if (s[i] == 'x') nxt ^= 1;

		if(!nxt) {
			if (a[l] != a[r]) return;
		} else {
			if (a[l] == a[r]) return;
		} 

	}

	for (int i = 1; i <= n; i ++)
		cout << (a[i] ? "W" : "S");
	exit(0);
}

int main () {
	SpeedForce;
	cin >> n >> s;
	s = '#' + s;


	for (int a = 0; a < 2; a++) {
		for (int b = 0; b < 2; b++) {
			sol(a, b);
		}
	}

	puts("-1");

   	return Accepted;
}

// B...a


Measured memory_bytes: 1024
def JOIOI(l) :
    count_j = 0
    count_i = 0
    for i in range(len(l)-2) :
        if l[i] == "J" and l[i+1] == "O" and l[i+2] == "I" :
            count_j += 1
        if l[i] == "I" and l[i+1] == "O" and l[i+2] == "I" :
            count_i += 1
    return count_j, count_i

while True :
    try :
        l = input()
    except EOFError :
        break
    
    j, i = JOIOI(l)
    print(j)
    print(i)



Measured memory_bytes: 5572
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	static final Scanner s=new Scanner(System.in);

	public static void main(String args[]){
		int n, in[];
		while((n=s.nextInt())!=0){
			in=new int[n];
			for(int i=0; i<n; i++)
				in[i]=s.nextInt();
			double ave=Arrays.stream(in).average().getAsDouble();
			System.out.println(
					Math.sqrt(
							Arrays.stream(in)
									.mapToDouble(
											i->(i-ave)*(i-ave))
									.sum()
							/n
							)
					);
		}
	}
}

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

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

     int ans = 0;
    int l, r;
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        ans += r - l + 1;
    }

     cout << ans << endl;

     return 0;
}

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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,a,b) for(ll i=a-1;i>=b;i--)
#define vi vector<ll>
#define pii pair<int,int>
#define vii vector< pair<int,int> >
#define pb push_back
#define inf 1000000000000
#define hell 1000000007

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    vi a(n);
    rep(i,0,n)
        cin>>a[i];
    ll sum=0;
    rep(i,0,n){
        rep(j,i+1,n){
            sum+=a[i]*a[j];
        }
    }
    cout<<sum;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
int main()
{
    std::string S,T;
    std::cin >> S >> T; //変数.size()

    for (int i = 0; i < S.size(); i++){
            if (S[i]!=T[i]){
                std::cout << "No" << std::endl;
                return 0;
            }
    }
            if (S.size()+1==T.size()){
                std::cout << "Yes" << std::endl;
            }
            else{
                std::cout << "No" << std::endl;
            }
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int mod=1e9+7;
int  c[5];
int  a[30500];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%1d",&a[i]);
    }
    ll sum=0;
    for(int i=0; i<10; i++)
    {
        c[1]=i;
        for(int j=0; j<10; j++)
        {
            c[2]=j;
            for(int k=0; k<10; k++)
            {
                c[3]=k;
                int ans=1;
                for(int t=0; t<n; t++)
                {

                    int  a1=a[t],b1=c[ans];
                    if(a1==b1)
                    {
                        ans++;
                    }
                    if(ans>3)
                    {
                        sum++;
                        break;
                    }
                }
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3876
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

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

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

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

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void solve(){
    
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    ll dp[55];
    dp[0]=1;
    dp[1]=1;
    for(ll i=2;i<n+1;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    cout<<dp[n]<<endl;
    return 0;
}




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

static const int N = 1000;

int lcs(string X, string Y)
{
  int c[N + 1][N + 1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 0; i <= m; i++)
  {
    c[i][0] = 0;
  }
  for (int j = 1; j <= n; j++)
  {
    c[0][j] = 0;
  }

  for (int i = 1; i <= m; i++)
  {
    for (int j = 1; j <= n; j++)
    {
      if (X[i] == Y[j])
      {
        c[i][j] = c[i - 1][j - 1] + 1;
      }
      else
      {
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }

  return maxl;
}

int main()
{
  string s1, s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }

  return 0;
}


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

double dist(double x,double y,double x2,double y2){
    return sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
}

int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    vector<pair<int,int> >v(n);
    for(int i=0;i<n;i++)
        cin >> v[i].first >> v[i].second;
    sort(v.begin(),v.end());
    double sum;
    int cnt=0;
    do{
        for(int i=0;i<n-1;i++)
            sum+=dist(v[i].first,v[i].second,v[i+1].first,v[i+1].second);
        cnt++;
    }while(next_permutation(v.begin(),v.end()));

    cout << setprecision(12) << fixed << sum/cnt;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
set<long long> s;
int map1[10][10];
int k[10];
int t;
queue<long long> x,y;
void input(){
	int g=0;
	for(int i=0;i<3;++i){
		for(int j=0;j<3;++j){
			cin>>map1[i][j];
			g=g*10+map1[i][j];
		}
	}
	s.insert(g);
	x.push(g);
	y.push(0);
}
void syf(){
	while(!x.empty()){
		if(x.front()==123456780){
			cout<<y.front()<<endl;
			return;
		}
		int g=x.front(),tot=0,kl=-1;
		while(g!=0){
			if(g%10==0) kl=tot;
			k[tot++]=g%10;
		    g/=10;
		}
		if(kl==-1) {
			kl=tot;
			k[tot++]=0;
		}
		if(kl%3>0){
			t=k[kl];
			k[kl]=k[kl-1];
			k[kl-1]=t;
			long long ss=0;
			for(int i=tot-1;i>=0;--i){
				ss=ss*10+k[i];
			}
			if(s.count(ss)==0){
				x.push(ss);
				y.push(y.front()+1);
				s.insert(ss);
			}
			t=k[kl];
			k[kl]=k[kl-1];
			k[kl-1]=t;
		}
		if(kl%3<2){
			t=k[kl];
			k[kl]=k[kl+1];
			k[kl+1]=t;
			long long ss=0;
			for(int i=tot-1;i>=0;--i){
				ss=ss*10+k[i];
			}
			if(s.count(ss)==0){
				x.push(ss);
				y.push(y.front()+1);
				s.insert(ss);
			}
			t=k[kl];
			k[kl]=k[kl+1];
			k[kl+1]=t;			
		}
		if(kl+3<=8){
			t=k[kl];
			k[kl]=k[kl+3];
			k[kl+3]=t;
			long long ss=0;
			for(int i=tot-1;i>=0;--i){
				ss=ss*10+k[i];
			}
			if(s.count(ss)==0){
				x.push(ss);
				y.push(y.front()+1);
				s.insert(ss);
			}	
			t=k[kl];
			k[kl]=k[kl+3];
			k[kl+3]=t;		
		}
		if(kl-3>=0){
			t=k[kl];
			k[kl]=k[kl-3];
			k[kl-3]=t;
			long long ss=0;
			for(int i=tot-1;i>=0;--i){
				ss=ss*10+k[i];
			}
			if(s.count(ss)==0){
				x.push(ss);
				y.push(y.front()+1);
				s.insert(ss);
			}	
			t=k[kl];
			k[kl]=k[kl-3];
			k[kl-3]=t;			
		}
		x.pop();
		y.pop();
	}
}
int main(){
	input();
	syf();
	return 0;
}

Measured memory_bytes: 11688
#include <iostream>
using namespace std;
int main() {
    int cnt=0;
    int N;
    cin >> N;
    int A[N],B[N-1];
    for (int i=0; i<N-1; i++) {
        cin >> B[i];
        A[i+1] = B[i];
    }
    A[0] = A[1];
    for (int i=0; i<N-1; i++) {
        if (A[i] > A[i+1]) A[i] = A[i+1];
    }
    for (int i=0; i<N; i++) {
        cnt += A[i];
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	char a;
	cin >> a;

	if ('A' <= a && a <= 'Z') cout << "A" << endl;
	else cout << "a" << endl;

	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<vector>
#include<cstring>
#include<sstream>
#include<algorithm>
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;

#define MOD 1000000007

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

    int h, w, k;
    cin >> h >> w >> k;

    char g[h][w];
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) cin >> g[i][j];

    long long res = 0;
    for (int i = 0; i <= (1<<h)-1; i++) {
        for (int j = 0; j <= (1<<w)-1; j++) {

            int black = 0;
            for (int s = 0; s < h; s++) {

                if (i&(1<<s)) continue;

                for (int r = 0; r < w; r++) {
                    if (j&(1<<r)) continue;

                    black += (g[s][r] == '#');
                }
            }

            if (black == k) res ++;
        }
    }

    cout << res << endl;

    return 0;
}


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

int main(){
	int n;
	cin >> n;
	int def_n = n;
	long long ans = def_n;
	bool is_two_div = false;
	while(!(n&1)){
		n >>= 1;
		is_two_div = true;
	}
	if(is_two_div){
		ans /= 2;
	}
	for(int i=3;i*i<=def_n&&n>1;i+=2){
		bool is_div = false;
		while(n%i == 0){
			n /= i;
			is_div=true;
		}
		if(is_div){
			ans *= i-1;
			ans /= i;
		}
	}
	if(n>1){
		ans *= n-1;
		ans /= n;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3108
use std::cmp;

const INF: u32 = 1 << 30 as u32;

fn main() {
    let sc = std::io::stdin();
    let mut sc = Scanner { reader: sc.lock() };
    let s: Vec<u32> = sc
        .read::<String>()
        .chars()
        .map(|c| c as u32 - 'a' as u32)
        .collect();
    let n = s.len();
    let mut hash: Vec<u32> = vec![0; n + 1];
    for i in 0..n {
        hash[i + 1] = hash[i] ^ (1 << s[i]);
    }

    let mut prefix: Vec<u32> = vec![0];
    for i in 0..26 {
        prefix.push(1 << i);
    }

    let mut opt = vec![INF; n + 1];
    let mut dp = vec![INF; 1 << 26];
    opt[0] = 0;
    dp[0] = 0;

    for i in 0..n {
        let hash = hash[i + 1];
        for &prefix in prefix.iter() {
            let suffix = hash ^ prefix;
            opt[i + 1] = cmp::min(opt[i + 1], dp[suffix as usize] + 1);
        }
        dp[hash as usize] = cmp::min(dp[hash as usize], opt[i + 1]);
    }

    println!("{}", opt[n]);
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 268668
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long  ull;

#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define sz(x) int (x.size());
//typedef pair<int,int> P;

using namespace std;
const int MOD=1000000007;
const int INF=1001001001;

int main(){
  double a,b,xl1,xl2,xh1,xh2;
  cin>>a>>b;
  xl1=a*100/8;
  xh1=(a+1)*100/8;
  xl2=b*10;
  xh2=(b+1)*10;
  xl1=max(xl1,xl2);
  xh1=min(xh1,xh2);
  double x=ceil(xl1);
  int ans;
  if (x<xh1) ans=x;
  else ans=-1;
  cout<<ans;



}


Measured memory_bytes: 256
N, W = map(int, input().split())
v = [0]*(N+1)
w = [0]*(N+1)
for i in range(1, N+1):
    v[i], w[i] = map(int, input().split())

dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
    for j in range(1, W+1):
        if w[i] > j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-w[i]]+v[i], dp[i-1][j-w[i]]+v[i])

print(dp[N][W])

Measured memory_bytes: 17816
#include<bits/stdc++.h>
using namespace std;
int x,y,ans=INT_MAX;
int main()
{
	scanf("%d %d",&x,&y);
	if(x<=y)
	{
		ans=min(y-x,ans);
	}
	if(-x<=y)
	{
		ans=min(y+x+1,ans);
	}
	if(x<=-y)
	{
		ans=min(-y-x+1,ans);
	}
	if(-x<=-y)
	{
		ans=min(-y+x+2,ans);
	}
	printf("%d",ans);
}

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

int main() {

    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }

    ll ans = 0;
    for(auto& p : mp){
        int s = p.second;
        ans += (ll)s * (s - 1) / 2 ;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  int n;
  cin >> n;
  vector <int> a(n);
  REP(i,n){
      cin >> a[i];
  }
  int cnt = 0;
  REP(i,n-1){
      if(a[i] == a[i+1] && a[i] != -1){
          a[i+1] = -1;
          cnt++;
      }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#スペース区切りの整数の入力
N,M = map(int, input().split())
#スペース区切りの整数の入力リスト
A_list = list(map(int, input().split()))

sum_ = 0
for i in range(len(A_list)):
  sum_ = sum_ + A_list[i]
  
  
ans = N - sum_
if(ans>=0):
  print(ans)
else:
  print("-1")


Measured memory_bytes: 10040