akhauriyash/Code-Regression huggingface dataset:
n = int(input())

arr = list(map(int,input().split()))

dp = [float('inf')] * n

dp[0] = 0
dp[1] = abs(arr[0] - arr[1])

for i in range(2,n):
	dp[i] = min(abs(arr[i-1] - arr[i]) + dp[i -1],abs(arr[i-2]-arr[i])+dp[i-2])

print(dp[-1])
	
	



Measured memory_bytes: 13928
N = int(input())
s = list(map(int, input().split()))
a=[0]*N#N個の要素の配列
total=0

for i in range(N):
 a[i]=int(s[i])

while 1==1:
 b=0
 for i in range(N):
  if a[i]%2==0:
        a[i]=a[i]/2
        b+=1
 if b==N:
  total+=1
 else: 
  break

print(total)

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define SX(x) (x).begin(), (x).end()
typedef pair<int, int> P;
using ll =long long;

int main()
{
  string s; cin >> s;
  
  string ans = "yes";
  rep(i, s.size())
  {
    for (int j=i+1; j<s.size(); j++)
    {
      if (s[i] == s[j])
        ans = "no";
    }
  }
  cout << ans << endl;  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int x[N+1];
  x[0] = 0;
  for(int i = 0; i< N; i++){
    if(S.at(i) == 'I'){
      x[i+1] = x[i]+1;
    }
    else{
      x[i+1] = x[i]-1;
    }
  }
  sort(x,x+N+1);
  cout << x[N] << endl;
}

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

/* クイックソート
constexpr auto MAX = 100100;
int A[MAX], n;

int partition(int p, int r)
{
	int x, i;
	x = A[r];
	i = p - 1;

	for (int j = p; j < r; j++)
	{
		if (A[j] <= x)
		{
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

void quickSort(int p, int r)
{
	int q;

	if (p < r)
	{
		q = partition(p, r);
		quickSort(p, q - 1);
		quickSort(q + 1, r);
	}
}
*/

/* 二分探索木
struct Node
{
	int key;
	Node* right, * left, * prarent;
};

Node* root, * NIL;

void insert(int k)
{
	Node* y = NIL;
	Node* x = root;
	Node* z;

	z = (Node*)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL)
	{
		y = x;
		if (z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}

	z->prarent = y;

	if (y == NIL)
	{
		root = z;
	}
	else
	{
		if (z->key < y->key)
		{
			y->left = z;
		}
		else
		{
			y->right = z;
		}
	}
}

Node* find(Node* u, int k)
{
	while (u != NIL && k != u->key)
	{
		if (k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

void inorder(Node* u)
{
	if (u == NIL) return;
	inorder(u->left);
	cout << " " << u->key;
	inorder(u->right);
}

void preoder(Node* u)
{
	if (u == NIL) return;
	cout << " " << u->key;
	preoder(u->left);
	preoder(u->right);
}

int main()
{
	int n, x;
	string com;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> com;
		if (com == "find")
		{
			cin >> x;
			Node* t = find(root, x);
			if (t != NIL) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
		else if (com == "insert")
		{
			cin >> x;
			insert(x);
		}
		else if (com == "print")
		{
			inorder(root);
			cout << endl;
			preoder(root);
			cout << endl;
		}
	}
}

*/

class UnionFind
{
public:
	vector<int> rank, p;

	UnionFind() {}
	UnionFind(int size)
	{
		rank.resize(size, 0);
		p.resize(size, 0);
		for (int i = 0; i < size; i++) makeSet(i);
	}

	void makeSet(int x)
	{
		p[x] = x;
		rank[x] = 0;
	}

	bool same(int x, int y)
	{
		return findSet(x) == findSet(y);
	}

	void unite(int x, int y)
	{
		link(findSet(x), findSet(y));
	}

	void link(int x, int y)
	{
		if (rank[x] > rank[y]) p[y] = x;
		else p[x] = y;

		if (rank[x] == rank[y]) rank[y]++;
	}

	int findSet(int x)
	{
		if (x != p[x])
		{
			p[x] = findSet(p[x]);
		}
		return p[x];
	}
};

int main()
{
	int n, a, b, q;
	int t;

	cin >> n >> q;

	UnionFind ds = UnionFind(n);

	for (int i = 0; i < q; i++)
	{
		cin >> t >> a >> b;

		if (t == 0) ds.unite(a, b);
		else if (t == 1)
		{
			if (ds.same(a, b)) cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
}


Measured memory_bytes: 3192
import java.util.*;

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

    String s = sc.next();
    int n = s.length();
    int ans = 0;
    
    for(int i = 0; i < n; i++){
      for(int j = n; j > i; j--){
        if(s.substring(i, j).matches("[ACGT]*")){
          if(s.substring(i, j).length() > ans){
            ans = s.substring(i, j).length();
          }
        }
      }
    }
    System.out.println(ans);
  }
}


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

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

  int n;
  cin >> n;
  int less_than_one = 0, abs_min = 1e9 * 2;
  ll abs_total = 0;
  vector<int> a(n);
  rep(i, 0, n) {
    cin >> a[i];
    if (a[i] < 1) less_than_one++;
    int t = abs(a[i]);
    abs_total += t;
    abs_min = min(abs_min, t);
  }

  if (less_than_one & 1)
    cout << abs_total - abs_min * 2 << endl;
  else
    cout << abs_total << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  sort(all(A), greater<ll>());
  ll ans = accumulate(begin(A), begin(A)+n/2, 0LL) * 2 - A[0];
  if(n%2==1) ans += A[n/2];
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define ms memset
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define lower_bound lb
#define upper_bound ub

int main()
{
    int n; cin >> n;
    int arr[n]; FOR(i,0,n-1) cin >> arr[i];
    sort(arr, arr+n);
    ll ans = arr[n-1];
    int k = n-2; int c = n-2;
    while (k > 0){
        ans += arr[c]; k--;
        if (k == 0) break;
        ans += arr[c]; k--;
        c--;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4404
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a[][];
		
		a = new int[10][10];
		while (sc.hasNext()) {
			String str = sc.next();
			for (int i = 0; i < 10; i++) {
				a[0][i] = str.charAt(i) - '0';
			}
			for (int i = 0; i < 9; i++) {
				for (int j = 0; j < 9 - i; j++) {
					a[i + 1][j] = (a[i][j] + a[i][j + 1]) % 10;
				}
			}
			System.out.println(a[9][0]);
		}
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
string s;
bool check(char A){
    if(A=='G' || A=='A' || A=='C' || A=='T'){
        return true;
    }
    return false;
}

bool fun(int i,int j){
    for(int I=i;I<=j;I++){
        if(!check(s[I])){
            return false;
        }
    }
    return true;
}

int32_t main(){
	ios::sync_with_stdio(false);
    
    cin>>s;
    int len=0;
    for(int i=0;i<s.size();i++){
        for(int j=i;j<s.size();j++){
            int temp=0;
            if(fun(i,j)){
                temp=j-i+1;
            }
            len=max(len,temp);

        }
    }
    cout<<len<<"\n";


	return 0;
}

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

const long long mod=(1e9)+7;
long long n, k, res;

void _input(){
    cin>>n>>k;
}

void _solve(){
    for(long long i=k; i<=n+1; ++i)
        res=(res+((n+n-i+1)*i-(i-1)*i)/2+1)%mod;
}

void _output(){
    cout<<res;
}

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

//    freopen("input.inp", "r", stdin);

    _input();
    _solve();
    _output();

    return 0;
}


Measured memory_bytes: 3648
#!/usr/bin/env fsharpi

open System;

let ParseIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let ParseInt1 ( str : string ) =
    ParseIntN str |> fun arr -> arr.[0]

let ParseInt2 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1])

let ParseInt3 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let ReadLinesN ( n : int ) =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.take n

let ReadLines =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.takeWhile ((<>) null)

Console.ReadLine()
|> ParseInt1
|> fun n -> n * (n + 1) / 2
|> Console.WriteLine


Measured memory_bytes: 11220
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n; 
    cin >> n;
    string s; 
    cin >> s;
    int k;
    cin >> k;

    for(size_t i = 0; i < s.length(); i++){
        if(s[i] != s[k-1]){
            s[i] = '*';
        }
    }

    cout << s;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


class RollingHash:
    def __init__(self, string):
        self.n = len(string)
        self.BASE = 1234
        self.MOD = (1 << 45) - 1
        self.hash = [0] * (self.n + 1)
        self.pow = [1] * (self.n + 1)

        for i, char in enumerate(string):
            self.hash[i + 1] = (self.hash[i] + ord(char)) * self.BASE % self.MOD
            self.pow[i + 1] = (self.pow[i] * self.BASE) % self.MOD

    def get_hash(self, l, r):
        """string[l:r]のハッシュ値を返す。O(1)"""
        res = (self.hash[r] - self.hash[l] * self.pow[r - l]) % self.MOD
        return res


n = int(input())
s = [input()[:-1] for i in range(n)]


s.sort(key=len)
str_set = set()
cnt = 0

for string in s:
    string = string[::-1]
    n = len(string)
    rh = RollingHash(string)

    for r in range(1, n + 1):
        if rh.get_hash(0, r) in str_set:
            cnt += 1

    set_char = set()
    for r in range(1, n + 1)[::-1]:
        set_char.add(string[r - 1])
        for char in set_char:
            if char == string[r - 1]:
                continue
            h = (rh.hash[r - 1] + ord(char)) * rh.BASE % rh.MOD
            if h in str_set:
                cnt += 1
    str_set.add(rh.get_hash(0, n))

print(cnt)

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

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<8>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<int>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1e9+7

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

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

int main()
{
    int r;
    ci >> r;

    co << 3 * r * r << en;
  
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF 1000000
#define BLACK 2
#define GRAY 1
#define WHITE 0
using namespace std;

int Node[100][100];
int Cost[100];

void dijkstra()
{
	int Color[100];
	REP(i, 100)Color[i] = WHITE;
	REP(i, 100)Cost[i] = INF;

	Color[0] = GRAY;
	Cost[0] = 0;

	while (true)
	{
		int min_index = -1;
		int min_value = INF;
		REP(i, 100)
		{
			if (Color[i] != BLACK && min_value>Cost[i])
			{
				min_value = Cost[i];
				min_index = i;
			}
		}
		if (min_index == -1)break;

		REP(i, 100)
		{
			if (Color[i] != BLACK && i != min_index && Node[min_index][i]!=INF && Node[min_index][i]+min_value<Cost[i])
			{
				Cost[i] = min_value+Node[min_index][i];
				Color[i] = GRAY;
			}
		}
		Color[min_index] = BLACK;
	}
}

int main()
{
	REP(i,100)
	{
		REP(j, 100)
		{
			Node[i][j] = INF;
		}
	}
	REP(i, 100)Node[i][i] = 0;
	int n;
	cin >> n;
	REP(i,n)
	{
		int u, k;
		cin >> u >> k;
		REP(j,k)
		{
			int v, c;
			cin >> v >> c;
			Node[u][v] = c;
		}
	}
	dijkstra();
	REP(i, n)
	{
		cout << i << " " << Cost[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3124
#include<stdio.h>

int main(void)
{
    int s;
    scanf("%d",&s);
    int flont,back;

    flont=s/100;
    back=s%100;

    if(1<=flont && flont<=12){
        if(1<=back && back<=12){
            puts("AMBIGUOUS");
        }else{
            puts("MMYY");
        }
    }else{
        if(1<=back && back<=12){
            puts("YYMM");
        }else{
            puts("NA");
        }
    }

    return 0;
}

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

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

	set<int> s;
	for(int i = 0; i < 4; ++i)
	{
		int x;
		cin >> x;
		s.insert(x);
	}

	if(s == set<int>{1,9,7,4}) {
		cout << "YES";
	} else
		cout << "NO";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	int n,x; cin>>x>>n;
	vector<int> occ(101+1);
	for(int i=1;i<=n;++i){
		int y; cin>>y;
		occ[y]=1;
	}
	int dif=INT_MAX,ans=INT_MAX;
	for(int i=x;i>=0;--i){
		if(!occ[i]){
			if(abs(i-x)<dif){
				dif=abs(i-x);
				ans=i;
			}
			break;
		}
	}
	for(int i=x+1;i<=101;++i){
		if(!occ[i]){
			if(abs(i-x)<dif){
				dif=abs(i-x);
				ans=i;
			}
			break;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3636
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    double h, max, min;

    h = sc.nextDouble();
    max = h; min = h;
    for(;sc.hasNext();){
      h = sc.nextDouble();
      if(max < h)max = h;
      if(min > h)min = h;
    }
    out.printf("%f%n", max - min);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 19088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    string S;
    cin >> S;
    string ss = "";

    for(int i=S.size()-1; i>=0; i--) {
        ss += S[i];
        if(ss == "maerd") ss = "";
        else if(ss == "remaerd") ss = "";
        else if(ss == "esare") ss = "";
        else if(ss == "resare") ss = "";
        else continue;
    }
    if(ss == "") cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3740
#pragma comment(linker, "/STACK:10240000")
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main ()
{
    int n, m, k;
    scanf ("%d%d%d", &n, &m, &k);
    bool flag = false;
    for (int i = 0; i <= n; i ++)
    {
        for (int j = 0; j <= m; j ++)
        {
            int ans = i * m + j * n;
            ans -= i * j * 2;
            if (ans == k)
            {
                flag = true;
                break;
            }
        }
        if (flag)
        {
            break;
        }
    }
    if (flag)
    {
        printf ("Yes\n");
    }
    else
    {
        printf ("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int AB, BC, CA;

  cin >> AB >> BC >> CA;

  cout << AB*BC/2 << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
	int n,x;
	long long sum;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		sum=sum+x-1;
	}
	cout<<sum<<endl;
    return 0;
}

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

vector<vector<int> >adj;

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(0);   
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif

  int n,m;
  cin>>n>>m;
  adj.resize(n+1);
  int a[n+1];
  for(int i=1;i<=n;i++)
    cin>>a[i];
  int x,y;
  for(int i=0;i<m;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int cnt=0;
  for(int i=1;i<=n;i++)
  {
    bool flag=true;
    for(auto j:adj[i])
    {
      if(a[j]>=a[i])
        flag=false;
    }
    if(flag)
      cnt++;
  }
  cout<<cnt;

}

Measured memory_bytes: 9812
/*input
21
0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1
1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 0
0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1
0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0
1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0
0 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1
0 1 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 0
0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1
0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1 1
0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1
0 1 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 0 1 1 0
0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 0 0 0 1
0 1 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 0 1 1
1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1
0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1
1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 1 1 0
0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1
0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1 0 1
0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0
1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 1 0
1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 0 0
*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7,N = 22;
int dp[N][1<<N],g[N][N];
int n;

int fun(int pos,int mask)
{
	if(dp[pos][mask]!=-1) return dp[pos][mask];
	if(pos==n) return 1;
	dp[pos][mask]=0;
	for(int i=0;i<n;i++) if(((mask>>i)&1)==0 &&  g[pos][i]==1) dp[pos][mask]+=fun(pos+1,mask|(1<<i)),dp[pos][mask]%=mod;
	// cout<<pos<<" "<<mask<<" "<<dp[pos][mask]<<"\n";
	return dp[pos][mask];
}

int main()
{
	memset(dp,-1,sizeof dp);
	cin>>n;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>g[i][j];
	cout<<fun(0,0)<<"\n";

	return 0;
}


Measured memory_bytes: 364080
<?php
  
fscanf(STDIN,"%d",$N);

$input_org = $input_changed = explode(" ",trim(fgets(STDIN)));

asort($input_changed);

for($i=0;$i<$N/2;$i++){
  $n = current($input_changed);
  next($input_changed);
}
$n_1 = current($input_changed);

foreach($input_org as $elem){
  if($elem <= $n){
    echo "$n_1\n";
  }else{
    echo "$n\n";
  }
}

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

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

    while(s.find("Z")<s.find("A")) s[s.find("Z")]='F';
    int maxv=0;
    bool flag=true;
    while(flag){
        int n=s.find("Z")-s.find("A")+1;
        maxv=max(maxv,n);
        s[s.find("Z")]='F';
        if(s.find("A")==string::npos) flag=false;
        if(s.find("Z")==string::npos) flag=false;
    }
    cout<<maxv<<"\n";
    return 0;
}

Measured memory_bytes: 3684
N = int(input())

x = 0
y = 0

for _ in range(N):
    t, a, b = [int(i) for i in input().split()]

    diff_a = abs(a - x)
    diff_b = abs(b - x)

    p = t - (diff_a + diff_b)
    if p < 0 or p % 2 != 0:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 3060
n,m=map(int,input().split())
a=list(map(int,input().split()))
rep=[]
for i in range(m):
    b,c=map(int,input().split())
    rep.append([c,b])
rep.sort(reverse=True)
Card=[0]*n
cnt=0
fg=0
while fg<n and cnt<m:
    tt=0
    while tt<rep[cnt][1] and fg+tt <n :
        Card[fg+tt]=rep[cnt][0]
        tt+=1
    fg+=tt
    cnt+=1


ans=a+Card
ans.sort(reverse=True)
tmp=0
for i in range(n):
    tmp+=ans[i]

print(tmp)

Measured memory_bytes: 27196
#include<cstdio>
using namespace std;
int main(){
char str;
while(scanf("%c",&str)!=EOF){
    if(str>='a' && str<='z'){
        str=str-32;
        printf("%c",str);
    }else if(str>='A'&& str<='Z'){
        str=str+32;
        printf("%c",str);
    }else{
        printf("%c",str);
    }
}

return 0;
}


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

int main()
{
    int d,s;
    while(cin >> d){
        s=0;
        for(int i=0 ; i<600 ; i+=d){
            s+=i*i*d;
        }
        cout << s << endl;
    }
	return 0;
}

Measured memory_bytes: 1160
package main

import (
	"fmt"
)

func sort(nums []int, n int) {
	for i := 1; i < n; i++ {
		v := nums[i]
		j := i - 1
		for j >= 0 && v < nums[j] {
			nums[j+1] = nums[j]
			j--
		}
		nums[j+1] = v
	}
}

func main() {
	tasks := make([]int, 3)
	for i := range tasks {
		fmt.Scan(&tasks[i])
	}

	sort(tasks, 3)

	fmt.Println((tasks[1] - tasks[0]) + (tasks[2] - tasks[1]))
}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
		
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		for(char c : sc.next().toCharArray()){
			System.out.print((c - 3) < 'A' ? (char)('Z' - ('A' - (c - 3) - 1)) : (char)(c - 3));
		}
		System.out.println();
	}
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const LL mod = 1e9 + 7;
LL S;
int d[10];

LL pw(LL x , LL y){
	LL res = 1;
	LL z = x;
	for(LL i = y ; i > 0 ; i >>= 1){
		if(i&1) (res *= z) %= mod;
		z = z * z % mod;
	}
	return res;
}

int main(){
	cin >> S;
	LL ans = 0;
	int j = 1;
	int x = 1 , y = 1;
	LL z = 0;
	d[0] = 1;
	repp(i,0,9) d[i+1] = d[i] * 10;
	repp(i,1,1e7){
		if(i == d[x]) ++x;
		while(z < S){
			z += y;
			++j;
			if(j == d[y]) ++y;
		}
		if(z == S) ++ans;
		z -= x;
	}
	(ans += S/8) %= mod;
	for(LL i = 1 ; i * i <= S ; ++i){
		if(S%i) continue;
		if(i >= 8){
			(ans += 9 * pw(10,i-1) - S/i + 1) %= mod;
			--ans;
		}
		if(S/i >= 8 && i * i < S){
			(ans += 9 * pw(10,S/i-1) - i + 1) %= mod;
			--ans;
		}
	}
	if(ans<0) ans += mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
n,x=map(int,input().split())
def b(j):
    return 2**(j+2)-3
def p(j):
    return 2**(j+1)-1
def f(n,x):
    if n==0:
        return 0 if x<=0 else 1
    elif x<=b(n-1)+1:
        return f(n-1,x-1)
    elif x==b(n-1)+2:
        return p(n-1)+1
    elif 2+b(n-1)<x<=2*b(n-1)+2:
        return p(n-1)+1+f(n-1,x-b(n-1)-2)
    else:
        return 2*p(n-1)+1
print(f(n,x))

Measured memory_bytes: 3064
#include<cstdio>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
using namespace std;
typedef long long ll;
const int maxn=4010;
const int mod=1000000007;
int n,k,fac[maxn],ifac[maxn];
int C(int a,int b) {return (ll)fac[a]*ifac[b]%mod*ifac[a-b]%mod;}
int main() {
	scanf("%d%d",&n,&k);
	ifac[1]=ifac[0]=fac[0]=1;
	rep(i,2,n+k) ifac[i]=(ll)(mod-mod/i)*ifac[mod%i]%mod;
	rep(i,1,n+k) fac[i]=(ll)fac[i-1]*i%mod,ifac[i]=(ll)ifac[i-1]*ifac[i]%mod;
	int ans=(C(n-1+k-1,k-1)-(k>=2?C(n+k-2,k-2):0)+mod)%mod;
	rep(i,1,n-k-1) ans=(ans+ans)%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int n;
Graph G;

void dfs(int v, int p, int pc, int &K, map<pair<int,int>, int> &color){
  int c = 1;
  for (int nv : G[v]){
    if (nv == p) continue;
    if (c == pc) c++;
    color.at({min(v, nv), max(v, nv)}) = c;
    chmax(K, c);
    dfs(nv, v, c, K, color);
    c++;
  }
}

int main() {
  cin >>n;
  G.assign(n, vector<int>());
  vector<int> A(n-1), B(n-1);
  map<pair<int,int>, int> color;
  rep(i, n-1){
    int a,b; cin >>a >>b; a--; b--;
    A[i] = a; B[i] = b;
    G[a].push_back(b);
    G[b].push_back(a);
    color[{a, b}] = 0;
  }
  int K = 0;
  dfs(0, 0, 0, K, color);

  cout <<K <<endl;

  rep(i, n-1){
    int a = A[i], b = B[i];
    cout <<color.at({a, b}) <<endl;
  }
}


Measured memory_bytes: 14080
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

const int MAX = 16000;
bool dp[90][90][MAX*2];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];
  rep(i, h) rep(j, w) {
    int b;
    cin >> b;
    a[i][j] = abs(a[i][j]-b);
  }
  dp[0][0][MAX+a[0][0]] = true;
  dp[0][0][MAX-a[0][0]] = true;
  rep(i, h) rep(j, w) rep(k, MAX*2){
    if (dp[i][j][k]) {
      if (i+1 < h) {
        dp[i+1][j][k+a[i+1][j]] = true;
        dp[i+1][j][k-a[i+1][j]] = true;
      }
      if (j+1 < w) {
        dp[i][j+1][k+a[i][j+1]] = true;
        dp[i][j+1][k-a[i][j+1]] = true;
      }
    }
  }
  int ans = 1e9;
  rep(i, MAX*2) {
    if (dp[h-1][w-1][i])
      chmin(ans, abs(i-MAX));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 224128
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // not prime num
            return false;
        }
    }
    // prime num
    return true;
}

struct Town{
    int p, num;
    Town(int in_p, int in_num){
        p=in_p;
        num=in_num;
    }

    bool operator<(const Town &another) const
    {
        return p < another.p;
    };
};

int main() {
    int N;
    ll ans=0LL;
    cin >> N;
    vector<int>A(N);
    rep(i,N){
        cin >> A[i];
    }

    vector<int>p1,p2;
    sort(A.begin(), A.end());

    for(int i=0; i<N; i++){
        p1.push_back(A[N-1-i]);
        p1.push_back(A[i]);
    }

    for(int i=0; i<N; i++){
        p2.push_back(A[i]);
        p2.push_back(A[N-1-i]);
    }

    ll temp=0LL;
    for(int i=0; i<N-2; i++){
        temp+=abs(p1[i]-p1[i+1]);
    }
    ans=temp+abs(p1[N-1]-p1[0]);

    temp=0LL;
    for(int i=0; i<N-2; i++){
        temp+=abs(p2[i]-p2[i+1]);
    }
    ans=max(ans,temp+abs(p2[N-1]-p2[0]));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2932
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n - 1);
	rep(i, n) {
		cin >> a[i];
		if (i == 0)continue;
		if (a[i - 1] <= a[i]) b[i - 1] = 0;
		else b[i - 1] = 1;

	}

	ll money = 1000;
	ll t = 0;

	for (int j = 0; j < n; j++) {
		if (j == n - 1) {
			if (t != 0) {
				money += t * a[j];
			}
			cout << money << endl;
			return 0;
		}
		if (t == 0 && b[j] == 0) {
			t = money / a[j];
			money = money % a[j];
		}
		else if (t != 0 && b[j] == 1) {
			money += t * a[j];
			t = 0;
		}
		else {
			continue;
		}
	}
}


Measured memory_bytes: 3660
using System;
using System.Linq;

class C
{
	static void Main()
	{
		Console.ReadLine();
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		Console.WriteLine(a.Aggregate(Lcm));
	}

	static int Gcd(int a, int b) { for (int r; (r = a % b) > 0; a = b, b = r) ; return b; }
	static int Lcm(int a, int b) => a / Gcd(a, b) * b;
}



Measured memory_bytes: 18468
#include <iostream>

using namespace std;
int main(){
	int i,n,ans = 0;
	cin >> n;
	for(i=1;i<=n;i++){
		int x = i,cnt = 0;
		while(x){
			cnt++;
			x /= 10;
		}
		if(cnt&1) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int H, W, d[60][60];

bool v(int x, int y) {
	return 0 <= x && x < W && 0 <= y && y < H;
};
int solve(int x, int y) {
	int ret = 1;
	if (!d[y][x])
		return 0;
	d[y][x] = 0;
	constexpr int dxy[][2] = { {-1,0}, {1,0}, {0,-1}, {0, 1} };
	for (auto t : dxy)
		if (v(x + t[0], y + t[1]))
			ret += solve(x + t[0], y + t[1]);
	return ret;
}

int main() {
	char t;
	bool ans = true;
	cin >> H >> W;
	loop(y, H) loop(x, W) {
		cin >> t;
		d[y][x] = (t == '#');
	}
	loop(y, H) loop(x, W)
		if (d[y][x]) 
			if (solve(x, y) < 2)
				ans = false;
	YesNo(ans);
	return 0;
}


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

int main () {
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int ans = 0;
    for (int i = 0; i <= a; i++)
        for (int j = 0; j <= b; j++)
            for (int k = 0; k <= c; k++)
                if (500 * i + 100 * j + 50 * k == x)
                    ans++;

    cout << ans;
}

Measured memory_bytes: 3572
#include<stdio.h>

int search(int A[], int n, int key)
{
	int i=0;
	A[n]=key;
	while(A[i]!=key)i++;
	return i!=n;
}

int main(void){
	int i,n,A[10000+1],q,key,sum=0;
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d",&A[i]);
		}
		scanf("%d",&q);
		for(i=0; i<q; i++){
			scanf("%d",&key);
			if(search(A,n,key)){sum++;}
			}
		
	printf("%d\n", sum);
	return 0;
		}


Measured memory_bytes: 2068
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


int main(void){
	int a, b; cin >> a >> b;
	for(int i=1; i<=3; i++){
		if(a!=i && b!=i) cout << i;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int max = 1e9 + 7;

int main()
{
    int x;
    cin >> x;
    if(x == 1)
    cout << 0 << '\n';
    if(x == 0)
    cout << 1 << '\n';
}


Measured memory_bytes: 3632
n = int(input())
a = [[0]*3 for _ in range(n+1)]
for i in range(n):
    a[i] = list(map(int, input().split()))

#print(a)
    
dp = [[0]*3 for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(3):
        dp[i][j] = max(dp[i-1][(j+1)%3]+a[i-1][j], dp[i-1][(j+2)%3]+a[i-1][j])
        
ans = max(dp[n][j] for j in range(3))
print(ans)

Measured memory_bytes: 47368
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nh = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var ab = new int[nh[0]][];
        for (var i = 0; i < nh[0]; i++)
            ab[i] = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        ab = ab.OrderByDescending(a => a[1]).ToArray();
        var max = ab.Max(b => b[0]);
        var res = 0;
        for(var i = 0; i < nh[0]; i++)
        {
            if (max < ab[i][1] && nh[1] > 0)
            {
                res++;
                nh[1] -= ab[i][1];
            }
            else
                break;
        }
        res += Max(0, (int)Ceiling((double)nh[1] / max));
        WriteLine(res);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 28356
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.regex.Pattern
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.math._
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val a = input.split(" ").head.toInt
    val b = input.split(" ").tail.head.toInt
    (a * b).toString
  }

  def divisors(n: Long): Vector[Long] = {
    val halfList = (1 to sqrt(n).toInt).toVector.filter(_ % n == 0).map(_.toLong)
    val reversedList = if (sqrt(n).floor == sqrt(n)) halfList.reverse.tail.map(n/_) else halfList.reverse.map(n/_)
    halfList ++ reversedList
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """3 3 10
      |60 2 2 4
      |70 8 7 9
      |50 2 3 9""".stripMargin -> """120
                                        |
                                   |
                                |""".stripMargin,
    """3 3 10
      |100 3 1 4
      |100 1 5 9
      |100 2 6 5""".stripMargin -> """-1
                                         |
                               |""".stripMargin,
    """8 5 22
      |100 3 7 5 3 1
      |164 4 5 2 7 8
      |334 7 2 7 2 9
      |234 4 7 2 8 2
      |541 5 4 3 3 6
      |235 4 8 6 9 7
      |394 3 6 1 6 2
      |872 8 4 3 7 2""".stripMargin -> """1067"""
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 55308
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <cmath>
using namespace std;


int main(){ 
    int a[1000001] = {0};
    int n,q;
    long long int s =0;
    cin >> n ;
    rep(i,n){
        int m;
        cin >> m;
        a[m] ++ ;
    }
    rep(i,1000001){
        s += (long long int)a[i]*(long long int)i;
    }
    cin >> q;
    rep(i,q){
        int b,c;
        cin >> b >> c;
        s += (long long int)a[b]*(long long int)(c-b);
        a[c] +=a[b];
        a[b] = 0;
        cout << s << endl;
    }

}

Measured memory_bytes: 7128
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

// Range Max Quely
int op(int a, int b) {
    return max(a, b);
}

int e() {
    return (int)(0);
}

int main(void)
{
    IOS
    constexpr int N = 300000;
    int n, k;
    cin >> n >> k;
    atcoder::segtree<int,op,e> seg(N+1);
    int ans = 0;
    REP(_,n) {
        int a; cin >> a;
        int p = seg.prod(max(0,a-k),min(N+1,a+k+1))+1;
        seg.set(a,p);
        ans = max(ans,p);
        //cerr << ans << endl;
    }
    cout << ans << '\n';

    return 0;
}

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

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define VPII vector<PII>
#define LD long double

string S,T;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    cin >> S >> T;
    int cnt=0,max_cnt=0;
    R(i,S.size()-T.size()+1){
        cnt=0;
        R(j,T.size()){
            if(S[i+j] == T[j]) cnt++;
        }
        max_cnt=max(cnt,max_cnt);
    }
    cout << to_string(T.size() - max_cnt) << endl;
}


Measured memory_bytes: 3692
n,x = tuple(map(int, input().split()))
h=[]
sum=0
min=1001
for i in range(0,n):
    h.append(int(input()))

for j in range(0,n):
    sum=sum+h[j]
    if min>h[j]:
        min=h[j]

nokori=x-sum

print(n+int(nokori/min))



Measured memory_bytes: 3060
# Here your code !
ans = 0
while ((n = gets)!=nil)
    n = n.chomp.to_i
    a = []
    next if(n == 0)
    n.times do |i|
        a[i] = (gets.to_i)
        ans += a[i]
    end
    ans -= (a.max + a.min)
    puts ans/(n - 2)
    ans = 0
end

Measured memory_bytes: 8624
#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()

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

  vector<pii>a(5);
  for(int i=0;i<5;i++)cin>>a[i].second;
  for(int i=0;i<5;i++)a[i].first=(a[i].second%10==0)?10:a[i].second%10;
  sort(rng(a));
  reverse(rng(a));
  int ans=0;
  for(int i=0;i<5;i++){
    while(ans%10)ans++;
    ans+=a[i].second;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.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 int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe



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


int a,b,c,ans;
cin >> a >> b >> c;
ans = c-a+b;

if (ans >= 0)
{
    cout << ans << endl;
}else
{
    cout << 0 << endl;
}







//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
use std::collections::HashMap;

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn read_stdin() -> String {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

fn count(s: &str) -> [u8; 26] {
    let mut a = [0; 26];
    for c in s.chars() {
        a[(c as u8 - 'a' as u8) as usize] += 1;
    }
    a
}

fn comb2(n: u64) -> u64 {
    n * (n - 1) / 2
}

fn main() {
    read_line();
    let mut h = HashMap::new();
    for s in read_stdin().lines() {
        let c = h.entry(count(s)).or_insert(0);
        *c += 1;
    }
    
    println!("{}", h.into_iter().map(|(_, n)| comb2(n)).sum::<u64>());
}

Measured memory_bytes: 18584
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int n;
		cin>>n;
		mii ma;
		ll int x[n+1],l[n+1];
		for(int i=1;i<=n;i++)
		{
			cin>>x[i]>>l[i];
			ma[x[i]-l[i]]=x[i]+l[i];
		}
		for(int i=1;i<=n;i++)
		{
			// cin>>x[i]>>l[i];
			ma[x[i]-l[i]]=min(ma[x[i]-l[i]],x[i]+l[i]);
		}
		vector<pii> v;
		for(auto it:ma) v.pb({it.F,it.S});
		vector<pii> sel;
		for(auto it:v)
		{
			if(sel.size()==0)
			{
				sel.pb(it);
			}
			else
			{
				if(sel.back().S<=it.F)
				{
					sel.pb(it);
				}
				else
				{
					if(sel.back().S>it.S)
					{
						sel.ppb();
						sel.pb(it);
					}
				}
			}
		}
		cout<<sel.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 12660