akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int K, N;
  cin >> K >> N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  
  
  vector<int> sa(N-1);
  int saidai = 0;
  for(int i=0;i<N-1;i++){
    sa.at(i) = A.at(i+1)-A.at(i);
    if(sa.at(i)>saidai){ saidai=sa.at(i);}
  }
  
  int sa0=0;
  sa0 = A.at(0) + K-A.at(N-1);
  
  if(sa0>saidai){ saidai=sa0;}
  
  cout << K-saidai << endl;
  
  
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	string s;
	cin >>n >>s;
	int cw=0;
	rep(i, n) if(s[i]=='W') cw++;
	int cr=n-cw;
	int cnd = min(cw, cr);
	
	int j=n-1;
	int ans = 0;
	rep(i, n){
		if(s[i] =='R') continue;
		for(;j>=0;j--){
			if(j<=i) goto brout;
			if(s[j]=='W') continue;
			swap(s[i], s[j]);
			ans++;
			break;
		}
	}
	brout:;
	
	rep(i, n-1) if(s[i]=='W' && s[i+1]=='R') ans++;
	
	cout <<ans <<"\n";
	return 0;
}



Measured memory_bytes: 3736
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>

#include <stack>
#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(x)            std::cerr << #x << "=" << (x) << " | "

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define no                puts("NO")
#define yes               puts("YES")

using ll  = long long int;
using vi  = std::vector<int>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

void solve() {
    inn(n); inn(m);
    vi adj[n];
    vi inv[n];
    rep(i, m) {
        inn(x); --x;
        inn(y); --y;
        adj[x].push_back(y);
        inv[y].push_back(x);
    }

    std::stack<int> tsort;
    std::function<void()> dfs = [&]() {
        bool visited[n] = {0};

        std::function<void(int)> idfs = [&](int i) {
            std::stack<int> s; s.push(i);
            while (!s.empty()) {
                int u = s.top();
                if (visited[u] == 1) {
                    s.pop();
                    tsort.push(u);
                    continue;
                }
                visited[u] = 1;
                for (int v: adj[u]) if (!visited[v]) {
                    s.push(v);
                }
            }
        };

        rep(i, n) if (!visited[i]) idfs(i);
    }; dfs();

    int d[n] = {0};
    d[tsort.top()] = 0; tsort.pop(); 
    while (!tsort.empty()) {
        int u = tsort.top(); tsort.pop();
        for (int v: inv[u]) d[u] = std::max(d[u], d[v] + 1);
    }

    out(*std::max_element(d, d + n));
}

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

    //inn(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}


Measured memory_bytes: 12032
package main

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

var heights []int
var k int

func isPossible(goal int) bool {

	for i := 0; i+k-1 < len(heights); i++ {
		diff := heights[i+k-1] - heights[i]
		if diff <= goal {
			return true
		}
	}

	return false
}

func calc(min, max int) int {

	if min+1 == max {
		return max
	}

	mid := (min + max) / 2
	if isPossible(mid) {
		return calc(min, mid)
	} else {
		return calc(mid, max)
	}
}

func parse() {

	stdin := bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanWords)

	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())

	stdin.Scan()
	k_, _ := strconv.Atoi(stdin.Text())
	k = k_

	heights = make([]int, n)
	for i := 0; i < n; i++ {
		stdin.Scan()
		h, _ := strconv.Atoi(stdin.Text())
		heights[i] = h
	}

	sort.Sort(sort.IntSlice(heights))
}

func main() {

	parse()
	answer := calc(-1, 1000000000)
	fmt.Println(answer)
}


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

using namespace std;

int n,sum,lst;
long long ans;
char s[1<<20];

int main(){
	scanf("%s",s+1); n=strlen(s+1);
	lst=0;
	for (int i=n;i;--i){
		if (s[i]=='C'){
			if (lst!=1) sum=0;
			lst=2;
		}
		if (s[i]=='A'){
			if (lst==1) ans+=sum;
			else{lst=sum=0;}
		}
		if (s[i]=='B'){
			if (lst==2){++sum; lst=1;}
			else{lst=1; sum=0;}
		}
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 384
#include <stdio.h>
typedef struct{
  char name[10];
  int time;
}Rrobin;

Rrobin dequeue(void);
void enqueue(Rrobin);


int head, tail, n;
Rrobin queue[100000];

int main(){

  int q, i, count=0, total=0;
  Rrobin a;

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

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

  //ok from here

  while(total!=n){
    
    a=dequeue();//先頭を取り出してaに入れる

    if(a.time==0){
      //  enqueue(a);
      continue;
    }
    if(a.time<=q){

      count+=a.time;
      a.time=0;
      //      enqueue(a);
      printf("%s %d\n", a.name, count);
      total++;
    }  
    if(a.time>q){//100より大きい
     
      count+=q;
      a.time-=q;
      enqueue(a);

    }
    
  }
  return 0;
    
}


Rrobin dequeue(void){

  Rrobin b;
  b=queue[head];
  head=(head+1)%n;
  
  return b;
}

void enqueue(Rrobin a){

  tail=(tail+1)%n;
  queue[tail]=a;
}



Measured memory_bytes: 2492
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
ll n;
ll x[20];
ll y[20];
ll p[20];

vector<vector<ll>> ab(ll* xy){
    vector<vector<ll>> a(n,vector<ll>(1<<n,INF));
    for(ll bit=0;bit<(1<<n);bit++){
        vector<ll> xx;
        rep(i,n){
            if(bit>>i&1){
                xx.push_back(xy[i]);
            }
        }

        rep(i,n){
            rep(j,xx.size()){
                a[i][bit] = min(a[i][bit],abs(xy[i]-xx[j]));
            }
        }
    }
    return a;
}

int main(){
    cin >> n;
    rep(i,n) cin >> x[i] >> y[i] >> p[i];
    vector<vector<ll>> a = ab(x);
    vector<vector<ll>> b = ab(y);

    /*
    rep(i,n){
        rep(j,1<<n) cout << b[i][j] << " ";
        cout << endl;
    }
    */

    vector<ll> ans(n+1,LINF);

    for(ll bit=0;bit<(1<<n);bit++){
        ll res = 0;
        vector<ll> own(n,0);
        int c = 0;
        rep(i,n){
            if(!(bit>>i&1)) own[i] = 1,++c;
        }
        for(int i=bit;i>=0;i--){
            i &= bit;
            int xx = 0;
            int yy = 0;
            rep(j,n){
                if(i>>j&1) xx += (1<<j);
                else if(own[j]==0) yy += (1<<j);
            }
            rep(i,n){
                if(own[i]==1) res += p[i] * min({abs(x[i]),abs(y[i]),a[i][xx],b[i][yy]});
            }
            ans[n-c] = min(ans[n-c],res);
            res = 0;
        }
    }
    rep(i,n+1) cout << ans[i] << endl;
    return 0;
}

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

using namespace std ;

#define ll long long 
#define N 200010

int n ;
ll a[ N ] ;

// xor 性质： a xor b <= a + b 
// a xor b == a + b 时当且仅当 a & b = 0 
//所以a_l xor ... xor a_r == a_l xor ... xor a_r 当且仅当a_l到a_r每一位上只有一个1 
//于是这个区间是有单调性的（对于合法的a_l 和 a_r ， a_{l+1} 和 a_{r} 显然也合法） 
//所以用two-pointers搞搞 

int main() {
    scanf( "%d" , &n ) ;
    for( int i = 1 ; i <= n ; i ++ ) {
        scanf( "%lld" , &a[ i ] ) ;
    }
    int l = 1 , r = 1 , now = 0 ;
    ll ans = 0 ;
    while( r <= n ) {
        while( ( now ^ a[ r ] ) == now + a[ r ] && r <= n ) now ^= a[ r ++ ] , ans += r - l ;
        now ^= a[ l ++ ] ;
    }
    printf( "%lld\n" , ans ) ;
} 



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int A=0,B=0;
    cin>>s;
    for(int i=0; i<3; i++){
        if(s[i] =='A'){
            A++;
        }
        else{
            B++;
        }
    }
    if(A>=1&&B>=1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


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

int main(int argc, char const *argv[])
{
  long long N, K;
  cin >> N >> K;
  long long ans = 1;
  for(int i = 0; i < N-1; i++)
    ans *= K-1;
  cout << K * ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	string s;
	cin >> N >> s;
	vector<int> b(N);
	for (b[0] = 0; b[0] < 2; b[0]++) {
		for (b[1] = 0; b[1] < 2; b[1]++) {
			for (int i = 2; i < N; i++) {
				b[i] = (s[i - 1] != 'o') ^ (b[i - 1] ^ b[i - 2]);
			}
			if ((b[N - 2] ^ b[N - 1] ^ b[0]) != (s[N - 1] != 'o')) continue;
			if ((b[N - 1] ^ b[0] ^ b[1]) != (s[0] != 'o')) continue;
			for (int i = 0; i < N; i++) {
				printf("%c", "SW"[b[i]]);
			}
			puts("");
			return 0;
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 896
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){

int N;
ll K;
cin>>N>>K;
ll sum=0;
map<ll,int> m;
ll ans=0;
m[0]++;
ll A[N+1],sum2=0;
rep3(i,N)cin>>A[i];
A[0]=0;
rep3(i,N){
   
    sum+=A[i];
    if(i>=K){
        sum2+=A[i-K];
        m[(sum2-i+K)%K]--;
    }
    ans+=m[(sum-i+K)%K];
    m[(sum-i+K)%K]++;

}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 17668
H,W=map(int,input().split())
s=[]
s.append(['.' for i in range(W+2)])
for i in range(H):
    kr=list(input())
    kr=["."]+kr+["."]
    s.append(kr)
s.append(['.' for i in range(W+2)])
ans='Yes'
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j]=='#':
            if s[i+1][j]=='.'and s[i-1][j]=='.'and s[i][j+1]=='.'and s[i][j-1]=='.':
                ans='No'
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <stack>

#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rep_to(a,i,x) for(int i=a;i<x;i++)

using namespace std;


int main()
{
	int L,A,B,C,D;
	cin>>L>>A>>B>>C>>D;

	while(1)
	{
		if(A<=0 && B<=0)break;
		A-=C;
		B-=D;
		L--;
	}
	cout<<L<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll num[10][10];
    REP(i, 0, 10) {
        fill(num[i], num[i] + 10, 0);
    }
    REP(i, 1, N + 1) {
        ll lo = i % 10;
        ll hi = to_string(i)[0] - '0';
        // cout << i << " " << lo << " " << hi << endl;
        num[hi][lo]++;
    }
    ll ans = 0;
    REP(i, 1, 10) {
        REP(j, i, 10) {
            if (i == j) {
                ans += num[i][j] * num[i][j];
            } else {
                ans += num[i][j] * num[j][i] * 2;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int x,n,flag[101],i;
  scanf("%d",&x);
  scanf("%d",&n);
  for(i=1;i<=100;i++){
    flag[i]=1;
  }
  while(n>0){
    scanf("%d",&i);
    flag[i]=0;
    n--;
  }
  for(i=0;i<=100;i++){
    if((x-i)>=0){
      if(flag[x-i]){
        printf("%d",x-i);
        return 0;
      }
    }
    if((x+i)<=101){
      if(flag[x+i]){
        printf("%d",x+i);
        return 0;
      }
    }
  }
  return 0;
}
  
  

Measured memory_bytes: 1728
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String S = in.next();
		Pattern pattern = Pattern.compile("[ACGT]+");
		Matcher matcher = pattern.matcher(S);
		int ret = 0;
		while (matcher.find()) {
			int length = matcher.group().length();
			ret = Math.max(ret, length);
		}
		System.out.println(ret);
	}
}


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

int main(){
	int p,q,r;
	cin >> p >> q >> r;
	cout << min(p+r,min(p+q,q+r)) << endl;
}

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

Measured memory_bytes: 3568
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int list1[] = {a,b,c};
		Arrays.sort(list1);


		System.out.println(list1[0] + " " + 
		list1[1] + " " + list1[2]);

		
	}
}


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

using namespace std;
using ll=long long;

void solve() {
    ll n,a,d;
    cin >> n >> a >> d;
    if (d == 0) {
        if (a == 0) {
            cout << 1;
        } else {
            cout << n+1;
        }
        return;
    }

    if (d < 0) {
        a *= -1; d *= -1;
    }

    map<ll, vector<pair<ll,ll>>> mp;
    mp[0].emplace_back(0, 1);
    for (ll i = 1; i <= n; i++) {
        ll s = a*i;
        ll l = i*(i-1)/2;
        ll r = (2*n-i-1)*i/2 + 1;
        ll x = ((s%d)+d)%d;
        ll k = (s-x)/d;
        l += k, r += k;
        mp[x].emplace_back(l, r);
    }

    ll res = 0;
    for (auto& _: mp) {
        auto& a = _.second;
        sort(a.begin(), a.end());
        ll l, r;
        tie(l, r) = a[0];
        for (auto& p: a) {
            ll _l, _r;
            tie(_l, _r) = p;
            if (_l > r) {
                res += r - l;
                r = _r;
                l = _l;
            } else {
                r = max(r, _r);
            }
        }
        res += r - l;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 22144
x = [int(i) for i in '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'.split(', ')]
K = int(input())
print(x[K - 1])


Measured memory_bytes: 2940
X = int(input())

import math
def is_beki(n):
  for i in range(2, int(math.sqrt(n)//1)+1):
    beki = i
    while beki <= n:
      if beki == n:
        return True
      beki = beki * i
  return False

if X == 1:
  print(1)
else:
  for i in range(X, 1, -1):
    if is_beki(i):
      break
  print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	string s;
	cin >> s;
	cout << s.substr(0, 4) << " " << s.substr(4, 12) << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string.h>
using namespace std;

int main(){
    string n;

    cin >> n;

    if(n[n.length()-1]=='2'||n[n.length()-1]=='4'||n[n.length()-1]=='5'||n[n.length()-1]=='7'||n[n.length()-1]=='9') cout << "hon" << endl;
    else if(n[n.length()-1]=='0'||n[n.length()-1]=='1'||n[n.length()-1]=='6'||n[n.length()-1]=='8') cout << "pon" << endl;
    else if(n[n.length()-1]=='3')cout << "bon" << endl;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const ll MOD=1e9+7;
int main()
{
    int m1, d1, m2, d2;
	cin>>m1>>d1>>m2>>d2;
	if(m1!=m2) cout<<1<<endl;
	else cout<<0<<endl;
    return 0;
}

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

namespace Project2
{
    class MaximumValue
    {
        public static void Main()
        {
            string s = Console.ReadLine();
            int N = int.Parse(s);
            int sum = 0;

            s = Console.ReadLine();
            int[] b = s.Split(' ').Select(y => int.Parse(y)).ToArray();
            var a = new List<int>();

            a.Add(b[0]);
            for(int i=1; i<N-1; i++)
            {
                a.Add(Math.Min(b[i - 1], b[i]));
            }
            a.Add(b[N - 2]);

            for(int i=0; i< a.Count(); i++)
            {
                sum += a[i];
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
	
	
	static void canMultiply(int a) {
		
		for(int i=1;i<10;i++) {
			for(int j=1;j<10;j++) {
				if(a==j*i) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
		
		
	}
		public static void main(String[] args) {
			
			Scanner sc =new Scanner(System.in);
			
			
			int a,b;
			a=sc.nextInt();
			
			canMultiply(a);
			
			
		
		
		
		}

}


Measured memory_bytes: 21844
import java.util.Scanner;

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

        n=nextInt();
        sum=0;

        int[] arr = new int[n];

        for(int i=0;i<n;i++){
            arr[i]=nextInt();
        }
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                sum+=arr[i]*arr[j];
            }
        }
        print(sum);
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}

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

struct node {
	int key;
	node *right, *left, *parent;
	node(int key_) {
		key = key_;
		right = left = parent = NULL;
	}
	~node() {
		if (right != NULL) delete right;
		if (left != NULL) delete left;
	}
};

struct Binary_Tree {
	node *head;
	Binary_Tree() {
		head = NULL;
	}
	~Binary_Tree() {
		if (head != NULL) delete head;
	}
	void insert(int z) {
		insert(new node(z));
	}
	void insert(node* z) {
		node *y = NULL, *x = head;
		while(x != NULL){
			y = x;
			if (z->key < x->key)
				x = x->left;
			else
				x = x->right;
		}
		z->parent = y;

		if (y == NULL) {
			head = z;
		}
		else if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
	void Inorder(node *n) {
		if (n == NULL) return;
		Inorder(n->left);
		cout << ' ' << n->key;
		Inorder(n->right);
	}
	void Preorder(node *n) {
		if (n == NULL) return;
		cout << ' ' << n->key;
		Preorder(n->left);
		Preorder(n->right);
	}
	void print() {
		Inorder(head); cout << endl;
		Preorder(head); cout << endl;
	}
	void find(int z) {
		bool flag = false;
		node *x = head;
		while (x != NULL) {
			if (z == x->key) {
				flag = true;
				break;
			}
			else if (z < x->key)
				x = x->left;
			else
				x = x->right;
		}
		if (flag) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
};

int main()
{
	int m;
	string s;
	Binary_Tree bt;
	cin >> m;
	for (int i = 0, n; i < m; i++) {
		cin >> s;
		if (s == "insert") {
			cin >> n;
			bt.insert(n);
		}
		else if (s == "find") {
			cin >> n;
			bt.find(n);
		}
		else {
			bt.print();
		}
	}
	return 0;
}

Measured memory_bytes: 21928
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(N - 1):
        min_j = i
        for j in range(i, N):
            if A[j] < A[min_j]:
                min_j = j
        if min_j != i:
            A[i], A[min_j] = A[min_j], A[i]
            ans += 1

    print(" ".join(map(str, A)))
    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

int main(){
    long int N, max_k=1, subN=1; 
    cin >> N;
    string ans="";

    long int abs_N = abs(N);
    while (abs_N > 0) {
        abs_N /= 2;
        max_k++;
    }

    for (long int k=0; k<=max_k; k++) {
        if (abs(N) % (abs(subN) * 2) == 0) ans = "0" + ans;
        else {
            ans = "1" + ans;
            N -= subN;        
        }
        subN *= -2;
    }

    while ((ans[0] == '0') and (ans.size()>1)) ans = ans.substr(1);

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
# 最小公倍数

def input():
    import sys
    return sys.stdin.readline().rstrip()


def lcm(a, b):
    import fractions
    return a * b // fractions.gcd(a, b)

def main():
    import math
    import collections
    import itertools
    import functools

    n = int(input())
    ts = [int(input()) for _ in range(n)]
    ans = functools.reduce(lcm, ts)
    print(ans)
        
if __name__ == '__main__':
    main()

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

int main(){

string s;
  cin >> s;
bool app[26];
  for(int i=0;i<26;i++){
    app[i]=false;
  }
for(int i=0;s[i]!='\0';i++){
  app[s[i]-'a'] = true;
}
for(int i=0;i<26;i++){
if(!app[i]){
  printf("%c\n",(char)(i+'a'));
  return 0;
}
}
cout << "None" << endl;
}

Measured memory_bytes: 3764
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200){
    printf("%s\n",s.c_str() );
  }else{
    printf("red\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
using namespace std;
using lint = long long;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)

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

    int N;
    cin >> N;

    lint ret = 0;
    REP(i, N) ret += 1LL * (i + 1) * (N - i);

    REP(i, N - 1)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        if (u > v) swap(u, v);
        ret -= 1LL * (u + 1) * (N - v);
    }
    cout << ret << '\n';
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
const int N = 1e6+7 ;
string s ;

int main(){fast ;
	int n,k ;
	cin >> s ;
	n = s.length() ;
	string p1= "" , p2 = "" ;
	F(i,0,n){
		if(i%2)
		p1 += '0' , p2 += '1';
		else p1+= '1' , p2 += '0';
	}
	int cnt1 = 0 , cnt2 = 0 ;
	F(i,0,n){
		if(p1[i] != s[i])
			cnt1++ ;
		if(p2[i] != s[i])
			cnt2++ ;
	}
	cout << min(cnt1 , cnt2) << endl ;
}




Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int count=0;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R')
    {
        count+=3;
    }
    else if((s[0]=='R' && s[1]=='R')|| (s[1]=='R' && s[2]=='R'))
    {
        count+=2;
    }
    else if(s[0]=='R' || s[1]=='R' || s[2]=='R')
    {
        count=1;
    }
    cout<<count<<endl;
} 

Measured memory_bytes: 3624
import sys
import math
MAX_INT = int(10e11)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
print(K*(K-1)**(N-1))

Measured memory_bytes: 38256
//#pragma warning(disable:4996)
//#include <Windows.h>
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;
template<class T>
using pqueue = priority_queue<T, vector<T>, function<bool(T, T)>>;

template<class T>
inline void chmin(T& a, T b) {
	a = min(a, b);
}

template<class T>
inline void chmax(T& a, T b) {
	a = max(a, b);
}

void input();
void solve();

void daminput();
void naive();

void outputinput();

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	input();
	//daminput();
	solve();
	//naive();
	//outputinput();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////

int N, M;
VI A, B;

void input() {
	cin >> N >> M;
	A.resize(M);
	B.resize(M);
	for (int m = 0; m < M; m++) {
		cin >> A[m] >> B[m];
	}
}

void daminput() {
}

//unionFind
class unionFind {
private:
	int* p;   //親配列のポインタ
	int* rank;
	int N;   //要素数
	int* check;   //同値な要素の数
public:
	unionFind(int);   //コンストラクタ
	int parent(int);   //親要素を返す
	void unit(int, int);   //2要素をつなぐ
	int operator[](int);   //parentの省略形
	~unionFind();
	int size(int n);   //頂点nと同値な要素数を返す
};

unionFind::unionFind(int n) {
	N = n;
	p = new int[N];
	rank = new int[N];
	for (int i = 0; i < N; i++) {
		p[i] = i;
		rank[i] = 0;
	}
	check = new int[N];
	for (int n = 0; n < N; n++)check[n] = 1;
	return;
}

int unionFind::parent(int n) {
	if (n < 0 || n >= N)return -1;
	if (p[n] == n)return n;   //自分が一番上の親
	return p[n] = parent(p[n]);   //つなぎ直しと上にたどる操作
}

int unionFind::operator[](int n) {
	return parent(n);
}

void unionFind::unit(int x, int y) {
	x = parent(x), y = parent(y);
	if (x == y)return;   //根が同じだから何もせずに帰る
	int sum = check[x] + check[y];
	if (rank[x] < rank[y])p[x] = y;
	else {
		p[y] = x;
		if (rank[x] == rank[y])rank[x]++;
	}
	check[x] = sum;
	check[y] = sum;
	return;
}

unionFind::~unionFind() {
	delete(p);
	delete(rank);
	delete(check);
	return;
}

int unionFind::size(int n) {
	return check[parent(n)];
}

void solve() {
	unionFind UF(N);
	for (int m = 0; m < M; m++) {
		UF.unit(A[m] - 1, B[m] - 1);
	}
	int ans = -1;
	for (int n = 0; n < N; n++) {
		if (UF[n] == n)ans++;
	}
	cout << ans << "\n";
}

void naive() {
}

void outputinput() {
}

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

int main() {
int n,x;
cin >> n >> x;
vector<int> l(n);
rep(i,n) cin >> l.at(i);
int d = 0,cnt = 1;

rep(i,n){
  d += l.at(i);
  if(d <= x) cnt++;
  else break;
}

cout << cnt << endl;
}
  


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

using namespace std;

long long f(long long a, long long b, long long c)
{
    /*if(a%c==0)
    {
        return (b/c - a/c)+1;
    }
    return (b/c) - (a/c);*/

    return (b/c) - ((a-1)/c);
}

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

int main()
{
    long long a, b, c, d;

    cin>>a>>b>>c>>d;

    long long sum = b - a + 1;

    long long countc = 0, countd = 0, countlcm;

    countc = f(a,b,c);
    countd = f(a,b,d);

    long long lcm = (c*d)/gcd(c,d);

    countlcm = f(a,b,lcm);

    cout<<sum-countc-countd+countlcm;

    //cout<<endl<<sum<<" "<<countc<<" "<<countd<<" "<<lcm<<" "<<countlcm;

    /*
    long long sum=0;

    for(int i=a; i<=b; i++)
    {
        if(i%c!=0 && i%d!=0)
        {
            sum++;
        }
    }
    cout<<sum;
    */
}


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

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

	int ans;

	if (a * n <= b) {
		ans = a * n;		
	}
	else {
		ans = b;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
k = int(input())

def f(num):
  return num / sum(map(int, list(str(num))))

order = 0
sunuke = 1
for i in range(k):
  print(sunuke)
  sunuke += 10**order
  if f(sunuke + 10**(order+1)) < f(sunuke + 10**order):
    order += 1

Measured memory_bytes: 3188
//#pragma GCC optimize(2)
//ÄÏ¾©ÊÐµÚÈýÇøOIÎ¯ÌáÐÑÄú£º
//´úÂëÇ§ÍòÌõ£¬-O2µÚÒ»Ìõ¡£
//-O2²»¹æ·¶£¬³¬Ê±Á½ÐÐÀá¡£
// Happy TLE and WA every day!
// by: zxb
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            4557430888798830399
#define pb              push_back
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
#define read            ZXBs_fast_input
#define write           ZXBs_fast_output
//#define usingFiles
using namespace std;

typedef unsigned int ui;
typedef pair<int, int> pii;
typedef long long ll;

inline bool read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool write(int x){
	if(x >= 10) write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;

int n;
int a[100100];
map<int, int> cnt;
map<int, bool> done;

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> n;
	rep(i, n){
		cin >> a[i];
		cnt[a[i]]++;
	}
	int ans = 0;
	rep(i, n){
		if(done[a[i]]) continue;
		done[a[i]] = 1;
		if(cnt[a[i]] >= a[i]) ans += (cnt[a[i]] - a[i]);
		else ans += (cnt[a[i]]);
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  long long n, m, l, b[100][100], a[100][100], c[100][100] = {};
  cin >> n >> m >> l;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      cin >> b[i][j];
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      for(int k = 0; k < l; k++){
        c[i][k] += a[i][j] * b[j][k];
      }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
      cout << (j == 0 ? "": " ") << c[i][j];
    }
    cout << endl;
  }
}



Measured memory_bytes: 3300
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    int n,i;
    scanf("%d", &n);
    for(i=1;i<10;++i)
    {
        if(n%i==0 && n/i<10)
        {
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}


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

string str[7] = {
	"Monday",
	"Tuesday",
	"Wednesday",
	"Thursday",
	"Friday",
	"Saturday",
	"Sunday"
};

int day[13] = {
	0,
	31, 29, 31, 30,
	31, 30, 31, 31,
	30, 31, 30, 31
};

int main() {
	ios :: sync_with_stdio(false);
	while(true) {
		int m, d; cin >> m >> d;
		if(!m && !d) break;
		int s = d;
		for(int i = 1; i < m; i ++)
			s += day[i];
		cout << str[(s + 2) % 7] << '\n';
	}
	return 0;
}

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

int max(int x, int y) {
  if(x>y) return x;
  return y;
}

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

  int s = -1, e = -1;
  for(int i=0; i<x.size(); i++) {
    if(x[i] == 'A' && s == -1) s = i;
    if(x[i] == 'Z') {
      e = max(e, i);
    }
  }

  cout << (e-s+1) << endl;
}


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

typedef long long ll;

int main() {
    int n;
    ll x;
    cin >> n >> x;
    ll r = 0;
    vector<ll> as(n);
    for(int i=0; i<n; i++){
        cin >> as[i];
        r += as[i];
    }

    for(int magic=1;;magic++) {
        bool out = true;
        ll tmp = 0;
        ll last = as[n-1];
        for(int i=n-1; i>0; i--) {
            if(as[i-1]<as[i]) {
                as[i] = as[i-1];
                out = false;
            }
            tmp += as[i];
        }
        if(last<as[0]) {
            as[0] = last;
            out = false;
        }
        tmp += as[0];
        if(r==tmp) break;
        r = min(r, tmp + x * magic);
        if(out) break;
    }
    cout << r << endl;

}

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

int a[15]={0};

int main(){
    int n;
    cin >> n;
    int ans = pow(3,n);
    int odd = 1;
    for(int i=0;i<n;++i){
        cin >> a[i];
        if(a[i] % 2 == 0)odd *= 2;
    }

    cout << ans - odd << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;


signed main() {
    ll d, t, s;
    cin >> d >> t >> s;
    
    if (d <= s*t) {
        mes("Yes");
        re0;
    }
    mes("No");
    
    
    
        
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main()
{int a[20][20],x[20];
int n,m,c,t=0,sum=0;
cin>>n>>m>>c;
for(int i=0;i<m;i++)
cin>>x[i];
for(int i=0;i<n;i++)
for(int k=0;k<m;k++)
cin>>a[i][k];
for(int i=0;i<n;i++)
{for(int k=0;k<m;k++)
{t=t+a[i][k]*x[k];

}
if((t+c)>0) sum++;
t=0;
}
cout<<sum;
}

Measured memory_bytes: 256
import sys
N=int(input())
S=input()

def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

answer=0
for i in range(N):
  zlist=z_alg(S[i:])
  #print(i,S[i:],zlist)
  for j in range(N-i):
    if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
      
print(answer)

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

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

    vector<int> p(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];

    int count = 0;
    for (int i = 0; i+2 < n; i++)
    {
        if ((p[i] < p[i+1] && p[i+1] < p[i+2]) ||
            (p[i] > p[i+1] && p[i+1] > p[i+2]))
            count++;
    }
    
    cout << count << endl;
}

Measured memory_bytes: 256
S = list(input())
N = len(S)
mod = int(1E9+7)

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

dp[N][3] = 1
for i in range(N-1, -1, -1):
    m = 3 if S[i] == '?' else 1
    dp[i][3] = m*dp[i+1][3]
    if S[i] == '?':
        dp[i][0] = m*dp[i+1][0] + dp[i+1][1]
        dp[i][1] = m*dp[i+1][1] + dp[i+1][2]
        dp[i][2] = m*dp[i+1][2] + dp[i+1][3]
    if S[i] == 'A':
        dp[i][0] = m*dp[i+1][0] + dp[i+1][1]
        dp[i][1] = m*dp[i+1][1]
        dp[i][2] = m*dp[i+1][2]
    if S[i] == 'B':
        dp[i][0] = m*dp[i+1][0]
        dp[i][1] = m*dp[i+1][1] + dp[i+1][2]
        dp[i][2] = m*dp[i+1][2]
    if S[i] == 'C':
        dp[i][0] = m*dp[i+1][0]
        dp[i][1] = m*dp[i+1][1]
        dp[i][2] = m*dp[i+1][2] + dp[i+1][3]
    dp[i][0] %= mod
    dp[i][1] %= mod
    dp[i][2] %= mod
    dp[i][3] %= mod
    
print(dp[0][0])

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];


  ll z = 0;
  rep(i, n) z = z ^ a[i];

  cout << (z? ("No"):("Yes")) << endl;

  return 0;
}


Measured memory_bytes: 1024
N = int(input())
flag = 0
for h in range(1,3500):
    for n in range(1,3500):
        a = 4*h*n-N*(h+n)
        if a>0 and (N*h*n)%a==0:
            w = (N*h*n)//a
            flag = 1
            break
    if flag==1:break
if flag==1:
    print(h,n,w)
else:
    print()

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

int main()
{
	string w;
	cin >> w;
	vector<bool> b(26);
	for (auto c : w) {
		b[c - 'a'] = b[c - 'a'] ^ true;
	}
	cout << (count(b.begin(), b.end(), true) == 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
a = list(input())
 
while len(a) >= 5:
    if a[-5:] == list('dream'):
        del a[-5:]
        continue
    if a[-7:] == list('dreamer'):
        del a[-7:]
        continue
    if a[-5:] == list('erase'):
        del a[-5:]
        continue
    if a[-6:] == list('eraser'):
        del a[-6:]
        continue
    break
 
if a == []:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 50800
n = int(input())
x = [int(w) for w in input().split()]

d = {}

for i in x:
    d[i] = d.get(i, 0) + 1
    
ans = 0
l = list(d.keys())
l = sorted(l)
#print(l)
for i in range(len(l)-2):
    for j in range(i+1, len(l)-1):
        for k in range(j+1, len(l)):
            if l[k] < l[i] + l[j]:
                #print(l[i], l[j], l[k])
                ans += d[l[i]]*d[l[j]]*d[l[k]]
            
            else:
                break
            
print(ans)

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

int main(){
    string str;
    int begin,last;
    int i = 0;

    cin >> str;

    while(str[i] != '\0'){
        if(str[i] == 'A'){
            begin = i;
            break;
        }
        i++;
    }

    i = str.size();
    //cout << i << endl;
    while(str[i - 1] != '\0'){
        if(str[i] == 'Z'){
            last = i;
            break;
        }
        i--;
    }

    //cout << begin << endl << last << endl;

    cout << last - begin + 1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define INF 1 << 30

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

int main(void) {
	int num, i, ma = 0;
	string s;
	map<string, int> mp;
	cin >> num;
	rep(i, num) {
		cin >> s;
		mp[s]++;
		chmax(ma, mp[s]);
	}
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		if(itr -> second == ma)
			cout << itr->first << "\n";
	}
	return 0;
}

Measured memory_bytes: 25216
from itertools import permutations

N = int(input())
P = tuple(input().split())
Q = tuple(input().split())
p = q = 0
s = ''.join([str(i) for i in range(1, N+1)])
for idx, n in enumerate(permutations(s)):
    if P == n: p = idx
    if Q == n: q = idx
print(abs(p-q))

Measured memory_bytes: 3064
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


class LazySegmentTree:
    """ range add and range max"""

    def __init__(self, A):
        INF = 10 ** 18
        self.unit = -INF
        self.N = len(A)
        self.H = (self.N - 1).bit_length()
        self.W = 1 << self.H
        self.lazy = [0] * (2 * self.W)
        self.build(A)

    def build(self, A):
        W = self.W
        data = [self.unit] * (2 * W)
        for i, x in enumerate(A):
            data[W + i] = x
        for i in range(W - 1, 0, -1):
            data[i] = max(data[i << 1], data[i << 1 | 1])
        self.data = data

    def apply(self, p, value):
        self.data[p] += value
        self.lazy[p] += value

    def build_local(self, i):
        while i > 1:
            i >>= 1
            self.data[i] = max(self.data[i << 1], self.data[i << 1 | 1]) + self.lazy[i]

    def propagate(self, p):
        for s in range(self.H, 0, -1):
            i = p >> s
            x = self.lazy[i]
            self.apply(i << 1, x)
            self.apply(i << 1 | 1, x)
            self.lazy[i] = 0

    def range_add(self, L, R, x):
        """ add x to [L,R) """
        L += self.W
        R += self.W
        L0 = L
        R0 = R
        while L < R:
            if L & 1:
                self.apply(L, x)
                L += 1
            if R & 1:
                R -= 1
                self.apply(R, x)
            L >>= 1
            R >>= 1
        self.build_local(L0)
        self.build_local(R0 - 1)

    def range_max(self, L, R):
        """ max of [L,R) """
        L += self.W
        R += self.W
        self.propagate(L)
        self.propagate(R - 1)
        ret = self.unit
        while L < R:
            if L & 1:
                x = self.data[L]
                if ret < x:
                    ret = x
                L += 1
            if R & 1:
                R -= 1
                x = self.data[R]
                if ret < x:
                    ret = x
            L >>= 1
            R >>= 1


N, M = map(int, readline().split())
R_to_LA = [[] for _ in range(N + 1)]
m = map(int, read().split())
for L, R, A in zip(m, m, m):
    R_to_LA[R].append((L, A))

seg = LazySegmentTree([0] * (N + 1))

for R in range(1, N + 1):
    x = seg.data[1]
    seg.range_add(R, R + 1, x)
    for L, A in R_to_LA[R]:
        seg.range_add(L, R + 1, A)
print(seg.data[1])


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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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 mod=1000000007;

int N;
int A[200005];
int sum;
int ans;

signed main(){
    cin>>N;
    for(int i=0;i<N;++i){
        cin>>A[i];
        ans+=A[i]*sum;
        ans%=mod;
        sum+=A[i];
        sum%=mod;
    }
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 5188
#include <iostream>

using namespace std;

// N^P mod M
size_t modM(size_t N, size_t M, size_t P)
{
    size_t a = 1;
    size_t p = 1;

    while (p <= P)
    {
        if ((p & P) != 0) { a = (a * N) % M; }
        N = (N * N) % M;
        p *= 2;
    }

    return a;
}

int main()
{
    size_t M = 1000000000 + 7;

	size_t N;
    cin >> N;

    // 10^N + 8^N - 2 * 9^N mod P を計算すればよいはず

    size_t a = modM(10, M, N);
    size_t b = modM( 8, M, N);
    size_t c = modM( 9, M, N);
    size_t c2 = (2 * c) % M;

    size_t aa = (a + b) % M;

    if (aa >= c2)
    {
        aa = (aa - c2) % M;
    }
    else
    {
        aa = ((aa + M) - c2) % M;
    }

    cout << aa << endl;

    return 0;
}


Measured memory_bytes: 3588