akhauriyash/Code-Regression huggingface dataset:
N = int(input())
s = input()

def judgment(animal):
    #print(animal)
    for i in range(N):
        left = i-1
        right = i+1
        if i == 0:
            left = -1
        if i == N - 1:
            right = 0
        if animal[i] == "S" and animal[left] != animal[right] and s[i] == "o":
            return False
        elif animal[i] == "S" and animal[left] == animal[right] and s[i] == "x":
            return False
        elif animal[i] == "W" and animal[left] == animal[right] and s[i] == "o":
            return False
        elif animal[i] == "W" and animal[left] != animal[right] and s[i] == "x":
            return False
    return True

def set_animal(animal1 , animal2):
    animal_round = [animal1,animal2]
    for i in range(2,N):
        if animal_round[i-2] == "S" and animal_round[i-1] == "S":
            if s[i-1] == "o":
                animal_round.append("S")
            elif s[i-1] == "x":
                animal_round.append("W")
        elif animal_round[i-2] == "S" and animal_round[i-1] == "W":
            if s[i-1] == "o":
                animal_round.append("W")
            elif s[i-1] == "x":
                animal_round.append("S")
        elif animal_round[i-2] == "W" and animal_round[i-1] == "S":
            if s[i-1] == "o":
                animal_round.append("W")
            elif s[i-1] == "x":
                animal_round.append("S")
        elif animal_round[i-2] == "W" and animal_round[i-1] == "W":
            if s[i-1] == "o":
                animal_round.append("S")
            elif s[i-1] == "x":
                animal_round.append("W")
    return animal_round


list = [["S","S"],["W","S"],["S","W"],["W","W"]]
for e in list:
    animal_round = set_animal(e[0],e[1])
    flag = judgment(animal_round)
    #print(animal_round)
    if flag:
        break

if flag:
    print("".join(animal_round))
else:
    print(-1)


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

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

  vector<int> dp(200001, 0);
  for ( int i = 1; i <= 200000; i++ ) {
    dp[i] = dp[i % __builtin_popcount(i)] + 1;
  }

  int popct = count(x.begin(), x.end(), '1');

  // xi=1->0 のときの各桁の10進での大きさ rem mod (popct-1)
  vector<int> rem0(n, 0);
  if ( popct > 1 ) {
    rem0[n-1] = 1;
    for ( int i = n-2; i >= 0; i-- ) {
      rem0[i] = (rem0[i+1]*2) % (popct-1);
    }
  }
  // xi=0->1 のときの各桁の10進での大きさ rem mod (popct+1)
  vector<int> rem1(n, 0);
  rem1[n-1] = 1;
  for ( int i = n-2; i >= 0; i-- ) {
    rem1[i] = (rem1[i+1]*2) % (popct+1);
  }

  // xi=1->0 のときの10進でのx mod (popct-1)
  int x0 = 0;
  if ( popct > 1 ) {
    for ( int i = 0; i < n; i++ ) {
      if ( x[i] == '1' ) {
        x0 += rem0[i];
        x0 %= (popct-1);
      }
    }
  }
  // xi=0->1 のときの10進での x mod (popct+1)
  int x1 = 0;
  for ( int i = 0; i < n; i++ ) {
    if ( x[i] == '1' ) {
      x1 += rem1[i];
      x1 %= (popct+1);
    }
  }

  for ( int i = 0; i < n; i++ ) {
    int ans;
    if ( x[i] == '1' ) {
      if ( popct < 2 ) {
        ans = 0;
      } else {
        int r = x0 - rem0[i];
        r += (popct-1);
        r %= (popct-1);
        ans = dp[r] + 1;
      }
    } else {
      int r = x1 + rem1[i];
      r %= (popct+1);
      ans = dp[r] + 1;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 5932
N, K = map(int, input().split())
P = list(map(int, input().split()))
expects = [0.0]
for i in range(1, 1001):
    p = 0.0
    for j in range(i, 0, -1):
        p += j * 1.0 / i
    expects.append(p)
exp_P = [0.0]
for i in range(N):
    exp_P.append(exp_P[-1] + expects[P[i]])

# print(exp_P)
ans = float('-inf')
for i in range(K, N+1):
    ans = max(ans, exp_P[i] - exp_P[i-K])
print(ans)


Measured memory_bytes: 25060
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

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

  if (s.length()<=K){
    cout << s << endl;
  }else {
    cout << s.substr(0,K) << "..." << endl;
  }
}

Measured memory_bytes: 3596
// Ryo Kamoi

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

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

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

int INF = 1000000000;

int n;
int main(){
  cin >> n;
  cout << 180 * (n-2) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define ll long long

// void swap(ll *a,ll *b){
//   ll tmp=*a;
//   *a=*b;
//   *b=tmp;
// }

ll gcd(ll a,ll b){
  // if(a<b) swap(&a,&b);
  if(b==0) return a;
  return gcd(b,a%b);
}

// ll gcd(ll a, ll b)
// {
// 	ll r = a % b;
// 	while (r > 0){
// 		a = b;
// 		b = r;
// 		r = a % b;
// 	}
// 	return b;
// }

int main(){
  ll n,m,i,a[100005];
  scanf("%lld %lld",&n,&m);
  for(i=0;i<n;i++){
    scanf("%lld", &a[i]);
    a[i] /= 2;
  }
  ll l=a[0];
  for(i=0;i<n;i++) l = l/gcd(l,a[i])*a[i];
  for(i=0; i<n; i++){
    if(l/a[i]%2==0){
      printf("0\n");
      return 0;
    }
  }
  printf("%lld\n",(m/l+1)/2);
  return 0;
}

Measured memory_bytes: 896
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<bitset>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=2010;
const int maxm=4000010;
bitset<maxm> f;
int n,sum,A[maxn];
int main() {
	n=read();f[0]=1;
	rep(i,1,n) sum+=(A[i]=read()),f|=f<<A[i];
	int k=(sum+1)/2;
	rep(i,k,sum) if(f[i]) {
		printf("%d\n",i);
		return 0;
	}
    return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<stdlib.h>
int main() {
	int i, j, k, f = 0, t, x, y;
	int year, month, day;
	scanf( "%d/%d/%d", &year, &month, &day);
	if (month > 4) {
		f = 1;
	}
	if (f == 0) {
		printf("Heisei");
	}
	else {
		printf("TBD");
	}
	return 0;
}

Measured memory_bytes: 128
n=int(input())
A=list(map(int, input().split()))
A.insert(0,0)
A.append(0)

K=[]
for i in range(1,n+2):
    K.append(abs(A[i]-A[i-1]))

K_sum=sum(K)
for i in range(1,n+1):
    print(K_sum-K[i-1]-K[i]+abs(A[i+1]-A[i-1]))


Measured memory_bytes: 14048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC141
{
    class C
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);
            int Q = int.Parse(input[2]);
            int[] points = new int[N];
            for (int i = 0; i < N; i++)
            {
                points[i] = K;
            }

            int A;
            for (int i = 0; i < Q; i++)
            {
                A = int.Parse(Console.ReadLine());
                points[A - 1]++;
            }
            points = points.Select(p => p - Q).ToArray();


            for (int i = 0; i < N; i++)
            {
                if (points[i] <= 0)
                {
                    Console.WriteLine("No");
                }
                else
                {
                    Console.WriteLine("Yes");
                }
            }

        }
    }
}


Measured memory_bytes: 17372
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long int lli;
const lli mod = 1e9+7;
using namespace std;

int main()
{

    string s;cin>>s;
    int n=s.length();
    string a="";
    string b="";
    for(int i=0 ;i<(n/2); i++)
        a+=s[i];
    for(int i=n/2 +1;i<n; i++)
        b+=s[i];
    //cout<<a<<" "<<b<<"\n";
    string x=s;
    reverse(s.begin(),s.end());
    //cout<<x<<" "<<s<<" ";
    if(x==s)
    {
        string y=b;
        x=a;
        reverse(a.begin(),a.end());
        reverse(b.begin(),b.end());

        //cout<<x<<" "<<a<<" "<<y<<" "<<b<<"\n";
        if(x==a && y==b)
        cout<<"Yes"<<"\n";
        else
            cout<<"No";

    }
    else
        cout<<"No";

    return 0;
}


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

#define MAX 100000

typedef struct cpu
{
	char name[10];
	int time;
} cpu_t;

cpu_t queue[MAX];
int number = 0, head = 0, tail = 0;

void enq( cpu_t info )
{
	if ( tail == number )
	{
		tail = 1;
	}
	else 
	{
		tail = tail + 1;
	}

	queue[tail] = info;
}

cpu_t deq( )
{
	if ( head == number )
	{
		head = 1;
	}
	else 
	{
		head = head + 1;
	}

	return queue[head];
}

int main()
{
	int num, i, q, time_com = 0, count = 0;
	cpu_t cpuinfo;

	scanf( "%d %d", &number, &q );

	for ( i = 1 ; i < number+1 ; i++ )
	{
		scanf( "%s", queue[i].name );
		scanf( "%d", &queue[i].time );
	}

	while ( count != number )
	{
		cpuinfo = deq();
		if ( cpuinfo.time <= q )
		{
			time_com = time_com + cpuinfo.time;
			count++;
			fprintf( stdout, "%s %d\n", cpuinfo.name, time_com );
		}
		else
		{
			time_com = time_com + q;
			cpuinfo.time = cpuinfo.time - q;
			enq( cpuinfo );
		}
	}

	return 0;
}

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

Measured memory_bytes: 4372
n=int(input())
a=[int(i) for i in input().split()]
cnt={}
for i in range(n):
    cnt[a[i]]=0
ok=1
for i in range(n):
    cnt[a[i]]+=1
    if cnt[a[i]]==2:
        print("NO")
        ok=0
        break
if ok==1:
    print("YES")



Measured memory_bytes: 35380
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan=new Scanner(System.in);
    		
    		int n=Integer.parseInt(scan.next());
    		int a=Integer.parseInt(scan.next());
    		int b=Integer.parseInt(scan.next());
    		
    		System.out.print(a*n>b?b:a*n);
  
    				
 
     
    }
    }
// end 

Measured memory_bytes: 21844
use std::collections::VecDeque;
use std::io::*;
use std::str::FromStr;

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

type Weight = i32;
#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
struct Edge {
    index: usize,
    src: usize,
    dest: usize,
    weight: Weight,
}
#[allow(dead_code)]
impl Edge {
    fn new(index: usize, src: usize, dest: usize, weight: Weight) -> Edge {
        Edge {
            index: index,
            src: src,
            dest: dest,
            weight: weight,
        }
    }
}
impl std::cmp::Ord for Edge {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        (self.weight, self.src, self.dest).cmp(&(other.weight, other.src, other.dest))
    }
}
impl std::cmp::PartialOrd for Edge {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}
type Edges = Vec<Edge>;
type Graph = Vec<Edges>;
#[allow(dead_code)]
fn graph_new(n: usize) -> Graph {
    vec![vec![]; n]
}
#[allow(dead_code)]
fn add_bi_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    graph[dest].push(Edge::new(*index, dest, src, weight));
    *index += 1;
}
#[allow(dead_code)]
fn add_uni_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    *index += 1;
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut g = graph_new(n);
    let mut e = 0;
    for _i in 0..m {
        let f = read::<usize>() - 1;
        let t = read::<usize>() - 1;
        add_uni_edge(&mut g, &mut e, f, t, 1);
    }
    let mut ans = vec![n; n + 1];
    for start in 0..n {
        let mut parents = vec![n; n];
        let mut queue = VecDeque::<(usize, usize)>::new();
        queue.push_back((start, 0));
        while let Some((from, depth)) = queue.pop_front() {
            if from == start && depth != 0 {
                let mut tans = vec![];
                let mut f = from;
                while parents[f] != start {
                    tans.push(f);
                    f = parents[f];
                }
                tans.push(f);
                if tans.len() < ans.len() {
                    ans = tans;
                }
                break;
            }
            for e in g[from].iter() {
                let to = e.dest;
                if parents[to] != n {
                    continue;
                }
                parents[to] = from;
                queue.push_back((to, depth + 1));
            }
        }
    }
    if ans.len() == n + 1 {
        println!("-1");
        return;
    }
    println!("{}", ans.len());
    for &p in ans.iter() {
        println!("{}", p + 1);
    }
}


Measured memory_bytes: 2280
H, W, D = map(int, input().split())
m = [None] * (H * W + 1)
for i in range(H):
    l = map(int, input().split())
    for j, a in enumerate(l):
        m[a] = (i, j)
Q = int(input())
LR = []
for _ in range(Q):
    l, r = map(int, input().split())
    LR.append((l, r))
 
S = [0] * (H * W + 1)
for k in range(D + 1, H * W + 1):
    x, y = m[k]
    i, j = m[k - D]
    S[k] = S[k - D] + abs(x - i) + abs(y - j)
 
for l, r in LR:
    print(S[r] - S[l])

Measured memory_bytes: 67548
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int X;
	cin >> X;
	if (X == 7 || X == 5 || X == 3) {
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;
	return 0;
}

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

using namespace std;

main(){
  int n, m, p;
  int data[1000];

  while(1){
    cin >> n >> m;
    if(n==0 && m==0) break;

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

    sort(data, data+n);
    int sum=0;

    for(int i=n, count=0;i>=0;i--, count++){
      if(count%m!=0){
	sum+=data[i];
      }
    }

    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int M = reader.nextInt();
		int[] arr = new int[M];
		for (int i = 0; i < N; i++) {
			int K = reader.nextInt();
			for (int j = 0; j < K; j++) {
				int num = reader.nextInt();
				arr[num - 1]++;
			}
		}
		reader.close();
		int ans = 0;
		for (int i = 0; i < M; i++) {
			if (arr[i] == N) {
				ans++;
			}
		}
		System.out.print(ans);
	}
}



Measured memory_bytes: 23764
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	string s;
	cin >> s;
	bool ok = true;
	for(int i = 0; i < s.length(); i+= 2){
		if(s[i] =='L') ok = false;
	}
	for(int i = 1; i < s.length(); i += 2){
		if(s[i] == 'R') ok = false;
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define ll              long long
#define Ull             unsigned long long
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 2;
const ll MOD = 1e9 + 7;


void Solve()
{
	ll n, w;
	cin >> n >> w;
	ll dp[n][w + 1];
	for (ll i = 0; i < n; i++)
	{
		for (ll j = 0; j <= w; j++)
			dp[i][j] = 0;
	}




	ll wt[n], val[n];

	for (ll i = 0; i < n; i++)
		cin >> wt[i] >> val[i];


	for (ll i = 0; i <= w; i++)
	{
		if (i >= wt[0])
			dp[0][i] = val[0];
	}

	for (ll i = 1; i < n; i++)
	{
		for (ll j = 0; j <= w; j++)
		{
			if (j >= wt[i])
				dp[i][j] = max(dp[i - 1][j], val[i] + dp[i - 1][j - wt[i]]);

			else
				dp[i][j] = dp[i - 1][j];
		}
	}
	/*for (ll i = 0; i < n; i++)
	{
		for (ll j = 0; j <= w; j++)
		{
			cout << dp[i][j] << " ";
		}
		cout << "\n";
	}*/
	cout << dp[n - 1][w] << "\n";



}


int main()
{

	FastRead;
	int T = 1;
	//cin>>T;
	while (T--)
	{
		Solve();
	}

	return 0;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    int sum = 0;

    for(int i = 0; i < n; i++){
        cin >> m[i];
        sum += m[i];
    }
    int ans = n;
    sort(m.begin(), m.end());
    while(sum + m[0] <= x){
        ans++;
        sum += m[0];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>

#include <map>
 
using namespace std;
typedef long long ll; 


ll ans,mx,sum,mn=1e18,flag;

string k,l;
int main(){
	ll n,m;
	cin>>n>>m;
	for(ll i=1; i<n; i++) sum += i;
	for (ll i=1; i<m; i++) ans += i;
	cout<<sum+ans;
}

Measured memory_bytes: 256
#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;
}

vector<int> z_algorithm(const string& s){
    int len = s.length();
    vector<int> prefix(len, 0);

    for(int i = 1, j = 0; i < len; ++i){
        if(i + prefix[i - j] < j + prefix[j]){
            prefix[i] = prefix[i - j];
        }
        else{
            int k = max(0, j + prefix[j] - i);
            while(i + k < len && s[k] == s[i + k]){
                ++k;
            }
            prefix[i] = k;
            j = i;
        }
    }
    prefix[0] = len;
    
    return prefix;
}

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

    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for(int i = 0; i < N - 1; ++i){
        string s = S.substr(i, N - i);
        vector<int> table = z_algorithm(s);
        for(int j = 0; j < (int)table.size(); ++j){
            chmax(ans, min(table[j], j));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GS(s);
  bool f1 = 0, f2 = 0;
  FOR(i, s.size()) {
    if (s[i] == 'C')
      f1 = 1;
    if (f1 && s[i] == 'F')
      f2 = 1;
  }
  print(f2 ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K;
	cin >> K;
	vector<int> vec={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
	};
	cout << vec.at(K-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    int d = n % 10;
    if(d == 3) cout << "bon" << endl;
    else if(d == 0 || d == 1 || d == 6 || d == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){

  long n;
  long i, j, temp;
  long min, max, sum = 0;

  scanf("%ld", &n);

  long a[n];

  for(i = 0; i < n; i++){
    scanf("%ld", &a[i]);
  }

  for(i = 0; i < n; i++){
    for(j = i + 1; j < n; j++){
      if(a[i] > a[j]){
	temp = a[i];
	a[i] = a[j];
	a[j] = temp;
      }
    }
  }

  min = a[0];
  max = a[n - 1];

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

  printf("%ld %ld %ld\n", min, max, sum);
  
  return 0;
}


Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int dp[100010][3];

int main() {
	int N, K, R, S, P;
	string T;
	cin >> N >> K >> R >> S >> P >> T;
	for(int i=0; i<K; ++i){
		dp[i][0]=(T[i]=='s' ? R : 0);
		dp[i][1]=(T[i]=='p' ? S : 0);
		dp[i][2]=(T[i]=='r' ? P : 0);
		for(int j=i+K; j<N; j += K){
			dp[j][0]=(T[j]=='s' ? R : 0)+max(dp[j-K][1], dp[j-K][2]);
			dp[j][1]=(T[j]=='p' ? S : 0)+max(dp[j-K][0], dp[j-K][2]);
			dp[j][2]=(T[j]=='r' ? P : 0)+max(dp[j-K][0], dp[j-K][1]);
		}
	}
	int ans=0;
	for(int i=0; i<K; ++i) ans += max(dp[N-1-i][0], max(dp[N-1-i][1], dp[N-1-i][2]));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<complex>
#include<cmath>
#include<string>
#include<queue>
using namespace std;
typedef complex<double> xy_t;
int main()
{
  const double eps = 1e-11;
  int n;
  double x[4],y[4];
  queue<string> qs;
  cin >> n;
  for( int i = 0; i < n; ++i){
    xy_t p[4];
    for( int j = 0; j < 4; ++j){
      cin >> x[j] >> y[j];
      p[j] = xy_t(x[j],y[j]);
    }
    double S;
    S =(conj(p[0] - p[1])*(p[2] - p[3])).imag();
    if( abs(S) < eps) qs.push("YES");
    else qs.push("NO");
  }
  while(!qs.empty()){
    cout << qs.front() << endl;
    qs.pop();
  }
}

Measured memory_bytes: 1244
import java.util.Scanner;
class Main {

	public static void printArray(int[] a,int n){
    	for(int f=0;f<n;f++){
    		if(f<n-1)System.out.print(a[f]+" ");
    		else System.out.println(a[f]);
    	}
	}

	public static void scanArray(int[] a,int n, Scanner s){
    	for(int i=0;i<n;i++){
    		a[i] = s.nextInt();
    	}
	}

	public static void insertSort(int[] a,int n){
		int v,j;
    	for(int i=1;i<n;i++){
    		v=a[i];
    		j=i-1;
    		while(j>=0 && a[j]>v){
    			a[j+1]=a[j];
    			j--;
    		}
    		a[j+1]=v;

    		printArray(a,n);
    	}
	}

	public static void bubbleSort(int[] a,int n){
		int f = 1;
		int c = 0;
		int tmp;
		while(f==1){
			f=0;
			for(int j=n-1;j>=1;j--){
				if(a[j]<a[j-1]){
					c+=1;
					tmp=a[j];
					a[j]=a[j-1];
					a[j-1]=tmp;
					f=1;
				}
			}
		}
		printArray(a,n);
		System.out.println(c);
	}

	public static void selectionSort(int[] a,int n){
		int minj;
		int tmp;
		int c=0;
		for(int i=0;i<n;i++){
			minj=i;
			for(int j=i;j<n;j++){
				if(a[j]<a[minj]){
					minj=j;
				}
			}
			if(minj!=i)c+=1;{
				tmp=a[i];
				a[i]=a[minj];
				a[minj]=tmp;
			}
		}
		printArray(a,n);
		System.out.println(c);
	}

	public static void main(String args[]) {
    	Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int a[] = new int[n];

    	scanArray(a,n,scan);
    	//printArray(a,n);
    	//insertSort(a,n);
    	//bubbleSort(a,n);
    	selectionSort(a,n);


    }
}

Measured memory_bytes: 26172
#include<iostream>
#include<stdio.h>
#include<vector>
#include <algorithm>
#include<string>

using namespace std;

int main(){
        int a,b,i=0;
        string s;
        cin >> a >> b;
        cin >> s;
        for(i=0;i<a;i++){
                if(i==b-1){
                        if(s[i]=='A'){
                                cout << 'a';
                        }else if(s[i]=='B'){
                                cout << 'b';
                        }else{
                                cout << 'c';
                        }
                }else{
                        cout << s[i];
                }
        }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int bingo[3][3];
    int i, j, yes=0;
    for(i=0; i<3; i++){
        for(j=0; j<3; j++){
            scanf("%d", &bingo[i][j]);
        }
    }
    int N;
    scanf("%d", &N);
    int ans[N];
    for(i=0; i<N; i++){
        scanf("%d", &ans[i]);
    }
    int c;
    for(c=0; c<N; c++){
        for(i=0; i<3; i++){
            for(j=0; j<3; j++){
                if(ans[c]==bingo[i][j]){
                    bingo[i][j]=0;
                }
            }
        }
    }
    for(i=0; i<3; i++){
        if(bingo[i][0]==0 && bingo[i][1]==0 && bingo[i][2]==0){
            yes=1;
        }
    }
    for(i=0; i<3; i++){
        if(bingo[0][i]==0 && bingo[1][i]==0 && bingo[2][i]==0){
            yes=1;
        }
    }
    if(bingo[0][0]==0 && bingo[1][1]==0 && bingo[2][2]==0){
        yes=1;
    }
    if(bingo[0][2]==0 && bingo[1][1]==0 && bingo[2][0]==0){
        yes=1;
    }
    if(yes==1){
        puts("Yes");
    }
    if(yes==0){
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 128
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

x = I()
if x == 0:
    print(1)
else:
    print(0)

Measured memory_bytes: 9108
n = gets.to_i
hash = Hash.new(0)
n.times do
  s = gets.chomp
  if s[0] =~ /[MARCH]/
	  hash[s[0]] += 1
  end
end
sum = 0

hash.values.combination(3).each do |a|
  sum += a.inject(:*)
end
puts sum

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
 
typedef long long               ll;
typedef long double             ld;
 
 
#define racecar          ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define si(a)            scanf("%d", &a)
#define si2(a,b)         scanf("%d %d", &a,&b)
#define sll(a)           scanf("%I64d",&a)
#define sll2(a,b)        scanf("%I64d %I64d",&a,&b)
#define pb               push_back
#define pi(a)            printf("%d",int(a))
#define pll(a)           printf("%I64d",ll(a))
#define all(x)           (x).begin(),(x).end()
#define rall(x)          (x).rbegin(),(x).rend()
#define ps               printf(" ")
#define nln              printf("\n")
#define ff               first
#define ss               second
#define vi               vector<int>
#define vll              vector<ll>
#define vstr             vector<string>
#define vc               vector<char>
#define pii              pair<int,int>
#define PLL              pair<ll,ll>
#define PI               acos(-1)
#define sq(x)            x*x
#define forr(i,a,b)      for(ll i=ll(a);i<ll(b);i++)
#define forn(i,a,b)      for(ll i=ll(a);i>ll(b);i--)
#define max3(a,b,c)      max(a,max(b,c))
#define max4(a,b,c,d)    max(max3(a,b,c),d)
#define min3(a,b,c)      min(a,min(b,c))
#define mod              1000000007
#define inf              9223372036854775807

///knight moves:
///int dx[] = {-2, -1, 1, 2, -2, -1, 1, 2}; 
///int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};

 
ll power(ll b,ll n)
{
    if(n==0) return 1;
    else if(n%2) return b*power(b,n/2)*power(b,n/2);
    else return power(b,n/2)*power(b,n/2);
}
 
ld root(ll n,ll r)
{
    ld dif=0.0001;
    ld guess=n/2.0;
    while(abs(pow(guess,r)-n)>=dif)
    {
        ld temp=pow(guess,r)-n;
        ld tmp=r*pow(guess,r-1);
        guess-=temp/tmp;
    }
    return guess;
}
 
void fileio()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}


		
int solve()
{
	string x;
	cin>>x;
	int ans=754;
	forr(i,0,x.size()-2)
	{
		int p,q,r;
		p=x[i]-'0';
		q=x[i+1]-'0';
		r=x[i+2]-'0';
		int x=p*100+q*10+r;
		ans=min(ans,abs(753-x));
	}
	cout<<ans;
		
		
	return 0;
}
	
 
int main()
{   
 
//    racecar;
//    cout<<fixed<<setprecision(6);
//    fileio();
    solve();
}

 
 
///    Before submission=>
///    ***check for integer overflow,array bounds
///    ***check for n


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll ;
typedef double db;
typedef unsigned long long ull ;
const double pi = acos(-1.0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define for0(i,n)          for(int i=0;i<n;i++)
#define for1(i,n)          for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define gcd(a,b)     __gcd(a,b)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)     cout<<"Case "<<z<<": "<<x<<"\n"
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;

int main()
{
	double a,b,h,m;
	double hour,miniute,c,d;
	cin>>a>>b>>h>>m;
	hour=(h+(m*1.0/60))*30;
	//cout<<hour<<nw;
	miniute=m*6.0;
	d=abs(hour-miniute);
	d=min(360-d,d);
	//cout<<d<<nw;
	
	c=a*a+b*b-2*a*b*cos(d*pi/180.0);
	c=sqrt(c);
	printf("%.20f\n", c);
	//cout<<c<<nw;

	return 0;
}


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

int main()
{
  int S, h, m, s;
  cin >> S;
  s = S % 60;
  S /= 60;
  m = S % 60;
  h = S / 60;
  cout << h << ':' << m << ':' << s << endl;
  return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define deb1(x) cout<<#x<<" "<<x<<endl
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;	


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	string s;
	ci2(n,s);
	vi h[2];
	unordered_map<int ,bool> B;
	fo(i,n){
		if(s[i]=='R'){
			h[0].pb(i);
		}
		else if(s[i]=='G'){
			h[1].pb(i);
		}
		else{
			B[i]=true;
		}
	}
	int m =B.size();
	ll cnt=(h[0].size())*(h[1].size())*m;
	for(auto r: h[0]){
		for(auto g: h[1]){
			if((r+g)%2==0 && B[(r+g)/2]){
				cnt--;
			}
			if(B[2*r-g]){
				cnt--;
			}
			if(B[2*g-r]){
				cnt--;
			}
		}
	}
	co(cnt);
}


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

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

int main() {
  int X;
  cin >> X;
  
  while (true) {
    if (prime(X)) break;
    ++X;
  }
  
  cout << X << endl;
  return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n;
vint a,b1,b2;

int main(){
  cin >> n; a.resize(n);
  rep(i,n) cin >> a[i];
  rep(i,n){
    if(i%2==0) b1.push_back(a[i]);
    else b2.push_back(a[i]);
  }
  if(n%2==0){
  rep(i,n/2) cout << b2[n/2-1-i] << ' ';
  for(auto x: b1) cout << x << ' ';
  }
  else{
    rep(i,n/2+1) cout << b1[n/2-i] << ' ';
    for(auto x:b2) cout << x << ' ';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3956
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}


int main(void){
  ull N, M;
  cin >> N >> M;
  ull ans;
  if (N>=2 && M>=2) ans = (N-2)*(M-2);
  else if (N==1 && M==1) ans = 1;
  else if (N==1) ans = M-2;
  else if (M==1) ans = N-2;

  cout << ans << endl;

}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

int a,b,k;

int main() {
    //int ans =0;
    cin>>a>>b>>k;


    REP(i,k)
    {
        if((i+2)%2 == 0)
        {
            //takahashi kun
            if (a==0)
                continue;

            if ((a+2)%2 == 1)
                a--;

            b += a / 2;
            a -= a / 2;
        }
        else
        {
            //aoki kun
            if (b==0)
                continue;

            if ((b+2)%2 == 1)
                b--;

            a += b / 2;
            b -= b / 2;

        }
        
    }
    cout << a << " " << b << endl;
    return 0;
}

int solve(int cookie)
{
    if ((cookie+2)%2 == 0)
    {
        
    }
    else
    {
        
    }
    
}

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

int main() {
    char str[10] = { 0 };
    scanf("%s", str);
    if (strcmp(str, "hi") == 0 || strcmp(str, "hihi") == 0 || strcmp(str, "hihihi") == 0 ||
        strcmp(str, "hihihihi") == 0 || strcmp(str, "hihihihihi") == 0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


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

using namespace std;

double A[2][2];
double B[2];
double Ainv[2][2];

int main()
{
	while(scanf("%lf %lf %lf %lf %lf %lf", &A[0][0], &A[0][1], &B[0],
				&A[1][0], &A[1][1], &B[1]) != EOF)
	{
		double det = A[0][0] * A[1][1] - A[1][0] * A[0][1];
		if(det == 0.0)
		{
			cout << "this equation has no answer." << endl;
			return -1;
		}

		Ainv[0][0] = A[1][1] / det;
		Ainv[0][1] = -A[0][1] / det;
		Ainv[1][0] = -A[1][0] / det;
		Ainv[1][1] = A[0][0] / det;
		
		double ans_x = Ainv[0][0] * B[0] + Ainv[0][1] * B[1];
		double ans_y = Ainv[1][0] * B[0] + Ainv[1][1] * B[1];

		printf("%.3f %.3f\n", ans_x, ans_y);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
  int y, m, d, a;
  while(  cin >> y >> m >> d ) {

    a = y*10000 + m*100 + d;
    if(a >= 18680908) {
      if(a >= 19120730) {
	if(a >= 19261225) {
	  if(a >= 19890108) cout << "heisei" << ' ' << y - 1989 + 1;
	  else cout << "showa" << ' ' << y - 1926 + 1;
	}
	else cout << "taisho" << ' ' << y - 1912 + 1;
      }
      else cout << "meiji" << ' ' << y - 1868 + 1;
      cout << ' ' << m << ' ' << d << endl;
    }
    else cout << "pre-meiji" << endl;
  }
}

Measured memory_bytes: 1164
import io,sys
sys.setrecursionlimit(10**6)
def main(): 
    n = int(input())
    D = []
    for _ in range(n):
        a,b = map(int,input().split())
        D.append(a-b)
    
    for i in range(n-2):
        if D[i]==0 and D[i+1]==0 and D[i+2]==0:
            print("Yes")
            sys.exit()
    
    print("No")

main()

Measured memory_bytes: 9124
local n = tonumber(io.read())
local a = {3,5,7}
function dfs(s)
    if s>n then
        return 0
    end
    local t = s
    local rtn =0
    local e3=false
    local e5=false
  	local e7=false
  	local ee = true
    while t>0 do
        if t%10==3 then
            e3 = true
        elseif t%10==5 then
            e5=true
        elseif t%10==7 then
            e7=true
        else
            ee=false
        end
        t = t//10
    end
    if e3 and e5 and e7 then
        rtn = rtn+1
    end
    if ee then
        for i=1,3,1 do
            rtn = rtn + dfs(s*10+a[i])
        end
    end
    return rtn
end
print(dfs(0))



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

using namespace std;

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

    int c1 = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != i % 2 + '0') {
            c1++;
        }
    }

    if (s.length() - c1 < c1) {
        c1 = s.length() - c1;
    }

    cout << c1 << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int h,w,m;
int a,b;
map<pair<int,int> ,bool> mp;
int x[300010],y[300010];
vector<int> v;
vector<int> t;
int mx=0,mx2=0;
int main(){
	cin>>h>>w>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		x[a]++;
		y[b]++;
		mp[make_pair(a,b)]=1;
		mx=max(mx,x[a]);
		mx2=max(mx2,y[b]);
	}
	for(int i=1;i<=h;i++){
		if(x[i]==mx){
			v.push_back(i);
		}
	}
	for(int i=1;i<=w;i++){
		if(y[i]==mx2){
			t.push_back(i);
		}
	}
	for(int i=0;i<v.size();i++){
		for(int j=0;j<t.size();j++){
			if(!mp[make_pair(v[i],t[j])]){
				cout<<mx+mx2<<endl;
				return 0;
			}
		}
	}
	cout<<mx+mx2-1<<endl;
	return 0;
}

Measured memory_bytes: 28436
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int n;
	cin >>n;
	long long sum=0;
	for(int i=1;i<=n;i++){
		long long temp=n/i;
		sum+=i*((temp*(temp+1))/2);
	}
	cout <<sum<<endl;
	return 0;
}

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

int64_t modpow(int64_t x, int64_t n) {
  const int MOD = 1000000007;
  x = x%MOD;
  if(n==0) return 1;  //再帰の終了条件

  else if(n%2==1) {
    return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
  }
  else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}


int64_t comb(int64_t n, int64_t k) {
  const int MOD = 1000000007;
  int64_t x = 1;
  for(int i=n-k+1; i<=n; i++) {
    x = x*i%MOD;
  }

  int64_t y = 1;
  for(int i=1; i<=k; i++) {
    y = y*i%MOD;
  }
  y = modpow(y, MOD-2);

  return x*y%MOD;
}


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

  const int MOD = 1000000007;
  sort(a, a+n);

  int64_t plus = 0;
  int64_t minus = 0;

  int64_t com = 1;
  for(int i=0; i<=n-k; i++) {
    plus += (a[k-1+i]*com)%MOD;
    minus += (a[n-k-i]*com)%MOD;
    plus = plus%MOD;
    minus = minus%MOD;

    com = ((com*(k+i))%MOD*(modpow(i+1, MOD-2)))%MOD;
  }

  int64_t ans = (plus-minus)%MOD;

  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 4336
#include<bits/stdc++.h>
#define IL inline
#define _ 600005
#define ll long long
using namespace std ;

IL ll gi(){
    ll data = 0 , m = 1; char ch = 0;
    while(ch!='-' && (ch<'0'||ch>'9')) ch = getchar();
    if(ch == '-'){m = 0 ; ch = getchar() ; }
    while(ch >= '0' && ch <= '9'){data = (data<<1) + (data<<3) + (ch^48) ; ch = getchar(); }
    return (m) ? data : -data ; 
}


ll n,c[_],Ans ; 
int main() {
	n = gi() ; 
	for(int i = 1; i <= n; i ++) c[i] = gi() ; 
	sort(c + 1 , c + n + 1) ; 
	int l = c[1] , r = c[1] ; 
	int ql = 2 , qr = n ; 
	while(ql <= qr) {
		int lql = abs(l - c[ql]) , rql = abs(r - c[ql]) , lqr = abs(l - c[qr]) , rqr = abs(r - c[qr]) ;
		int w = max(max(lql , rql) , max(lqr , rqr)) ; 
		if(w == lql) l = c[ql] , ql ++ ; 
		else if(w == rql) r = c[ql] , ql ++ ; 
		else if(w == lqr) l = c[qr] , qr -- ; 
		else if(w == rqr) r = c[qr] , qr -- ; 
		Ans += w ;  
	}
	cout << Ans << endl ; 
	return 0 ; 
}

Measured memory_bytes: 1024
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

a_minus = a_zero = a_plus = 0
for i in range(n):
    if a[i] > 0:
        a_plus += 1
    elif a[i] == 0:
        a_zero += 1
    else:
        a_minus += 1

aa_minus = a_minus * a_plus
aa_zero = a_zero * (n - a_zero) + a_zero * (a_zero - 1) // 2


def check_minus(x):
    # k番目の数がx(<0)以下であるか
    # x以下の数字がk個以上あるか
    cnt = 0
    j = a_minus + a_zero
    for i in range(a_minus):
        # a[i] < 0
        while j < n and a[i] * a[j] > x:
            j += 1
        cnt += n - j

    return cnt >= k


def check_plus(x):
    # k番目の数がx(>0)以下であるか
    # x以下の数字がk個以上あるか

    def func(b, m):
        # 昇順ソート済みの数列b (長さm)
        # 掛け算してx以下となる数を求める
        c = 0
        j = m - 1
        for i in range(m):
            while j > 0 and b[i] * b[j] > x:
                j -= 1
            c += max(j - i, 0)
        return c

    cnt = aa_minus + aa_zero
    cnt += func(a[-a_plus:], a_plus)
    cnt += func(list(reversed(a[:a_minus])), a_minus)
    return cnt >= k


if k <= aa_minus:
    # k番目の数は負の数
    lb = a[0] * a[-1] - 1  # False
    ub = 0  # True
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if check_minus(mid):
            ub = mid
        else:
            lb = mid

    ans = ub
elif k <= aa_minus + aa_zero:
    # k番目の数は0
    ans = 0
else:
    # k番目の数はプラス
    lb = 0  # False
    ub = max(a[0]**2, a[-1]**2) + 1  # True
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if check_plus(mid):
            ub = mid
        else:
            lb = mid

    ans = ub

print(ans)


Measured memory_bytes: 125300
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/


signed main() {
	string s; cin >> s;
	int ans = 0;
	rep(i, s.size()) {
		for (int j = i; j < s.size(); j++) {
			for (int k = i; k <= j; k++) {
				if (s[k] != 'A'&&s[k] != 'C'&&s[k] != 'G'&&s[k] != 'T')goto loop;
			}
			ans = max(ans, j - i + 1);
		loop:;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
function Main (input) {
  var S = parseInt(input.split(" ")[0]);
  var W = parseInt(input.split(" ")[1]);
  if (W >= S) {
  	console.log("unsafe");
  } else {
  	console.log("safe");
  }
}

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

Measured memory_bytes: 30132
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

input = sys.stdin.readline
a = input()

tmp =  int(a[0] * 3)
if int(a[0] * 3) < int(a):
    print(str(int(a[0]) + 1) * 3)
else:
    print(str(int(a[0])) * 3)


Measured memory_bytes: 2940