akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a_ = [0]*n
b_ = [0]*n
c = [0]*n
for i in range(n):
    a_[i],b_[i] = map(int,input().split())
    c[i] = a_[i]
lb_ = 1
ub_ = 10**9
c.sort()
med = c[(n-1)//2]
med_ub = c[(n-1)//2+1]


def ok_odd(m):
    cnt = 0
    for i in range(n):
        a = a_[i]
        if a <= m:
            cnt += 1
    if cnt < (n+1)//2:
        return False
    cnt = 0
    for i in range(n):
        b = b_[i]
        if b >= m:
            cnt += 1
    if cnt < (n+1)//2:
        return False
    cnt = 0
    for i in range(n):
        a,b = a_[i],b_[i]
        if a <= m and m <= b:
            return True
    return False

def ok_even_lb(m):
    cnt = 0
    for i in range(n):
        a = a_[i]
        if a <= m:
            cnt += 1
    if cnt < n//2:
        return False
    cnt = 0
    for i in range(n):
        b = b_[i]
        if b >= m:
            cnt += 1
    if cnt < n//2 + 1:
        return False
    cnt = 0
    for i in range(n):
        a,b = a_[i],b_[i]
        if a <= m and m <= b:
            return True
    return False

def ok_even_ub(m):
    cnt = 0
    for i in range(n):
        a = a_[i]
        if a <= m:
            cnt += 1
    if cnt < n//2 + 1:
        return False
    cnt = 0
    for i in range(n):
        b = b_[i]
        if b >= m:
            cnt += 1
    if cnt < n//2:
        return False
    cnt = 0
    for i in range(n):
        a,b = a_[i],b_[i]
        if a <= m and m <= b:
            return True
    return False

if n % 2 == 1:
    lb = 1
    ub = med
    while lb < ub:
        mid = (lb+ub)//2
        if ok_odd(mid):
            ub = mid
        else:
            lb = mid+1
    lb_ret = lb
    lb = med
    ub = 10**9
    while lb < ub:
        mid = (lb+ub+1)//2
        if ok_odd(mid):
            lb = mid
        else:
            ub = mid-1
    ub_ret = lb
    print(ub_ret-lb_ret+1)
else:
    lb = 1
    ub = med
    while lb < ub:
        mid = (lb+ub)//2
        if ok_even_lb(mid):
            ub = mid
        else:
            lb = mid+1
    lb_lb = lb
    lb = med
    ub = 10**9
    while lb < ub:
        mid = (lb+ub+1)//2
        if ok_even_lb(mid):
            lb = mid
        else:
            ub = mid-1
    lb_ub = lb

    lb = 1
    ub = med_ub
    while lb < ub:
        mid = (lb+ub)//2
        if ok_even_ub(mid):
            ub = mid
        else:
            lb = mid+1
    ub_lb = lb
    lb = med_ub
    ub = 10**9
    while lb < ub:
        mid = (lb+ub+1)//2
        if ok_even_ub(mid):
            lb = mid
        else:
            ub = mid-1
    ub_ub = lb
    print(ub_ub+lb_ub-lb_lb-ub_lb+1)

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

int main(){
  int i,j,n,a[3],flag,r;
  int na[3];
  while(1){
    cin >> a[0] >> a[1] >> a[2];
    if(a[0] == 0 && a[1] == 0 && a[2] == 0) break;
    cin >> n;

    for(i=0;i<2;i++) na[i] = a[i] * a[i] + a[i+1] * a[i+1];
    na[2] = a[2]*a[2] + a[0] * a[0];

    for(i=0;i<n;i++){
      cin >> r;
      flag = 0;
      for(j=0;j<3;j++){
	if(r*r*4 > na[j]){
	  flag = 1;
	  break;
	}
      }

      if(flag == 1) cout << "OK" << endl;
      else cout << "NA" << endl;
    }


  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int a,b;
  cin>>a>>b;
  if(a<=b) cout<<a<<endl;
  else cout<<a-1<<endl;
  return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

long long N;
vector<long long> L;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i=0; i<N; i++){
		long long tmp;
		cin >> tmp;
		L.push_back(tmp);
	}
	sort(L.begin(), L.end());

	long long ans = 0;
	for(int i = 0; i < N - 2; i++){
		for(int j = i + 1; j < N - 1; j++){
			for(int k = j + 1; L[k] < L[i] + L[j]; k++){
				if( L[j] < L[k] + L[i]){
					ans++;
				}
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#include <iostream>
#include <string> 
using namespace std;
int main(){
  int X,Y;
  while(1){
    cin >> X >> Y;
    if(X==0 && Y==0){
      break;
    }
    cout << min(X,Y) << " " << max(X,Y)  << endl;
  } 
}


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

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int INF=INT_MAX;
const ld PI=3.1415926535897932384626433;
const ld E=2.71828183;
const int MOD=1e9+7;

vi bfs(vector<vi>adj,int src){
    //adjacency list, not-weighted, possibly directed ,src is 1-indexed, adj[0].size()=0!!!
    //for n vertices, adj.size()=n+1. (constructed via push_back() ).

    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return dst;
}
vi bfsParents(vector<vi>adj,int src){
    vi parents=vi(adj.size(),INF);
    parents[src]=-1;
    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                parents[nbr]=c;
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return parents;
}
vi shortestPath(vector<vi>adj,int src,int dst){
    vi bfsParetns=bfsParents(adj,src);
    vi ans;
    while(src!=dst){
        if(bfsParetns[src]==INF)
            return {};
        ans.push_back(src);
        src=bfsParetns[src];
    }
    return ans;
}
int powMod(int base,int exp,int mod){
    //(base^exp) %mod
    int ans=1;
    for(int i=0; i<exp; i++)
        ans=((ans%mod)*(base%mod))%mod;
    return ans;
}
vi divisorsOf(int n){
    //vector of divisors of n (inc. 1 , excl.n)
    vi ans;
    for(int i=1; i*i<=n; i++){
        if(n%i==0)
            ans.push_back(i);
        if(i*i!=n && i!=1)
            ans.push_back(n/i);
    }
    return ans;
}
int gcd(int a,int b){
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}

ld log (ld a,ld b){return log(b)/log(a);}
void solve();
int inverseXor(int a,int b);
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
  //  cin >> t;
  //  while(t--)
        solve();
    return 0;
}

void solve(){

    string s;
    cin >> s;
    if(s!="AAA" && s!="BBB")
        cout << "Yes\n";
    else
        cout << "No\n";

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (cin >> n, n != -1) {
		vector<int>v;
		do {
			v.push_back(n % 4);
			n /= 4;
		} while (n != 0);
		for (int i = v.size() - 1; i >= 0;i--) {
			cout << v[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPD(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define TLE() cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms.\n";
const ll MOD = 1E9+7;
const ll IINF = 1E18;
const int INF = 1e9;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s>>i&1;}
template<class T> void flipbit(T& s, int i) {s^=(1LL<<i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%MOD;a=a*a%MOD;p>>=1LL;} return res;}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int r,d,x;
	cin>>r>>d>>x;
	REP(i,10){
		x=r*x-d;
		cout<<x<<'\n';
	}
}



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

int main(){
  int n,k;
  cin >> n >> k;
  int x[n];
  int ans = 1000000000;
  for(int i=0; i<n; i++){
    cin >> x[i];
  }
  for(int i=0; i<=n-k; i++){
    ans = min((abs(x[i])+abs(x[i]-x[i+k-1])),ans);
    ans = min((abs(x[i+k-1])+abs(x[i]-x[i+k-1])),ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;

using namespace std;

bool check(string &s, ll mid)
{
    map<string,ll> ma;
    ll n = s.length();
    ll maxi = 1;
    for(ll i=n-2*mid;i>-1;i--)
    {
        ma[s.substr(i+mid,mid)]++;
        maxi = max(maxi,ma[s.substr(i,mid)]+1);
    }
    if(maxi>=2)
        return 1;
    return 0;    
}

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   string s;
   cin>>s;
   
   ll start = 0;
   ll end = n/2;
   
   while(end - start > 1)
   {
       ll mid = start + (end - start)/2;
       bool temp = check(s,mid);
       if(temp == 1)
            start = mid;
       else end = mid-1;        
   }
   
   bool temp = check(s,end);
   if(temp)
        cout<<end;
   else cout<<start;       
   
   return 0;
}


Measured memory_bytes: 5828
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 1000000007;

    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        Long X = sc.nextLong();
        for(long i = -1000; i<1000;i++){
            Long A = i * i * i * i * i;
            for(long j = -1000;j<1000;j++){
                Long B = j * j* j * j * j;
                if(A - B == X){
                    System.out.println(i + " " + j);
                    System.exit(0);
                }
            }
        }
    }

}









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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0, cnt = 0;
    

    //0のとき-,1のとき+
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '0')
        {
            if (cnt > 0)
            {
                ans += 2;
            }
            
            cnt--;
        }
        if (s[i] == '1')
        {
            if (cnt < 0)
            {
                ans += 2;
            }
            
            cnt++;
        }
        
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			int ohajiki = 32;
			int[] a = new int[n];
			for(int i = 0;i < n;i++){
				a[i] = scan.nextInt();
			}
			boolean turn = true;
			int count = 0;
			while(ohajiki > 1){
				if(turn){
					ohajiki -= (ohajiki-1)%5;
				}else{
					ohajiki -= a[count%n];
					count++;
				}
				System.out.println(ohajiki);
				turn ^= true;
			}
			System.out.println(0);
		}
	}
}

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

int main(){
	int n,m;
	cin>>n>>m;
	int a[m],s=0;
	for(int i=0; i<=m-1; i++){
		cin>>a[i];
		s+=a[i];
	}
	n-=s;
	if(n<0){
		cout<<"-1"<<endl;
	}
	else{
		cout<<n<<endl;
	}
	return 0;
}

Measured memory_bytes: 3672
from collections import Counter

N = int(input())
D = list(map(int, input().split()))

mod = 998244353
c = Counter(D)
m = max(c.keys())

if D[0] == 0 and c[0] == 1:
  ans = 1
  for i in range(1, m+1):
    ans *= c[i-1]**c[i] % mod
    ans %= mod
  print(ans)
else:
  print(0)

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define int ll

ull modpow(ull x,ull n){
  if(n==0)return 1;
  if(n%2)return ((x%MOD)*(modpow(x,n-1)%MOD))%MOD;
  else {
    ll half=modpow(x,n/2)%MOD;
    return (half*half)%MOD;
  }
}

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

  int N;
  cin>>N;
  vector<ull>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  vector<ull>B=A;

  vector<bool>p(80001,true);
  p[0]=false,p[1]=false;
  for(int i=2;i<=80000;i++){
    if(p[i])for(int j=i+i;j<=80000;j+=i)p[j]=false;
  }
  vector<int>pp;
  for(int i=0;i<=80000;i++)if(p[i])pp.push_back(i);
  map<int,int>mp;
  for(int i=0;i<pp.size();i++){
    mp[pp[i]]=i;
  }

  map<int,int>m;
  for(int i=0;i<N;i++){
    for(int j=0;pp[j]*pp[j]<=B[i];j++){
      int c=0;
      while(B[i]%pp[j]==0){
        c++;
        B[i]/=pp[j];
      }
      m[pp[j]]=max(m[pp[j]],c);
    }
    if(B[i]!=1)m[B[i]]=max(m[B[i]],1ll);
  }
  int LCM=1;
  for(auto it:m){
    LCM=((LCM%MOD)*(modpow(it.first,it.second)%MOD))%MOD;
  }
  LCM%=MOD;
  int ans=0;
  for(int i=0;i<N;i++)ans=((ans%MOD)+(LCM*(modpow(A[i],MOD-2)))%MOD)%MOD;
  cout<<ans%MOD<<endl;
  return 0;
}


Measured memory_bytes: 1664
import java.util.*;

public class Main{
  public static void main(String[] args){

  Scanner sc = new Scanner(System.in);
  int[] data = {0,0,0};
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
     data[0] = a;
     data[1] = b;
     data[2] = c;
     for(int i = 0; i <data.length-1; i++){
       for(int j = i+1; j <data.length; j++){
         if(data[i] > data[j]){
           int k = data[i];
           data[i] = data[j];
           data[j] = k;
         }
       }
     }
     for(int i = 0; i < data.length-1; i++){
       System.out.print(data[i] + " ");
     }
     System.out.print(data[2]);
     System.out.print("\n");
     }
   }




Measured memory_bytes: 26160
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();


            var dic1 = new Dictionary<long,long>();
            var dic2 = new Dictionary<long,long>();
            dic1.Add(-1, 0);
            dic2.Add(-1, 0);
            for (int i = 0; i < N; i++)
            {
                var now = A[i];

                if (i%2 == 0)
                {
                    if (dic1.ContainsKey(now))
                    {
                        dic1[now]++;
                    }
                    else
                    {
                        dic1.Add(now, 1);
                    }
                }
                else
                {
                    if (dic2.ContainsKey(now))
                    {
                        dic2[now]++;
                    }
                    else
                    {
                        dic2.Add(now, 1);
                    }
                }
            }


            var dic1max1 = -1L;
            var dic1val1 = 0L;
            var dic1max2 = -1L;
            var dic1val2 = 0L;

            foreach (var item in dic1)
            {
                if(item.Value > dic1val1)
                {
                    dic1max2 = dic1max1;
                    dic1val2 = dic1val1;
                    dic1max1 = item.Key;
                    dic1val1 = item.Value;
                }
                else if(item.Value > dic1val2)
                {
                    dic1max2 = item.Key;
                    dic1val2 = item.Value;
                }
            }

            var dic2max1 = -1L;
            var dic2val1 = 0L;
            var dic2max2 = -1L;
            var dic2val2 = 0L;

            foreach (var item in dic2)
            {
                if (item.Value > dic2val1)
                {
                    dic2max2 = dic2max1;
                    dic2val2 = dic2val1;
                    dic2max1 = item.Key;
                    dic2val1 = item.Value;
                }
                else if (item.Value > dic2val2)
                {
                    dic2max2 = item.Key;
                    dic2val2 = item.Value;
                }
            }

            if(dic1max1 != dic2max1)
            {
                Console.WriteLine(N -dic1val1 - dic2val1);
            }
            else
            {

                Console.WriteLine(Min(N - dic1val1 - dic2val2,N - dic1val2 - dic2val1));
            }

            
        }


    }

}


Measured memory_bytes: 26336
#include<stdio.h>
#include<math.h>

int main(){
  int w,h,n;
  scanf("%d",&w);
  scanf("%d",&h);
  scanf("%d",&n);
  if(w>h){
   double i=ceil((double)n/w);
   printf("%.0f",i);
  }
  else{
   double k=ceil((double)n/h);
   printf("%.0f",k);
  }


}


Measured memory_bytes: 128
#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 pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define ff                first
#define ss                second
#define pii               pair<int,int>
#define vi                vector<int>
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define repe(i,a,b)        for(int i=a;i<=b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define INF 100000000000
#define mod 1000000007
#define esp 10e-7
const int mx=100001;

signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    //freopen("error.txt" , "w" , stderr);
    #endif
    IOS
    string s,t;
    cin>>s;
    cin>>t;
    // cout<<s<<t<<endl;
    int n=s.length();
    int k=t.length();
    vector<string>v;
    int i=0,j=k-1;
    string temp;
    while(i<=(n-k))
    {
      temp=s.substr(i,k);
      v.pb(temp);
      i++;
    }
    int ans=INT_MAX;
    for(int i=0;i<v.size();i++)
      { int cnt=0;
        for(int j=0;j<k;j++)
            if(v[i][j]!=t[j])
                cnt++;
            ans=min(cnt,ans);
      }
      cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define eb emplace_back
#define PI 3.14159265
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double ld;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ld r;
    cin>>r;
    cout.precision(28);
    cout<<2*PI*r<<"\n";
    return 0;
}

Measured memory_bytes: 3812
import math
N,K = map(int,input().split())

if N >= K:
  s = (N-K+1) / N
else:
  s = 0

for i in range (1,min(N+1,K)):
  a = K / i
  x = math.ceil(math.log(a,2))
  s = s + (1/2) ** x / N
print(s)

Measured memory_bytes: 3060
#include<iostream> 
using namespace std; 
int main(){
    int a, b, c;
    cin>>a >>b >>c;
    if(a<b && b<c)cout<<a<<" "<<b<<" "<<c<<endl;
    else if(a<=c && c<=b)cout<<a<<" "<<c<<" "<<b<<endl;
    else if(b<=a && a<=c)cout<<b<<" "<<a<<" "<<c<<endl;
    else if(b<=c && c<=a)cout<<b<<" "<<c<<" "<<a<<endl;
    else if(c<=a && a<=b)cout<<c<<" "<<a<<" "<<b<<endl;
    else cout<<c<<" "<<b<<" "<<a<<endl;
    
    return 0;
}


Measured memory_bytes: 3016
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
import time

#A
def A():
    s = S()
    t = S()
    ans = 0
    for i in range(3):
        if s[i] == t[i]:
            ans += 1
    print(ans)
    return

#B
def B():
    a, b = LI()
    ans = 0
    b -= 1
    while b > 0:
        b -= a - 1
        ans += 1
    print(ans)

    return

#C
def C():
    n = II()
    h = LI()
    i = 0
    ans = 0
    while i < n:
        down = i+1
        while down < n:
            if h[down - 1] >= h[down]:
                down += 1
            else:
                break
        ans = max(ans, down - i - 1)
        i = down
    print(ans)
    return

#D
def D():
    n = II()
    print(n * (n - 1) // 2)
    return

#E
def E():
    start = time.time()
    n = II()
    a = LIR_(n)
    ans = 0
    tern = [0] * n
    while 1:
        ans += 1
        f = True
        c = defaultdict(int)
        for i in range(n):
            if c[i]:
                continue
            if tern[i] == n - 1:
                continue
            rival = a[i][tern[i]]
            if c[rival]:
                continue
            if tern[rival] == n - 1:
                continue
            if a[rival][tern[rival]] == i:
                c[i] += 1
                c[rival] += 1
                tern[rival] += 1
                tern[i] += 1
                f = False
        if time.time() - start >= 1.8:
            print(n * (n - 1) // 2)
            return
        if f:
            if tern == [n - 1] * n:
                print(ans-1)
                return
            else:
                print(-1)
                return
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    E()


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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int H, W;
vector<string> s;
int dx[] = {1, -1, 0, 0}, dy[]={0, 0, 1, -1};
int mdist = INF;
vector<vector<int>> homon;
void bfs(int x, int y, int depth){
  if(x == W-1 && y == H-1){
    mdist = min(mdist, depth);
    return;
  }
  REP(i, 4){
    int next_x = x+dx[i], next_y = y+dy[i];
    if(next_x >= 0 && next_x < W && next_y >= 0 && next_y < H){
      //cout << next_x << " " << next_y << endl;
      if(s[next_y][next_x] == '.' && homon[next_y][next_x] > depth+1){
        homon[next_y][next_x] = depth+1;
        bfs(next_x, next_y, depth+1);
      }
    }
  }
}

int main(){
  cin >> H >> W;
  s.resize(H);
  REP(i, H){
    cin >> s[i];
  }
  int white = 0;
  REP(i, H){
    REP(j, W){
      if(s[i][j] == '.'){
        white++;
      }
    }
  }
  homon.resize(H, vector<int>(W, INF));
  homon[0][0] = 0;
  bfs(0, 0, 1);
  if(mdist == INF){
    cout << -1 << endl;
  }
  else{
    cout << white - mdist << endl;
  }



  return 0;
}


Measured memory_bytes: 512
// https://atcoder.jp/contests/abc043/tasks/abc043_b
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    string s;cin>>s;
    for(int i=0;i<s.size();i++) {
        if(s[i]=='B') {
            if(i>0) {
                s.erase(i-1, 2);
                i-=2;
            } else {
                s.erase(i, 1);
                i--;
            }
        }
    }
    cout<<s<<"\n";
}

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

int main(){
    int n;
    cin>>n;
    int b[100];
    int ans=0;
    rep(i,n-1) {
        cin>>b[i];
    }
    vector<int> c(n,-1);
    rep(i,n-1){
        if(i!=n-2){
            if(b[i]<=b[i+1]){
                //cout<<c[i]<<endl;
                if(c[i]==-1) c[i]=b[i];
                c[i+1]=b[i];
                //cout<<1<<endl;
            }else{
                //cout<<c[i]<<endl;
                if(c[i]==-1) c[i]=b[i];
                //cout<<2<<endl;
            }
        }else{
            if(c[i]==-1) c[i]=b[i];
            c[i+1]=b[i];
        }
        //cout<<c[i]<<endl;
    }
    rep(i,n) {
        ans+=c[i];
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

template<class Monoid, class InputIterator> typename Monoid::value_type fold(InputIterator first, InputIterator last) {
  Monoid m = Monoid();
  using T = typename Monoid::value_type;
  T acc = m.id();
  std::for_each(first, last, [&](T &x) { acc = m(acc, x); });
  return acc;
}

constexpr int gcd(int a, int b) {
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}

constexpr int lcm(const int &a, const int &b) { return a * b / gcd(a, b); }

template<typename T> struct lcmMonoid {
  using value_type = T;
  constexpr T id() const { return 1; }
  T operator()(const T &a, const T &b) const { return lcm(a, b); }
};

main {
  int n;
  cin >> n;
  vi a(n);
  cin >> a;
  cout << fold<lcmMonoid<int>>(all(a)) << endl;
}

Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lli N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    lli G = gcd(N, M);
    /*
    if (N > M) {
        swap(S, T);
        swap(N, M);
    }
    */
    lli X = N / G * M;
    lli nI = X / N, mI = X / M;
    lli AB = nI / gcd(nI, mI) * mI;

    for (lli x = 0; x < X; x += AB) {

        lli nA = x / nI, mA = x / mI;
        if (S[nA] != T[mA]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << X << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define ull unsigned long long int
#define ll long long
#define vi vector<int>
#define mii map<int,int>
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define MOD 1e9+7
#define INF 0x3f3f3f3f
//#define show(x) cerr<<x#<<" "<<x<<"\n";

//typedef tree<pair<int,int>,null_type, 
//less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)\
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("O3")
//uncoment for large int requirement

//using boost::multiprecision::cpp_int;
//using namespace _gnu_pbds;
using namespace std;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main() {
	 long long n, ans=0,tmp=0;
	cin>>n;
	vector<ll> v;
 while(n)
 {n--;
     v.push_back(n%26);
     n/=26;
 }
 for(ll i = long(v.size())-1 ; i>=0;i--)
 {        cout<<char('a'+v[i]);
      }
	return 0;
}


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

int main(){
 string s;
 cin >> s ;
 int t=0;
 for(int i=0; i<s.size()/2; i++){
     if(s.at(i)!=s.at(s.size()-i-1)) t++;
 }
 cout << t << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

int main(void)
{
	int a, b;
	char op;
	cin >> a >> op >> b;
	if (op == '+')
	{
		cout << a + b;
	}
	else
	{
		cout << a - b;
	}
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))

switch = [False] * n

def valid():
  for i, indices in enumerate(s):
    if sum((switch[index-1] for index in indices)) % 2 != p[i]:
      return False
  return True

cnt = 0
def dfs(start):
  global cnt
  if valid():
    cnt += 1  
  for i in range(start, n):
    if not switch[i]:
      switch[i] = True
      dfs(i+1)
      switch[i] = False
      # dfs(i+1)
      
dfs(0)
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  if (N % 2) {
    int M = (N - 1) * (N - 3) / 2;
    M += N - 1;
    cout << M << endl;
    for (int i = 1; i <= N - 1; i ++) {
      cout << N << ' ' << i << endl;
    }
    N --;
  }
  else {
    int M = N * (N - 2);
    M /= 2;
    cout << M << endl;
  }
  for (int i = 1; i <= N - 1; i ++) {
    for (int j = i + 1; j <= N;) {
      if (j + i == N + 1) j ++;
      if (j == N + 1) break;
      cout << i << ' ' << j << endl;
      j ++;
    }
  }
}
  


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

int main()
{
    string s;cin>>s;int f=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]==s[i+1]) f=1;
    }
    if(f==1) cout<<"Bad";
    else cout<<"Good";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = 
#define REVERSE(x) reverse(ALL(x))
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(ALL(x), greater<>())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SIZE(x) ll((x).size())
#define gcd __gcd
const int INF = 1001001001;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
template <typename T = int> inline T in(){
  T x; cin >> x; return x;}
template <typename T> inline void print(const T& x){
  cout << x << "\n";}
inline int lcm(int a, int b){
  return a / gcd(a, b) * b;}
bool is_prime(int n){
  if (n < 2) return false;
  FOR(i, 2, (int)(sqrt(n) + 1)){
    if (n % i == 0) return false;
  }
  return true;
}


signed main(){
  int N = in();
  string S = in<string>();
  
  int counter = 1;
  REP(i, N-1){
    if (S.at(i) != S.at(i+1)) ++counter;
  }
  print(counter);  
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
	int n;
	while(true){
		cin>>n;
		if(n==0)break;
		vector<int>a(n);
		int sum=0;
		for(int i=0;i<n;i++){
			cin>>a[i];
			sum+=a[i];
		}
		int ans=0;
		for(int i=0;i<n;i++){
			if(n*a[i]<=sum)ans++;
		}
		cout<<ans<<endl;
	}
    return 0;
}


Measured memory_bytes: 3016
#include<iostream>
#include<string>
std::string ans;
int sx, sy, tx, ty;
int main() {
	std::cin >> sx >> sy >> tx >> ty;
	for (int i = 0; i < tx - sx; i++) ans += 'R';
	for (int i = 0; i < ty - sy; i++) ans += 'U';
	for (int i = 0; i < tx - sx; i++) ans += 'L';
	for (int i = 0; i < ty - sy; i++) ans += 'D';
	ans += 'D';
	for (int i = 0; i <= tx - sx; i++) ans += 'R';
	for (int i = 0; i <= ty - sy; i++) ans += 'U';
	ans += 'L';
	ans += 'U';
	for (int i = 0; i <= tx - sx; i++) ans += 'L';
	for (int i = 0; i <= ty - sy; i++) ans += 'D';
	ans += 'R';
	std::cout << ans << std::endl;
	return 0;
}

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

int main()
{
    long long H;
    std::cin >> H;

    long long cnt = 0;
    long long num = 1;
    while (H > 0)
    {
        H = H / 2;
        cnt += num;
        num *= 2;
    }

    std::cout << cnt << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,M;
  cin >> N >> M;
  ll x[N],y[N],z[N];
  ll ans=0;
  ll ans2 = -10000000000LL;
  ll d[N];
  ll a[8]={1,1,1,-1,-1,-1,1,-1};
  ll b[8]={1,1,-1,1,-1,1,-1,-1};
  ll c[8]={1,-1,1,1,1,-1,-1,-1};
  for(int i=0;i<N;i++){
    cin >> x[i] >> y[i] >> z[i];
  }
  for(int i=0;i<8;i++){
    for(int j=0;j<N;j++){
      d[j]=a[i]*x[j]+b[i]*y[j]+c[i]*z[j];
    }
    sort(d,d+N,greater<ll>());
    ans=0;
    for(int k=0;k<M;k++){
       ans+=d[k];
    }
    ans2=max(ans2,ans);
  }

  cout << ans2 << endl;
  return 0;
}

Measured memory_bytes: 256
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

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

const int N = 2000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

bitset<N> LR[N][N], L[N], R[N], A[N];
int n;

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 2; i <= n; i++) for (int j = 1; j < i; j++){
		char x;
		cin >> x;
		A[i][j] = (x == '1');
		A[j][i] = (x == '0');
	}
	for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++){
		LR[i][j] = LR[i][j - 1];
		LR[i][j][j] = 1;
//		cout << i << ' ' << j << '\n';
//		for (int k = 1; k <= n; k++) cout << LR[i][j][k];
//		cout << '\n';
	}
	for (int i = 1; i <= n; i++) L[i][i] = 1, R[i][i] = 1;
	for (int len = 2; len <= n; len++){
		for (int l = 1; l <= n - len + 1; l++){
			int r = len + l - 1;
			bitset<N> bt;
			bt = (R[r] & L[l + 1] & A[l] & LR[l + 1][r]);
			if (bt.count() > 0) R[r][l] = 1;
			else R[r][l] = 0;
			bt = (R[r - 1] & L[l] & A[r] & LR[l][r - 1]);
			if (bt.count() > 0) L[l][r] = 1;
			else L[l][r] = 0;
//			cout << l << ' ' << r << ' ' << L[l][r] << ' ' << R[r][l] << '\n';
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		if (L[1][i] == 1 && R[n][i] == 1) ans++;
	}
	cout << ans;






	return 0;
}


Measured memory_bytes: 513132
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
int main(){

  while(1){
    int x,y,s;
    cin >> x >> y >> s;
    if(x==0 && y==0 && s==0)break;
    int max=0;
    for(int i=1;i<s;i++){
      for(int j=1;j<s && i+j<=s;j++){
	if(i*(100+x)/100 + j*(100+x)/100 == s){
	  if(i*(100+y)/100 + j*(100+y)/100 > max){
	    max = i*(100+y)/100 + j*(100+y)/100;
	  }
	}
      }
    }
    cout << max << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>

using namespace std;

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

int main(){
    long a, b, x, n;
    cin >> a >> b >> x;
   
    a += x - remain(a,x);
    b -= b % x;
    if (b >= a){
        n = (b - a)/x + 1;
    }else{
        n = 0;
    }
    
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"

using namespace std;

int SelectionSort(vector<int>& A) {
  int counter = 0;
  for (int i = 0; i < A.size(); ++i) {
    int mini = i;
    for (int j = i; j < A.size(); ++j) {
      if (A[j] < A[mini]) {
        mini = j;
      }
    }
    swap(A[i], A[mini]);
    if(A[i] != A[mini])  ++counter;
  }
  return counter;
}

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (auto& a : A)
    cin >> a;
  int counter = SelectionSort(A);

  for (int i = 0; i < A.size(); ++i) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << counter << endl;
}

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

int main() {
  int s1,total=0;
  cin >> s1;
  
  if(s1/100 == 1) total += 1;
  if(s1%100/10 == 1) total += 1;
  if(s1%10 == 1) total += 1;
  
  cout << total << endl;
}


Measured memory_bytes: 256
// C.

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

static const LL MOD = 1000000007;

int main(int argc, char *argv[])
{
	LL n, a[100000] = {}, ans = 1;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		if (i % 2) {
			ans = (ans * 2) % MOD;
		}
		if (n % 2) {
			if (a[i] != ((i + 1) / 2) * 2) {
				ans = 0;
			}
		} else {
			if (a[i] != ((i / 2) * 2 + 1)) {
				ans = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int gcd2(int,int);
int gcd3(int,int,int);

int main(){
  int K;
  int count = 0;
  scanf("%d",&K);
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      for(int k=1;k<=K;k++){
	count += gcd3(i,j,k);
      }
    }
  }
  printf("%d",count);
  return 0;
}

int gcd2(int a,int b){
  int temp;
  if(a<b){
    temp = a;
    a = b;
    b = temp;
  }
  while(b>0){
    temp = b;
    b = a%b;
    a = temp;
  }
  return a;
}

int gcd3(int a,int b,int c){
  int d;
  d = gcd2(b,c);
  d = gcd2(a,d);
  return d;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define ii pair <int, int>
#define x first
#define y second
#define db(x) cerr << flush, cerr << #x << " = " << x << endl;
#define _ << ", " << 

using namespace std;

inline void read(int &x){register int c = getchar();x = 0; int neg = 0;for (;((c<48 || c>57) && c != '-') ;c = getchar());if(c=='-') {neg=1;c=getchar();}for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
inline void read(long long &x){register int c = getchar();x = 0; int neg = 0;for (;((c<48 || c>57) && c != '-') ;c = getchar());if(c=='-') {neg=1;c=getchar();}for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
inline void writeln(long long x){char buffor[21];register int i=0;int neg=0; if (x<0) {neg=1; x= -x;}do{buffor[i++]=(x%10)+'0';x/=10;} while(x);i--;if (neg) putchar('-');while(i>=0) putchar(buffor[i--]);putchar('\n');}
inline void write(long long x){char buffor[21];register int i=0;int neg=0; if (x<0) {neg=1; x= -x;}do{buffor[i++]=(x%10)+'0';x/=10;} while(x);i--;if (neg) putchar('-');while(i>=0) putchar(buffor[i--]);putchar(' ');}

const int N = 1e5 + 7;

struct TFunction{
	int b, l, u;

	TFunction() {}
	TFunction(int b, int l, int u): b(b), l(l), u(u) {}

	long long get(int x){
		if (x <= b)
			return 1LL * l * (x - b);
		return 1LL * u * (x - b);
	}
}f[N];

int n, x;
long long tot;
long long pre[N], suf[N];

bool check(long long k){
	long long div = k / x;
	long long rem = k - div * x;

	if (rem == 0){
		rem = x;
		div--;
	}

	long long mx = -(long long)1e18;

	for (int i = 1; i <= n; i++)
		if (i <= div)
			mx = max(mx, pre[div + 1] + suf[div + 2] - f[i].get(x) + f[i].get(rem));
		else
			mx = max(mx, pre[div] + suf[div + 1] - f[i].get(0) + f[i].get(rem));
	// db(mx)
	return mx >= 0;
}

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

	cin >> n >> x;
	for (int i = 1; i <= n; i++){
		cin >> f[i].b >> f[i].l >> f[i].u;
	}

	sort(f + 1, f + n + 1, [](TFunction &a, TFunction &b){
		return (1LL * a.b * a.l + 1LL * (x - a.b) * (a.u)) > (1LL * b.b * b.l + 1LL * (x - b.b) * (b.u));
	});

	// for (int i = 1; i <= n; i++)
	// 	db(f[i].b _ f[i].l)

	for (int i = 1; i <= n; i++)
		pre[i] = pre[i - 1] + f[i].get(x);

	for (int i = n; i >= 1; i--)
		suf[i] = suf[i + 1] + f[i].get(0);

	// db(check(19))

	long long l = 0;
	long long r = 1LL * n * x;

	while (l <= r){
		long long mid = l + r >> 1;
		if (check(mid))
			r = mid - 1;
		else
			l = mid + 1;
	}

	cout << l;
}

Measured memory_bytes: 2944
def solve(s):
    n = len(s)
    for i in range(n // 2):
        if s[i] != s[n - i - 1]:
            return False
    for i in range(n // 4):
        if s[i] != s[n // 2 - i - 1]:
            return False
    return True


s = input()
print('Yes' if solve(s) else 'No')


Measured memory_bytes: 2940
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  string s;cin>>s;
  
  if(s[2]==s[3] && s[4]==s[5])cout<<"Yes"<<ENDL;
  else cout<<"No"<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
slst = []
llst = []
stmp = 201
ltmp = 0
for i in a:
    if stmp >= i:
        stmp = i
    else:
        slst.append(stmp)
        stmp = i

for i in reversed(a):
    if ltmp <= i:
        ltmp = i
    else:
        llst.insert(0, ltmp)
        ltmp = i

total = 1000
for i in range(len(slst)):
    cnt = total // slst[i]
    total -= (slst[i] * cnt)
    total += (llst[i] * cnt)

print(total)

Measured memory_bytes: 9208
N, K, Q = tuple(int(elem) for elem in input().split())
Ai = []
while True:
  try:
  	Ai.append(int(input()))
  except(EOFError):
    break
cand = [K-Q]*N

for elem in Ai:
  cand[elem-1] += 1

for point in cand:
  if point > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 10424
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

public class Main {
    static In in = new In();
    static Out out = new Out();
    static final long mod = 1000000007;
    static final long inf = 0xfffffffffffffffL;
    static final int iinf = 0xfffffff;

    void solve() {
        String n = in.next();
        out.println(n.contains("7") ? "Yes" : "No");
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private PrintWriter out = new PrintWriter(System.out);
    boolean autoFlush = false;

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(int[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int i : a) {
            joiner.add(Integer.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(long[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (long i : a) {
            joiner.add(Long.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 32868