akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    vector<int> a(N, 0);
    for(int i=0; i<N; i++) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());

    ll ans = 0;
    
    if(N%2 == 1){
        ll tmp = 0;
        for(int i=0; i<N; i++){
            if(i < (N-1)/2) tmp += 2*a[i];
            else if(i < (N-1)/2 + 2) tmp -= a[i];
            else tmp -= 2*a[i];
        }
        ans = max(ans, tmp);

        tmp = 0;
        for(int i=0; i<N; i++){
            if(i < (N-3)/2) tmp += 2*a[i];
            else if(i < (N-3)/2 + 2) tmp += a[i];
            else tmp -= 2*a[i];
        }
        ans = max(ans, tmp);
    }
    else{
        ll tmp = 0;
        for(int i=0; i<N; i++){
            if(i < N/2-1) tmp += 2*a[i];
            else if(i < N/2) tmp += a[i];
            else if(i < N/2 + 1) tmp -= a[i];
            else tmp -= 2*a[i];
        }
        ans = max(ans, tmp);
    }

    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

template< typename T >
class CumulativeSum
{
public:
    vector< T > m_data;
    CumulativeSum() {};
    CumulativeSum(int sz) : m_data(sz, 0) {};

    // k に x を加える O(1)
    void Add(int k, T x) {
        assert(m_data.size() >= k);
        if(m_data.size() <= k) { m_data.push_back(x % MOD); }
        else {
            m_data[k] += x;
            m_data[k] %= MOD;
        }
    }

    // 累積和の構築 O(m_data.size())
    void Build() {
        for(int i = 1; i < m_data.size(); i++) {
            m_data[i] += m_data[i - 1];
            m_data[i] %= MOD;
        }
    }

    // 区間 [0, k] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int k) {
        if(k < 0) { return T(0); }
        return (m_data[min(k, (int) m_data.size() - 1)]);
    }

    // 区間 [l, h] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int l, int h) {
        return (this->Query(h) - this->Query(l-1) + MOD) % MOD;
    }
};

ll N;
ll A[MAX_N];
// ブロック i を取り除くとき、 i と j が連結である確率 P'ij を考える。
// このときの各 j について、 P'11 + P'21 + ... + P'N1 = P[i]
// A[1] が P'11 の確率で 1 回、 P'21 の確率で 1 回 ... P'N1 の確率で 1 回でるので、
// 1 回 N 個のブロックを取り切ったときに、コストとして加算すべき A[i] は期待値的に P[i] 回出ることになる。
ll P[MAX_N];

// 1~nの逆元を求める(mod m)
vector<ll> ListModInverse(ll n, ll m)
{
    vector<ll> inv(n + 1);
    inv[1] = 1;
    for (int i = 2; i <= n; ++i)
        inv[i] = inv[m % i] * (m - m / i) % m;
    return inv;
}

signed main()
{
    cin >> N;
    REP(i, N) { cin >> A[i]; }

    // 逆元の作成
    vector<ll> inv = ListModInverse(N, MOD);

    // 累積和の構築
    CumulativeSum<ll> cs(N+1);
    for(int i = 1; i <= N; ++i) {
        cs.Add(i, inv[i]);
    }
    cs.Build();

    // P の構築
    REP(i, N) {
        int low = i;        // 自分より小さいものの数
        int high = N - low; // 自分以上のものの数
        P[i] = cs.Query(high);
        P[i] %= MOD;
        if(low > 0) {
            P[i] += cs.Query(2, 2 + (low - 1));
            P[i] %= MOD;
        }
    }

    // 1 回 N 個のブロックを取り切ったときのコストの期待値
    ll X = 0;
    REP(i, N) {
        X += ((A[i] * P[i]) % MOD);
        X %= MOD;
    }

    // N! の計算
    ll N_f = 1;
    for(int i = 2; i <= N; ++i) {
        N_f *= i;
        N_f %= MOD;
    }

    ll ans = (X * N_f) % MOD;
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define mp make_pair 
#define pb push_back 
#define fi first
#define se second

#define DOMOD(d) if ((d) >= MOD) d %= MOD;
#define DONEGMOD(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;

#define inp(a) scanf("%d", &a)
#define inp2(a,b) scanf("%d %d", &a, &b)
#define inp3(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define inp4(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)

#define inpl(a) scanf("%lld", &a)
#define inpl2(a,b) scanf("%lld %lld", &a, &b)
#define inpl3(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define inpl4(a,b,c,d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i=a;i<b;i++)
#define mset(a,val) memset(a,val,sizeof(a))
#define printv(v) for (int i=0;i<(int) v.size(); i++) cout<<v[i]<<" " 
#define MAX 100005
using namespace std ;
typedef long long int ll ;
typedef pair<int,int> pii ;
typedef pair<long long , long long > pll ;
typedef pair<int,pii> pipi ;
typedef pair<int,pair<int,string>> piis ;
typedef pair<ll,string> pls ;



int main()
{
	 #ifdef DHEER
  freopen("inp.txt","r",stdin) ;
  freopen("out.txt","w",stdout) ;
  #endif
   
  int n ;
  cin>>n ;
  ll a[n] ;
  ll dist[n] ;
  for (int i=0;i<n;i++) {
	  cin>>a[i] ;
  }
  sort(a,a+n) ;
  dist[0] = a[0] ;
  for (int i=1;i<n;i++)
  {
	  dist[i] = dist[i-1] + a[i] ;
  }
  ll count = 1 ;
  for (int i=1;i<n;i++)
  {
	  //cout<<a[i]<<" "<<dist[i-1]<<endl ;
	  if (a[i] <= 2*dist[i-1]) {
		  count++ ;
	  }
	  else {
		 count = 1 ; 
	  }
	  //cout<<count<<" "<<i<<endl ;
  }
  
  cout<<count<<endl ;
  return 0 ;
}


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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //n個の点
		int d = stdIn.nextInt(); //d次元
		
		int[][] x = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		}
		
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		}
		System.out.println(cnt);
		
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<ll,ll> pint;
int main(){
    int n; cin>>n;
    vector<ll> a(n);rep(i,n)cin>>a[i];
    vector<ll> s(n+1);
    vector<ll> sm(n+1);
    rep(i,n){
        s[i+1]=s[i]+a[i];
        sm[i+1]=s[i]+a[i];
    }
    ll ans1 =0;
    ll ans2=0;
    ll cnt1=0;
    ll cnt2=0;
    if(0<s[1]){
        ans2=s[1]+1;
        sm[1]=-1;
        cnt2=-s[1]-1;
    }
    else if(0>s[1]){
        ans1=-s[1]+1;
        cnt1=abs(s[1])+1;
        s[1]=1;
    }
    else{
        sm[1]=-1;
        cnt2=-1;
        s[1]=1;
        ans1 =1;
        cnt1=1;
        ans2=1;
    }
    REP(i,1,n){
        s[i+1]+=cnt1;      
        sm[i+1]+=cnt2;
        //rep(i,n+1) cout<<s[i]<<" ";cout<<"sa"<<endl;
        if(0<=s[i]*(s[i+1])){
            if((i+1)%2==1){
                ans1+=abs(s[i+1])+1;
                cnt1+=abs(s[i+1])+1;
                s[i+1]=1;
            }
            else{
                ans1+=abs(s[i+1])+1;
                cnt1+=-1*abs(s[i+1])-1;
                s[i+1]=-1;
            }
        }
        if(0<=sm[i]*sm[i+1]){
            if((i+1)%2==0){
                ans2+=abs(sm[i+1])+1;
                cnt2+=abs(sm[i+1])+1;
                sm[i+1]=1;
            }
            else{
                ans2+=abs(sm[i+1])+1;
                cnt2+=-1*sm[i+1]-1;
                sm[i+1]=-1;
            }
        }
    //rep(i,n+1) cout<<s[i]<<" ";cout<<endl;
    }
    ll res=min(ans1,ans2);
    cout<<res<<endl;
    //rep(i,n+1) cout<<s[i]<<" ";
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).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;}
const ll INF = 1LL << 56;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main(){
    ll k;
    cin >> k;
    ll x=7,ans=0;
    ll p[k+1];
    fill(p,p+k+1,-1);
    ll p1,p2;
    if (k%2==0 or k%5==0){
        cout << -1 << endl;
        return 0;
    }
    while(true){
        ll q=x%k;
        if (p[q]>0){
            p2=p[q];
            break;
        }else{
            p[q]=p1;
        }
        x*=10;
        x+=7;
        x%=k;
        p1++;
    }
    cout << p1-p2 << endl;
    return 0;
}


Measured memory_bytes: 11400
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int r,g,b;
  cin >> r >> g >> b;
  if((100*r+10*g+b)%4==0)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import collections

k = int(input())

li = [str(i) for i in range(1,10)]
st_li = li[:]
q = collections.deque(li)
count = 0
n = 10 ** 10

for i in range(1, n):
    a = q.popleft()
    num = int(a[-1])
    if num != 0:
        aa = a + str(num-1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    aa = a + str(num)
    st_li.append(aa)
    q.append(aa)
    count += 1
    if num != 9:
        aa = a + str(num+1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    if count > k+1:
        print(st_li[k - 1])
        exit(0)

Measured memory_bytes: 10868
#include<iostream>
using namespace std;
int main(){
	  int n,a,b,A,B;
  while(1){
	  cin>>n;
    if(n==0)break;
	 A=0;
	B=0;
      for(int i = 0; i < n;i++){
       cin>>a>>b;
	  if(a < b){  
	   B+=a+b;
	  }
	  else if(a > b){
	   A+=a+b;
	  }
	   else{
	   A+=a;
	  B+=b;
	  }
  }
	  cout<<A<<" "<<B<<endl;
}
return 0;
}


Measured memory_bytes: 2968
N, M = map(int,input().split())
A = list(map(int,input().split()))
# 17:22

import sys
from math import gcd
def lcm(a,b):
    return a//gcd(a,b)*b
#%%
ans = 0
L = 1
for i in range(N):
    L = lcm(L, A[i])
    if L>2*M:
        print(0)
        sys.exit()

L2 = L
L1 = L//2
for a in A:
    if (L//a)&1==0:
        print(0)
        sys.exit()
ans = M//L1 - M//L2
print(ans)


Measured memory_bytes: 85124
import sys
from pprint import pprint

A, B, M = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))
b = list(map(int, sys.stdin.readline().strip().split()))

ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, sys.stdin.readline().strip().split())
    ans = min(ans, a[x-1] + b[y-1] - c)

print(ans)

Measured memory_bytes: 64720
import sys

input = sys.stdin.readline
a, b, c, x, y= map(int, input().split())
ab = 2*c
count_x = 0
count_y = 0
buy_a = 0
buy_b = 0
buy_c = 0

if ab < a+b:
    min_count = min(x,y)
    count_x = min_count
    count_y = min_count
    buy_c = 2*min_count
    if x - count_x > 0:
        if ab > a:
            buy_a += x - count_x
        else:
            buy_c += 2 * (x - count_x)
    
    elif y - count_y > 0:
        if ab > b:
            buy_b += y - count_y
        else:
            buy_c += 2*(y - count_y)
else:
    min_count = min(x,y)
    if min_count == x:
        buy_a = min_count
        if ab > b:
            buy_b += y
        else:
            buy_c += 2 * y
    else:
        buy_b = min_count
        if ab > a:
            buy_a += x
        else:
            buy_c += 2 * x

print(buy_a * a + buy_b * b + buy_c * c)

Measured memory_bytes: 9196
import time
startTimeProblem=time.time()

import fileinput, sys, itertools
from math import *
from bisect import *
from heapq import *
from collections import *

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

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

N = In.int()
arr = []

for i in range(1, N+1):
    line = In.str().split()

    arr.append((i, line[0], int(line[1])))

arr.sort(key=lambda x: (x[1], -x[2]))

res = [x[0] for x in arr]

Out.intsNL(res)


######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

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

int main()
{
  bool flag = true;
  int a, b;
  string s;

  cin >> a >> b >> s;
  for (int i = 0; i < a + b + 1; i++)
  {
    if (i == a)
    {
      if (s[i] != '-')
      {
        flag = false;
        break;
      }
    }
    else
    {
      if (s[i] == '-')
      {
        flag = false;
        break;
      }
    }
  }
  cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	char X, Y;
	cin >> X>>Y;
 
	// 解法
	char ans;
	if (X>Y) ans = '>';
	else if (X==Y) ans = '=';
	else if (X<Y) ans = '<';

	//出力
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();
	
	int x, y; cin >> x >> y;
	int ans = 0;
	if (x == 3)ans += 100000;
	else if (x == 2)ans += 200000;
	else if (x == 1)ans += 300000;
	if (y == 3)ans += 100000;
	else if (y == 2)ans += 200000;
	else if (y == 1)ans += 300000;
	if (x == 1 && y == 1)ans += 400000;
	cout << ans << "\n";

	return 0;
}

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

using namespace std;
#define ll long long 
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  ll a[100050] = {};
  ll b[100050] = {};
  ll c[100050] = {};

  priority_queue<pair<int, int>> que;
  cin >> n >> m;

  REP(i, n){
    cin >> a[i];
  }

  REP(i, m){
    cin >> b[i] >> c[i];
  }

  REP(i, n){
    que.push(make_pair(a[i], 1));
  }

  REP(i, m){
    que.push(make_pair(c[i], b[i]));    
  }

  ll ans = 0;
  REP(i, n){
    auto p = que.top();
    que.pop();
    ans += p.first;
    if(p.second > 1){
      p.second--;
      que.push(p);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 4724
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N, M = MI()
    switch_pat = []
    for i in range(M):
        k, *s = MI()
        switch_pat.append(s)
    p = LI()
    ans = 0
    for bit in range(2 ** N):
        frag = False
        for m in range(M):
            cnt = 0
            for switch in switch_pat[m]:
                if 1 << (switch-1) & bit:
                    cnt += 1
            if cnt % 2 == p[m]:
                continue
            else:
                frag = True
                break
        if not frag:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

int N, M, mx = 0;
vector<int> under(400, 0);
vector<int> upper(400, 0);
vector<int> point(400, 0);
vector<int> span(400, 0);
vector<int> dp(400, -1);

int main(void){
	
	cin >> N;
	for(int i = 0; i < N; ++i) cin >> under[i] >> upper[i] >> point[i];
	cin >> M;
	for(int i = 0; i < M; ++i){
	    cin >> span[i]; mx = max(mx, span[i]);
	}
	
	dp[0] = 0;
    for(int s = 0; s <= mx; ++s){
        if(~dp[s]){
            for(int i = 0; i < N; ++i){
                for(int j = under[i]; j <= upper[i]; ++j){
                    if(s + j <= mx) dp[s + j] = max(dp[s + j], dp[s] + point[i]);
                }
            }
        }
        else{
            for(int i = 0; i < M; ++i){
                if(s == span[i]){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
	for(int i = 0; i < M; ++i) cout << dp[span[i]] << endl;
	
	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    LL n;cin >> n;
    LL x,d;cin >> x >> d;
    if(x==0&&d==0){
        cout << 1 << endl;
        return 0;
    }
    if(d==0){
        cout << n + 1 << endl;
        return 0;
    }
    else if(x==0){
        cout << n * (n - 1) / 2 + 1 %mod << endl;
        return 0;
    }
    if(x*d>=0) x=abs(x),d=abs(d);
    else if(d<0) d=-d,x=-x;
    vector<LL> c(n+1,0),fc(n+1,0);
    for (int i = n-1; i >= 0; i--) {
        c[i] = c[i+1] + i;
    }
    for (int i = 0; i < n; i++) {
        fc[i+1] = fc[i] + i;
    }
    unordered_map<LL,vector<P>> ma;
    for (LL i = 0; i <= n; i++) {
        LL p = i * x;
        LL q = p / d;
        LL a = (p%d + d) %d;
        ma[a].pb(mp(q+fc[i],q+c[n-i]));
    }
    LL ans = 0;
    for(auto m:ma){
        sort(ALL(m.sc));
        ans += m.sc[0].sc - m.sc[0].fs + 1;
        LL af = m.sc[0].sc;
        for (int i = 0; i < m.sc.size(); i++) {
            if(m.sc[i].sc <= af) continue;
            else if(m.sc[i].fs <= af){
                ans += m.sc[i].sc - af;
            }
            else{
                ans += m.sc[i].sc - m.sc[i].fs + 1;
            }
            af = m.sc[i].sc; 
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21064
from string import ascii_lowercase
alp=ascii_lowercase
ans=[float("inf")]*26
n=int(input())
for i in range(n):
    cnt=[0]*26
    s=input()
    for j in s:
        p=alp.index(j)
        cnt[p]+=1
    for j in range(26):
        ans[j]=min(ans[j],cnt[j])
output=[]
for i in range(26):
    for j in range(ans[i]):
        output.append(alp[i])
print("".join(output))

Measured memory_bytes: 74244
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data)

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

d, t, s = I()
print('Yes' if d/s <= t else 'No')

Measured memory_bytes: 26920
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	s := getNextString(scanner)
	q := getNextInt(scanner)
	dec := newDecomposition(n)
	for i := 0; i < n; i++ {
		dec.update(i, s[i])
	}
	for i := 0; i < q; i++ {
		t := getNextInt(scanner)
		if t == 1 {
			index := getNextInt(scanner) - 1
			c := getNextString(scanner)
			dec.update(index, c[0])
			continue
		}
		l := getNextInt(scanner) - 1
		r := getNextInt(scanner)
		fmt.Fprintln(writer, onescount32(dec.charset(l, r)))
	}
}
func onescount32(u uint32) int {
	c := 0
	for u > 0 {
		if u%2 == 1 {
			c++
		}
		u >>= 1
	}
	return c
}

type decomposition struct {
	chunk  int
	bucket [][]uint32
}

func newDecomposition(n int) decomposition {
	bucket := make([][]uint32, 1)
	bucket[0] = make([]uint32, n)
	chunk := 8
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		bucket = append(bucket, make([]uint32, n))
	}
	return decomposition{
		chunk:  chunk,
		bucket: bucket,
	}
}
func (dec *decomposition) upleft(l int) int {
	return (l + dec.chunk - 1) / dec.chunk
}
func (dec *decomposition) upright(r int) int {
	return r / dec.chunk
}

func (dec *decomposition) update(index int, value byte) {
	dec.bucket[0][index] = 1 << uint(value-'a')
	h := len(dec.bucket)
	for i := 0; i < h-1; i++ {
		p := index / dec.chunk
		r := (p + 1) * dec.chunk
		if r >= len(dec.bucket[i]) {
			r = len(dec.bucket[i])
		}
		dec.bucket[i+1][p] = 1 << uint(value-'a')
		for j := p * dec.chunk; j < r; j++ {
			dec.bucket[i+1][p] = dec.bucket[i+1][p] | dec.bucket[i][j]
		}
		index /= dec.chunk
	}
}
func (dec *decomposition) charset(l, r int) uint32 {
	return dec.charseth(l, r, 0)
}
func (dec *decomposition) charseth(l, r, h int) uint32 {
	var u uint32
	ll := dec.upleft(l)
	rr := dec.upright(r)
	for i := l; i < r && i < ll*dec.chunk; i++ {
		u = u | dec.bucket[h][i]
	}
	if ll < rr {
		u = u | dec.charseth(ll, rr, h+1)
	}
	for i := rr * dec.chunk; i < r && ll <= rr; i++ {
		u = u | dec.bucket[h][i]
	}

	return u
}


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

int main(){
  int x, a, b;
  string s;
  stack<int> S;

  while( cin >> s ){
    if ( s[0] == '+' ){
      a = S.top(); S.pop();
      b = S.top(); S.pop();
      S.push(a+b);
    } else if ( s[0] == '-' ){
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a-b);
    } else if ( s[0] == '*' ){
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a*b);
    } else {
      S.push(atoi(s.c_str()));

    }
  }

  cout << S.top() << endl;

  return 0;
}


Measured memory_bytes: 3196
import sys
import array
from collections import deque


def main():
    n = int(input())
    #l = array.array('L')
    l = deque()
    for _ in range(n):
        c = sys.stdin.readline().split()
        if c[0] == "insert":
            l.appendleft(int(c[1]))
        elif c[0] == "delete":
            if int(c[1]) in l:
                l.remove(int(c[1]))
        elif c[0] == "deleteFirst":
            l.popleft()
        elif c[0] == "deleteLast":
            l.pop()
    print(*l)


if __name__ == "__main__":
    main()


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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define lb         lower_bound
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define btpc       __builtin_popcountll
#define spc(x)     cout<<fixed<<setprecision(x)

const   long long  inf = 1e18;
const   long long  cs =  200005;
const   long long  mod = 1000000007;
const   double     PI =  2 * acos(0.0);
void solve()
{
    long long t,n,m,a,b,i,j,k,x,y,cnt=1;
    bool flag = false; string s;

    cin>>n;
    cin>>s;
    if(n<3200) cout<<"red"<<endl;
    else cout<<s<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);

    // ll tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}

Measured memory_bytes: 3660
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N, x = in_nn()
    max_n = 2 * N - 1

    if x == 1 or x == max_n:
        print("No")
        exit()

    if x < N:
        ans = []
        pyr = set(range(1, max_n + 1))
        center = [x + 2, x + 1, x, x - 1, x + 3]
        pyr -= set(center)
        pyr = list(pyr)
        t_len = (max_n - 5) // 2
        ans = pyr[:t_len] + center + pyr[t_len:]
    elif x == N:
        ans = list(range(1, max_n + 1))
    elif x > N:
        ans = []
        pyr = set(range(1, max_n + 1))
        center = [x - 2, x - 1, x, x + 1, x - 3]
        pyr -= set(center)
        pyr = list(pyr)
        t_len = (max_n - 5) // 2
        ans = pyr[:t_len] + center + pyr[t_len:]

    print("Yes")
    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 34096
#include <bits/stdc++.h>
#include <stdlib.h>
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);(i)++)
#define drep(i,l,r) for(int (i)=(l);(i)>=(r);(i)--)
#define MOD 1000000007
#define ll long long
using namespace std;
typedef struct Data{int a,b;}data;
bool cmp(const data& m,const data& n){return m.a<n.a;}

int main(){
    int n,m,ans=0;
    cin>>n>>m;
    vector<data> num(n);
    rep(i,0,n)cin>>num[i].a>>num[i].b;
    sort(num.begin(),num.end(),cmp);

    priority_queue<int> job;
    int i=0;
    erep(day,1,m){
        for(;num[i].a<=day;i++)job.push(num[i].b);
        if(job.size()){
            ans+=job.top();
            job.pop();
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll =long long;

int main (void) {
  int N;
  cin  >> N;
  int t=0;
  int T[101]={0};
  int time=0;
  for (int i=1; i<=N; i++) {
    cin >> t;
    T[i]=t;
    time = time +T[i];
  }
  int M;
  cin >> M;
  int P,X;
  for (int i=1; i<=M; i++) {
    cin >> P >>X;
    cout << time-(T[P]-X) << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    string S; cin >> S;
    int N = sz(S);
    ll dp[N+1][13];
    F0R(i, N+1) {
        F0R(j, 13) {
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;

    F0R(i, N) {
        F0R(j, 10) {
            int nxt = S[i] - '0';
            if (S[i] == '?') {
                nxt = j;
            }
            F0R(k, 13) {
                int rem = (10*k + nxt) % 13;
                dp[i+1][rem] += dp[i][k];
                dp[i+1][rem] %= MOD;
            }
            if (S[i] != '?') break;
        }
    }
    cout << dp[N][5] << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 10704
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,h;
    cin >> n >> h;
    int a[n],b[n];
    for(int i=0;i<n;i++)cin >> a[i] >> b[i];
    sort(a,a+n);
    sort(b,b+n);
    int ans=0;
    for(int i=n-1;i>=0;i--){
        h -= b[i];
        ans++;
        if(h<=0)break;
        if(a[n-1]>b[i-1])break;
    }
    if(h<=0){
        cout << ans;
        return 0;
    }
    cout << ans + (h+a[n-1]-1)/a[n-1];
}

Measured memory_bytes: 4420
object Main extends App {
  val in = readLine()
  val arr = in.toArray
  val rev = arr.reverse
  val mid = arr.size / 2
  println(arr.take(mid).zip(rev.take(mid)).foldLeft(0)((a, b) => if (b._1 != b._2) a + 1 else a))
}

Measured memory_bytes: 27296
import java.util.Scanner;

public class Main {
  static final long M = 998244353L;

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    long K = scanner.nextLong();

    System.out.println(solve(N, A, B, K));
  }

  private static long solve(int N, long A, long B, long K) {
    if (A > B) return solve(N, B, A, K);

    long[] fact = new long[N + 1];
    fact[0] = 1;
    for (int i = 0; i < N; i++) {
      fact[i + 1] = fact[i] * (N - i) % M;
    }
    long[] factinv = new long[N + 1];
    factinv[0] = 1;
    for (int i = 1; i <= N; i++) {
      factinv[i] = factinv[i - 1] * inverse(i, M) % M;
    }

    long res = 0;
    for (int i = 0; i <= Math.min(N, K / B); i++) {
      if ((K - B * i) % A == 0) {
        long j = (K - B * i) / A;
        if (j > N) continue;
        int jj = (int) j;
        long c = fact[i] * factinv[i] % M;
        c *= fact[jj] * factinv[jj] % M;
        res += c % M;
        res %= M;
      }
    }
    return res;
  }

  public static long inverse(long a, long mod) {
    return modpow(a, mod - 2, mod);
  }

  public static long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
      if (n % 2 == 1) res = (res * a) % mod;
      a = (a * a) % mod;
      n >>= 1;
    }
    return res % mod;
  }
}


Measured memory_bytes: 26068
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  i64 N,K;
  cin >> N >> K;
  i64 ans = 0;
  for(int i = 0;i < K;i++) {
    if((i + i) % K == 0) {
      i64 a = N / K + !!(N % K >= i && i != 0);
      i64 b = N / K + !!(N % K >= (K - i) % K && i != 0);
      ans += a * b * a;
    }
  }

  cout << ans << endl;
}


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

int bubbleSort(int A[], int N) {
    int flag = 1;
    int i = 0;
    int swap_cnt = 0;

    while (flag) {
        flag = 0;
        for (int j = N-1; j > i; j--) {
            if (A[j] < A[j-1]) {
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                swap_cnt++;
            }
        }
        i++;
    }
    return swap_cnt;
}

int main() {
    int N, A[100];

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

    int swap_cnt = bubbleSort(A, N);

    for (int i = 0; i < N; i++) {
        cout << A[i];
        if (i < N-1) cout << " ";
    }
    cout << "\n";
    cout << swap_cnt << endl;
    return 0;
}


Measured memory_bytes: 3124
#include <stdio.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

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

  long long ans = 0;
  for (int i = n - 1; i >=0; --i) {
    long long a_ = a[i];
    long long b_ = b[i];

    a_ += ans;
    long long remain = a_ % b_;
    if (remain > 0) {
      ans += b_ - remain;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

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

  int result = pow(2,29);
  rep(i, N) {
    int c, t; cin >> c >> t;
    if (t<=T) result = min(result, c);
  }
  if (result==pow(2,29)) cout << "TLE" << endl;
  else cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include "stdio.h"
#include <iostream>
#include "string.h"
#include "limits"
#include "algorithm"
#include "vector"

using namespace std;

char boins[5] = {'a', 'i', 'u', 'e', 'o'};

int main(){

	while(1){
		int n; cin >> n;
		if(!n) break;

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

		vector<string> vv(n);
		for(int i=0; i<n; i++){
			bool boin = false;
			for(int j=0; j<v[i].size(); j++){
				if(!j){
					for(int k=0; k<5; k++){
						if(v[i][j] == boins[k]){
							boin = true;
						}
					}
					vv[i].push_back(v[i][j]);
					continue;
				}
				if(boin){
					vv[i].push_back(v[i][j]);
					boin = false;
				}
				for(int k=0; k<5; k++){
					if(v[i][j] == boins[k]){
						boin = true;
					}
				}
			}
		}

		// for(int i=0; i<vv.size(); i++){
		// 	cout << vv[i] << endl;
		// }

		int ans = 0;
		bool ans_not = false;
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				int k = min(vv[i].size(), vv[j].size());
				bool tmp = true;
				for(int z=0; z<k; z++){
					if(vv[i][z] != vv[j][z]){
						ans = max(ans, z + 1);
						tmp = false;
						break;
					}
				}
				if(tmp) {
					if(vv[i].size() != vv[j].size()){
						ans = max(ans, (int)min(vv[i].size(), vv[j].size()) + 1);
						// cout << (int)min(vv[i].size(), vv[j].size()) + 1 << endl;
					}
					else{
						ans_not = true;
					}
				}
			}
		}

		if(ans_not){
			cout << -1 << endl;
		}
		else{
			cout << ans << endl;
		}

		// cout << endl;

	}

	return 0;
}



Measured memory_bytes: 3028
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int a, count=0;
    int b[21];
    scanf("%d", &a);
    for(int i=0; i<a; i++) scanf("%d", &b[i]);
    for(int i=0; i<a-2; i++)
        if((b[i]<b[i+1] && b[i+1]<b[i+2]) ||  (b[i]>b[i+1] && b[i+1]>b[i+2])) count++;
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666;
int n,m,a[N],res=1e9;
struct Link{
	int head,nxt[N],pre[N];
	void init(int *a, int n){
		head=a[1];rep(i,1,n-1)nxt[a[i]]=a[i+1],pre[a[i+1]]=a[i];
	}
	void erase(int x){
		if(head==x)head=nxt[x];
		nxt[pre[x]]=nxt[x];pre[nxt[x]]=pre[x];pre[x]=nxt[x]=0;
	}
}s[N];
int main() {
	read(n);read(m);rep(i,1,n){
		rep(j,1,m)read(a[j]);s[i].init(a,m);
	}
	rep(t,1,m){
		static int cnt[N];memset(cnt,0,sizeof(cnt));
		rep(j,1,n)cnt[s[j].head]++;int mx=0;rep(j,1,m)mx=max(mx,cnt[j]);
		res=min(res,mx);
		rep(j,1,m)if(cnt[j]==mx){
			rep(i,1,n)s[i].erase(j);
			break;
		}
	}
	printf("%d\n",res);
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(v) (v).begin(),(v).end()
#define endl '\n'

using namespace std;

const int N = 100005;
const int MOD = 1e9 + 7;
const int INF = 2000000000;
const ll INFLL = 1LL * INF * INF;

int n, m, a[N], dp[N];
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int x; cin >> x; a[x] = 1;
    }
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        if (a[i] == 1) continue;
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void) {
        int nums[10000];
        int i, count = 1;

        while(1) {
                scanf("%d",&nums[count]);
                if(nums[count] == 0) break;
                count++;
        }

        for(i = 1; i < count; i++) {
                printf("Case %d: %d\n", i, nums[i]);
        }

        return 0;
}



Measured memory_bytes: 2040
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;

int W,a,b;
int main()
{
    //std::ios::sync_with_stdio(false);
    scanf("%d%d%d", &W, &a, &b);
    if( b > a+ W)
    {
        printf("%d\n", b-a-W);
    }
    else if( b+W<a)
    {
        printf("%d\n", a-b-W);
    }
    else puts("0");
    //system("pause");
}


Measured memory_bytes: 256
from fractions import gcd
a,b,c,d = (int(x) for x in input().split())
val = gcd(c,d)
lcm = (c*d) // val
div_by_c = (b // c) - (a // c) + (1 if a % c == 0 else 0)
div_by_d = (b // d) - (a // d) + (1 if a % d == 0 else 0)
div_by_lcm = (b // lcm) - (a // lcm) + (1 if a % lcm == 0 else 0)

print(b-a+1 - div_by_c - div_by_d + div_by_lcm)


Measured memory_bytes: 5556
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding


	int n;
	cin>>n;
	vi a(n);
	int s = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s ^= a[i];
	}

	for(int i=0;i<n;i++){
		printf("%d%c",a[i]^=s," \n"[i+1==n]);
	}

	
	return 0;
}
int main(){
	int test = 1;
  	//scanf("%d", &test);
  	while (test--)solve();return 0;
}

Measured memory_bytes: 3960
n = raw_input()
a = map(int, raw_input().split())
r = sum(a)
l= a[0]
min = abs(a[0] - (r-a[0]))
r = r- a[0]
for k in a[1:]:
  l += k
  r -= k
  temp = abs(l - r)
  if temp < min:
    min = temp
print min

Measured memory_bytes: 2568
def codefes17f_a():
    s = str(input())
    if s.replace('A', '') != 'KIHBR': return print('NO')
    if 'AA' in s: return print('NO')
    if not 'KIH' in s: return print('NO')
    return print('YES')

if __name__ == '__main__':
    codefes17f_a()

Measured memory_bytes: 9112
N, L = map(int, input().split())

start = L
end = L + N - 1

def aji(n):
    return n * (n+1) // 2

if start * end <= 0:
    print(aji(N-1) + L * N)
elif start > 0:
    print(aji(N-1) + L * (N-1))
elif end < 0:
    print(aji(N-2) + L * (N-1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


vector<int> Zalgo(string s){
    int n = s.size();
    vector<int> a(n, 0);
    int from = -1, last = -1;
    for(int i = 1; i < n; i++){
        int &same = a[i];
        if (from != -1){
            same = min(a[i-from], last - i);
            same = max(same, 0);
        } 
        while(same+i < s.size() && s[same] == s[i+same]) same++;
        if (last < i+same) {
            last = i + same;
            from = i;
        }
    }
    a[0] = n;
    return a;
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    rep(i, n-1){
        string t = s.substr(i);
        vector<int> a = Zalgo(t);
        rep(i, a.size()) {
            // cout << a[i] << " ";
            if (a[i] >= i+1) continue;
            ans = max(a[i], ans);
        }
        // cout << endl;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
s = gets.split("").map { |e| e.to_i }
k = gets.to_i

flag = 0 #==1である=>0
for i in 0..k-1 do
  if s[i] != 1
    puts s[i]
    flag = 1
    break
  end
end

if flag == 0
  puts 1
end


Measured memory_bytes: 1788
#include<stdio.h>

int main(void){
    int a,b,i;
    char s[12];
    scanf("%d%d",&a,&b);
    scanf("%s",s);
    for(i=0;i<=a+b;i++){
        if(i==a && s[i]!='-'){
            printf("No\n");
            return 0;
        }
        if(i!=a && s[i]=='-'){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}



Measured memory_bytes: 128
#include <vector>
#include <iostream>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge> >;

Graph G;
vector<int> d;
void Dfs(int v, int parent)
{ 
    for (auto e : G[v])
    {
        if (e.first == parent) continue; // 逆流を防ぐ(探索の肝！)
        d[e.first] = d[v] + e.second;
        Dfs(e.first, v);
    }
}

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

    int u, v, w;
 
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N - 1; ++i)
    {
        cin >> u >> v >> w;
        --u; --v;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }

    d.assign(N, 0);
    Dfs(0, -1);
    for (auto ans : d) cout <<(ans & 1)<< endl;
    return 0;
};


Measured memory_bytes: 8192