akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };
// struct edge{ll to; ll cost;};



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// struct UnionFind {
//     vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
//
//     UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
//         for(int i = 0; i < N; i++) par[i] = i;
//     }
//
//     int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
//         if (par[x] == x) return x;
//         return par[x] = root(par[x]);
//     }
//
//     void unite(int x, int y) { // xとyの木を併合
//         int rx = root(x); //xの根をrx
//         int ry = root(y); //yの根をry
//         if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
//         par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
//     }
//
//     bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };
//
// vint divisor(ll n){ // nの約数
//   vint ret;
//   for(ll i=1;i*i<=n;i++){
//     if(n%i == 0){
//       ret.pb(i);
//       if(i*i!=n) ret.pb(n/i);
//     }
//   }
//   vsort(ret);
//   return ret;
// }
//
// ll get_digits_num(ll n){
//   ll ret=0;
//   while(n){
//     n/=10;
//     ret++;
//   }
//   return ret;
// }

ll gcd(ll m, ll n){
  if(m<n) swap(m,n);
  if(n==0) return m;
  return gcd(n, m%n);
}

int main() {
  cout<<fixed<<setprecision(10);

  ll n,k;cin>>n>>k;
  vint h(n);rep(i,n)cin>>h[i];

  vsort(h);
  ll ans = LLONG_MAX;
  rep(i,n-k+1){
    ans = min(ans,h[i+k-1]-h[i]);
  }
  cout << ans << endl;



}

















//


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

ll dp[200010][3]={};

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<ll> v(n);rep(i,0,n)cin>>v[i];
  rep(i,0,200010)rep(j,0,3)dp[i][j]=-LINF;
  dp[0][0]=0;
  dp[1][1]=0;
  if(n%2)dp[2][2]=0;

  rep(i,0,n){
    chmax(dp[i+2][0],dp[i][0]+v[i]);
    chmax(dp[i+2][1],dp[i][1]+v[i]);
    chmax(dp[i+2][2],dp[i][2]+v[i]);


    chmax(dp[i+3][1],dp[i][0]+v[i]);
    chmax(dp[i+3][2],dp[i][1]+v[i]);
    chmax(dp[i+4][2],dp[i][0]+v[i]);
  }

  if(n%2==0)cout<<max(dp[n+1][1],dp[n][0])<<ENDL;
  else cout<<max({dp[n+1][2],dp[n][1],dp[n-1][0]})<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 9536
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  V v(n);
  REP(i, n) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int cnt = 1;
  REP(i, n-1) {
    if(v[i] < v[i+1]) cnt++;
  }
  dump(cnt);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    int ans = 1;
    while(n * 2 <= k) {
        ans++;
        n *= 2;
    }
    cout << ans << endl;
}

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



// last submission

typedef long long  int ll;
#define s(n) scanf("%lld",&n)
#define s2(n,m) scanf("%lld%lld",&n,&m)



int main()
{
    ll a,b,k;
    cin>>a>>b>>k;
    for(int i=0;i<k;i++)
    {
        if(i%2==0)
        {
            if(a&1) a--;

                a/=2;
                b+=a;

        }
        else
        {
            if(b&1) b--;

                b/=2;
                a+=b;

        }
    }

    cout<<a<<" "<<b<<endl;



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  bool ans = false;
  int value = a;
  for(int i = 0; i < b ; ++i){
    value += a;
    if(value % b == c){
      ans = true;
      break;
    }
  }
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
 
using namespace std;

void solve(){

	return;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n,m;
	cin >> n >> m;

	cout << (n%m==0 ? n/m : n/m + 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N;
  std::cin >> N;
  if(N%2==0){
    std::cout << N/2-1 << '\n';
  }else{
    std::cout << N/2 << '\n';
  }
  return 0;
}


Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def f(a,b,x):
        return a*x//b-a*(x//b)

    a,b,n=MI()
    x=min(b-1,n)
    print(f(a,b,x))

main()

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

int main() {
    int n;
    cin >> n;
    int s[n];

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

    int cnt = 0;
    for(i = 0; i < n; i++) {
        while(i+1 < n && s[i] == s[i+1]) {
            i++;
        }
        if (i+1 < n && s[i] < s[i+1]) {
            while(i+1 < n && s[i] <= s[i+1]) {
                i++;
            }
        }
        else if (i+1 < n && s[i] > s[i+1]) {
            while(i+1 < n && s[i] >= s[i+1]) {
                i++;
            }
        }
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 640
S = input()
N = len(S)

A = [0]*(N+1)
for i,s in enumerate(S,1):
    if s=="1":
        A[i] = A[i-1]+1
    else:
        A[i] = A[i-1]-1

m = max(A)
B = [A[-1]]*(N+1)
C = [m-A[-1]]*(N+1)
for i in range(N):
    i = N-i-1
    B[i] = max(A[i],B[i+1])
    C[i] = m-B[i]

d = 0
e = 0
D = A[:]
E = A[:]
for i,s in enumerate(S,1):
    if s=='?' and C[i] >= d+2:
        d += 2
    if s=='?' and C[i] >= e+1:
        e += 2
    D[i] += d
    E[i] += e
ans = min(max(D)-min(D),max(E)-min(E))
print(ans)

Measured memory_bytes: 110720
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <algorithm>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool neg=c=='-';
	neg?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return neg?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
template<class T>inline void mset(T a,int v,int n){memset(a,v,n*sizeof(a[0]));}
const int N=100010;
int intvl[N],intvr[N];
int lst1[N],lst2[N];
template<int sat[]>inline bool sat_cmp(int a,int b){
	return sat[a]<sat[b];
}
bool vis[N];
inline lint walk(int n,bool r){
	int x=0;
	lint ans=0;
	int i=n,j=1;
	mset(vis+1,0,n);
	for(int tt=n;tt--;r^=1){
		int p;
		if(r){
			for(;vis[lst1[i]];i--);
			p=lst1[i];
		}else{
			for(;vis[lst2[j]];j++);
			p=lst2[j];
		}
		vis[p]=true;
		if(x<intvl[p]){
			ans+=intvl[p]-x;
			x=intvl[p];
		}else if(x>intvr[p]){
			ans+=x-intvr[p];
			x=intvr[p];
		}
	}
	if(x>=0){
		ans+=x;
	}else{
		ans+=0-x;
	}
	return ans;
}
int main(){
	const int n=ni;
	for(int i=1;i<=n;i++){
		intvl[i]=ni,intvr[i]=ni;
		lst1[i]=lst2[i]=i;
	}
	sort(lst1+1,lst1+n+1,sat_cmp<intvl>);
	sort(lst2+1,lst2+n+1,sat_cmp<intvr>);
	printf("%lld\n",max(walk(n,0),walk(n,1)));
	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define ll long long
#define MAX_N 51
using namespace std;

//r,s,p

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k;
    cin>>n>>k;
    ll ss,pp,rr;
    cin>>ss>>pp>>rr;
    map<char,int>winp;
    winp['s'] = ss;
    winp['p'] = pp;
    winp['r'] = rr;
    string t;
    cin>>t;
    ll ans =0;
    vector<char> pre(n);
    for(int i = 0; i<n; i++){
        char tt = t[i];
        if(tt == pre[i%k]){
            pre[i%k] = 'e';
        }else{
            ans += winp[tt];
            pre[i%k] = tt;
        }
    }
    cout<< ans <<endl;
  	return 0;
}


Measured memory_bytes: 512
S = input()
T = input()

min_count = len(T)
for i in range(len(S) - len(T) + 1):
    count = 0
    for x in range(len(T)):
        if S[i+x] != T[x]:
            count += 1

    if count < min_count:
        min_count = count

print(min_count)


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

using namespace std;

#define SENTINEL 1000000001
int n;
int cnt;

void merge( vector<int>& S, int left, int mid, int right )
{
	int n1 = mid - left;
	int n2 = right - mid;

	vector<int> L;
	vector<int> R;
	for( vector<int>::size_type i=0; i<n1; i++ ) {
	    L.push_back( S.at( left+i ) );
	}
	for( vector<int>::size_type i=0; i<n2; i++ ) {
	    R.push_back( S.at( mid+i ) );
	}
	
	L.push_back( SENTINEL );
	R.push_back( SENTINEL );	
	vector<int>::size_type i, j;
	i = j = 0;
	for( vector<int>::size_type k=left; k<right; k++ ) {
	    cnt++;
	    if( L.at(i) <= R.at(j) ) {
	        S.at(k) = L.at( i++ );
	    } else {
	        S.at(k) = R.at( j++ );
	    }
	}
	
    return;
}
void mergeSort( vector<int>& S, int left, int right )
{
	if( left+1 < right ) {
		int mid = ( left+right )/2;
		mergeSort( S, left, mid );
		mergeSort( S, mid, right );
		merge( S, left, mid, right );
	}
	return;
}

int main()
{
	ios::sync_with_stdio( false );
	cin>>n;
	vector<int> S;
	int num;
	for( int i=0; i<n; i++ ) {
		cin>>num;
		S.push_back( num );
	}
	cnt = 0;
	mergeSort( S, 0, n );
	vector<int>::iterator itrE = S.end();
	for( vector<int>::iterator itr = S.begin(); itr!=itrE; itr++ ) {
		cout<<*itr;
		if( itr < itrE-1 ) { cout<<' '; }
	}
	cout<<'\n'<<cnt<<endl;	
    return 0;
}

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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;
const double PI = 3.14159;

using namespace std;

int main() {

    int a;
    cin >> a;

    AA(a + a*a + a*a*a);
}

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

#define debug(x) cout<<#x<<"="<<x<<endl
#define RD(x) freopen((x),"r",stdin)
#define WT(x) freopen((x),"w",stdout)
#define pii pair<int,int>
#define PQ priority_queue
#define ll long long
#define pb push_back
#define mp make_pair
const int INF=0x7fffffff;

int n,m;
map <int,int> M;

int main(){
	cin>>n;
	while (n--){
		cin>>m;
		M[m]++;
	}
	cin>>n;
	while (n--){
		cin>>m;
		if (!M[m]){
			cout<<"NO";
			return 0;
		}
		M[m]--;
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  string S;
  cin >> S;
  vector<char> c(0);
  rep(i,S.size()){
    bool check = true;
    for(auto C : c){
      if(S.at(i)==C) check = false;
    }
    if(check){
      // Unconfirmed
      c.push_back(S.at(i));
    }else{
      //Unconfirmed
      puts("no");
      return 0;
    }
  }
  puts("yes");
}

Measured memory_bytes: 256
while 1:
    n = int(input())
    if n == 0:
        break

    datas = []
    for _ in range(n):
        t = int(input())
        datas.append(t)

    datas.sort()
    waits = [0]
    for i, data in enumerate(datas):
        waits.append(waits[i] + data)
    waits.pop(-1)

    print(sum(waits))


Measured memory_bytes: 6108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    vector<pair<LL,LL>> l;
    REP(i,N){
        LL X,L; cin >> X >> L;
        l.eb(X+L,X-L);
    }
    sort(l.begin(),l.end());
    LL pre = -LINF;
    int ans = 0;
    REP(i,N){
        if(pre <= l[i].second){
            ans++;
            pre = l[i].first;
        }
    }
    cout << ans << endl;



}


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

int main(){
int i, j, n, k, l;

scanf("%d", &n);

i = n/100;
l = i*100+i*10+i;
k = (i+1)*100+(i+1)*10+(i+1);
if(l - n >= 0){
j = l;
}else{
j = k;
}

printf("%d\n", j);
  return 0;
}


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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  priority_queue <P> q;
  rep(i,n){
    cin>>a[i];
    q.push(P(a[i],1));
  }
  rep(i,m){
    int b,c;
    cin>>b>>c;
    q.push(P(c,b));
  }
  ll ans=0;
  rep(i,n){
    P temp=q.top();
    q.pop();
    ans+=temp.first;
    if (temp.second==1)continue;
    temp.second--;
    q.push(temp);
  }
  cout<<ans;
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000009;
const double pi = acos(-1);

int main() {
    int H,W; cin >> H >> W;
    int Ch, Dh,Cw,Dw;
    cin >> Ch >> Cw;
    cin >> Dh >> Dw;
    Ch--;Cw--; Dh--; Dw--;
    vector<string> S(H);
    REP(i,H) cin >> S[i];

    vecveci dist(H,veci(W,1e9));
    dist[Ch][Cw] = 0;

    priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>>> que;
    que.push({0,{Ch, Cw}});

    while(!que.empty()){
        // 先頭を取る
        auto p = que.top(); 
        que.pop();
        auto q = p.second;
        int i = q.first;
        int j = q.second;
        int d = p.first;
 
        // 方向の遷移
        for(int dy = -2; dy<=2; dy++){
            for(int dx = -2; dx <= 2; dx++) {
                if(dy == 0 && dx == 0) continue;
                int i2 = i + dy, j2 = j + dx;
                if(i2 < 0 || i2 >= H || j2 < 0 || j2 >= W) continue;
                if(S[i2][j2] == '#') continue;
                // この経路での始点から遷移先までの距離。
                bool wall = (abs(dy) == 2 || abs(dx) == 2 || (abs(dy)==1 && abs(dx)==1));
                int d2 = d + wall;

                //cout << i << " " << j << " " << i2 << " " << j2 << " " <<wall << " " << d2 << endl;
    
                // 暫定距離より短い経路が得られた場合は更新して、+1なら後ろに、+0なら前に付ける
                if(dist[i2][j2] > d2){
                    dist[i2][j2] = d2;
                    que.push({dist[i2][j2],{i2,j2}});
                }
            }
        }
    }
    /*
    REP(i,H) {
        REP(j,W) cout << dist[i][j] << " ";
        cout << endl;
    }
    */
    if(dist[Dh][Dw] == 1e9) cout << -1 << endl;
    else cout << dist[Dh][Dw]  << endl;
}

Measured memory_bytes: 9480
#include <iostream>
#include <cmath>
#include <utility>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
#define mp make_pair
#define x first
#define y second

int main () {
	int n;
	cin>>n;
	int br=0,tr=0;
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		if(a==b) br++;
		else br=0;
		if(br==3) tr=1;
	}
	if(tr) cout<<"Yes";
	else cout<<"No";


return 0;
}

Measured memory_bytes: 3632
// space 区切りの文字を入力として、Yが存在すれば、Four, else Threeを出力

#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  char s[n]; // 配列の初期化はs[n] n：要素数
  int ans = 0; // if ans == 0, Three
  for (int i=0;i < n ;i++){
    cin >> s[i];
    //cout << s[i];
    if ( s[i] == 'Y' ){
      ans = 1;
      break;
    }
  }
  if ( ans == 0){
    cout << "Three" << endl;
  }
  else{
    cout << "Four" << endl;
  }
}
        


Measured memory_bytes: 256
n,m = map(int,input().split())

k = 1
k_even = n//2+1
p_even = k_even+1

def rotate(s,diff):
    if s + diff < 1:
        return s+diff+n
    elif s + diff > n:
        return s+diff-n
    return s+diff

for i in range(m+1):
    if i != 0 and i % 2 == 0:
        print(rotate(k,-(i//2)),rotate(k,i//2))

    if i % 2 == 1:
        print(rotate(k_even,-(i//2)),rotate(p_even,i//2))




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

int main()
{
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  if (A.size() == N)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    map<int,int> mp;
    for(int i=0;i<n;i++){
        int a; cin >> a;
        map<int,int> q;
        q=mp;
        for(auto p:q){
            mp[p.first+a]++;
        }
        mp[a]++;
    }
    int q; cin >> q;
    for(int i=0;i<q;i++){
        int m; cin >> m;
        if(mp[m]){
            cout << "yes" << endl;
        }
        else{
            cout << "no" << endl;
        }
    } 
}


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

#define IL __inline__ __attribute__((always_inline))

#define For(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++ i)
#define Rep(i, a, b) for (int i = (a), i##end = (b); i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = (b); i >= i##end; -- i)

typedef long long LL;

template<class T>
IL bool chkmax(T &a, const T &b) {
  return a < b ? ((a = b), 1) : 0;
}

template<class T>
IL bool chkmin(T &a, const T &b) {
  return a > b ? ((a = b), 1) : 0;
}

template<class T>
IL T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}

template<class T>
IL T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}

template<class T>
IL T myabs(const T &a) {
  return a > 0 ? a : -a;
}

const int INF = 0X3F3F3F3F;
const double EPS = 1E-10, PI = acos(-1.0);

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
/*------------------------------header------------------------------*/

int main() {
  LL n, x;
  scanf("%lld%lld", &n, &x);
  LL answer = n, p = x, q = n - x;
  for (; ; ) {
    if (p < q) {
      std::swap(p, q);
    }
    if (!(p % q)) {
      answer += (p << 1) - q;
      break;
    }
    answer += ((p / q) << 1) * q;
    p %= q;
  }
  printf("%lld\n", answer);
  return 0;
}

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

int main(){
  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;
  if (M1 != M2) cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
N,K,S = map(int,input().split())

if N == K:
    A=[S]*N
    print(' '.join(map(str, A)))
    exit(0)
    
# K < N
if S == 1:
    A=[1]*K
    B=[2]*(N-K)
    print(' '.join(map(str, A)) + ' ' + ' '.join(map(str, B)))
    exit(0)
    
if S == 2:
    A=[1]*(K+1)
    B=[3]*(N-K-1)
    print(' '.join(map(str, A)) + ' ' + ' '.join(map(str, B)))
    exit(0)
    
if S == 3:
    if (K+1) % 2 == 0:
        A=[1,2]*((K+1)//2)
        B=[4]*(N-K-1)
        print(' '.join(map(str, A)) + ' ' + ' '.join(map(str, B)))
        exit(0)
    else:
        A=[1,2]*(K//2)
        A2=[1]
        B=[4]*(N-K-1)
        print(' '.join(map(str, A)) + ' ' + ' '.join(map(str, A2)) + ' ' + ' '.join(map(str, B)))
        exit(0)

# K < N かつ S >= 4
if S % 2 == 0:
    A=[S//2]*(K+1)
    B=[S//2+1]*(N-K-1)
    print(' '.join(map(str, A)) + ' ' + ' '.join(map(str, B)))
    exit(0)
else:
    if (K+1) % 2 == 0:
        A=[(S-1)//2,(S+1)//2]*((K+1)//2)
        B=[(S+1)//2]*(N-K-1)
        print(' '.join(map(str, A)) + ' ' + ' '.join(map(str, B)))
        exit(0)
    else:
        A=[(S-1)//2,(S+1)//2]*(K//2)
        A2=[(S-1)//2]
        B=[(S+3)//2]*(N-K-1)
        print(' '.join(map(str, A)) + ' ' + ' '.join(map(str, A2)) + ' ' + ' '.join(map(str, B)))
        exit(0)

Measured memory_bytes: 73068
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

template<int mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x(x%mod) {}
    mint(std::string s) {
        long long z = 0;
        REP(i, s.size()) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& n) {
        return os << n.x;
    }
    bool operator==(const mint a) const {
        return this->x == a.x;
    }
};

int main() {
    int n; cin >> n;
    map<int, int> mp;
    mint<MOD> ans = 1;
    mp[-1] = 3;
    REP(i, n) {
        int a; cin >> a;
        if (mp.find(a - 1) == mp.end() || mp[a - 1] <= 0) {
            puts("0");
            return 0;
        }
        ans *= mp[a - 1]--;
        mp[a]++;
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF (INT_MAX/3)

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

using namespace std;

int main(void)
{
    int N; cin >> N;
    string str, str2; cin >> str;
    str2 = str;

    auto pos = string::npos;
    while( (pos = str.find( "()" )) != string::npos )
    {
        str.erase( pos, 2 );
    }

    int start = 0, end = 0;
    for( auto c : str )
    {
        if( c == ')' )
            start++;
        if( c == '(' )
            end++;
    }

    REP(i, start) putchar('(');
    cout << str2;
    REP(i, end) putchar(')');

    return 0;

}


Measured memory_bytes: 256
fn main() {
    let s = read::<String>();
    let mut idx = s.len();

    while idx >= 5 {
        if idx >= 5 && s[(idx-5)..idx] == "dream".to_string() {
            idx -= 5;
        } else if idx >= 7 && s[(idx-7)..idx] == "dreamer".to_string() {
            idx -= 7;
        } else if idx >= 5 && s[(idx-5)..idx] == "erase".to_string() {
            idx -= 5;
        } else if idx >= 6 && s[(idx-6)..idx] == "eraser".to_string() {
            idx -= 6;
        } else {
            println!("NO");
            return
        }
    }

    if idx == 0 {
        println!("YES");
    } else {
        println!("NO");   
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

bool is_kaibun(string S) {
    int N = S.size();
    rep(i, N) {
        if (S[i] != S[N - 1 - i]) {
            return false;
        }
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;

    int N = S.size();
    if (is_kaibun(S) == false) {
        cout << "No" << endl;
        return 0;
    }
    if(is_kaibun(S.substr(0, (N - 1)/2)) == false) {
        cout << "No" << endl;
        return 0;
    }
    if (is_kaibun(S.substr((N + 3)/2 - 1)) == false) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

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

int main() {
	int n,count;
	count = 0;
	cin >> n;
	vi arr(n);
	repz(i, n)cin >> arr[i];
	vi arr_sorted = arr;
	sort(arr_sorted.begin(), arr_sorted.end());
	repz(i, arr.size()) {
		if (arr[i] != arr_sorted[i])count++;
	}
	if (count == 2 || count == 0)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1)
                ans = mul(ans, x);
        return ans;
    }
}; // namespace modular
using namespace modular;

namespace Base {
    template <typename Tp> inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-')
                y = -1;
            c = getchar();
        }
        if (c == EOF)
            return 0;
        while ('0' <= c && c <= '9')
            x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); }
    template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; }
    template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; }
}; // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 607

int N, N2, M;
int a[MAX_N];
int f[MAX_N][MAX_N / 2][MAX_N / 2];
int flg[MAX_N], col[MAX_N];

void solve() {
    int cnt = 0;
    for (int i = 1; i <= N2; i += 2) {
        if (a[i] != -1 && a[i + 1] != -1) flg[a[i]] = flg[a[i + 1]] = -1;
        else if (a[i] != -1) flg[a[i]] = 1;
        else if (a[i + 1] != -1) flg[a[i + 1]] = 1;
        else cnt++;
    }
    Rep(i, N2)
        if (flg[i] == 1) col[++M] = 1;
        else if (!flg[i]) ++M;
    f[M][0][0] = 1;
    int ed = std::min(N, M);
    IRep(i, M) {
        rep(j, 0, ed) {
            rep(k, 0, ed) if(f[i][j][k]) {
                if (col[i]) {
                    inc(f[i - 1][j + 1][k], f[i][j][k]);
                    if (k) inc(f[i - 1][j][k - 1], f[i][j][k]);
                } else {
                    inc(f[i - 1][j][k + 1], f[i][j][k]);
                    if (j) inc(f[i - 1][j - 1][k], mul(f[i][j][k], j));
                    if (k) inc(f[i - 1][j][k - 1], f[i][j][k]);
                }
            }
        }
    }
    int res = f[0][0][0];
    Rep(i, cnt) res = mul(res, i);
    printf("%d\n", res);
}

int main() {
    read(N);
    N2 = N * 2;
    Rep(i, N2)
        read(a[i]);
    solve();
    return 0;
}


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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if((A + B) > (C + D))
    cout << "Left\n";
  else if((A + B) < (C + D))
    cout << "Right\n";
  else
    cout << "Balanced\n";
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define pi 3.1415926535897932384

long long n;

double cedge(long long x){
  if(2*x==n){return 2.0;}
  if(2*x>n){x=n-x;}
  double w,alpha,theta=(2.0*pi*(double)x)/((double)n);
  alpha=(pi-theta)/2;
  w=1.0-cos(theta);
  return (w/cos(alpha));
}

double calc(long long a,long long b,long long c){
  return (cedge(a)*cedge(b)*cedge(c))/4.0;
}

int main(){
  long long k,i,j,nst,nfi,nte,ncnt;
  double st=0.0,fi=3.0,te;
  scanf("%lld%lld",&n,&k);
  for(i=0;i<32;i++){
    te=(st+fi)/2.0;
    ncnt=0;
    for(j=1;j*3<n;j++){
      nst=j+1;
      if((n-j)%2==0){nfi=((n-j)/2)-1;}
      else{nfi=(n-j)/2;}
      while(nst<=nfi){
        nte=(nst+nfi)/2;
        if(calc(j,nte,n-j-nte)<=te){
          nst=nte+1;
        }
        else{
          nfi=nte-1;
        }
      }
      ncnt+=2*n*(nst-j-1);
      if(calc(j,j,n-2*j)<=te){
        ncnt+=n;
      }
      if((n-j)%2==0){
        if(calc(j,(n-j)/2,(n-j)/2)<=te){
          ncnt+=n;
        }
      }
    }
    if(n%3==0){
      if(calc(n/3,n/3,n/3)<=te){
        ncnt+=n/3;
      }
    }
    if(ncnt<k){st=te;}else{fi=te;}
  }
  printf("%.12lf\n",(st+fi)/2.0);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,i,n;
	scanf("%d", &n);
	a=n/100;
		if(n>=a*100 && n<=105*a)
		{
			printf("1\n");
			return 0;
		}
	printf("0\n");
	return 0;
}

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

#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
#define nrep(i,a,b) for(int i=int(a);i>=int(b);--i)
#define trv(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define watch(x) cout<<"\n"<<#x<<" is "<<x<<"\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ZERO(box) memset(box, 0, sizeof(box));
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define chkbit(s, b) (s & (1<<b))
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1e9+7;


void solve(){
	string s;
	cin>>s;
	vi a(26,0);
	for(char c:s){
		a[c-'a']++;
	}
	rep(i,0,25){
		if(a[i]%2) {
		cout<<"No\n";
		return;
		}
	}
	cout<<"Yes\n";
	return;
}


int main(){
	int t=1;
	//cin>>t;
	while(t--){
		solve();	
	}	
	return 0;
}
/*input
10
*/

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


int main()
{
	int n; cin >> n;
	string s; cin >> s;
	int c = 0;
	for (int i = 0; i < n; ++i)
		if (s[i] == 'A')
			if (i + 1 < n && s[i+1] == 'B')
				if (i + 2 < n && s[i+2] == 'C')
					c++, i+=2;
	cout << c << endl;
}



Measured memory_bytes: 3552
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<string.h>
using namespace std;
int main(){
long long n,m,z,a;
cin>>n>>m;
z=n*(n-1)/2;
a=m*(m-1)/2;
cout<<(a+z);




}


Measured memory_bytes: 3468
#include <cstdio>
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

char x[5][30];
bool conflict[30];
int dp[2][1<<20];

int main(){
  int n;
  while(scanf("%d", &n), n){
    REP(i,5) scanf("%s", x[i]);
    while(true){
      bool flag = false;
      REP(i,5) if(x[i][n - 1] == 'X')
	flag = true;

      if(!flag) n--;
      if(flag) break;
    }

    REP(i,n){
      conflict[i] = false;
      REP(j,5) REP(k,n) if(i + k < n){
	if(x[j][k] == 'X' && x[j][i + k] == 'X')
	  conflict[i] = true;
      }
    }
    conflict[0] = true;

    REP(i,1<<n) dp[0][i] = 0;
    dp[0][1] = 1;
    int *now  = dp[0];
    int *next = dp[1];
    
    REP(t, 20 * 10 * 10){
      REP(i,1<<n) next[i] = 0;
      REP(i,1<<n) if(now[i] > 0){
	// printf("t=%d i=%d : %d\n", t, i, now[i]);
	if(now[i] == 10){
	  printf("%d\n", t + n);
	  goto next;
	}
	bool ok = true;
	REP(j,n - 1) if(i & (1 << j)){
	  if(conflict[j + 1]){
	    ok = false;
	  }
	}
	
	if(ok){
	  next[((i << 1) | 1) & ((1 << n) - 1)] = now[i] + 1;
	}
	next[(i << 1) & ((1 << n) - 1)] = now[i];
      }
      swap(now, next);
    }
  next:;
  }
  return 0;
}

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

#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define int long long
const int N = 3e6 + 10;

signed main(){

	int p,q,r;
	cin>>p>>q>>r;
	int ans = min(p+q , min(q+r , r+p));

	cout<<ans<<endl;
}

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

//モジュラー逆数
long long modinv(long long n, long long p) {
  long long a = p, u = 1, v = 0;
  while (a) {
    long long t = n / a;
    n -= t * a;
    swap(n, a);
    u -= t * v;
    swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

int main() {
  long long n, k, p = 1000000007;
  cin >> n >> k;
  long long ans = 1;
  for (long long i = 1; i <= k; i++) {
    for (long long j = 0; j < i - 1; j++) {
      ans *= k - 1 - j;
      ans %= p;
    }
    if (i >= 3) {
      for (long long j = 2; j <= i - 1; j++) {
        ans *= modinv(j, p);
        ans %= p;
      }
    }
    for (long long j = 0; j < i; j++) {
      ans *= n - k + 1 - j;
      ans %= p;
    }
    if (i >= 2) {
      for (long long j = 2; j <= i; j++) {
        ans *= modinv(j, p);
        ans %= p;
      }
    }
    cout << ans << endl;
    ans = 1;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 2e5+5, M = 1e6+6, OO = 0x3f3f3f3f;
int tc;
ll n, k;
ll p[5005], c[5005]; bool vis[5005];
int main()
{
    FIO
    cin>>n>>k;
    for(int i = 1 ; i<= n ; i++)
        cin>>p[i];
    for(int i = 1 ; i<= n ; i++)
        cin>>c[i];
    ll ans = -1e17;
    for(int i = 1 ; i<= n; i ++)
    {
        memset(vis, 0, sizeof vis);
        ll tmpc = 0, tmpans = -1e18, cyclelength = 0;
        ll nxt = p[i];
        while(!vis[i] && cyclelength<k)
        {
            // cout<<nxt<<endl;
            vis[nxt] = 1;
            tmpc+= c[nxt];
            cyclelength++;
            tmpans = max(tmpans, tmpc);
            nxt = p[nxt];
        }
        // cout<<i<<" "<<cyclelength<<" "<<tmpc<<" "<<tmpans<<endl;
        if(cyclelength < k && tmpc > 0)
        {
            // ans*= k / cyclelength;
            tmpans += tmpc * ((k / cyclelength) - 1);
            tmpc *= (k / cyclelength);
            // cout<<tmpans<<endl;
            tmpans = max(tmpans, tmpc);
            nxt = p[i];
            ll rem = k%cyclelength;
            while(rem--)
            {
                tmpc+= c[nxt];
                nxt = p[nxt];
                tmpans = max(tmpans, tmpc);
            }
        }
        ans = max(ans, tmpans);
    }
    cout<<ans<<endl;
    return 0;
}


/*


3 18
2 3 1
8 -10 3

3 18
2 3 1
2 3 -1

3 18
2 3 1
-2 3 -5


*/

Measured memory_bytes: 3740
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val str = sc.next()
    val chars = str.toCharArray()
    val int = ArrayList<Int>()
    for(i in 0..3) {
        int.add(Character.getNumericValue(chars[i]))
    }
    val fugo = listOf(listOf(1,1,1,1),listOf(1,1,1,-1),listOf(1,1,-1,1),listOf(1,-1,1,1),listOf(1,1,-1,-1), listOf(1,-1,1,-1),listOf(1,-1,-1,1),listOf(1,-1,-1,-1))
    for (e in fugo) {
        if(fugou(int, e)) {
            print(int[0])
            for(i in 1..3) {
                print(hugo(e[i]))
                print(int[i])
            }
            println("=7")
            return
        }

    }
}
fun fugou(num: List<Int>, fugo: List<Int>):Boolean {
    var sum = 0
    for(i in 0..3) {
        sum = if(fugo[i] == 1) sum + num[i] else sum - num[i]
    }
    return sum == 7
}
fun hugo(a: Int) = if(a==1) "+" else "-"

Measured memory_bytes: 35920
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s; cin >> s;
    int k; cin >> k;
    char ans = '1';

    for (int i = 0; i < k; ++i) {
        if (s[i] != '1') {
            ans = s[i];
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000000000009
#define int long long
using P = pair<int,int>;

vector<P> prime_factorize(int n){
  vector<P> res;
  for(int p = 2;p*p <= n;p++){
    if(n % p != 0) continue;
    int num = 0;
    while(n % p == 0){
      num++;
      n /= p;
    }
    res.push_back(make_pair(p,num));
  }
  if(n != 1) res.push_back(make_pair(n,1));
  return res;
}

signed main(){
  int n,p;
  cin >> n >> p;
  auto res = prime_factorize(p);
  int ans = 1;
  for(auto p:res){
    for(int j = 0;j < p.second/n;j++){
      ans *= p.first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main ()
{
    int arr[100],i,temp,j;
    for (i=0; i<10; i++)
    {
        scanf("%d",&arr[i]);
    }
    for (i=0; i<9; i++)
    {
        for (j=i+1; j<10; j++)
        {
            if (arr[i]<arr[j])
            {
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
    }
    for (i=0; i<3; i++)
    {
        printf ("%d\n", arr[i]);
    }
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> h;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		h.push_back(tmp);
	}
	int cntmax = 0;
	int cnt = 0;

	for (int i = 0; i < n - 1; i++) {
		if (h[i] >= h[i + 1]) {
			cnt++;
		}
		else
		{
			if (cnt > cntmax) {
				cntmax = cnt;
			}
			cnt = 0;
		}
	}
	if (cnt > cntmax) {
		cntmax = cnt;
	}
	cout << cntmax << endl;
	return 0;
}

Measured memory_bytes: 892
N = int(input())
A = [0] * N
for _ in range(N):
    A[_] = int(input())
    if _ == 1:
        b1 = max(A[0], A[1])
        b2 = min(A[0], A[1])
    elif _ != 0 and A[_] >= b1:
        b2 = b1 
        b1 = A[_]
    elif _ != 0 and A[_] > b2:
        b2 = A[_]

for _ in range(N):
    if A[_] == b1:
        print(b2)
    else:
        print(b1)

    


Measured memory_bytes: 12508
#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;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
const ll INF = 1LL << 60;
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}

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 n,m,q;
    cin >> n >> m >> q;
    ll ex[n+1][n+1];
    memset(ex,0,sizeof(ex));
    for (ll i=0;i<m;i++){
        ll l,r;
        cin >> l >> r;
        for (ll j=r;j<=n;j++){
            ex[l][j]++;
        }
    }
    for (ll i=n;i>=1;i--){
        for (ll j=0;j<=n;j++){
            ex[i-1][j]+=ex[i][j];
        }
    }
    for (ll i=0;i<q;i++){
        ll l,r;
        cin >> l >> r;
        cout << ex[l][r] << endl;
    }
    return 0;
}



Measured memory_bytes: 5524