akhauriyash/Code-Regression huggingface dataset:
import numpy as np


def solve(string):
    n, m, c, *ba = map(int, string.split())
    """
    b = np.asarray(ba[:m])
    a = np.asarray(ba[m:])
    a.resize((n, m))
    return str(np.sum(np.dot(a, b.T) > -c))
    """
    b = ba[:m]
    s, t = m, 2 * m
    ans = 0
    while s < (n + 1) * m:
        if sum([_b * _a for _b, _a in zip(b, ba[s:t])]) + c > 0:
            ans += 1
        s, t = t, t + m
    return str(ans)


if __name__ == '__main__':
    n, m, o = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, o) + '\n'.join([input() for _ in range(n + 1)])))


Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B;
  cin >>A>>B;
  for(int i=0;i<1000000000;i++){
    if(abs(A-i)==abs(B-i)){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>

#define rep(p,q) for(int i = p;i < q;i++)

using namespace std;

//B
int main(void) {
	int max = 0;
	string str;
	cin >> str;
	int count = 0;
	rep(0, str.length()) {
		if (str[i] == 'A' || str[i] == 'C' || str[i] == 'G' || str[i] == 'T')count++;
		else count = 0;
		if (count > max)max = count;
	}
	cout << max << endl;
}

Measured memory_bytes: 256
N,A,B = map(int, input().split())
ans = 0
sumj = 0
for i in range(1,N+1):
    for j in range(len(str(i))):
        sumj += int(str(i)[j])
    if  A <= sumj <= B:
        ans += i
    sumj = 0
print(ans)

Measured memory_bytes: 3060
N,M = map(int,input().split())

A_list = []
for i in range(1, M+1):
    A_list.append("A_" + str(i))
A_list = map(int,input().split())

answer = N - sum(A_list)

if answer >= 0:
    print(answer)
else:
    print(-1)


Measured memory_bytes: 10360
using System;
 
class Program
{
  static void Main()
  {
    int R = int.Parse(Console.ReadLine());
    if (R < 1200)
    {
      Console.WriteLine("ABC");
    }
    else if (R < 2800)
    {
      Console.WriteLine("ARC");
    }
    else
    {
      Console.WriteLine("AGC");
    }
  }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define reg register
#define int long long
#define maxn 200001
using namespace std;
struct node{int x, opt, id;} c[maxn];
bool cmp(node g, node h){return g.x < h.x;}
int n, a[maxn], b[maxn], ans, sum, cnt, d[maxn], w[3], t;
inline int  read() {
    reg int s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
signed main()
{
	n = read();
	for(int i = 1; i <= n; i++){
		a[i] = read(); b[i] = read();
		c[++cnt].x = a[i]; c[cnt].id = i; c[cnt].opt = 0;
		c[++cnt].x = b[i]; c[cnt].id = i; c[cnt].opt = 1;
	}
	sort(c + 1, c + cnt + 1, cmp);
	for(int i = 1; i <= n; i++){
		d[c[i].id]++; ans += c[i].x;
		w[c[i].opt]++; if(d[c[i].id] == 2) t = 1;
	}
	if(t == 1 || w[1] == 0 || w[0] == 0){
		cout << ans << endl; return 0;
	}
	sum = 1000000000000000000;
	for(int i = 1; i <= n; i++){
		if(c[n].id != i) sum = min(sum, ans + max(a[i], b[i]) - c[n].x);
		else sum = min(sum, ans + max(a[i], b[i]) - c[n - 1].x);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, i;
  cin >> N;
  vi X(N);
  REP(0, N, i) {
    cin >> X[i];
  }
  i64 ans = 10000000LL, P;
  REP(1, 101, P) {
    i64 candidate = 0;
    REP(0, N, i) {
      candidate += (X[i] - P) * (X[i] - P);
    }
    ans = min(ans, candidate);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int t = 0;
		int c = n;

		while (c != 0) {
			t += c % 10;
			c /= 10;
		}

		if (n % t == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define MAXN 305
#define LL long long
using namespace std;

int N;
int d[MAXN][MAXN];

LL ans = 0;
bool chk(){
	
	for(int i=1;i<=N;i++){
		for(int j=i+1;j<=N;j++){
			int x = d[i][j];
			bool f = 0;
			for(int k=1;k<=N;k++){
				if(k==i || k==j) continue;
				if(d[i][k] + d[k][j] < x) return 0;
				if(d[i][k] + d[k][j] == x) f = 1;
			}
			if(!f) ans += x;
		}
	}
	return 1;
}

int main(){
	
	cin>>N;
	
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			cin>>d[i][j];
		}
	}
	
	if(chk()==0){
		cout<<"-1"<<endl;
		return 0;
	}
	else{
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 640
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
ans = 0
for l in range(len(N)):
    S = "x" + N[l]
    for i in range(len(S)):
        if S[i].isdigit() and not(S[i-1].isdigit()):
            d = int(S[i])
            for j in range(i+1, len(S)):
                if S[j].isdigit():
                    d = d*10 + int(S[j])
                else:
                    break
            ans += d
print(ans)


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

int n, m, f[200200], u[200200], v[200200], a[200200], b[200200];
char s[200200];
bool del[200200];

queue<int> Q;
struct edge {int to;  edge *nxt;} *head[200200], e[400400];

int main() {
	scanf("%d%d%s",&n,&m,s+1);
	for (int i=1,u,v;i<=m;i++) {
		scanf("%d%d",&u,&v);
		if (u != v) {
			head[u] = &(e[i*2-2] = (edge) {v,head[u]});
			head[v] = &(e[i*2-1] = (edge) {u,head[v]});
		}
		if (s[v] == 'A') ++a[u];  else ++b[u];
		if (s[u] == 'A') ++a[v];  else ++b[v];
	}
	for (int i=1;i<=n;i++) if (a[i] == 0 || b[i] == 0) {del[i] = 1;  Q.push(i);}
	while (!Q.empty()) {
		int u = Q.front();  Q.pop();
		for (edge *p=head[u];p;p=p->nxt) if (!del[p->to]) {
			if (s[u] == 'A') --a[p->to];  else --b[p->to];
			if (a[p->to] == 0 || b[p->to] == 0) {del[p->to] = 1;  Q.push(p->to);}
		}
	}
	for (int i=1;i<=n;i++) if (!del[i]) {
		for (edge *p=head[i];p;p=p->nxt) if (!del[p->to] && s[i] != s[p->to]) {
			puts("Yes");
			return 0;
		} 
	}
	puts("No");
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
#define ll long long int
#define N 200005
using namespace std;

int main()
{
    int a,b,c;
    
    cin >> a >> b >>c;
    
    if(a+b+c >=22) cout << "bust\n";
    
    else cout << "win\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;

int n,m,flag;
string str,kari;
string c;
struct DATA{
	string b,a;
};
DATA data[256];

int main(){
	while(1){
		str=kari;
		cin>>n;
		if(n==0){break;}
		for(int i=0;i<n;i++){
			cin>>data[i].b>>data[i].a;
		}
		cin>>m;
		for(int i=0;i<m;i++){
			cin>>c;
			for(int j=0;j<n;j++){
				flag=0;
				if(data[j].b==c){str+=data[j].a;flag++;break;}
			}
			if(flag==0){str+=c;}
		}
		cout<<str<<endl;
	}
	return 0;
}

Measured memory_bytes: 1348
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree < int,  null_type,  less<int>,  rb_tree_tag,  tree_order_statistics_node_update > ordered_set;
typedef long long ll;
#define pb push_back
#define pi (acos(-1))
#define ull  unsigned long long
#define ld long double
#define all(v) v.begin(), v.end()
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
ll LCM(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a/g)*b ;
}
string numtostr(ll n)
{
    ostringstream str1 ;
    str1 << n ;
    return str1.str();
}
ll strtonum(string s)
{
    ll x ;
    stringstream str1(s);
    str1 >> x ;
    return x ;
}
ll pwr(ll b,ll p)
{
    if(p==0)
        return 1;
    if(p%2==0)
    {
        ll a=pwr(b,p/2);
        return a*a;
    }
    else
        return b*pwr(b,p-1);
}
int t,n,i;
string s;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  cin>>s;
  if(s[s.length()-1]=='s')
    cout<<s<<"es\n";
  else
    cout<<s<<"s\n";
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vvchar vector<vector<char>>
#define vchar vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    int s=0,ma=0;
    for(int i=1; ; i++){
        if(i*(i+1)/2>=n){
            ma=i;
            break;
        }
    }
    
    int ng=ma*(ma+1)/2-n;
    
    for(int i=1; i<=ma; i++){
        if(ng!=i)cout<<i<<endl;
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int N, M, d[100][100], a, b, c, ans;
using T = tuple<int, int, int>;
T e[1000];
constexpr int INF{ numeric_limits<int>::max() / 3 };
int main() {
    cin >> N >> M;
    fill(d[0], d[100], INF);
    for(int i{}; i < N; ++i) d[i][i] = 0;
    for(int i{}; i < M; ++i) {
        cin >> a >> b >> c;
        --a, --b;
        d[a][b] = min(d[a][b], c);
        d[b][a] = min(d[b][a], c);
        e[i] = make_tuple(a, b, c);
    }
    for(int i{}; i < N; ++i)
        for(int j{}; j < N; ++j)
            for(int k{}; k < N; ++k)
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
    for(int i{}; i < M; ++i) {
        int a, b, c; tie(a, b, c) = e[i];
        ++ans;
        for(int j{}; j < N; ++j)
            if(d[j][a] + c == d[j][b]) {
                --ans;
                break;
            }
    }
    cout << ans << endl;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.12Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int n ;
    cin >> n ;

    vld p ( n + 1 ) ;
    for ( int i = 1 ; i <= n ; i ++ )
    {
        ld t ; cin >> t ;
        p[i] = t ;
    }

    vld dp ( n + 1 ) ;
    dp[0] = 1 ;

    /// dp[i] is probability of having 'i' heads till now ( used 'c' coins yet )

    for ( int c = 1 ; c <= n ; c ++ )
    {
        for ( int i = c ; i >= 0 ; i -- )
        {
            ld t1 = 0 , t2 = 0 ;

            t1 = dp[i] * ( 1 - p[c] ) ;
            if ( i ) t2 = dp[i - 1] * p[c] ;

            dp[i] = t1 + t2 ;
        }
    }

    ld ans = 0 ;
    for ( int head = 1 ; head <= n ; head ++ )
    {
        int tail = n - head ;

        if ( head > tail )
            ans += dp[head] ;
    }

    pp ( ans ) ;

}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  x=min(a[i],b[i])
  a[i]-=x
  b[i]-=x
  y=min(a[i+1],b[i])
  a[i+1]-=y
  b[i]-=y
  cnt+=x+y
print(cnt)

Measured memory_bytes: 18624
A,B,N=map(int,input().split())

def func(t):
    return int(t)

#NはBより大きいかもしれないし小さいかもしれない
#B-1が最高だが、NがB-1より小さいとどうしようもない
x=min(B-1,N)
print(func(A*x/B)-A*func(x/B))

Measured memory_bytes: 61580
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

 
signed main(void){
    int r;
    cin >> r;
    cout <<r*r << endl;
    
    return 0;
}



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

using namespace std;

int main ()
{
  string s;
  cin >> s;
  int i = 0;
  int count = 0;
  char c[26];
  
  while(i < 26)
  {
   c[i] = 0;
    i++;
  }
  i = 0;
  while(i < 4)
  {
   	 c[s[i] - 'A']++;
     i++;
  }
  i = 0;
  while(i < 26)
  {
   if(c[i] == 2)
     count++;
    i++;
  }
  if(count == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll N; cin >> N;
    vector<ll> A(N + 1);
    reps(i, N) cin >> A[i];

    ll cnt = 0, button = 1;
    reps(i, N) {
        if (button == 2) {
            cout << cnt << endl;
            return 0;
        }
        button = A[button];
        cnt++;
    }
    cout << "-1" << endl;
}

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

int gcd(int a, int b) {
    if (b == 0) return a;

    int r = a % b;
    return gcd(b, r);
}

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

    int a, b;
    cin >> a >> b;

    cout << gcd(a, b) << endl;

    return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    string s;
    cin >> s;
    ll a = s.size();
    ll z = 0;
    for (ll i = 0; i < s.size(); ++i) {
        if(s[i] == 'A'){
            a = min(a,i);
        }
        if(s[i] =='Z'){
            z = max(z,i);
        }
    }
    cout << z - a +1 << endl;
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;


namespace _121c
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] read = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            List<Tuple<long,long>> AB = new List<Tuple<long, long>>();
            long[] readLong = new long[2];
            for(long i = 0; i < read[0]; i++){
                readLong = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
                AB.Add(new Tuple<long,long>(readLong[0],readLong[1]));
            }
            var sortrdAB = AB.OrderBy(x=>x.Item1);
            long count = 0;
            long sum = 0;
            foreach(var tekito in sortrdAB){
                if(count+tekito.Item2<=read[1]){
                    sum += tekito.Item1 * tekito.Item2;
                    count += tekito.Item2;
                }else{
                    sum += tekito.Item1 * (read[1]-count);
                    break;
                }
            }
            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 24380
import java.util.*;
 
public class Main { //クラス名はMain
    public static void main(String[] args) {
      //整数の入力
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      
      //重複はSetでいい
      Set<String> numSet = new HashSet<>();
      for (int i=0; i<n; i++) {
          String di = sc.next();
          numSet.add(di);
      }
 
      System.out.println(numSet.size());
    }
}

Measured memory_bytes: 76848
#![allow(unused_imports, dead_code, unused_variables, unused_mut)]
use std::cmp;
use std::mem::swap;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use permutohedron::LexicalPermutation;
use text_io::{read, scan};
use proconio::input;
const INF: i32 = std::i32::MAX;
const MOD: i32 = 1e9 as i32 + 7;

fn main() {
    input! {n: i32, x: i32, t: i32}

    let mut sum = 0;
    let mut ans = 0;

    while sum < n {
        ans += t;
        sum += x;
    }

    println!("{}", ans);
}

Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl;
#define pb push_back
const ll INF=99999999999999999;
const ll MAX_N=100010;
ll a,b,c,d,e,x,y,m,n,k,l,q,ans=0;
vl v,v1,v2;
int main(){
    cin>>a>>b>>c>>d>>e>>k;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    v.push_back(e);
    sort(v.begin(),v.end());
    if(v[4]-v[0]>k){
        cout<<":("<<endl;
    }
    else{
        cout<<"Yay!"<<endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanVecInt(A, N);
    ll all = 1;
    ll rest = 1;
    REP(i, N){
        all *= 3;
        if (A[i] % 2 == 0){
            rest *= 2;
        }else{
            rest *= 1;
        }
    }
    printf("%lld\n", all - rest);
}


Measured memory_bytes: 256
object Main extends App {

  while (true) {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

    if (n == 0 && x == 0) {
      sys.exit()
    }
    var count = 0
    for (a <- 1 to n; b <- a + 1 to n; c <- b + 1 to n if a + b + c == x) {
      count += 1
    }
    println(count)
  }

}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;
ll comb(ll a, ll b);
int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
    int abc[3] = {0, 0, 0};
    string s;
    cin >> s;
    rep(i, s.size())
    {
        if (s[i] == 'a')
            abc[0]++;
        else if (s[i] == 'b')
            abc[1]++;
        else
            abc[2]++;
    }
  
    int small = min(abc[0], min(abc[1], abc[2]));
    int big = max(abc[0], max(abc[1], abc[2]));
    
    if (big - small > 1)
    {
        c("NO");
    }
    else
    {
        c("YES");
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int maxN = 100 * 1000 + 9;
const int MOD = 1e9 + 7;
const double EPS = 1e-18;

int n, m;
bool visited[maxN];
vector<int> g[maxN];

void read(){
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int u, v, z;  cin >> u >> v >> z;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}

void dfs(int u){
  visited[u] = true;
  for(int i = 0, L = g[u].size(); i < L; i++){
    int v = g[u][i];
    if(visited[v])  continue;
    dfs(v);
  }
}

void solv(){
  fill_n(visited, n + 1, false);
  int cc = 0;
  for(int i = 1; i <= n; i++){
    if(!visited[i]){
      cc++;
      dfs(i);
    }
  }

  cout << cc << '\n';
}

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

  read();
  solv();

  return 0;
}


Measured memory_bytes: 8960
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=100005;
int n,s;
vector<int>all;

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

int main(){
	s=-1;
	scanf("%d",&n);
	rep(i,n){
		int x;
		scanf("%d",&x);
		all.push_back(x);
	} 
	sort(all.begin(),all.end(),cmp);
	int i=0;
	while(i<all.size()){
		int j=i;
		while(j<all.size()&&all[j]==all[i])j++;
		if(j-i>=4){
			if(s!=-1)printf("%lld",(ll)s*(ll)all[i]);
			else printf("%lld",(ll)all[i]*(ll)all[i]);
			return 0;
		}
		else if(j-i>=2){
			if(s!=-1){
				printf("%lld",(ll)s*(ll)all[i]);
				return 0;
			}
			s=all[i];
		} 
		i=j;
	}
	printf("0");
	return 0;
} 

Measured memory_bytes: 892
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

const int mod = 10;
int k;

int calc(const int idx, vector<int> rests) {
	if(idx == k) return 0;
	if(rests[idx] == 0) return calc(idx + 1, rests);

	int res = calc(idx + 1, rests) + 1;
	for(int i = idx + 1; i < k; ++i) {
		rests[i] = (rests[i] - rests[idx] + mod) % mod;
		chmin(res, calc(idx + 1, rests) + 1);
	}

	return res;
}

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

	while(cin >> k && k) {
		string initial, unlock;
		cin >> initial >> unlock;

		vector<int> rests(k);
		for(int i = 0; i < k; ++i) {
			rests[i] = (unlock[i] - initial[i] + mod) % mod;
		}

		cout << calc(0, rests) << endl;
	}

	return EXIT_SUCCESS;
}

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


int main() {
  int n , k ;
  cin >> n >> k ;
  
  vector<int> vec(n);
  for(int i=0 ;i<n;i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int sum =0;
  for(int i=0 ; i<k ;i++){
    sum+=vec.at(i);
  }
    
  
  cout << sum << endl;
}

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

int main() {
    string s;
    cin >> s;
    if (s.size() == 2)
        cout << s << endl;
    else
        for (int i = 2; i >= 0; i--)
            cout << s[i];
        cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define min(X, Y) ((X) < (Y) ? (X) : (Y))

int n, a, b, c;
int l[10];
int use[10];

int dfs(int i);

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

	printf("%d\n", dfs(0));

	return 0;
}

int dfs(int i)
{
	if (i >= n) {
		int len[4] = {};
		int mp = 0;

		for (int j = 0; j < n; j++) {

			if (len[use[j]] && use[j]) {
				mp += 10;
			}

			len[use[j]] += l[j];

		}

		mp += abs(a - len[1]);
		mp += abs(b - len[2]);
		mp += abs(c - len[3]);

		if (!len[1] || !len[2] || !len[3]) {
			mp = INT_MAX;
		}
		
		return mp;
	}

	int rec;

	use[i] = 1;
	rec = dfs(i + 1);

	use[i] = 2;
	rec = min(rec, dfs(i + 1));

	use[i] = 3;
	rec = min(rec, dfs(i + 1));

	use[i] = 0;
	rec = min(rec, dfs(i + 1));

	return rec;
}


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

#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)
#define sz(s) ((int) (s).size())

int main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (c - a - b > 0 && 1LL * (c - a - b) * (c - a - b) > 1LL * 4 * a * b) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra() {
	int minv;
	int d[MAX], color[MAX];

	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;
	while (1) {
		minv = INFTY;
		int u = -1;
		for (int i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if (u == -1)break;
		color[u] = BLACK;
		for (int v = 0; v < n; v++) {
			if (color[v] != BLACK&&M[u][v] != INFTY) {
				if (d[v] > d[u] + M[u][v]) {
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = INFTY;
		}
	}

	int k, c, u, v;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}

	dijkstra();

	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#ifdef DEBUG
std::ostream& dout = cout;
#else
stringstream dout;
#endif
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
vector<vector<int>> edge;
P dfs(int n,int par){
    rep(i,edge[n].size()){
        int it=edge[n][i];
        if(it==par)continue;
    }
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int x,y,z;
    cin>>x>>y>>z;cout<<z<<' '<<x<<' '<<y<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


ll divisormax_min(ll n)
{
    ll ans = LLINF;
    for(ll i = 1;i*i<= n;i++){
        if(n%i == 0){
            ans = log10(n/i)+1;
        }
    }
    return ans;
}

int main(void)
{
    ll n;
    cin >> n;
    ll ans = divisormax_min(n);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;cin>>N>>M;
  int x=M/2+1;
  if(N==1){
    cout<<M;return 0;
  }
  
  while(1){
    if(M%x==0&&M/x>=N){
      cout<<x;return 0;
    }x--;
  }
  
}


Measured memory_bytes: 256
using System;

class program
{
    public static int Main()
    {
        var In = Console.ReadLine();
        var W = int.Parse(In.Split(' ')[0]);
        var H = int.Parse(In.Split(' ')[1]);
        var x = int.Parse(In.Split(' ')[2]);
        var y = int.Parse(In.Split(' ')[3]);
        var r = int.Parse(In.Split(' ')[4]);

        if (x + r > W || x - r < 0 || y + r > H || y - r < 0)
        {
            Console.WriteLine("No");
        }
        else
        {
            Console.WriteLine("Yes");
        }

        return 0;
    }
}

Measured memory_bytes: 19612
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <vector>

using namespace std;

int main(){
    vector<int> antenna(5);
    REP(i,5){
        cin >> antenna[i];
    }
    SORT(antenna);
    int k;
    cin >> k;
    string ans="Yay!";

    REP(i,5){
        FOR(j,i,5){
            if(antenna[j]-antenna[i]>k){
                ans = ":(";
            }
        }
    }
    cout << ans << endl;

    return 0;   
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;



int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    int n;
    cin >> n;

  	map<string,int> mp;

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


  	cout << "AC x " << mp["AC"] << endl;
  	cout << "WA x " << mp["WA"] << endl;
  	cout << "TLE x " << mp["TLE"] << endl;
  	cout << "RE x " << mp["RE"] << endl;

 






    return 0;
}


Measured memory_bytes: 3672
import datetime as dt

H1, M1, H2, M2, K = map(int, input().split())
start = dt.timedelta(hours=H1, minutes=M1)
end = dt.timedelta(hours=H2, minutes=M2)
# print((end - start).seconds // 60)
total = (end - start).seconds // 60
print(total - K)


Measured memory_bytes: 9340
n=int(input())
s=[0]*13
h=[0]*13
c=[0]*13
d=[0]*13
for i in range(n):
    a,b=map(str,input().split())
    if a=='S':
        s[int(b)-1]=1
    elif a=='H':
        h[int(b)-1]=1
    elif a=='C':
        c[int(b)-1]=1
    else:
        d[int(b)-1]=1

for i in range(13):
    if s[i]==0:
        print('S',i+1)
for i in range(13):
    if h[i]==0:
        print('H',i+1)
for i in range(13):
    if c[i]==0:
        print('C',i+1)
for i in range(13):
    if d[i]==0:
        print('D',i+1)



Measured memory_bytes: 5616
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

answer = "Yay!"

if abs(a-b)>k:
    answer = ":("

if abs(a-c)>k:
    answer = ":("

if abs(a-d)>k:
    answer = ":("

if abs(a-e)>k:
    answer = ":("

if abs(b-c)>k:
    answer = ":("

if abs(d-b)>k:
    answer = ":("

if abs(e-b)>k:
    answer = ":("

if abs(c-d)>k:
    answer = ":("

if abs(c-e)>k:
    answer = ":("

if abs(d-e)>k:
    answer = ":("

print(answer)



Measured memory_bytes: 3064
t = list(input())

for i in range(len(t)-1):
  if t[i] == "P":
    if t[i+1] == "?":
      t[i+1] = "D"
  elif t[i] == "D":
    if t[i+1] == "?":
      if i+2 < len(t):
        if t[i+2] == "P":
          t[i+1] = "D"
        else:  
          t[i+1] = "P"
          t[i+2] = "D"
  elif t[i] == "?":
    if t[i+1] == "P": t[i] = "D"
    else:
      t[i] = "P"
      t[i+1] = "D"
if t[-1] == "?":
  t[-1] = "D"
print("".join(t))

Measured memory_bytes: 10680
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0) 
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={-2,-2,1,-1,-1,-1,1,1};
int dy[8]={1,-1,-2,-2,-1,1,-1,1};
vector<int> adj[100010],dis(100010,inf),par(100010,0);
vector<vector<int>> vis(15,vector<int> (15,0)),state(15,vector<int> (15,0));

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    multiset<pair<int,int>>mt;
    int n;
    cin>>n;
    vector<int> v(n);
    f(i,n)
    {
        cin>>v[i];
    }
    int cnt=1;
    for(int i=0;i<n;i++)
    {
        mt.insert({v[i],-1});
        auto itr=mt.find({v[i],-1});
        if(itr==mt.begin())
        {
            mt.erase(itr);
            mt.insert({v[i],cnt++});
        }
        else
        {
            auto itk=itr;
            itr--;
            mt.erase(itk);
            mt.insert({v[i],itr->ss});
            mt.erase(itr);
        }
    }
    cout<<cnt-1<<endl;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 998244353

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    long long N;
    cin >> N;
    vector<long long> D(N);
    REP(i, N) cin >> D[i];
    if(D[0] != 0){
        cout << 0 << endl;
        return 0;
    }
    vector<long long> cnt(N);
    REP(i, N) cnt[D[i]]++;

    if(cnt[0] != 1){
        cout << 0 << endl;
        return 0;
    }
    long long mx = *max_element(D.begin(), D.end());
    for(int i=0; i<=mx; i++){
        if(cnt[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    long long ans = 1;
    for(int i=1; i<N; i++){
        for(int j=0; j<cnt[i]; j++){
            ans = (ans * cnt[i-1]) % MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
def partial_match_table(word):
    table = [0] * (len(word) + 1)
    table[0] = -1
    i, j = 0, 1
    while j < len(word):
        matched = word[i] == word[j]
        if not matched and i > 0:
            i = table[i]
        else:
            if matched:
                i += 1
            j += 1
            table[j] = i
    return table

def kmp_search(text, word):
    table = partial_match_table(word)
    i, p = 0, 0

    results = []
    while i < len(text) and p < len(word):
        if text[i] == word[p]:
            i += 1
            p += 1
            if p == len(word):
                p = table[p-1]
                results.append((i-len(word), i))
                i -= 1
        elif p == 0:
            i += 1
        else:
            p = table[p]
    return results

inf = 10**18
s = input().strip()
t = input().strip()
m=(len(t)+len(s)-1+len(s)-1)//len(s)
es = set()
d = [set() for _ in range(len(s)+1)]
d2 = [set() for _ in range(len(s)+1)]
#print(t, m*s)
#print(kmp_search(m*s, t))
for a, b in kmp_search(m*s, t):
    a, b = a%len(s)+1, b%len(s)+1
    es.add((a, b))
    d[a].add(b)
    d2[b].add(a)

#print(es)
fs = set()
r = 0
for x in range(len(s)+1):
    if x in fs:
        continue
    vs = set()
    vs.add(x)
    fs.add(x)
    depths = dict()
    depths[x] = 0
    stack = [x]
    mt = x
    while stack:
        v = stack.pop()
        if v > 0:
            for u in d[v]:
                if u in vs:
                    r = inf
                    break
                stack.append(-v)
                stack.append(u)
                depths[u] = depths[v] + 1
                if depths[u] > depths[mt]:
                    mt = u
                vs.add(u)
                fs.add(u)
        else:
            pass
    vs = set()
    vs.add(mt)
    depths = dict()
    depths[mt] = 0
    stack = [mt]
    mt2 = mt
    while stack:
        v = stack.pop()
        if v > 0:
            for u in d2[v]:
                if u in vs:
                    r = inf
                    break
                stack.append(-v)
                stack.append(u)
                depths[u] = depths[v] + 1
                if depths[u] > depths[mt2]:
                    mt2 = u
                vs.add(u)
                fs.add(u)
        else:
            pass
    r = max(depths[mt2], r)
print(r if r != inf else -1)


Measured memory_bytes: 470568
n = gets.to_s.to_i
x,y,h =  Array.new(n){ gets.to_s.split.map{|t| t.to_i } }.sort_by{|_,_,h| -h }.transpose

0.upto(100) do |c_x|
  0.upto(100) do |c_y|
    
    t = nil
    ok = true
    n.times do |i|
      
      t ||= h[i] + (x[i]-c_x).abs + (y[i]-c_y).abs
      tmp = t - (x[i]-c_x).abs - (y[i]-c_y).abs
      tmp = 0 if tmp < 0
      
      if h[i] != tmp
        ok = false
        break
      end
    end
    
    if ok
      puts "#{c_x} #{c_y} #{t}"
      exit
    end
  end
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <random>
 
using namespace std;
 
using i32 = int;
using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;
 
#define rep(i, n) for (i32 i = 0; i < (n); ++i)
#define repr(i, n) for (i32 i = ((n)-1); i >= 0; --i)
#define urep(i, n) for (u32 i = 0; i < (n); ++i)
#define urepr(i, n) for (u32 i = ((n)-1); i >= 0 && i < (n); --i)
#define all(v) v.begin(), v.end


int main() {
    i64 N;
    cin >> N;

    vector<i64> A(N + 1);
    vector<i64> B(N);
    rep(i, N+1) cin >> A[i];
    rep(i, N) cin >> B[i];

    i64 num_defeated = 0;
    rep(i, N) {
        i64 capacity0 = B[i];
        i64 capacity1 = max(0ll, capacity0 - A[i]);
        i64 capacity2 = max(0ll, capacity1 - A[i+1]);
        A[i+1] = max(0ll, A[i+1] - capacity1);
        num_defeated += capacity0 - capacity2;
    }
    printf("%lld\n", num_defeated);

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
	int n;
	int round;
	int layer[100010];
	int layered=0;
	cin>>n;
	while(n--)
	{
		cin>>round;
		layer[round]++;
		if(layer[round]==1)
		{
			layered++;
		}
	}
	cout<<layered<<endl;
	return 0;
}

Measured memory_bytes: 256
<?php

$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));

$chars = str_split($s);

// A: 65
// Z: 90
foreach ($chars as $char) {
    $code = ord($char);
    if ($code + $n > 90) {
        $diff = $code + $n - 90 - 1;
        echo chr(65 + $diff);
    } else {
        echo chr($code + $n);
    }
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,m;
  cin>>n>>m;
  vector<int> v(2*m),w(n);
  rep(i,2*m) cin>>v[i];
  rep(i,n) w[i]=0;
  rep(i,2*m) w[v[i]-1]++;
  rep(i,n){
    cout<<w[i]<<endl;
  }
}
///////////////////////////



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[200001];
int a,b,ans=0;
int main()
{
	scanf("%s",s);
	int ls=strlen(s);
	int i=0;
	while(s[i]!='A') i++;
	a=i;
	i=ls-1;
	while(s[i]!='Z') i--;
	b=i;
	for(int i=a;i<=b;i++)
		if(s[i]>='A'&&s[i]<='Z') ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    map<string,int> mp;
    string s;
    int ma=0;
    for(int i=0;i<n;i++){
    	cin>>s;
    	mp[s]++;
    	ma=max(ma,mp[s]);
    }

    for(auto& i:mp){
    	if(i.second==ma){
    		cout << i.first<<endl;
    	}
    }

    return 0;
}


Measured memory_bytes: 23808