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

using namespace std;

int main()
{
  int n;
  cin>>n;
  vector<string>s;
  for(int i=0;i<n;i++)
  {
      string a;
      cin>>a;
      s.push_back(a);
  }
  sort(s.begin(),s.end());
  int ans=0;
  for(int i=0;i<n;i++)
  {
      if(s[i]!=s[i+1])
        ans++;
  }
  cout<<ans;
}


Measured memory_bytes: 11660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll mypow(ll a, ll b) {
    ll ret = 1;
    while (b--) {
        ret *= a;
    }
    return ret;
}

ll keta(ll a) {
    ll ret = 0;
    while (a) {
        ret++;
        a /= 10;
    }
    return ret;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll num = mypow(10, keta(b)) * a + b;
    //cout << num << endl;
    rep(i, 1000) {
        if (num == i * i) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";

    return 0;
}

Measured memory_bytes: 3604
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void calc(int a, int b) {
    int d = abs(a - b);
    if (d % 2 == 1) {
        writeln("IMPOSSIBLE");
        return;
    }
    writeln(min(a, b) + d / 2);
}

void main() {
    int a, b; scan(a, b);
    calc(a, b);
}


Measured memory_bytes: 256
# coding: utf-8
Pos = Struct.new(:x, :y)
LEFT = 0
DOWN = 1
RIGHT = 2
UP = 3
while true do
  # coding: utf-8
  rect_num = gets.to_i
  if rect_num == 0
   break
  end
  # ???,????????£?????????
  max_pos = {up:0, down:0,right:0,left:0}
  poses = []
  poses.push(Pos.new(0,0))
  # ???????????¨?????????
  (rect_num - 1).times do
    line = gets
    # ????????§????????£???????????????????????????????????????
    parent_index,rect_direction = line.split
    parent_index = parent_index.to_i
    rect_direction = rect_direction.to_i
    parent = poses[parent_index]
    x = 0
    y = 0
    case rect_direction
    when UP then
      y = 1
    when RIGHT then
      x = 1
    when DOWN then
      y = -1
    when LEFT then
      x = -1
    end
    new_pos = Pos.new(parent[:x] + x, parent[:y] + y)
    poses.push(new_pos)
    max_pos[:right] = new_pos[:x] if new_pos[:x] > max_pos[:right]
    max_pos[:left] = new_pos[:x] if new_pos[:x] < max_pos[:left]
    max_pos[:up] = new_pos[:y] if new_pos[:y] > max_pos[:up]
    max_pos[:down] = new_pos[:y] if new_pos[:y] < max_pos[:down]
  end
  width = (max_pos[:right] - max_pos[:left]) + 1
  height = (max_pos[:up] - max_pos[:down]) + 1
  puts "#{width} #{height}"
end

Measured memory_bytes: 8900
#include <stdio.h>
int main(){
	int i,j,n,tmp,min,count=0;
	int a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	
	for(i=0;i<n;i++){
		min=i;
		for(j=i;j<n;j++){
			if(a[min]>a[j]) min=j;
		}
		if(i!=min){
			tmp=a[min];
			a[min]=a[i];
			a[i]=tmp;
			count++;
		}
	}
	for(i=0;i<n-1;i++)printf("%d ",a[i]);
	printf("%d\n",a[i]);
	printf("%d\n",count);	
return 0;
}

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

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

            for (int i = 0; i < N; i++) {
                T[i] = long.Parse(Console.ReadLine());
            }

            long ans = T[0];

            for (int i = 0; i < N; i++) {

                ans = (ans / GCD(ans, T[i])) *  T[i];


            }

            Console.WriteLine(ans);
        }

        static long GCD(long a, long b) {
            if (a < b) {
                return GCDRecursive(b, a);
            } else {
                return GCDRecursive(a, b);
            }
        }

        static long GCDRecursive(long a, long b) {
            if (b == 0) {
                return a;
            } else {
                return GCDRecursive(b, a % b);
            }

        }
    }
}


Measured memory_bytes: 13140
#include<iostream>

using namespace std;

#define SIZE 100000

template<class T>
class Que{
	private:
		T array[SIZE];
		int lastPointer = 0;
		int fastPointer = 0;
	public:
		void push(T n);
		T pop();
		bool isEmpty();
};

template<class T>
void Que<T>::push(T a){
	array[lastPointer] = a;
	lastPointer = (lastPointer+1) % SIZE;
}

template<class T>
T Que<T>::pop(){
	T value = array[fastPointer];
	fastPointer = (fastPointer + 1) % SIZE;
	return value;
}

template<class T>
bool Que<T>::isEmpty(){
	return lastPointer == fastPointer;
}

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

	Que<string> names;
	Que<int> times;

	string name;
	int time;
	for(int i=0; i<n; i++){
		cin >> name >> time;
		names.push(name);
		times.push(time);
	}

	int totalTime=0;
	while(!names.isEmpty()){
		name = names.pop();
		time = times.pop();

		if(time<=q){
			cout << name << " " << time + totalTime << endl;
			totalTime += time;
		} else {
			time -= q;
			names.push(name);
			times.push(time);
			totalTime += q;
		}
	}

	return 0;
}


Measured memory_bytes: 6608
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
typedef pair<int,int> Pt;
typedef pair<Pt,Pt> P;
#define fr first
#define sc second
int h,w,sx,sy,gx,gy,d[]={0,1,0,-1},Time[101][101],cnt;
bool used[101][101][1<<5];
int ldx[]={-1,-1,-1,0,1,1,1,0},ldy[]={-1,0,1,1,1,0,-1,-1};
int sdx[]={-2,-2,-2,-2,-2,-1,0,1,2,2,2,2,2,1,0,-1};
int sdy[]={-2,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2};
char mas[101][101];
void BAD(int,int);
int bfs();
bool judge(int x,int y){ return ((x>=0&&x<h&&y>=0&&y<w)? true : false); }
int main(){
  cin >> w >> h;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> mas[i][j];
      if(mas[i][j] == 'S') sx = i,sy = j;
      else if(mas[i][j] == 'G') gx = i,gy = j;
      else if(mas[i][j] == '#') BAD(i,j);
      else if(mas[i][j] == 'M') mas[i][j] = cnt++;
    }
  }
  cout << bfs() << endl;
}
 
int bfs(){
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(Pt(0,sx),Pt(sy,0)));
  while(!que.empty()){
    P p = que.top();
    int t = p.fr.fr,px = p.fr.sc,py = p.sc.fr,BIT = p.sc.sc;
    que.pop();
    if(used[px][py][BIT])continue;
    used[px][py][BIT] = true;
    if(px == gx && py == gy && BIT ==(1<<cnt)-1 )return t;
    for(int i=0;i<4;i++){
      int nx = px + d[i],ny = py + d[3-i],bit = BIT;
      if(!judge(nx,ny)) continue;
      if(mas[nx][ny] == '#') continue;
      if(mas[nx][ny]>=0&&mas[nx][ny]<=10) bit |= 1<<mas[nx][ny];
      que.push(P(Pt(t+Time[px][py]+1,nx),Pt(ny,bit)));
    }
  }
}
void BAD(int x,int y){
  for(int i=0;i<8;i++){
    int nx=x+ldx[i],ny=y+ldy[i];
    if(judge(nx,ny)) Time[nx][ny] = 2;
  }
  for(int i=0;i<16;i++){
    int nx=x+sdx[i],ny=y+sdy[i];
    if(judge(nx,ny)) Time[nx][ny] = max(Time[nx][ny],1);
  }
}

Measured memory_bytes: 1764
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n; cin>>n;
	set<ll> s;
	rep(i,0,n){
		ll a; cin>>a;
		s.insert(a);
	}
	if(s.size()==n)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	return 0;
}

Measured memory_bytes: 12968
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


int main() {
    ll N, K;
    cin >> N >> K;
    ll ans = K * pow(K - 1, N - 1);
    cout << ans << endl;
    return 0;
}


// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        int N=sc.nextInt();
        long D=sc.nextLong();
        D *= D;
        HashMap<pair,Integer> p = new HashMap<>();
        for(int i=0;i<N;i++){
            long x=sc.nextInt(),y=sc.nextInt();
            pair t = new pair(x,y);
            x *= x;
            y *= y;
            if((!p.containsKey(t))&&(D>=x+y)){
                p.put(t,1);
            }
        }
        System.out.println(p.size());
    }
}
class pair {
    long a;
    long b;
    public pair(long a,long b){
        this.a=a;
        this.b=b;
    }
    public pair(){}
}

Measured memory_bytes: 75460
N = int(input())
A_list = list(map(int, input().split()))

prev_height = A_list[0]
result = 0

for i in range(1, N):
    cur_height = A_list[i]
    if prev_height > cur_height:
        result += prev_height - cur_height
    else:
        prev_height = cur_height

print(result)





Measured memory_bytes: 105144
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll N;
vector<ll> A(200010), B(200010);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  ll ans = 0;
  for(int k = 1; k <= 29; k++){
    //k桁目
    ll cnt = 0;
    vector<ll> a(N), b(N);
    rep(i, N){
      a[i] = A[i] % (1 << k), b[i] = B[i] % (1 << k);
    }
    sort(b.begin(), b.end());
    for(int i = 0; i < N; i++){
      //2^(k-1) - a[i] <= b < 2 * 2^(k-1) - a[i]
      //3 * 2^(k-1) ^ a[i] <= b
      ll m1, m2, m3, m4;
      m1 = upper_bound(b.begin(), b.end(), (1<<(k-1)) - a[i] - 1) - b.begin();
      m2 = upper_bound(b.begin(), b.end(), 2 * (1<<(k-1)) - a[i] - 1) - b.begin();
      m3 = upper_bound(b.begin(), b.end(), 3 * (1<<(k-1)) - a[i] - 1) - b.begin();
      cnt += m2 - m1;
      cnt += N - m3;
    }
    if(cnt % 2) ans += (1<<(k-1));
  }
  cout << ans << endl;
}


Measured memory_bytes: 7840
# coding: utf-8
# Your code here!
num_list = list(map(int, input().split())) 

a=num_list[2]-num_list[0]
b=num_list[3]-num_list[1]
if b<0:
    a=a-1
    b=b+60
a=a*60
c=b+a-num_list[4]
if c<0:
    c=0
print(c)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,c;cin>>n>>c;
    ll d[c][c];for(ll i=0;i<c;i++)for(ll j=0;j<c;j++)cin>>d[i][j];
    ll a[n][n];for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)cin>>a[i][j],a[i][j]--;
    map< ll , map<ll,ll> > mp;
    for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)mp[(i+j)%3][a[i][j]]++;
    ll ans = 1e16;
    for(ll i=0;i<c;i++){
        for(ll j=0;j<c;j++){
            for(ll k=0;k<c;k++){
                if(i==j || j==k || i==k)continue;
                ll cur = 0;
                for(auto &ele:mp[0])cur = cur + ele.second*d[ele.first][i];
                for(auto &ele:mp[1])cur = cur + ele.second*d[ele.first][j];
                for(auto &ele:mp[2])cur = cur + ele.second*d[ele.first][k];
                ans=min(ans,cur);
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n,m;
  cin >> n >> m;
  vl h(n);
  rep(i,n){
    cin >> h[i];
  }
  vl a(m),b(m);
  vl ok(n,1);
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--,b[i]--;
    if(h[a[i]]>=h[b[i]]){
      ok[b[i]]=0;
    }
    if(h[a[i]]<=h[b[i]]){
      ok[a[i]]=0;
    }
  }
  ll ans=0;
  rep(i,n){
    ans +=ok[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 6376
#include <bits/stdc++.h> 
#define pb push_back
#define M 100005
#define ll long long int
#define rep(i,n) for(int i=1;i<n;i++)
#define mp(a,b) make_pair(a,b)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
using namespace std;
int main(){
	ll n,x;
	string s,s1;
	cin>>s>>s1;
	if(s[0]==s1[2] and s[1]==s1[1] and s[2]==s1[0])puts("YES");
	else puts("NO");
return 0;
}

Measured memory_bytes: 384
def linearSearch(A, n, key):
	i = 0
	A.append(key) # 番兵を置く
	while A[i] != key:
		i += 1
	A.pop(-1) # 番兵を取り出す
	return i != n # 見つかったらTrue, 見つからなかったらFalse


if __name__ == "__main__":
	n = int(input())
	S = list(map(int, input().split()))
	q = int(input())
	sum = 0
	for key in list(map(int, input().split())):
		if linearSearch(S, n, key):
			sum += 1
	print(sum)


Measured memory_bytes: 6548
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n, k;
    cin >> n >> k;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        if (h >= k)
            sum++;
    }
    cout << sum << "\n";
}

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

#define LL long long
#define ULL unsigned long long int
LL INF=1000000000000000001;
#define mx 100009
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define INP freopen("in.txt","r",stdin)
#define OP  freopen("in.txt","w",stdout)

#define sf 	scanf
#define pf 	printf
#define F  	first
#define S  	second
#define pb 	push_back
#define NL	pf("\n")
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%I64d",&x);
#define sll(x,y)	sf("%I64d%I64d",&x,&y);
#define slll(x,y,z)	sf("%I64d%I64d%I64d",&x,&y,&z);
#define clr(x,y) 	memset(x,y,sizeof (x) )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v)		sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(i=0;i<n;i++)
#define FORE(i,n)	for(i=1;i<=n;i++)
#define FORR(i,n)	for(i=n-1;i>=0;i--)
#define FORRE(i,n)	for(i=n;i>0;i--)
// graph direction array [4]
//int X[4]={0,0,1,-1};
//int Y[4]={1,-1,0,0};

//bool cmp( int a,int b ){
//	return  a>b ;
//}

LL M=0,A=1,R=2,C=3,H=4;

LL occur[6];


int main(){

//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
	LL n,m,i,j,k,t,d,bs,cs=0,c,sq,x,s,f,v;
	clr(occur,0);
	string name;
	char cc;
	cin>>n;
	FOR(i,n){
		cin>>name;cc = name[0];
		if(cc=='M')occur[M]++;
		else if(cc=='A')occur[A]++;
		else if(cc=='R')occur[R]++;
		else if(cc=='C')occur[C]++;
		else if(cc=='H')occur[H]++;
	}

    LL ans=0;

    FOR(i,5){
		for(j=i+1;j<5;j++){
			for(k=j+1;k<5;k++){

                if( i==j || j==k || i==k )continue;
                ans += occur[i]*occur[j]*occur[k];

			}
		}
    }

    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
vector<string> lunlun;

void dfs(ll n,string s)
{
    int ss = s.size();
    if(ss==n){
        lunlun.pb(s);
        return;
    }
    int c = s[ss - 1]-'0';
    if(c==0){
        dfs(n, s + to_string(c));
        dfs(n, s + to_string(c+1));
    }
    else if(c==9){
        dfs(n, s + to_string(c-1));
        dfs(n, s + to_string(c));
    }
    else{
        dfs(n, s + to_string(c-1));
        dfs(n, s + to_string(c));
        dfs(n, s + to_string(c+1));
    }

}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll k;
cin >> k;
ll digit = 1;
while(lunlun.size()<k){
    reps(i,10,1){
        dfs(digit, to_string(i));
        if(lunlun.size()>=k)
            break;
    }
    digit++;
}
cout << lunlun[k-1] << endl;
//system("pause");
return 0;
}

Measured memory_bytes: 6388
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    long long x;
    scanf("%lld", &x);
    long long ans = 0;
    if(x % 11 == 0 || x % 11 == 6) ans = floor(x * 2.0 / 11);
    else ans = ceil(x * 2.0 / 11);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <inttypes.h>

#define INF INT64_C(77777777777777777)

int64_t kugyu(int64_t sakura, int64_t oonisi) {
	int64_t nadukakaori = sakura + oonisi;
	if (nadukakaori > INF) nadukakaori = INF;
	if (nadukakaori < -INF) nadukakaori = -INF;
	return nadukakaori;
}

int N, M, P;
int A[7777], B[7777], C[7777];

int64_t hanazawakana[7777];
char hayamisaori[7777];
int64_t igutiyuka[7777];


int main(void) {
	int i;
	if (scanf("%d%d%d", &N, &M, &P) != 3) return 1;
	for (i = 0; i < M; i++) {
		if (scanf("%d%d%d", &A[i], &B[i], &C[i]) != 3) return 1;
		C[i] -= P;
	}
	/* 最大スコア探索と、ゴールに行けるか判定 */
	for (i = 1; i <= N; i++) {
		hanazawakana[i] = -INF;
		hayamisaori[i] = 0;
	}
	hanazawakana[1] = 0;
	hayamisaori[N] = 1;
	for (i = 0; i < M; i++) {
		int j;
		for (j = 0; j < M; j++) {
			if (hanazawakana[A[j]] > -INF && kugyu(hanazawakana[A[j]], C[j]) > hanazawakana[B[j]]) {
				hanazawakana[B[j]] = kugyu(hanazawakana[A[j]], C[j]);
			}
			if (hayamisaori[B[j]]) hayamisaori[A[j]] = 1;
		}
	}
	/* この時点での最大スコアを保存して */
	for (i = 1; i <= N; i++) igutiyuka[i] = hanazawakana[i];
	/* スコアがもっと伸びるかをチェックする */
	for (i = 0; i < M; i++) {
		int j;
		for (j = 0; j < M; j++) {
			if (hanazawakana[A[j]] > -INF && kugyu(hanazawakana[A[j]], C[j]) > hanazawakana[B[j]]) {
				hanazawakana[B[j]] = kugyu(hanazawakana[A[j]], C[j]);
			}
		}
	}
	for (i = 1; i <= N; i++) {
		if (hayamisaori[i] && hanazawakana[i] > igutiyuka[i]) {
			puts("-1");
			return 0;
		}
	}
	printf("%" PRId64 "\n", hanazawakana[N] < 0 ? 0 : hanazawakana[N]);
	return 0;
}

/*

3 4 0
1 3 100000
1 2 1
2 2 1
2 3 1

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int N; cin >> N;
    vector<char> S(N);
    rep(i, N) cin >> S[i];
    vector<set<int>> vec(26);
    rep(i, N) {
        vec[S[i] - 'a'].insert(i);
    }
    int Q; cin >> Q;
    rep(_, Q) {
        int q; cin >> q;
        if (q == 1) {
            int i; char c; cin >> i >> c;
            i--;
            vec[S[i] - 'a'].erase(i);
            vec[c - 'a'].insert(i);
            S[i] = c;
        }
        else {
            int l, r; cin >> l >> r;
            l--; r--;
            int cnt = 0;
            rep(i, 26) {
                auto it = vec[i].lower_bound(l);
                if (it != vec[i].end() && *it <= r) cnt++;
            }
            cout << cnt << endl;
        }
    }
}


Measured memory_bytes: 27256
import sys
readline=sys.stdin.readline

# 入力のXORを取って、個別とのXORを出力

N = int(readline())
A = list(map(int,readline().split()))

xor = A[0]
for i in range(1,len(A)):
  xor ^= A[i]
  
ans = [-1] * N
for i in range(N):
  ans[i] = A[i] ^ xor
  
print(*ans)

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

int main() {
  int m;
  long double n,d;
  cin >> n >> m >> d;

  long double res = 0;
  for (int i = 0; i < m - 1; i++) {
    if(d == 0) {
      res += (1/n);
    } else {
      res += (2*(n - d)/n/n);
    }
  }
  cout << fixed << setprecision(10) << res << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    int N;
    cin >> N;
    int x = N % 10;
    if(x == 3) PRINT("bon");
    else if(x == 0 || x == 1 || x == 6 || x == 8) PRINT("pon");
    else PRINT("hon");
    return 0;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int a = Integer.valueOf(arr01[0]);
        int b = Integer.valueOf(arr01[1]);
        int c = Integer.valueOf(arr01[2]);
        int d = Integer.valueOf(arr01[3]);

        Boolean chkflg = true;
        Boolean isT = true;

        while (chkflg) {
            if (isT) {
                c -= b;
                if (c <= 0) {
                    System.out.println("Yes");
                    break;
                }

                isT = false;
            } else {

                a -= d;
                if (a <= 0) {
                    System.out.println("No");
                    break;
                }

                isT = true;
            }
        }

    }

}


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

int main() {
  int mod=1000000007;
  long t1,t2,a1,a2,b1,b2;
  cin >> t1>>t2>>a1>>a2>>b1>>b2;
  long k=t1*a1;
  long m=t1*b1;
  long l=k+t2*a2;
  long n=m+t2*b2;
  if((m-k>0&&n-l>0)||(m-k<0&&n-l<0)){
    cout<<0<<endl;
  }
  else if(n-l==0){
    cout<<"infinity"<<endl;
  }
  else{
    if(abs(m-k)%abs(n-l)==0){
      cout<<abs(m-k)/abs(n-l)*2<<endl;
    }
    else{
      cout<<abs(m-k)/abs(n-l)*2+1<<endl;
    }
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define M 100010


int main(){
    IOS;
     
 	ll l,r,d;cin>>l>>r>>d;
 	ll x=r/d-(l-1)/d;
 	cout<<x;
     
     
     
    return 0;
}


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

using namespace std;

int main(int argc, const char *argv[])
{
  int n, x, y;
  cin >> n >> x >> y;
  
  vector<int> dists(n, 0);

  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dist = j - i;
      dist = min(dist, abs(x - i) + min(j - x, 1 + abs(y - j)));
      dists[dist]++;
    }
  }
  
  for (int i = 1; i <= n - 1; i++) {
    cout << dists[i] << "\n";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    RSORT(A);
    int ali = 0;
    int bob = 0;

    REP(i, N) {
        if (i % 2 == 0)
            ali += A[i];
        else
            bob += A[i];
    }

    cout << ali - bob << endl;

    return 0;
}

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BStringRotation {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string s, t;
	    in >> s >> t;
	    bool res = false;
	    int len = s.length();
	    for(int i=0; i<len; i++){
            if(s == t){
                res = true;
                break;
            }
            s = s.substr(1, len) + s[0];
	    }

	    ans(res, out);
	}
};


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


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

int main(){
		int N,K;
		cin >> N >> K;

		vector<int> h(N);
		int count = 0;

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




		for(int i = 0;i < N;i++){
				if( h[i] >= K ) count++;
		}

		cout << count << endl;


}



Measured memory_bytes: 640
n = int(input())

if n == 1:
    print(0)
    exit()

def factrize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

l = factrize(n)
from collections import Counter
dic = Counter(l)

ans = 0
for i in dic.values():
    j = 0
    k = 1
    while i >= k:
        i -= k
        j += 1
        k += 1
    ans += j
print(ans)

Measured memory_bytes: 9464
#171-A
#文字列中の英字が大文字か小文字かを判定：str型（文字列）のメソッドであるisupper()やislower()を使用
#isupper()は大文字、islower()は小文字を判定

α=input()
if α.isupper():
    print("A")
else:
    print("a")

Measured memory_bytes: 9080
fun main(args: Array<String>) = println(run {
    val n = readLine()!!.toInt()
    val a = (1..n).map { readLine()!!.toInt() }

    val visit = mutableSetOf(1)
    var b = 1
    var count = 0
    while (true) {
        b = a[b-1]
        if(b in visit) return@run -1
        visit.add(b)
        count++
        if(b == 2) return@run count
    }

})


Measured memory_bytes: 48108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int i;
  string n,t;
  cin >> n;
  cin >> t;

  int answer=0;
  for(int i = 0; i<3;i++)
    if(n[i]==t[i])
      answer++;

  cout << answer;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> P;


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

    vector<bool> state(1000001, false);
    sort(a.begin(), a.end());

    int res = 0;
    for(int i = 0; i < n; i++){
        if(!state[a[i]]){
            if(i+1 >= n || a[i] != a[i+1]){
                res++;
            }
            int x = 1;
            while(x * a[i] <= 1000000){
                state[x * a[i]] = true;
                x++;
            }
        }
    }

    cout << res << endl;



    return 0;
}


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> d(N);

  for (int i=0; i<N; i++) {
    cin >> d.at(i);
  }

  sort(d.begin(), d.end());

  int prevSize = -1;
  int slices = 0;

  for (int i=0; i<N; i++) {
    int size = d.at(i);
    if (prevSize < size) {
      slices += 1;
      prevSize = size;
    }
  }

  cout << slices << endl;
}


Measured memory_bytes: 256
# ACGT
S =input()
ct = 0
ctM = [0]
for i in range(len(S)):
    if S[i] == "A" or S[i] == "C" or S[i] == "G" or S[i] == "T":
        ct +=1
        if i == len(S)-1:
            ctM.append(ct)
    else:
        ctM.append(ct)
        ct = 0
print(max(ctM))


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

int res[11][11]={
4,5,5,5,6,6,6,7,7,8,9,
4,4,4,5,5,6,7,7,8,8,8,
3,4,5,5,6,6,6,7,7,7,8,
4,4,4,5,5,5,6,6,7,8,8,
4,4,5,5,6,7,7,8,8,8,9,
3,4,4,5,5,5,6,6,6,7,7,
4,4,5,5,5,6,6,7,8,8,9,
3,4,4,5,6,6,7,7,7,8,8,
4,4,5,5,5,6,6,6,7,7,8,
4,5,5,5,6,6,7,8,8,9,9,
3,3,4,5,5,6,6,6,7,7,7,
};

int main()
{
    int n, k;
    int x;
    while(~scanf("%d%d", &n, &k))
        {
            int ans=0;
            if(n>=3 && n<10)
            {
                for(int i=1; i<=n-2; i++)
                {
                    for(int j=1; j<=5; j++)
                    {
                        int a=7*i-7+j;
                        int ma=a+1;
                        int mb=ma+7;
                        int mc=mb+7;
                        int sub=ma*3+mb*3+mc*3;
                        //cout<<i<<"****"<<j<<endl;
                        if(sub%11==k)
                        {
                            ans++;
                            //cout<<i<<" "<<j<<endl;
                        }
                    }
                }
            }
            else{
                ans=res[k][(n-10)%11]+5*((n-10)/11);
            }
            printf("%d\n", ans);
        }
    return 0;
}


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

namespace TestApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var length = Console.ReadLine()
                .Split(' ')
                .Select(x => int.Parse(x)).ToArray();
            int a = length[0];
            int b = length[1];

            var sum = a + b;
            var sub = a - b;
            var mul = a * b;
            var ls = new List<int>(new[]{ sum,sub,mul});
            Console.WriteLine(ls.OrderByDescending(x => x).FirstOrDefault());
            Console.ReadLine();

        }
    }
}



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

int main(){
    int in,ma,sc,en,in2,ma2,sc2,en2;
    cin >> in >> ma >> sc >> en >> in2 >> ma2 >> sc2 >> en2;
    if(in + ma + sc + en > in2 + ma2 + sc2 + en2){
        cout << in + ma + sc + en << endl;
    }
    else{
        cout << in2 + ma2 + sc2 + en2 << endl;
    }
}

Measured memory_bytes: 1160
import numpy as np

def getN():
    return int(input())


def getNM():
    return map(int, input().split())


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

h, w, k = getList()
ns = [1,1,2,3,5,8,13,21]

trans = np.zeros([w,w], dtype=np.int64)
inipos = np.zeros([w], dtype=np.int64)
inipos[0] = 1
for i in range(w):
    trans[i][i] = ns[i] * ns[w-i-1]
    if i < w-1:
        trans[i][i+1] = ns[i] * ns[w-i-2]
    if i > 0:
        trans[i][i-1] = ns[i-1] * ns[w-i-1]

#print(inipos)
#print(trans)
for i in range(h):
    inipos = (np.dot(trans,inipos))
    #inipos = list(map(lambda x:x%1000000007, inipos))
    temp = [num % 1000000007 for num in inipos]
    inipos = temp

print(inipos[k-1])

Measured memory_bytes: 12440
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

std::string s;

signed main(){
	std::cin >> s;
	for(int i = 0; i < s.length(); i++){
		for(int j = i; j <= s.length(); j++){
			std::string t = s.substr(0, i);
			t += s.substr(j, s.length() - j);
			if(t == "keyence"){
				printf("YES\n");
				return 0;
			}
		}
	}
	if(s.substr(0, s.length()) == "keyence"){
		printf("YES\n");
		return 0;
	}
	printf("NO\n");
	return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N; cin >> N;
  map<char, int64_t> mp;
  rep(i, N) {
    string s; cin >> s;
    mp[s[0]]++;
  }

  const string march = "MARCH";
  int64_t ans = 0;
  rep(i, 5) rep(j, i) rep(k, j) {
    ans += mp[march[i]] * mp[march[j]] * mp[march[k]];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(int i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define vinn(n,v) int n;cin>>n;vector<int>v(n);loop(i,0,n)cin>>v[i];
#define vinm(n,m,v) int n,m;cin>>n>>m;vector<int>v(n);loop(i,0,n)cin>>v[i];
#define debug(x) cerr<<#x<<" : "<<x<<endl;
signed main() 
{
    fastio();

    char s;
    while(cin>>s)
    {
        if(s=='7')
        {
            cout<<"Yes";return 0;
        }
    }
    cout<<"No";

    return 0;
}



Measured memory_bytes: 3668
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
  int l;
  cin >> l;
  double a = l / 3.0;
  double result = (l * l * l) / 27.0;
  cout << fixed;
  cout << setprecision(20) << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):0;}
    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;
        while(e)
        {
            if(e&1) ans=ans*x%MOD;
            x=x*x%MOD;e>>=1;
        }
        return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    vc<pr> nw;int L;
    ll calcnw()
    {
        ll ans=0,sum=0;
        for(int t=L-1;t<sz(nw);t++) sum+=nw[t-L+1].FR,ans+=sum*nw[t].SE;
        return ans;
    }
    vc< pair<pr,pr> > all,all2;//(fl,fr,li,ri)表示覆盖区间、作为端点的系数；里面所有数当前都是val
    vc<pr> num;
    void main()
    {
        int n=qread();L=qread();
        for(int i=1;i<=n;i++) num.PB(MP(qread(),i));sort(all(num));
        ll ans=n;int val=0,numpos=0;
        while(1)
        {
            if(!sz(all))
            {
                if(numpos==n) break;
                val=num[numpos].FR;
            } else val++;
            while(numpos<n and num[numpos].FR==val)//newguy
                all.PB(MP( MP(num[numpos].SE,num[numpos].SE),MP(1,1) )),numpos++;
            sort(all(all));all2.clear();
            for(int i=0,j;i<sz(all);i=j+1)
            {
                j=i;while(j+1<sz(all) and all[j].FR.SE+1==all[j+1].FR.FR) j++;//极长连续段
                int cnt=(j-i+1)/L;if(!cnt) continue;
                nw.clear();for(int k=i;k<=j;k++) nw.PB(all[k].SE);ans+=calcnw();
                vc<pr> pos,pp;pp.resize(cnt);
                for(int k=i;k<=j;k++)
                {
                    int tl=k-i+1,tr=j-k+1;
                    if(tl>=L) pp[tl/L-1].SE+=all[k].SE.SE;
                    if(tr>=L) pp[cnt-tr/L].FR+=all[k].SE.FR;
                }
                nw=pp;ans-=calcnw();
                for(int t=0;t<cnt;t++) pos.PB(MP(all[i].FR.FR+t,all[i].FR.FR+t));pos[cnt-1].SE=all[j].FR.SE;
                for(int t=0;t<cnt;t++) all2.PB(MP(pos[t],pp[t]));
            }
            all=all2;
        }
        write(ans);
    }
};
int main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 11372
n,a,b=map(int,input().split());k=10**9+7;c=(1<<n)%k-1;X=Y=1
for i in range(b):X=X*(n-i)%k;Y=Y*(i+1)%k;c-=X*pow(Y,k-2,k)if i+1 in(a,b)else 0
print(c%k)

Measured memory_bytes: 263412
def solve(letter)
  @memo = Hash.new{|h, k| h[k] = Hash.new{0}}
  dfs(letter.dup, 0, (0..9).to_a)
  @memo
end

def dfs(letter, sum, unused)
  return @memo[sum][(0..9).to_a - unused] += 1 if letter.empty?
  c = letter.shift
  unused.each do |i|
    next if i == 0 && @head[c]
    dfs(letter.dup, sum + @coefficient[c] * i, unused.select{|v| v != i})
  end
end

until (n = gets.to_i).zero?
  @head = Hash.new
  @coefficient = Hash.new{0}
  n.times do |i|
    string = gets.chomp
    @head[string.chr] = true if string.size > 1
    case i
      when n - 1
        @coefficient[string.slice!(0)] += 10 ** string.size until string.size.zero?
      else
        @coefficient[string.slice!(0)] -= 10 ** string.size until string.size.zero?
    end
  end

  former = solve(@coefficient.keys[0, @coefficient.size / 2])
  later = solve(@coefficient.keys[@coefficient.size / 2, @coefficient.size])
  answer = 0
  former.each do |sum, h|
    h.each do |used, count|
      later[-sum].each do |u, c|
        answer += count * c if (used & u).size == 0
      end
    end
  end
  p answer
end

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

const long long INF = 1LL * 1e18;

struct mseg {
	long long T[555555];
	void upd(int idx, int s, int e, int p, long long v) {
		if(p < s || e < p) return;
		if(s == e) {
			T[idx] = v;
			return;
		}
		int m = s+e >> 1;
		upd(idx*2, s, m, p, v);
		upd(idx*2+1, m+1, e, p, v);
		T[idx] = min(T[idx*2], T[idx*2+1]);
	}
	long long get(int idx, int s, int e, int l, int r) {
		if(r < s || e < l) return INF;
		if(l <= s && e <= r) return T[idx];
		int m = s+e >> 1;
		return min(get(idx*2, s, m, l, r), get(idx*2+1, m+1, e, l, r));
	}
} LS, RS;

long long D[200009];
int x[200009];

int main() {
	int N, Q, B; scanf("%d%d%d%d", &N, &Q, &x[0], &B);
	for(int i=1; i<=N; i++) {
		if(i == B) {
			LS.upd(1, 1, N, i, -i);
			RS.upd(1, 1, N, i, +i);			
		}
		else {
			LS.upd(1, 1, N, i, INF);
			RS.upd(1, 1, N, i, INF);
		}
	}
	long long os = 0;
	for(int i=1; i<=Q; i++) {
		scanf("%d", &x[i]);
		long long tmp = min(LS.get(1, 1, N, 1, x[i]) + x[i] + os, RS.get(1, 1, N, x[i], N) - x[i] + os);
		os += max(x[i-1] - x[i], x[i] - x[i-1]); tmp -= os;
		LS.upd(1, 1, N, x[i-1], tmp - x[i-1]);
		RS.upd(1, 1, N, x[i-1], tmp + x[i-1]);
	}
	long long ans = INF;
	for(int i=1; i<=N; i++) ans = min(ans, min(LS.get(1, 1, N, i, i) + i + os, RS.get(1, 1, N, i, i) - i + os));
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 9856
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    ans = 0

    A = list(accumulate([0] + A))
    B = list(accumulate([0] + B))

    for i in range(N, -1, -1):
        last = A[i]
        r = K - last
        if r < 0:
            continue
        bidx = bisect.bisect_right(B, r)
        ans = max(ans, i + bidx - 1)
        # print(r, bidx)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 128456
if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        flag = []
        for i in range(21):
            flag.append([0 for j in range(21)])
        for i in range(n):
            x,y = map(int,input().split())
            flag[x][y] = 1;
        m = int(input())
        nx,ny = 10,10
        for i in range(m):
            dre,num = input().split()
            num = int(num)
            if dre == 'N':
                for i in range(num):
                    ny += 1
                    if flag[nx][ny] == 1:
                        flag[nx][ny] = 0
            elif dre == 'W':
                for i in range(num):
                    nx -= 1
                    if flag[nx][ny] == 1:
                        flag[nx][ny] = 0
            elif dre == 'E':
                for i in range(num):
                    nx += 1
                    if flag[nx][ny] == 1:
                        flag[nx][ny] = 0
            else:
                for i in range(num):
                    ny -= 1
                    if flag[nx][ny] == 1:
                        flag[nx][ny] = 0
        ans = True
        for i in range(21):
            for j in range(21):
                if flag[i][j] == 1:
                    ans = False
        if ans:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 5624
program main
	implicit none
	character :: a*50000,b*100000
	integer nagasa,i
	read(*,*) b
	nagasa=len_trim(b)
	do i=1,(nagasa+1)/2
		a(i:i)=b(2*i-1:2*i-1)
	enddo
	write(*,*)a(1:(nagasa+1)/2)
end program main


Measured memory_bytes: 700
package main

import (
	"fmt"
)

func main() {
	var s string
	var start, end bool
	var sp, ep int
	fmt.Scan(&s)

	for i,j :=0, len(s)-1; i<len(s) && (!start || !end); i,j = i+1, j-1 {
		sc := string(s[i])
		if !start && sc == "A" {
			start = true
			sp = i
		}
		ec := string(s[j])
		if !end && ec == "Z" {
			end = true
			ep = j
		}
	}

	fmt.Println(len(s[sp:ep+1]))
}

Measured memory_bytes: 1920